[Solved]Getting Vector3 from Quaternion?

Problems building or running the engine, queries about how to use features etc.
Post Reply
dreadwulgaru
Halfling
Posts: 41
Joined: Sun May 20, 2007 4:09 am

[Solved]Getting Vector3 from Quaternion?

Post by dreadwulgaru » Sat May 29, 2010 7:37 pm

Hey all
I know that quaternions and vectors are almost completely different things, but I need a way around this. Basically, I need to find out the direction a node is pointing with a Vector3. However, getOrientation returns a quaternion, and to my knowledge there is no method for getting a vector.

The purpose of this is find the angle between a vector and the direction the node is pointing. What's happening is that I have a hovercraft that is turning. However, its current velocity is, for example, in direction (1,0,0) and the ship is pointed in (0,0,1). In this case, the ship would be drifting, but I need a way to slow down the ship considerably when it is not facing the direction of its current velocity. The best way I could figure out how to do this was to subtract a certain amount of speed from the current velocity in the opposite direction that the ship is pointed. This 'certain amount of speed' is to be directly proportional to the sine of the angle between the two directions, where the angle has the limits of -pi/2 to pi/2 (ie, if the ship is pointed at 90 degree angle compared to the velocity, it will slow down considerably, but when they are facing the same direction, angle of 0 degrees, the ship will not slow down at all). I need a way to do this, but cannot find a way to get the direction the ship is facing in a vector instead of a quaternion.

Any help is appreciated, whether you come up with a completely new way to do this or if you know/can figure out how to get the vector from the quaternion. Thanks!
Last edited by dreadwulgaru on Sat May 29, 2010 10:11 pm, edited 1 time in total.
0 x

User avatar
wacom
Gnome
Posts: 350
Joined: Sun Feb 10, 2008 2:07 pm

Re: Getting Vector3 from Quaternion?

Post by wacom » Sat May 29, 2010 8:05 pm

dreadwulgaru wrote:Hey all
I know that quaternions and vectors are almost completely different things, but I need a way around this. Basically, I need to find out the direction a node is pointing with a Vector3. However, getOrientation returns a quaternion, and to my knowledge there is no method for getting a vector.
But there is! Just multiply the quaternion with the forward vector, and you get the direction.
0 x

dreadwulgaru
Halfling
Posts: 41
Joined: Sun May 20, 2007 4:09 am

Re: Getting Vector3 from Quaternion?

Post by dreadwulgaru » Sat May 29, 2010 9:44 pm

by forward vector do you mean the direction the ship is traveling in or the unit z vector? because I believe I tried that method with the unit z method once and it didn't work after a while. It started out working but after turning a few times it started doing some really weird stuff. I don't really remember specifics, but I can try again and see.
0 x

dreadwulgaru
Halfling
Posts: 41
Joined: Sun May 20, 2007 4:09 am

Re: Getting Vector3 from Quaternion?

Post by dreadwulgaru » Sat May 29, 2010 10:11 pm

i tried doing what you said with the velocity vector and it worked! thanks :)
0 x

bunnii
Gnoblar
Posts: 1
Joined: Mon Oct 24, 2011 12:46 pm

Re: [Solved]Getting Vector3 from Quaternion?

Post by bunnii » Mon Oct 24, 2011 12:49 pm

Well that was not quite what I was looking for but it pointed me in the right direction,
my script works now so I never have to look at a wall in the way of my person again :lol: well hopefully.
0 x

Post Reply