jPCT - a 3d engine for Java > Support

Orbiting camera

(1/2) > >>

JonnyDee:
Hi,

I am currently trying to figure out how to rotate the camera around an object.  The effect i'm looking for is for the player object to always be maintained in the center of the view, whilst the camera orbits around the player and the player rotates so the camera is always looking at the same side of the player.  I have tried to use a dummy object which rotates around the player to give the coords to move the camera to, like this:

playerRotation = (float)(xDif * rotationMultiplier);

// Rotate the player and cameraHolder
cameraHolder.setRotationPivot(new SimpleVector(sphereX, sphereY, sphereZ));
sphere.rotateY((float)Math.toRadians(playerRotation));
cameraHolder.rotateY((float)Math.toRadians(playerRotation));

cameraX = cameraHolder.getCenter().x;
cameraY = cameraHolder.getCenter().y;
cameraZ = cameraHolder.getCenter().z;

// Move the camera back to the cameraHolder and look at the player
theWorld.getCamera().setPosition(
  new SimpleVector(
    cameraX,
    cameraY,
    cameraZ));
theWorld.getCamera().lookAt(new SimpleVector(sphereX, sphereY, sphereZ));

Whilst debugging this code, i've found that cameraX, Y and Z don't change from the initial values.  I can see the player rotating and if I use align to align the camera to the player, the camera rotates when I move the mouse, as it should, but I can no longer see the player!  Am I using getCenter() incorrectly?  I tried using calcCenter() before getting the cameraHolder center to reset the camera position, but this sets cameraX, Y and Z to NaN.

Any help would be appriciated!

Thanks,

Jon

EgonOlsen:
I see...the problem is, that getCenter() returns you the center in object-space while you want to get the center transformed into world-space. It should be possible to emulate this behaviour somehow, but i think it's better to add a new method like getTransformedCenter() to Object3D and maybe a convenience method to do the camera placement using this value to Camera too.
I'll add this to the next release, which should be out in the next 48h (i'll try to get things sorted today) and YOU will have to play beta-tester for this method  :lol:
I'll let you know...
BTW.: I'll document this behaviour of getCenter() in the docs, because it seems to be misleading the way it is documented now.

JonnyDee:
Thanks for the speedy reply!  As soon as the feature is available, i'm happy to be the beta tester  :D .  An easy way to place the camera using a helper method would be excellent and just what i'm looking for - looking forward to the new version!

Cheers,

Jon

EgonOlsen:
The beta of the new version available for download here:

EDIT: Removed the link. This version is now official.

The docs and the manual are still in need of some work and that's why this is not an "official" release, but this way you can already test the features you requested. This version is a major update, because some internals have changed and some obsolete stuff from Config has been removed. So in case of problems, please let me know.
Here's a list of the changes until now:

0.92 - Extended matrix-locking to cover the camera too (if locking is used). Worked on Matrix and SimpleVector to increase performance of some methods slightly. Removed unused transparency constants from Object3D. Added support for tiled textures (i.e. texture coordinates below zero and larger than 1) for the SoftGL-renderer. This requires that even the textures used for software-rendering only have to have a height of a power of 2 (jPCT will convert non-power-of-2-textures). Added some methods to SimpleVector, Camera and World to support first-person-shooter-like navigation better. Fixed a bug in the OcTree that caused collisions detection to fail in multi-threaded applications in some rare cases. Fixed a bug in the ray/polygon-collision detection in combination with octrees. Added an algorithm to automatically speed-up collision detection. Modified z-Sorting to ensure a defined sorting order (per frame) even for polygons with equal depth. Removed some unused or now useless configuration variables from Config (public and non-public ones). Reworked both software-renderers to be more pixel-perfect. Removed artifacts from the OptiZ-algorithm. It should work flawless in every situation now. Added the possibility to retrieve an object's center in worldspace.

Oh, and thanx for trying to call calcCenter() on a dummy-object... :lol:  It was bugged because it caused a division by zero in this case. Why the VM thinks that setting it to NaN instead is a better idea than throwing the exception, is still beyond my understanding. But it sometimes does this and after it, floating point code slows down to a crawl... :?

JonnyDee:
Thanks for the new version - getTransformedCenter() now works a treat!  For some reason my camera is moving in an elliptical path, rather than a circle as I intended, but I think that is my code  :D.

Navigation

[0] Message Index

[#] Next page

Go to full version