Sign in to follow this  

Rotating a local coordinate axis

This topic is 3736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an object (a flower petal) that has all its vertices stored in terms of the world coordinate axis (xyz). When it's drawn it runs along the y axis. However, this petal object has its own local coordinate system (abc) and I would like to transform the petal so that instead of being drawn down the y axis (of the xyz coordinate system) it is drawn down the b axis of its own local coordinate system. Unfortunately I can't get the transformation to happen. In fact, my petal object completely disappears from view. This is what I have been doing.
float m[16];
m[0] = a[X]; m[4] = a[Y]; m[8]  = a[Z]; m[12] = 0;
m[1] = b[X]; m[5] = b[Y]; m[9]  = b[Z]; m[13] = 0;
m[2] = c[X]; m[6] = c[Y]; m[10] = c[Z]; m[14] = 0;
m[3] = 0;    m[7] = 0;    m[11] = 0;    m[15] = 1;
	
glPushMatrix();

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(m);
petal->render();

glPopMatrix();
Note that the origin of the xyz coordinate axis is the same as the abc local coordinate axis. If I draw the local and world axes to the screen they are all in the right place. Also, if I was to do something like:
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glRotatef(45, 0, 0, 1)
petal->render();
glPopMatrix();
then it does the right thing, so the problem is definitely with the matrix or how I'm using it, so obviously I've misinterpreted things somewhere. Cheers Glenn [Edit] Well, after talking to some of my colleagues, I was informed of three issues. Yes, three, that's almost all of it. The matrix was back to front, the matrix mode should have been before the pushMatrix and I should have used glMultMatrixf. This is the working code for anyone who stumbles as much as I.
float m[16];
m[0] = a[X]; m[4] = b[X]; m[8]  = c[X]; m[12] = 0;
m[1] = a[Y]; m[5] = b[Y]; m[9]  = c[Y]; m[13] = 0;
m[2] = a[Z]; m[6] = b[Z]; m[10] = c[Z]; m[14] = 0;
m[3] = 0;    m[7] = 0;    m[11] = 0;    m[15] = 1;

glMatrixMode(GL_MODELVIEW);	
glPushMatrix();
glMultMatrixf(m);
petal->render();
glPopMatrix();
[Edited by - GlennNZ on September 18, 2007 10:40:59 PM]

Share this post


Link to post
Share on other sites
If the Origin and Scale of your local coordinate system are equal to those of the modelview space it doesn't matter whether you use glLoadMatrix or glMultMatrix. In fact, if you translated or scaled modelview space but don't want your own one to be affected by modelview transforms you should use glLoadMatrix instead of glMultMatrix.

Furthermore you also don't have to write column vectors... just use ARB_TRANSPOSE_MATRIX which is supported anywhere anyway ( use glLoadTransposeMatrixfARB instead of glLoadMatrixf )

Share this post


Link to post
Share on other sites

This topic is 3736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this