Author Topic: Simple Camera Movement example  (Read 1240 times)

Offline aeroxr1

  • int
  • **
  • Posts: 82
    • View Profile
Simple Camera Movement example
« on: September 07, 2014, 12:42:06 pm »
Hi :)
In this example :
http://www.jpct.net/wiki/index.php/Simple_Camera_Movement

I don't understand this passage very well :

Code: [Select]
if (touchTurn != 0) {
SimpleVector backVect = cube.getTransformedCenter();
backVect.scalarMul(-1.0f);
rotationmatrix.translate(backVect);
rotationmatrix.rotateY(touchTurn);
rotationmatrix.translate(cube.getTransformedCenter());
touchTurn = 0;

0- I create a matrix rotationmatrix = new matrix();
1- I create a vector to centerposition of my model
2- I multiply this vector for -1 , why ?
3- I apply the traslation created to my rotationmatrix 
4- I rotate it around the Y axis
5- I traslate my matrix to center of my model, why ?

Code: [Select]
if (touchTurnUp != 0) {
transformMatrix.translate(new SimpleVector(0, -touchTurnUp * 30,0));
touchTurnUp = 0;
}

transformMatrix is a mistake, right ? I have to traslated the rotationmatrix, right ? But why I have to do that ? The rotation round the Y axis is not enough ?

and at last :
Code: [Select]
transformMatrix.setIdentity();

fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();


}

I don't understand why I have to do setidentity .


Thanks :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Simple Camera Movement example
« Reply #1 on: September 07, 2014, 05:15:36 pm »
The camera is supposed to rotate the cube, i.e. it has to rotate around the cube's center and not around it's own origin. That's what this code does. The -1 is just there to change the direction of the translation, the additional translation at the end reverts this translation after applying the rotation. When thinking about moving the camera, one actually has to think about moving the world instead in the opposite direction. At least that is what happens when doing the math.
The translation in the second part seems fine, because it's just there to move the camera up a little. The matrix gets reset later to do this only once. The wiki actually explains this good enough IMHO.
« Last Edit: September 09, 2014, 05:35:34 pm by EgonOlsen »

Offline aeroxr1

  • int
  • **
  • Posts: 82
    • View Profile
Re: Simple Camera Movement example
« Reply #2 on: September 09, 2014, 03:54:52 pm »
ah Ok :)

Thanks :)


Offline aeroxr1

  • int
  • **
  • Posts: 82
    • View Profile
Re: Simple Camera Movement example
« Reply #3 on: September 09, 2014, 11:16:46 pm »
I have two another questions :

differents between world.draw(framebuffer) and framebuffer.display() ?   ;D

and the other question is in bones's sections, but no one can answer me because is  matematics's problems regarding bind pose and inverse bind pose  :-\
« Last Edit: September 09, 2014, 11:19:59 pm by aeroxr1 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Simple Camera Movement example
« Reply #4 on: September 10, 2014, 08:15:00 am »
One draws, the other one displays... ;) draw() renders the scene in the frame buffer, display simply brings the frame buffer on screen.

Offline aeroxr1

  • int
  • **
  • Posts: 82
    • View Profile
Re: Simple Camera Movement example
« Reply #5 on: September 10, 2014, 06:08:26 pm »
I'm trying to applicate the camera movement to my app.
I would like that the camera moved around my models while the my model stays in beginning position for all the time.   ;D

I'm using the code of ontouchevent from helloworld-ae , but I have some problem to apply the camera rotation, there is something different from cube example  :-\

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Simple Camera Movement example
« Reply #6 on: September 10, 2014, 06:24:28 pm »
I'm not sure what you mean...the cube example rotates the object in front of the camera. Rotating the camera around the object is a different thing. This thread has an example for desktop jPCT that might help: http://www.jpct.net/forum2/index.php/topic,977.0.html

Offline aeroxr1

  • int
  • **
  • Posts: 82
    • View Profile
Re: Simple Camera Movement example
« Reply #7 on: September 10, 2014, 07:52:42 pm »
For now I'm trying to rotate the model around his Y axes , something like this :
Code: [Select]
            for (Animated3D a : modello)
            {
               Matrix rotation=new Matrix(a.getRotationMatrix());
               rotation.rotateY((float)Math.toRadians(90));
               a.setRotationMatrix(rotation);
            }
            

But I will substitute 90 with touchTurn .
Initially I had thought to move the camera around the object, but if I rotate the object on his Y axes the result is the same , right ?


Now I'm going to read the thread that you have posted :)

Last thing :
http://www.jpct.net/wiki/index.php/Simple_Camera_Movement

Can I see complete code of this example ? Because there are some steps that I don't understand :)