|
Post by wallypog on Mar 3, 2012 20:50:18 GMT -5
I am trying to write an app to help me visualize unit quaternions. I would like to display the local axis and the amount of rotation around it. Is there a special transform matrix required? All help appreciated. Regards, John Fortier
|
|
|
Post by shadow008 on Mar 5, 2012 17:22:08 GMT -5
Well, I can't really help you with quaternions for I have very little knowledge of them, but exactly how are you trying to visualize them? Is it like the 3 axies(X,Y,Z) with a line representing the rotation?
Never-the-less, I don't think there is any "special transform matrix" required. What I think you could do is determine the graphics positions by doing all transformations in your code. And calling the final result using OpenGL immediate mode and implementing your transformed verticies in glVertex3f().
I have no idea if that answers your question because once again, I have very little knowledge of quaternions. Not sure how others on these forums fair with them...
|
|
|
Post by matthew on Mar 6, 2012 10:20:25 GMT -5
|
|
|
Post by wallypog on Mar 6, 2012 22:39:40 GMT -5
Perhaps I should rephrase dropping the quaternions. Picture a paper dart in profile view, pointy end to the left. Now rotate the paper dart 45 deg. c.c. around the z axis. It would now be in a profile view climbing to the left at an angle of 45 deg. above the horizon. I now wish to perform a barrel roll around the darts local (roll) axis. How do I do that? - John
|
|
|
Post by shadow008 on Mar 7, 2012 15:09:57 GMT -5
I know this isn't exactly what you were looking for, but it might help you understand the concept of how to do something like you said:
-----------------------------------------
function GetLookAtPos(&pos() as single,&lookat() as single,xang as single,yang as single)
lookat(0) = pos(0) - (sind(xang)*cosd(yang)) * 5 lookat(1) = pos(1) + (sind(yang)) * 5 lookat(2) = pos(2) + (cosd(xang)*cosd(yang)) * 5
return 0
endfunction
function CreateCube() dim ret = glGenLists(1) glNewList(ret,GL_COMPILE) glBegin(GL_QUADS) glNormal3f(0,0,1) glVertex3f(-0.5, 0.5, 0.5):glVertex3f(-0.5,-0.5, 0.5) glVertex3f( 0.5,-0.5, 0.5):glVertex3f( 0.5, 0.5, 0.5) glNormal3f(1,0,0) glVertex3f( 0.5, 0.5, 0.5):glVertex3f( 0.5,-0.5, 0.5) glVertex3f( 0.5,-0.5,-0.5):glVertex3f( 0.5, 0.5,-0.5) glNormal3f (0,0,-1) glVertex3f( 0.5, 0.5,-0.5):glVertex3f( 0.5,-0.5,-0.5) glVertex3f(-0.5,-0.5,-0.5):glVertex3f(-0.5, 0.5,-0.5) glNormal3f(-1,0,0) glVertex3f(-0.5, 0.5,-0.5):glVertex3f(-0.5,-0.5,-0.5) glVertex3f(-0.5,-0.5, 0.5):glVertex3f(-0.5, 0.5, 0.5) glNormal3f(0,1,0) glVertex3f(-0.5, 0.5,-0.5):glVertex3f(-0.5, 0.5, 0.5) glVertex3f( 0.5, 0.5, 0.5):glVertex3f( 0.5, 0.5,-0.5) glNormal3f(0,-1,0) glVertex3f(-0.5,-0.5, 0.5):glVertex3f(-0.5,-0.5,-0.5) glVertex3f( 0.5,-0.5,-0.5):glVertex3f( 0.5,-0.5, 0.5) glEnd() glEndList() return ret end function
dim BoxList = CreateCube()
dim BoxPos(2) as single = vec3(0,0,-5) dim CamPos(2) as single dim CamRot(1) as single
dim MouseX as single dim MouseY as single
while true glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) glPushMatrix() gluLookAt(CamPos(0),CamPos(1),CamPos(2), BoxPos(0),BoxPos(1),BoxPos(2), 0,1,0) glDisable(GL_CULL_FACE) glPushMatrix() 'The Box the Camera Rotates about glTranslatef(BoxPos(0),BoxPos(1),BoxPos(2)) glColor3f(1,0,0)
glCallList(BoxList) 'A plane floor for reference glColor3f(0,1,0) glBegin(GL_QUADS) glVertex3f( 10,-5,-10) glVertex3f(-10,-5,-10) glVertex3f(-10,-5, 10) glVertex3f( 10,-5, 10) glEnd()
glPopMatrix()
glPushMatrix() SwapBuffers() CamRot(0) = CamRot(0) + Mouse_XD() * 20 if CamRot(0) > 360 then CamRot(0) = 0:endif if CamRot(0) < 0 then CamRot(0) = 360:endif CamRot(1) = CamRot(1) - Mouse_YD() * 20 if CamRot(1) > 80 then CamRot(1) = 80:endif if CamRot(1) < -80 then CamRot(1) = -80:endif GetLookAtPos(CamPos, BoxPos, CamRot(0), CamRot(1)) wend
-----------------------------------------
Keep in mind that this is the "camera" rotating about the box, not the entire scene rotating about the camera. Hope this points you in the right direction.
On a side note, anyone know how to keep indents when posting code to these forums? I remember someone else bringing it up at some point, but I can't remember what the solution is...
|
|
|
Post by Darkjester on Mar 7, 2012 18:30:26 GMT -5
youll need to convert your quaternions to Euler angles, then you can use the standard opengl matrix functions to do the transformations.
|
|
|
Post by wallypog on Mar 8, 2012 17:19:19 GMT -5
Thanks to Mathew, dark jester, and shadow008l for all your help. btw shadow008, here in Canada we manufacture a confection called "Holy Crap". Actually quite tasty. I'd send you some, but most countries won't take any crap from Canada ;-) John
|
|
|
Post by Darkjester on Mar 12, 2012 4:35:57 GMT -5
Thanks to Mathew, dark jester, and shadow008l for all your help. btw shadow008, here in Canada we manufacture a confection called "Holy Crap". Actually quite tasty. I'd send you some, but most countries won't take any crap from Canada ;-) John lololol made my day ;D
|
|