Author Topic: World.checkCameraCollisionSpherical()  (Read 8216 times)

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #15 on: June 29, 2007, 08:06:45 am »
Ya that's exactly what I did, any problem with the code below ???

Code: [Select]
            SimpleVector camPos = new SimpleVector(getSpecialObject().getTransformedCenter());
            SimpleVector zOffset = getSpecialObject().getZAxis();
            SimpleVector yOffset = new SimpleVector(0, -dy, 0);
            zOffset.scalarMul(-dz);
           
            camPos.add(zOffset);
            camPos.add(yOffset);
           
            cam.setPosition(camPos);
           
            if (left) {
                world.checkCameraCollisionEllipsoid(Camera.CAMERA_MOVELEFT,
                        Util.CAM_ELLIPSOID_DIMENSION, 4, 1);
            }
            if (right) {
                world.checkCameraCollisionEllipsoid(Camera.CAMERA_MOVERIGHT,
                        Util.CAM_ELLIPSOID_DIMENSION, 4, 1);
            }
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: World.checkCameraCollisionSpherical()
« Reply #16 on: June 29, 2007, 08:34:17 am »
You'll never get sliding with a recursion depth of 1....

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #17 on: June 29, 2007, 08:57:34 am »
Alright people, I still couldn't solve the problem. As I will be busy these days, i have to put it aside for a while. But i do come up with a workaround to cover up the problem (somehow, with my fuzzy head 8)). Actually sliding occurs even if the recursion is 1, but the strength is very weak (i.e. after a few units of sliding, the cam will bump out of walls). But I cannot make it too high because my camera will keep shaking when the cam gets nearer to the char. I might be wrong because my code actually comes from the car example, whereby some camera smoothing is applied. Alas, i think the problem only comes when the camera slided to a point where it gets too near to the character, so I added a threshold of my own ==> if the actual distance between cam and char after collision is less than the threshold, the camera will stop moving, so i can prevent my camera from both jumping out of my wall, and from shaking when getting too near. It works without problems, but the outcome and the effect is quite different from that in karga LOL. I will accept my way as a workaround atm, until I have more time.

But to be honest - If you have never tried the collision system in jME, you will never realize how easy you can implement collision in jPCT. Hence appreciate whatever you do in jPCT.
« Last Edit: June 29, 2007, 09:09:19 am by hytparadisee »
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: World.checkCameraCollisionSpherical()
« Reply #18 on: June 29, 2007, 10:52:10 am »
With a recrusion depth of 1, it will stop on the first collision in one run. The idea behind ellipsoid collision detection in jPCT is to find the first collision on the way, correct the translation vector to avoid it and move on into the new direction as long as no other collisions occur or the recursion depth has been reached. 1 will make the camera stop after the first collision. It may still slide if applied multiple times, but it won't look very smooth. Of course, collision detection can go wrong due to rounding errors, but usually, it should be possible to tweak recursion depth, Config.collideOffset and Config.collideEllipsoidThreshold to get satisfying results.

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: World.checkCameraCollisionSpherical()
« Reply #19 on: June 29, 2007, 01:19:44 pm »
i've looked at karga code: i also use a recurse depth of 1, hence not allowing  the camera to slide. the main difference is, i dont use world.checkCameraCollisionEllipsoid(..) but world.checkCollisionEllipsoid(..) to calculate the farthest distance the camera can go, than interpolate between camera's current position and the calculated position. something like:

Code: [Select]
avatar.setVisible(false);
SimpleVector takeBackPoint = headOfAvatar();
SimpleVector moveableDistance = world.checkCollisionEllipsoid(takeBackPoint, takeBackDirection, cameraEllipsoid, 1);
avatar.setVisible(true);

SimpleVector desiredCameraPosition = new SimpleVector(takeBackPoint);
desiredCameraPosition.add(moveableDistance);
SimpleVector cameraPosition = interpolate(camera.getPosition(), desiredCameraPosition, smoothness); // 0.1is a good smoothness value
camera.setPosition(cameraPosition);
camera.lookAt(takeBackPoint);

this should feel like karga, you may add extra smoothness by interpolating camera lookAt position too

r a f t

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #20 on: June 29, 2007, 01:33:38 pm »
ROFL raft, no wonder it took you soooo long to post - you are searching your source!

avatar.setVisible(false);
...
avatar.setVisible(true);

r a f t
That's tricky ;)
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution