Example #1
0
	Matrix44 MatrixUtils::rotation_axis( const Vector3& axis, float angle )
	{
		Matrix44 res;

		float sin_a = sin(angle);
		float cos_a = cos(angle);

		float omc = 1.0f - cos_a;

		float xomc = axis.x * omc;
		float yomc = axis.y * omc;
		float zomc = axis.z * omc;

		float xxomc = axis.x * xomc;
		float xyomc = axis.x * yomc;
		float xzomc = axis.x * zomc;
		float yyomc = axis.y * yomc;
		float yzomc = axis.y * zomc;
		float zzomc = axis.z * zomc;

		float xs = axis.x * sin_a;
		float ys = axis.y * sin_a;
		float zs = axis.z * sin_a;

		res.m(0,0) = xxomc + cos_a;
		res.m(0,1) = xyomc + zs;
		res.m(0,2) = xzomc - ys;
		res.m(0,3) = 0;

		res.m(1,0) = xyomc - zs;
		res.m(1,1) = yyomc + cos_a;
		res.m(1,2) = yzomc + xs;
		res.m(1,3) = 0;

		res.m(2,0) = xzomc + ys;
		res.m(2,1) = yzomc - xs;
		res.m(2,2) = zzomc + cos_a;
		res.m(2,3) = 0; //-V525

		res.m(3,0) = 0;
		res.m(3,1) = 0;
		res.m(3,2) = 0;
		res.m(3,3) = 1;

		return res;
	}