Author Topic: Detecting camera collisions  (Read 5789 times)

jika

  • Guest
Detecting camera collisions
« on: January 27, 2003, 08:12:05 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Detecting camera collisions
« Reply #1 on: January 27, 2003, 09:23:57 pm »
Well, have a look at the Bounce-example and replace

Code: [Select]

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);}


with this:

Code: [Select]

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);}


and remove the

Code: [Select]

cube.rotateZ(0.005f);


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.