3d movement

Posts: 39
Joined: 2008.10
Post: #1
Hey guys,

Im working in 3d for the first time in a long time. Basically im rotating a sphere and projecting x y z coords to place things on the surface based on the spheres X and Y rotation.

Heres the code im using:

        #define piover180 0.01745329252f
        GLfloat cosy = cos(yrot * piover180);
        island[i].x = rad * sin(xrot * piover180)* cosy;
        island[i].y = rad * sin(yrot * piover180);
        island[i].z = rad * cos(xrot * piover180) * cosy;

Problem is the Xrot positioning works fine but the Yrot placement always draw the objects into the north and south pole so they all cross at the top, which isnt correct for rotating. I need a way to solve this. Heres a picture to help explain

[Image: 47bcde62.jpg]

Any help would be greatly appreciated, let me know if you need any more information
Quote this message in a reply
Posts: 39
Joined: 2008.10
Post: #2
I have tried to solve the problem of the strange Vertical movement (it always needing to go to the pole as it approaches the top or the bottom of the sphere) by using more simple transform techniques but the problem even persists then. There must be something im not considering since im only very experienced in 2d game development.

Here it is

// Apply latitudinal rotation (aka "xrot")
glRotatef(xrot, 0, 1, 0);

// Apply longitudinal rotation (aka "yrot")
glRotatef(yrot, 0, 0, 1);

// Move object out to its radius
glTranslatef(rad, 0, 0);

Let me know if you dont understand the problem and ill provide a video
Quote this message in a reply
Posts: 39
Joined: 2008.10
Post: #3
I ended up solving it using Spherical Coordinate System

Heres the code

island[i].x = rad*sin(xrot*(PI/180))*cos(yrot*(PI/180));

island[i].y = rad*sin(xrot*(PI/180))*sin(yrot*(PI/180));

island[i].z = cos(xrot*(PI/180));

Heres the equations

x = r sinq cosf, y = r sinq sinf, z = r cosq,

r = (x2 + y2 + z2)1/2, q =tan-1(z/(x2+y2)1/2), f = tan-1(y/x).

Just in case anyone could do with it, its perfect for camera control or any exact 3d coord calculations you need to do.


Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Enemy movement like in the 80's MikeD 4 4,138 Apr 16, 2009 03:46 AM
Last Post: MikeD
  Help with touch movement shadow021 1 2,402 Apr 7, 2009 12:19 AM
Last Post: wonza