CameraRange camera,near#,far#
Parameters
|
camera - camera handle near# - distance in front of the camera at which 3D objects start being drawn; 1 (default) far# - distance in front of the camera beyond which 3D objects stop being drawn; 1000 (default) |
Description
|
Sets a camera's near and far clipping range. Only geometry between the two distances is rendered. Anything closer than near is clipped (this stops the inside of the player's own head being drawn), and anything beyond far vanishes - so the far value is your draw-distance control, and a smaller far range means less to draw and faster rendering. Try to keep the ratio of far/near as small as possible for optimal depth-buffer precision. In practice, raise near as much as you can get away with (1 is far kinder than 0.01) - a huge far/near ratio concentrates depth precision close to the camera and causes distant polygons to 'z-fight', flickering through each other. Objects reaching the far range pop out of view abruptly; hide the transition with fog (CameraFogMode, fading out just inside the far range) or per-entity EntityAutoFade. See also: CameraZoom, CameraFogRange, EntityAutoFade, WBuffer. |
Example
; CameraRange Example ; ------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,0 light=CreateLight() RotateEntity light,45,45,0 ; Textured ground plane gives a sense of distance plane=CreatePlane() ground_tex=LoadTexture("media/MossyGround.BMP") ScaleTexture ground_tex,4,4 EntityTexture plane,ground_tex ; An avenue of pillars marching into the distance shows where the far plane clips For z=10 To 150 Step 10 pillar=CreateCylinder() ScaleEntity pillar,0.5,3,0.5 PositionEntity pillar,-4,3,z pillar=CreateCylinder() ScaleEntity pillar,0.5,3,0.5 PositionEntity pillar,4,3,z Next far_range#=50 While Not KeyDown(1) ; Press [ / ] to pull the far clipping plane closer or push it away If KeyDown(26) And far_range>5 Then far_range=far_range-0.5 If KeyDown(27) And far_range<300 Then far_range=far_range+0.5 ; Apply the near and far clipping range to the camera CameraRange camera,1,far_range ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrow keys: move camera [ / ]: change far range Esc: exit" Text 0,20,"Distant pillars vanish once they pass the far clipping plane" Text 0,40,"CameraRange camera,1,"+far_range Flip Wend End
Index