Author Topic: control camera using dkey / touch  (Read 2869 times)

Offline nsnatraj

  • byte
  • *
  • Posts: 8
    • View Profile
control camera using dkey / touch
« on: July 10, 2012, 03:06:38 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: control camera using dkey / touch
« Reply #1 on: July 10, 2012, 04:01:46 pm »
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.

Offline nsnatraj

  • byte
  • *
  • Posts: 8
    • View Profile
Re: control camera using dkey / touch
« Reply #2 on: July 12, 2012, 05:54:52 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: control camera using dkey / touch
« Reply #3 on: July 12, 2012, 07:17:09 am »
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.

Offline nsnatraj

  • byte
  • *
  • Posts: 8
    • View Profile
Re: control camera using dkey / touch
« Reply #4 on: July 12, 2012, 01:05:03 pm »
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.

Code: [Select]
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: control camera using dkey / touch
« Reply #5 on: July 12, 2012, 11:38:48 pm »
Just reduce the value...what is

Code: [Select]
((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?

Offline nsnatraj

  • byte
  • *
  • Posts: 8
    • View Profile
Re: control camera using dkey / touch
« Reply #6 on: July 13, 2012, 08:56:17 am »
What I am trying to do with this code is
Code: [Select]
((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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: control camera using dkey / touch
« Reply #7 on: July 13, 2012, 09:43:18 am »
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... ???