Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Graphics problem - noobie

Options
  • 28-03-2006 5:55pm
    #1
    Registered Users Posts: 3


    Just curious if anybody can help. Trying to create basic 3d scene in opengl , a sphere is constantly orbiting an object. If I have 2 Vector positions of the objects centers how do I find the angle by which to rotate the object in the middle around the y axis so that it is always facing the sphere. Both objects have the same Y value in the Vector positions.
    Any help is much appreciated.


Comments

  • Registered Users Posts: 1,272 ✭✭✭i_am_dogboy


    Something like this
    glRotatef(angle, 0f, 1f, 0f);
    drawCenterObject();
    glTransform(5f, 0f, 0f);
    drawSphere();
    

    In this case if the drawCenterObject() method draws your object facing along the x axis it'll always face the sphere. By performing the rotation before drawing the center object you are rotating it on it's own axis by the same amounnt as the object rotating around it, so it'll always face it, only works if the center object is drawn at the origin though. Have a look at Nehe for some really good opengl tutorials.

    Edit
    I just re read, you want to work out the angle from the positions...
    well in that case you have 2 vectors v1 and v2-which are the positions of the objects, and you want to get the angle from either x or z axis, lets assume it's the x. If you subtract v1 from v2 you get a vector that points to v2 from v1, call this v3. To ge the angle between 2 vectors you need to use the dot product and acos operators.

    angle = acos(dot(xaxis,v3))

    This will return the angle from the x axis that the object will need to be rotated by as long as xaxis and v3 are normalised. Then you'd just apply that rotation to the center object before rendering it. Another thing-you might have to rotate around [0, -1, 0] instead of [0, 1, 0].


  • Registered Users Posts: 3 jimmyruffin


    Thanks a lot, il try that.


Advertisement