Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Rotating quad around itself but move it to a specific position of another quad

  1. #1
    Newbie Newbie
    Join Date
    Jul 2013

    Rotating quad around itself but move it to a specific position of another quad

    i have the following problem: i have following setup:

    The red quad should always keep the position relative to the white quad. I got this working by using the same translation and rotation matrix as the white quad.
    The red one "recieves" the matrices from the white one.

    img at: (would have used IMG tag, but was denied )

    Now i want to rotate the red quad around itself. I do it, by adding the amout of degree to the one recieved from the parent object and using it as the values for the rotation matrix:

    Code :
    cos(deg+turnDeg), -sin(deg+turnDeg), 0.0, 0.0
    sin(deg+turnDeg),  cos(deg+turnDeg), 0.0, 0.0
                 0.0,               0.0, 1.0, 0.0
                 0.0,               0.0, 0.0, 1.0

    deg: the amout the white quad is rotated
    turnDeg: the amount the red quad should be rotated

    The problem now is, that if i let it rotate, it starts rotating around the center of the white quad.

    I now have the question, how i can rotate it around itself but let it stay at the position relative to the white quad?

    Source of the VertexShader:
    Code :
    #version 150 core
    in vec4 in_Position;
    in vec4 in_Color;
    in vec2 in_TextureCoord;
    uniform mat4 window_Matrix;
    uniform mat4 ikarus_Rotation_Matrix;
    uniform mat4 translation_Matrix;
    uniform mat4 ntranslation_Matrix;
    out vec4 pass_Color;
    out vec2 pass_TextureCoord;
    void main(void) {
    	gl_Position = window_Matrix * translation_Matrix * ikarus_Rotation_Matrix *  in_Position;
    	pass_TextureCoord = in_TextureCoord;
    	pass_Color = in_Color;

    Last edited by CDGJosh; 07-02-2013 at 02:32 PM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    To rotate an object around itself you must do the following

    1) translate the object rotation point (in your case the object's centre) to the origin
    2) rotate the object
    3) translate the object rotation point back to it's location

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts