Results 1 to 3 of 3

Thread: Position of an orbiting sphere

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2015
    Posts
    7

    Position of an orbiting sphere

    I'm trying to get the position of a sphere that is rotating around an idle object in my opengl application. This is how I perform the orbiting:

    Code :
                glTranslatef(positions[i].getPosX(), //center of rotation (yellow ball)
                               positions[i].getPosY(),
                               positions[i].getPosZ());
                glRotatef(rotation_angle,0.0,1.0,0.0); //angle of rotation
                glTranslatef(distance[i].getPosX(), //distance from the center of rotation
                               distance[i].getPosY(),
                               distance[i].getPosZ());

    Variable rotation_angle loops from 0 to 360 endlessly. In the distance vector I'm only changing the z-distance of the object, for example let's say the idle object is in (0,0,0), the distance vector could be (0,0,200). I need the position of the object that is orbiting to perform collision detection.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by drew_jewel View Post
    I need the position of the object that is orbiting to perform collision detection.
    In which case, forget about using any OpenGL matrix functions other than glLoadMatrix(). Just construct the matrices in the application (either use GLM or write your own code).

    For a single object and a simple program, you can get the matrices out of OpenGL using glGetDoublev() and use gluUnProject(). But if you have many objects or performance matters, that's highly inefficient.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    394
    I'm trying to get the position of a sphere that is rotating around an idle object in my opengl application.
    The first translate is o.k. I'd take out the glRotate and replace the second glTranslate with something like this -

    Code :
       float r = 200.0,
             x = r * cos (rotation_angle),       // This assumes rotation_angle is in units of radians
             y = 0.0,
             z = r * sin (rotation_angle);
     
       glTranslatef (x, y, z);

Similar Threads

  1. Orbiting spheres, sometimes in front, sometimes behind
    By TalysShade in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-06-2012, 03:46 AM
  2. orbiting
    By morello in forum OpenGL: General
    Replies: 4
    Last Post: 11-26-2010, 05:22 PM
  3. How to position a sphere and click on it
    By illuminator in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-21-2006, 09:05 AM
  4. Orbiting Camera
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-12-2004, 05:34 AM
  5. camera orbiting
    By Penance in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-17-2002, 11:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean