Example #1
0
void Quaternion::AxisToQuat(const Vector3D &v, const float angle)
{
  //float x,y,z;			// temp vars of vector
	double rad, scale;		// temp vars

	if (v.IsZero())			// if axis is zero, then return quaternion (1,0,0,0)
	{
		w	= 1.0f;
		x	= 0.0f;
		y	= 0.0f;
		z	= 0.0f;

		return;
	}

	assert(v.IsUnit());		// make sure the axis is a unit vector

	rad		= angle / 2;

	w		= (float)cos(rad);

	scale	= sin(rad);

	//v.GetValues(x, y, z);

	this->x = float(v.x * scale);
	this->y = float(v.y * scale);
	this->z = float(v.z * scale);

	Normalize();		// make sure a unit quaternion turns up

	return;
}	// end void AxisToQuat(..)