Author Topic: Orientation on spherical surface  (Read 837 times)

Offline frit

  • byte
  • *
  • Posts: 1
    • View Profile
Orientation on spherical surface
« on: July 24, 2012, 07:03:01 pm »
I am fairly new to 3d engines (obviously, to jPCT too!) and I'm starting to create an Android application using it.
What I am trying to achieve is a spherical world upon which models (like characters, trees, buildings) stand and move.
So far, I've managed to position them on the world surface (which took me a hard time hehe).

Now I want to know what is the best way to orientate them accordingly to their position (in relation to the sphere center) so they are always aligned to the normal of the surface regardless of where they stand/move.
I've found there is a method called "setOrientation" which requires 2 vectors as parameters, but I guess I didn't understand how it works. I've tried to fill the direction vector with the x,y,z coordinates of the object in the space (touching the surface) and the up vector with the same coordinates calculation, but considering a sphere of radius+1 (so the generated axis becomes normal to the sphere). Unfortunately, this didn't work... maybe someone can clear up for me how this method really works? Or maybe suggesting a better way for me to do what I need?
(sorry if this got confusing!)

Thank you for your time!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
Re: Orientation on spherical surface
« Reply #1 on: July 25, 2012, 07:26:20 am »
That method requires the direction and the up vector have to be perpendicular. In your case, they are not and that's why the method gives you strange results. Maybe you can combine the vector from the sphere's center to the object and the getRotationMatrix()-methods in SimpleVector to something that works but setting the result as the objects new rotation vector. You might have to apply some additional rotations though.