cam frustum calcul...
Blitz3D Forums/Blitz3D Programming/cam frustum calcul...
| ||
Hey, Ok, I have a tricky one, I am trying to calcul the visual WORLD coordinates view by a camera. Considering the camera isn’t static, camera positions and rotations need to be used in the equation. |
| ||
Can't you use CameraProject for this? |
| ||
I am not sure how I could use this to solve my problem? Basically, what I am trying to do is to use that as an optimization system. In my game, you can get up to 600 projectiles + the vehicles + ect... I want to use the screen limits like that because, in some cases, the objects will leave the screens but may come back! So, with the screen limits I could compute a % off-screen that will not delete the objects... That’s why I can't use a ''if entityinview=0 then delete.. “ I also want to avoid off-screen timers, I don't think it could works, imagine 300 objects off-screen that need a timer refresh... huummmm na ^^ |
| ||
Blitz will automatically cull entities which are outwith the view frustum and probably do it a good bit faster than you'd achieve using your own solution. You can use cameraproject to get the entities position relative to the viewport but projectedx, y will return 0,0 if outwith. Stevie |
| ||
Why not employ a range system? Do an entitydistance on every object? Determine the range, and delete or hide or leave unchanged as appropriate. EntityDistance calculations are lightning quick, so a couple of 1000 a loop isn't going to touch frame rate. |
| ||
@Stevie Yeah it woudn't work using 2d @Ross Well I am looking to detect positions within a square, entitydistance would return values within a circle (sphere) Ok I am adding a picture to explain better what I need. Thanks ^^ |
| ||
But you could use CameraProject, right ? Like Ross suggested. CameraProject EntityX(mesh), EntityY(mesh), EntityZ(mesh) -> returns ProjectedX() and ProjectedY() variables, that represent the coordinates on screen. |
| ||
Exact but what if the entity is off screen ? it will not return what I am looking for. But ok, I think I am on the good way now, here what I've got: Graphics3D 640,480 SetBuffer BackBuffer() CamDistance# = 10 CamFocus# = 1 camera=CreateCamera() light=CreateLight() control=CreateSphere( 32 ) ScaleEntity control,0.1,0.1,0.1 TL=CreateSphere( 32 ) TR=CreateSphere( 32 ) BL=CreateSphere( 32 ) BR=CreateSphere( 32 ) While Not KeyDown( 1 ) x#=0 : y#=0 : z#=0 If KeyDown( 203 )=True Then x#=-0.1 If KeyDown( 205 )=True Then x#=0.1 If KeyDown( 208 )=True Then y#=-0.1 If KeyDown( 200 )=True Then y#=0.1 If KeyDown( 44 )=True Then z#=-0.1 If KeyDown( 30 )=True Then z#=0.1 If KeyDown( 56 )=True Then : x#=x#/2 : y#=y#/2 : z#=z#/2 : End If MoveEntity control,x#,y#,z# If KeyDown( 74 )=True Then CamDistance# = CamDistance# + 1 If KeyDown( 78 )=True Then CamDistance# = CamDistance# - 1 If KeyDown( 26 )=True Then CamFocus# = CamFocus# + .01 If KeyDown( 27 )=True Then CamFocus# = CamFocus# - .01 CameraZoom camera,CamFocus# PositionEntity camera,0,0,-CamDistance# LimitW# = CamDistance# / CamFocus# LimitH# = LimitW# / 1.33 PositionEntity TL,-LimitW#,LimitH#,0 PositionEntity TR,LimitW#,LimitH#,0 PositionEntity BL,-LimitW#,-LimitH#,0 PositionEntity BR,LimitW#,-LimitH#,0 RenderWorld Text 0,20,"controlX: "+EntityX#(control,1) Text 0,40,"controlY: "+EntityY#(control,1) Text 0,60,"controlZ: "+EntityZ#(control,1) Flip Wend End |
| ||
My maths is not great :/, but maybe you can use TFormPoint ?TFormPoint EntityX#(control,1), EntityY#(control,1), EntityZ#(control,1), control, camera Text 0,20,"controlX: "+TFormedX#() Text 0,40,"controlY: "+TFormedY#() Text 0,60,"controlZ: "+TFormedZ#() |
| ||
oooh cool, this is great, but I am affraid this would kill the FPS considering I would have to apply this to 300 / 600 entities? |
| ||
The Tform commands are pretty fast in my experience. The only info your getting here is the entities local x, y, z position i relation to the camera .. you're still going to have to use some projection onto a 2d plane to get the x,y screen coords. |