Jamsb
asked on
Multiplying by Modelview Matrix Gives Unexpected result
In a previous question (https://www.experts-exchange.com/questions/23489987/Am-I-Doing-this-Matrix-Multiplication-Correctly.html)
I asked how to find the coordinates of an object after undergoing a transform.
To do this I had to multiply the point I wanted to translate by the modelview matrix. The issue is that the values I get back are the opposite to what's occuring on the screen. ie. if the objects are rotated clockwise on the screen the results I get back are moving anticlockwise.
Do I need to Invert the modelview matrix or somthing like that? Could someone provide code to aid me in this?
I asked how to find the coordinates of an object after undergoing a transform.
To do this I had to multiply the point I wanted to translate by the modelview matrix. The issue is that the values I get back are the opposite to what's occuring on the screen. ie. if the objects are rotated clockwise on the screen the results I get back are moving anticlockwise.
Do I need to Invert the modelview matrix or somthing like that? Could someone provide code to aid me in this?
//function to do multiplication
#include <gl/gl.h>
void MultiplyVMatrix(GLfloat* Vertex, GLfloat* Matrix, GLfloat* ResultMatrix)
{
for(int i=0;i<16;i++)
ResultMatrix[i/4]+=Matrix[i]*Vertex[i%4];
}
**************************************************************
//modelview matrix and multiply co-ordinate of cube
GLfloat matrix[16];
GLfloat vertex[4]={1,2,-5,1}; //any co-ordinate for testing
GLfloat resultmatrix[4]={0,0,0,0};
glGetFloatv(GL_MODELVIEW_MATRIX, matrix); //grab the modelview matrix
MultiplyVMatrix(vertex,matrix,resultmatrix);
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I feel so stupid now! Its hard trying to imagine what's going wrong with all this Matrix math! Thanks very much :)
ASKER
Exactly what I wanted.
The only reason I know to look for this is that I did something very similar a few weeks ago, so don't feel too bad.
ASKER
*Correction*
GLfloat vertex[4]={1,2,-5,1};