Results 1 to 2 of 2

Thread: Rotation About An Axis

  1. #1
    Newbie Newbie
    Join Date
    Oct 2016

    Rotation About An Axis

    I want to Rotate my object around it's axis , i.e i want to create a fan like rotation

    But i am not able to get the desired effect

    The following it's the code:

    Matrix4f matrix = new Matrix4f();
    Matrix4f.translate(translation, matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
    Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);

    My vertex code:

    vec4 worldPosition = transformationMatrix * vec4(position,1.0);
    vec4 positionRelativeToCam = viewMatrix*worldPosition;
    gl_Position = projectionMatrix *positionRelativeToCam;

    Main Game Loop:


    Rotating Along Z axis also make by object cange it's y and x position thus making it revoving with rotation.
    But, it's not rotating along it's own axis. What am I missing here?
    Please Help

    Full Code -
    sample image -

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2016
    Try moving it to the origin and then rotating it and then moving it back.

    You can easily wind up with an orbit instead of a rotation. That's one way of dealing with it, and probably not my first choice these days, but it works and it's in line with what you are currently doing.

    These days I would probably reverse the order of multiplication in the matrix operations, but you're not doing the matrix math yourself and so that's obfuscated to where you can't get to it.

Similar Threads

  1. Rotation by y axis
    By andrei.alex in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-14-2015, 12:36 PM
  2. Rotation not on the 0,0,0 axis
    By tzano in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-03-2004, 12:55 PM
  3. changing axis of rotation and center of rotation in openGL performer
    By ravishashi in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 07-08-2003, 04:42 AM
  4. Rotation around two fixed rotation axis
    By Roland in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 03-06-2002, 12:07 PM
  5. axis,rotation
    By amigos in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-15-2000, 12:44 AM

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