Author Topic: Need to self rotate an Object and revolve against another pivot point  (Read 2195 times)

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
Hi,

I have a 3D landscape map / object model (.obj) file with streets in it. I have the name boards of the streets in it. Each of the name boards are separate 3D object files that I have successfully loaded on the map. Also i have set the pivots of each board so that when the map is rotated, the name boards are also rotated along with the map.

Now the problem is that when the map is rotated, the name board gets turned and after certain degree of rotation, the name board is not readable as it is rotated along with the map. But I need the name board to keep facing the camera.

I had tried by changing the pivot to object center so i can rotate the board in opp direction when the map is rotated. After this I again change the pivot to the center of the map and rotate the object by multiplying the angle with (-1.0). But this makes the map stand still in one place and map along gets rotated. I have used the below code. Pls indicate what i am doing wrong?

public void onDrawFrame(GL10 gl) {
.
.
//poi is the name board 3D object model
poi.setRotationPivot(df); // where df is the changed simple vector referring the center of the map
poi.rotateY(touchTurn); // to rotate along with the map
poi.setRotationPivot(new SimpleVector(poi.getCenter())); // to get the object's own enter for self rotate
touchTurn = (float) (touchTurn * -1.0);  // change the angle to opp direction
poi.rotateY(touchTurn);   // for self rotation
.
.
}

I have been breaking my head to resolve this.  Need urgent solution as i need to complete my assignment.

Offline Lobby

  • int
  • **
  • Posts: 66
    • View Profile
    • flowersoft
Re: Need to self rotate an Object and revolve against another pivot point
« Reply #1 on: January 06, 2014, 01:06:18 pm »
According to JavaDoc of setRotationPivot: "Sets the rotation pivot of the object. The rotation pivot is the point in objectspace around which the object will be rotated using its rotation matrix."
So, firstly I think to set the rotation pivot to the center of poi you should call poi.setRotationPivot(new SimpleVector()); und so on. Secondly I'm not sure whether setRotationPivot takes care of current rotation and position - you could try to use rotateMesh() before doing your second rotation.

I'm not sure whether this can solve your problem. Would be nice to see a little bit more code.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Need to self rotate an Object and revolve against another pivot point
« Reply #2 on: January 06, 2014, 02:31:36 pm »
Rotations are cumulative, but pivots are not. That's why your way of trying to solve this doesn't work. Can't you simply use bill bording for the boards? Another approach might be to make the boards children of the map, set the pivot to the boards' center and simply rotate the board in the opposite direction.

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Need to self rotate an Object and revolve against another pivot point
« Reply #3 on: January 06, 2014, 06:13:52 pm »
Thank you so much EgonOlsen. Your second suggestion of making the board as child for map and turning them in opp direction had solved the problem. Also I had tried the billboard option earlier but the object was not facing the camera and hence left it. You are great !!

Lobby, i had tried rotatemesh, but it was not working unfortunately.