Results 1 to 5 of 5

Thread: rotating object

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2008

    rotating object

    Hello friends!

    I have the following code to rotate a cube (x&y direction). When I rotate xPosition object rotates on x axis with no problems. When I rotate with yPosition, again object rotates on y axis, remaining stationary with no problems. However, when I combine them together (as the code shows), my x-axis rotation changes to rotate the object around an imaginary line, such that the object comes closer to the screen and further back instead of staying in the same place. What have I done wrong?

    fAngle = ((-g_xRotation)/50);
    xPosition[0] = 0 + (sin(fAngle));
    xPosition[1] = 0;
    xPosition[2] = 0 + (cos(fAngle));

    Glu::gluLookAt(xPosition[0], 0, xPosition[2], 0, 0, 0, 0, 1, 0);

    fAngle = ((-g_yRotation)/50);
    yPosition[0] = 0 + (2 * cos(fAngle));
    yPosition[1] = 0;
    yPosition[2] = 0 + (2 * sin(fAngle));
    Glu::gluLookAt(yPosition[2],0,yPosition[0], 0, 0, 0, 1, 0, 0);

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006

    Re: rotating object

    I don't really understand what you are trying to achieve with the last code. One advice is to take care of the order of your transformations. I mean, the last transformation that you set with the opengl transformation functions like glTranslate or glRotate and friends is the first that affects objects geometry, as the modelview matrix is modified successively by these transformations (think of transformations as matrices).

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2008

    Re: rotating object

    I've spent about 11 hours on this so far and have modified my code to below:

    Glu::gluLookAt(-4.3, 5, 10, -4.3, 0, -50, 0, 1, 0);
    Gl::glRotatef(g_xRotation, 0.f, 1.f, 0.f);
    Gl::glRotatef(g_yRotation, 1.0, 0.0, 0.0);

    I'm using the first line to place my objects next to each other accordingly. Then, I want to set the camera position and angle. Then, I'd like to make my rotations based on the center of all my objects. However, the rotations are along the x axis only. For example, I want to rotate around a line parallel to x axis, but -50 spaces in the z direction.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2008

    Re: rotating object

    I'm putting together the above method because I've simply given up on what I actually want to happen.

    I'd want the camera to travel the path of an ovoid (egg shape) while keeping its focus on the center of the ovoid at all times. But I'm guessing the mathematical calculations for something like that would be extremely difficult.

  5. #5
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008

    Re: rotating object

    its a bit difficult if you just started with 3d. the camera movement you describe can be achieved best and the easiest way through "keyframes". the position and rotation gets interpolation over time and you get a smooth movement.

Similar Threads

  1. Rotating object
    By 3DPrgmer in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-26-2016, 08:38 AM
  2. Replies: 0
    Last Post: 10-28-2014, 08:51 PM
  3. rotating object
    By pbivens in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 07-19-2013, 01:35 PM
  4. rotating and object without rotating its axis
    By scam in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 12-17-2003, 08:30 AM
  5. Rotating about an object
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-01-2003, 12:12 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