0

I am trying to rotate a cube via its corner point, not from the center. Is this possible or do I need to rotate and then re-position it. I am trying to simulate a arm going up and down

// leg arm
    glVertexAttrib4f(2,1, 1,0, self.color.a);
    self.modelViewMatrix = GLKMatrix4MakeTranslation(self.position.x + 0.45,self.position.y + 0.1, self.position.z - 0.65);//(float)x, (float)y, -1.5f)
    self.modelViewMatrix = GLKMatrix4Rotate(self.modelViewMatrix,self.leftArmRotation, 1.0 ,0.0 ,0.0);
    self.modelViewMatrix = GLKMatrix4Scale(self.modelViewMatrix, 0.2, 0.2, 0.9);
    self.modelViewMatrix = GLKMatrix4Multiply(eyeBaseModelViewMatrix, self.modelViewMatrix);

    normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(self.modelViewMatrix), NULL);
    modelViewProjectionMatrix = GLKMatrix4Multiply(self.projectionMatrix, self.modelViewMatrix);

    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, modelViewProjectionMatrix.m);
    glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, normalMatrix.m);

    glDrawArrays(GL_TRIANGLES, 0, 36);

    // right arm
    glVertexAttrib4f(2,1, 1,0, self.color.a);
    self.modelViewMatrix = GLKMatrix4MakeTranslation(self.position.x - 0.45,self.position.y + 0.1, self.position.z - 0.65 );//(float)x, (float)y, -1.5f)
    self.modelViewMatrix = GLKMatrix4Scale(self.modelViewMatrix, 0.2, 0.2, 0.9);
    self.modelViewMatrix = GLKMatrix4Multiply(eyeBaseModelViewMatrix, self.modelViewMatrix);

    normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(self.modelViewMatrix), NULL);
    modelViewProjectionMatrix = GLKMatrix4Multiply(self.projectionMatrix, self.modelViewMatrix);

    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, modelViewProjectionMatrix.m);
    glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, normalMatrix.m);

    glDrawArrays(GL_TRIANGLES, 0, 36);
Burf2000
  • 5,001
  • 14
  • 58
  • 117
  • Here's my answer to a very similar question: http://stackoverflow.com/questions/23319269/is-there-a-standard-way-to-rotate-around-local-coordinates-that-is-from-a-mode/23319527#23319527. – Reto Koradi May 07 '14 at 03:21
  • Why is positioning it first an issue? To change the "anchor point" your first matrix operation should be translation by -anchor, from here on all should work the same as if you already had the vertex data so that the anchor is at zero. – Matic Oblak May 07 '14 at 07:17
  • I dont suppose you could give an example as my brain is hurting. Are you suggesting move it, rotate it, then move it back, Would I not need to work out the angle to work out its new position – Burf2000 May 07 '14 at 15:57

0 Answers0