Archived

This topic is now archived and is closed to further replies.

Extracting a direction from a Quaternion

This topic is 5014 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

OK Here is my problem. I am using a Quaternion to store the rotation of my model. I rotateting using the following method
	/**
	 * Rotates _currentRotation Quaternion around an axis and an angle
	 * @param angle
	 * @param rotationAxis
	 */
	public void rotate(float angle,Vector3 rotationAxis){
		
		Quaternion	key_quat,		
					temp_quat;		// temp quaternion

		
		//create new Quat from axis and angle

		key_quat = new Quaternion(rotationAxis,angle);	
		
		temp_quat = _currentRotation;				
		_currentRotation = temp_quat.mult(key_quat);		
		
	}

I want the direction in a vector.,because I need it as velocity so I can increment my position, in the correct direction.
	public void simulate(float dt) {
	
		
		_velocity._x += (_force._x/_m) *dt;
		_velocity._y += (_force._y/_m) *dt;
		_velocity._z += (_force._z/_m) *dt;


		_position._x += _velocity._x *dt;
		_position._y += _velocity._y *dt;
		_position._z += _velocity._z *dt;
		
		
	}

Share this post


Link to post
Share on other sites
simply take a vector that is suppose to be the forward direction of the vehicle, when no orientation is applied (like (0, 0, 1)), and multiply it by the quaternion.

Dir = Vector(0, 0, 1) * Quat;

Share this post


Link to post
Share on other sites
humm

Well I have drawn the damn velocity vector just to see it. It works when I DONT rotate :-)


//My quat is init like this

protected Quaternion _currentRotation = new Quaternion(0,0,0,1);

//I create this to make sure its rotated towards forward

this._currentRotation = Quaternion.mulVectorWithQuaternion(xVector,_currentRotation,null);


//this is my multvectorwith Quat code

/**
* multiply a vector and a quaternion , if dest is null it creates a new vector
* @param v
* @param q
* @param dest
* @return
*/

public static final Quaternion mulVectorWithQuaternion(Vector3 v,Quaternion q,Quaternion dest){
if(dest==null)
dest= new Quaternion(0,0,0,1);

dest._w =-(q._x*v._x + q._y*v._y + q._z*v._z);
dest._x = q._w*v._x + q._z*v._y - q._y*v._z;
dest._y = q._w*v._y + q._x*v._z - q._z*v._x;
dest._z = q._w*v._z + q._y*v._x - q._x*v._y;

return dest;


}



Share this post


Link to post
Share on other sites