control camera using dkey / touch

Started by nsnatraj, July 10, 2012, 03:06:38 PM

Previous topic - Next topic

nsnatraj

I want to create an app where I want to control the camera using dkey / touch. Say something like,  a cube which we can see from all sides.

I have checked the HelloWorld example. in it the cube is rotated, but I want to control the camera using dkey /touch so that the end user would see the four sides of the cube.

EgonOlsen

The HelloWorld example does rotate the cube by touch...i don't get the question here... ??? If you want to rotate it by using the dpad (which newer devices don't have btw.), implement your own listener for the keys and rotate the object accordingly. Just make sure that you don't fiddle around with the object in the event method itself, because it runs in parallel to the rendering thread and jPCT-AE isn't thread safe. Implement the listener methods, set some flags according to the keys pressed and evaluate them to an actual rotation in onDrawFrame.

nsnatraj

Thanks for the reply.

What I wanted was to rotate the camera around based on the key event, similar to waking in a maze or fps game.
For e.g. when the character moves forward the camera should also move in that direction and when the character moves in right / left direction the camera should also move in that direction.

The app which I am creating is just a Proof Of Concept for our sales team.

EgonOlsen

Well, then just move the camera...i'm not really getting your question. There's no magic "add a button and make everything move somehow"-class or method, if that's what you are looking for. You can get the Camera instance from the world and with the methods in it, you should be able to move the camera as you wish.

nsnatraj

Sorry that I am not able to properly explain my problem.

As you have told to get the camera from world I had done that and then I am rotating the camera.


world.getCamera().gtBack().setIdentity();
world.getCamera().rotateY((float) (cube.getYAxis().y + 0.2));


But when this code is executed the camera movement is to drastic any times the cube moves out of the screen. I want a smooth transition like FPS game.

Can you help me in controlling the camera in a smooth fashion?

EgonOlsen

Just reduce the value...what is

((float) (cube.getYAxis().y + 0.2)

supposed to do? Rotate around y with the length of the y-axis (which can be anythign between 0 and 1) +0.2? That doesn't make any sense to me. Have you tried something like 0.01 or 0.1 instead?

nsnatraj

What I am trying to do with this code is
((float) (cube.getYAxis().y + 0.2)
place the camera from the +0.2 from cube's y axis.

Same I had tried with camera.getYAxis() and camera.getPosition().y it is also giving me the same result or only once the camera moves. :(

I have tried following values 1, 0.1, 0.01, 0.001 but for each one the cube goes out of the screen.

EgonOlsen

You seem to be doing some strange things... ;)

The cube's y-axis is a direction vector, not a position vector. You can't use it to position the camera in relation to the cube, especially if you are trying this with a rotate?()-method, which has nothing to do with translations.

It's actually really simple and the HelloWorld example already does these things (i.e. place an object, place the camera, rotate the object). So i'm not sure what the actual problem is or what you are trying to achieve... ???