Author Topic: handling camera functions  (Read 909 times)

Hi!!

  • Guest
handling camera functions
« on: January 01, 2014, 02:42:56 pm »
I am working on android game. In this I am using JPCT framework. In this I want to use camera movement.As in some games the whole level view is viewed to the user( like in Angry Birds). I am putiing my code in OnDraw() function.
Code: [Select]
@Override
 public void onDrawFrame(GL10 gl)
 Camera cam = world.getCamera();
 cam.moveCamera(Camera.CAMERA_MOVELEFT,2);

Now, when this executes it continuously goes to the left. I want to use various camera functions like it goes left them zoom in on particular object then zoom out and then move right;something like that. How I would be able to do so?? I am very new to programming.
« Last Edit: January 01, 2014, 05:23:56 pm by Hi!! »

Offline Lobby

  • int
  • **
  • Posts: 66
    • View Profile
    • flowersoft
Re: handling camera functions
« Reply #1 on: January 01, 2014, 03:19:10 pm »
cam.moveCamera moves the camera relative to it's current Position, so I think it's not useful for your purpose. Use cam.setPosition() instead to set it to a absolute coordiante. Zooming can be done by using different z-values ;) .


ps. Could you please put source code into code-tags (they look like [code_]Your Code[/code_] without the _) so it differs from the other text . This will look like:
Code: [Select]
My greate source.
« Last Edit: January 01, 2014, 03:21:10 pm by Lobby »

Hi!!

  • Guest
Re: handling camera functions
« Reply #2 on: January 01, 2014, 05:27:28 pm »
oh! sorry and thanx... By the way my actual question is that How i would be able to set time. I mean camera moves to the left for 3 sec. then stop and get zoomed on particular object for sort of time then zoom out and move to the right.. Hope you are getting my question..  :(

Offline Lobby

  • int
  • **
  • Posts: 66
    • View Profile
    • flowersoft
Re: handling camera functions
« Reply #3 on: January 01, 2014, 06:08:14 pm »
Oh, so you want to do a more complex thing. The bad news is, that you have to do the position calculations yourself. To move smoothly to a point you could do for instance the following thing in your update-Method:
Code: [Select]
SimpleVector pos = cam.getPosition();
SimpleVector delta = new SimpleVector(targetPos);
delta.sub(pos);
delta.scalarMul(deltaTime * 0.1f);
pos.add(delta);
cam.setPosition(pos);
This is pseudocode, so never tested or something like that. targetPos is a SimpleVector and the position the cam should move to. deltaTime is the time in senconds since last update. Here the cam should move slightly to targetPos becoming more and more slowly.

Hi!!

  • Guest
Re: handling camera functions
« Reply #4 on: January 01, 2014, 07:02:49 pm »
Thanx!!! I think it will help!!!!!!!