jPCT - a 3d engine for Java > Support

Detecting camera collisions

(1/1)

jika:
Hi,

All my congratulations for your outstanding work.

I'm looking for some code samples explaining the use of the checkCameraCollision() method.

Can you help me?

EgonOlsen:
Well, have a look at the Bounce-example and replace


--- Code: ---
if (zoomin) {theWorld.getCamera().moveCamera(Camera.CAMERA_MOVEIN, zoomSpeed);}
if (zoomout) {theWorld.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, zoomSpeed);}
if (shiftleft) {theWorld.getCamera().moveCamera(Camera.CAMERA_MOVELEFT, zoomSpeed);}
if (shiftright) {theWorld.getCamera().moveCamera(Camera.CAMERA_MOVERIGHT, zoomSpeed);}
if (shiftdown) {theWorld.getCamera().moveCamera(Camera.CAMERA_MOVEDOWN, zoomSpeed);}
if (shiftup) {theWorld.getCamera().moveCamera(Camera.CAMERA_MOVEUP, zoomSpeed);}

--- End code ---


with this:


--- Code: ---
if (zoomin) {theWorld.checkCameraCollision(Camera.CAMERA_MOVEIN, zoomSpeed, Camera.DONT_SLIDE);}
if (zoomout) {theWorld.checkCameraCollision(Camera.CAMERA_MOVEOUT, zoomSpeed, Camera.DONT_SLIDE);}
if (shiftleft) {theWorld.checkCameraCollision(Camera.CAMERA_MOVELEFT, zoomSpeed, Camera.DONT_SLIDE);}
if (shiftright) {theWorld.checkCameraCollision(Camera.CAMERA_MOVERIGHT, zoomSpeed, Camera.DONT_SLIDE);}
if (shiftdown) {theWorld.checkCameraCollision(Camera.CAMERA_MOVEDOWN, zoomSpeed, Camera.DONT_SLIDE);}
if (shiftup) {theWorld.checkCameraCollision(Camera.CAMERA_MOVEUP, zoomSpeed, Camera.DONT_SLIDE);}

--- End code ---


and remove the


--- Code: ---
cube.rotateZ(0.005f);

--- End code ---


some lines above (to prevent the cube from spinning). This should show the basic usage of the camera collision (you can navigate using the num-pad in this example btw). The Camera.SLIDE option doesn't really work as it should...i'll have to fix this in a later version, but anyway...

I hope this helps. If it doesn't, feel free to ask again. Keep in mind that jPCT uses a ray/triangle-collision scheme for camera-collisions.
Depending on the scale of your world, you may have to adjust Config.collideOffset accordingly, but for Bounce, it should work fine the way it is.

Navigation

[0] Message Index

Go to full version