World.checkCameraCollisionSpherical()

Started by hytparadisee, June 26, 2007, 02:50:14 PM

Previous topic - Next topic

hytparadisee

Ya that's exactly what I did, any problem with the code below ???


            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

EgonOlsen

You'll never get sliding with a recursion depth of 1....

hytparadisee

#17
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.
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

EgonOlsen

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.

raft

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:

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

hytparadisee

ROFL raft, no wonder it took you soooo long to post - you are searching your source!

Quote from: raft on June 29, 2007, 01:19:44 PM
avatar.setVisible(false);
...
avatar.setVisible(true);

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