Author Topic: Object rotation  (Read 2309 times)

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Object rotation
« on: June 29, 2011, 11:44:23 am »
Hi,
I was going through the CollisionDemoSoftware and trying to understand how it works.There I noticed one thing that the small cube has been placed on the plane.Here I need to rotate the small cube along X-axis to a certain degree.But when rotated the cube, the entire scene was away from the other objects along with small cube. (In fact, only the small cube is visible). What I want to achieve here is everything should be there as expected but the small cube should be rotated along x axis. This is the code I have used.
               
Code: [Select]
                cube = Primitives.getCube(2);
cube.translate(-50, -10, -50);
                cube.rotateX(SPEED);
                cube.rotateMesh();
               
How to handle this? Thanks in advance.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Object rotation
« Reply #1 on: June 29, 2011, 12:36:20 pm »
That's because the camera aligns with the cube in this example and that cube still has a rotation in your modification. Add a call to cube.clearRotation(); after doing the rotateMesh().

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: Object rotation
« Reply #2 on: June 29, 2011, 12:49:27 pm »
Thanks, It worked !!!

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: Object rotation
« Reply #3 on: June 29, 2011, 12:52:09 pm »
sorry to ask one thing here. when we say clearRotation what exactly happens?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Object rotation
« Reply #4 on: June 29, 2011, 01:13:08 pm »
It sets the rotation matrix to the identity matrix. It's a shortcut to cube.getRotationMatrix().setIdentity();

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: Object rotation
« Reply #5 on: July 01, 2011, 04:35:46 am »
I am further understanding this rotation and camera movement.This time I have added the code for moving the cube along Y-axis.And this is the following code I have added.But what happens is that the camera itself is moving up and the cube disappears.
Code: [Select]
if(keyA) {
                    SimpleVector t = cube.getYAxis();
    //t.scalarMul(SPEED);
    moveRes.add(t);
                    System.out.println(" keyA x " + moveRes.x+ " keyA y " + moveRes.y + " keyA z " + moveRes.z);
                    moveRes = cube.checkForCollisionEllipsoid(moveRes, ellipsoid, 8);
                    System.out.println(" x " + moveRes.x+ " y " + moveRes.y + " z " + moveRes.z);
                     if(moveRes.y < 0) {
                         System.out.println(" less than zer0....");
                         cube.translate(0, 0.25f, 0);
                     }   
                     else {
                        cube.translate(moveRes);
                     }
                   
                    cube.translateMesh();
                    cube.clearTranslation();
                }
I have added the above two lines. But the cube is not moving along y-axis, similarly the way it is moving along z-axis. Instead of that, the camera itself is moving up as I described earlier.