Hi everyone,
assuming you have 100 Objects in a complex scene with many view blocking obstacles: the code below will help hiding the 100 Objects whenever they are not visible ! The idea is to use 'AI Get Entity Can See ( Entity Number, X#, Z#, Height )' to improve graphic performance
Rem Project: Dark Basic Pro Project
Rem Created: Tuesday, May 18, 2010
Rem ***** Main Source File *****
REM INITIALIZE:
SYNC ON
SYNC RATE 60
AUTOCAM OFF
AI START
REM CREATE 50 VIEW BLOCKING OBSTACLES:
FOR Z = 1001 TO 1050
IF OBJECT EXIST(Z)=0
MAKE OBJECT CUBE Z,8
POSITION OBJECT Z,RND(200),0,RND(200)
AI Add Static Obstacle Z
ENDIF
NEXT Z
REM CREATE 100 RED OBJECTS IN ORDER TO HIDE THEM WHENEVER THEY AREN'T IN THE CAMERA LINE OF SIGHT
FOR Z = 11 TO 110
IF OBJECT EXIST(Z)=0
MAKE OBJECT CUBE Z,5
POSITION OBJECT Z,RND(200),0,RND(200)
COLOR OBJECT Z,RGB(255,0,0)
ENDIF
NEXT Z
REM ADD THE PLAYER:
MAKE OBJECT SPHERE 1,4 : HIDE OBJECT 1
AI ADD FRIENDLY 1,1 : AI Set Entity Control 1, 0
AI Set Entity View Range 1, 30000 : AI SET ENTITY VIEW ARC 1,100.0,100.0
DO
REM CONTROL CAMERA
CONTROL CAMERA USING ARROWKEYS 0,1,1
AI Set Entity Position 1, CAMERA POSITION X(), CAMERA POSITION Z()
AI Set Entity Angle Y 1, CAMERA ANGLE Y ()
FOR Z = 11 TO 110
IF OBJECT Exist ( Z ) = 1
REM HERE IS IMPORTANT FUNCTION: IF ENTITY CAN SEE A POINT
IF AI Get Entity Can See (1,OBJECT POSITION X(Z),OBJECT POSITION Z(Z),1)=0
EXCLUDE OBJECT ON Z
ELSE
EXCLUDE OBJECT OFF Z
ENDIF
ENDIF
NEXT Z
AI UPDATE
SYNC
LOOP
But this method has a big drawback: since the center of the objects are used to compute if they are visible, the method produce clipping when the object is partly behind an obstacle...
please, help me improve this technique by using the ends of the objects to compute their visibility instead of the center, how can I do ?