![]() |
|
|
|
#1
|
|||
|
|||
|
All right, I've read QUITE A BIT about quaternions at this point but still don't get them ..
![]() Here's some sample code. Copy/paste and run this: Code:
import viz
viz.go(viz.FULLSCREEN)
ROTATION_INC = 2
TRANSLATE_INC = 0.1
i = 0
while (i < 50):
redBall = viz.add("white_ball.wrl")
redBall.setPosition([i, 0, 0])
redBall.color([255, 0, 0])
greenBall = viz.add("white_ball.wrl")
greenBall.setPosition([0, i, 0])
greenBall.color([0, 255, 0])
blueBall = viz.add("white_ball.wrl")
blueBall.setPosition([0, 0, i])
blueBall.color([0, 0, 255])
i += 0.1
viz.MainView.setQuat([0,1,0,0])
viz.MainView.setPosition(5, 0, 0.5)
vizact.whilekeydown(viz.KEY_UP, viz.move, 0, 0, TRANSLATE_INC)
vizact.whilekeydown(viz.KEY_DOWN, viz.move, 0, 0, -TRANSLATE_INC)
vizact.whilekeydown(viz.KEY_LEFT, viz.rotate, viz.BODY_ORI, -ROTATION_INC, 0, 0)
vizact.whilekeydown(viz.KEY_RIGHT, viz.rotate, viz.BODY_ORI, ROTATION_INC, 0, 0)
vizact.whilekeydown(viz.KEY_PAGE_UP, viz.rotate, viz.HEAD_ORI, 0, -ROTATION_INC, 0)
vizact.whilekeydown(viz.KEY_PAGE_DOWN, viz.rotate, viz.HEAD_ORI, 0, ROTATION_INC, 0)
What this is meant to be is "training grounds" for understanding quaternions. If you look at the code inside the while loop you'll see that X-axis is traced with red dots, Y with green, Z with blue (X-Y-Z -> R-G-B was my logic ). MainView's originally just slightly off red Y-axis and the rotation is set to [x,y,z,w] = [0,1,0,0]. What I'm trying to understand now that we have a well-defined system of coordinates right in front of us is how quaternions work: [0,1,0,0] SHOULD have defined a rotation of 0 degrees around axis [0,1,0] - the Y-axis, so the camera originally should just look down the green Y-axis. Instead we're looking down X!I hope someone more experienced with quaternions can explain to me how they work in Vizard using this simple script, that would be great. Thanks! Last edited by roman_suvorov; 06-11-2008 at 06:38 PM. |
|
#2
|
|||
|
|||
|
In my previous post I explained what the values mean. So given the quaternion rotation of [0,1,0,0], this would mean a 180 degree rotation around the Y axis (2 * acos(0) = 180 degrees). Printing the euler and axis-angle values of the main view after applying the quaternion will confirm this. Adding the following code at the end of the script:
Code:
print viz.MainView.getEuler() print viz.MainView.getAxisAngle() Code:
[-180.0, 0.0, 0.0] [0.0, -1.0, 0.0, 180.0] |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| coalesceing euler angles | epl | Vizard | 6 | 05-28-2004 06:25 PM |
| plug-ins that return quaternions | hotspur1 | Vizard | 2 | 02-05-2004 08:47 PM |