Simple Camera Movement example

Started by aeroxr1, September 07, 2014, 12:42:06 PM

Previous topic - Next topic

aeroxr1

Hi :)
In this example :
http://www.jpct.net/wiki/index.php/Simple_Camera_Movement

I don't understand this passage very well :

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 ?

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 :
transformMatrix.setIdentity();

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


}


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


Thanks :)

EgonOlsen

#1
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.


aeroxr1

#3
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  :-\

EgonOlsen

One draws, the other one displays... ;) draw() renders the scene in the frame buffer, display simply brings the frame buffer on screen.

aeroxr1

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  :-\

EgonOlsen

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

aeroxr1

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 :)