jPCT-AE - a 3d engine for Android > Support

Move Camera around a scene

(1/4) > >>

tyronetudehope:
Hi, I have a scene, which basically just contains a textured sphere object.

What I would like to do, is move the camera around the sphere in a circular motion, would look as if the sphere itself was rotating. I've got the sphere to rotate, but as an experiment would like to figure out how to rotate the camera.

I've been reading on all sorts of calculations and translations to do this, but have yet to get it right.

Any help please?

raft:
two approaches i can think of:

* keep track of an angle value, increase it every frame, calculate camera location around your sphere by using sin and cos angle, place camera accordingly and finally call Camera.lookAt(sphere)
* create two dummy objects, make second child of first, translate second to a distance (radius of your rotation), set parent object's location to sphere's location. each frame rotate parent object, set camera location to child objects location and finally call Camera.lookAt(sphere)

tyronetudehope:
Thank you! I went with the dummy object approach and it worked perfectly!

Thanks!

phoenicoperus:
I'm also using the dummy approach but I have a strange behaviour.

when I rotate the pivot dummy all works until I get closer to the top (90º) of the rotation, if I use camera.lookAt(), the camera should be upside down if you pass the top of the rotation, but it always stays upright, that causes a very nasty feel.

I also thought about using camera.setOrientation(dir,up) but I cant get it right.

The goal is to achieve a camara that moves around the object at a constant 3d radius with the camera Oriented to the centre of the object with "the exact same feel as the helloWorld AE" but rotating and moving the camera instead of rotating the 3dobject with a fixed camera

Here Is what I tried so far:

--- Code: ---private void resetCameraPosition() {
camera.setPosition(cameraSatellite.getTransformedCenter());
camera.lookAt(cameraPivot.getTransformedCenter());
}

private void initCamera() {

                //move the dummy pivot to the centre of the 3dobject
cameraPivot = Object3D.createDummyObj();
cameraPivot.translate(calcTrans(cameraPivot, 3dobject));

                //move the dummy satellite to the centre of the 3dobject and separated it by a radius (-20)
cameraSatellite = Object3D.createDummyObj();
cameraSatellite.translate(calcTrans(cameraSatellite, 3dobject));
cameraSatellite.translate(new SimpleVector(0, 0, -20));

                //Made child
cameraPivot.addChild(cameraSatellite);

camera = world.getCamera();
resetCameraPosition();
}
--- End code ---


 
To turn the cameraPivot dummy I'm using the same code as in the AE helloWorld

--- Code: ---if (touchTurn != 0) {
cameraPivot.rotateY(touchTurn);
resetCameraPosition();
// camera.rotateCameraY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
cameraPivot.rotateX(touchTurnUp);
resetCameraPosition();
// camera.rotateCameraX(touchTurnUp);
touchTurnUp = 0;
}
--- End code ---


I also tried several approaches for the resetCameraPosition() method, including getBack with invert, setOrientation etc etc. And none of them behaved as I would expect : (

Any idea of how to get this one right? Maby someone could do an example of the helloWorld using camera rotation instead of primitive cube rotation. It would be very handy.

EgonOlsen:
To create a camera moving around an object like in HelloWorld, you can do something like i did here: http://www.jpct.net/forum2/index.php/topic,977.msg6207.html#msg6207. It's for desktop jPCT, but the basic idea stays the same. That code has two options: Rotate object or rotate camera (default). Maybe that will help.

Navigation

[0] Message Index

[#] Next page

Go to full version