Exemplo n.º 1
0
MyMatrix MyQuat::convertToRotationMatrix(void) const
{
	MyMatrix result;
	GLfloat rotMatrix[16];

	float xx = this->w * this->w;
	float xy = this->w * this->v.x;
	float xz = this->w * this->v.y;
	float xw = this->w * this->v.z;
	float yy = this->v.x * this->v.x;
	float yz = this->v.x * this->v.y;
	float yw = this->v.x * this->v.z;
	float zz = this->v.y * this->v.y;
	float zw = this->v.y * this->v.z;

	rotMatrix[0] = 1 - 2 * (yy + zz);
	rotMatrix[1] = 2 * (xy - zw);
	rotMatrix[2] = 2 * (xz + yw);
	rotMatrix[4] = 2 * (xy + zw);
	rotMatrix[5] = 1 - 2 * (xx + zz);
	rotMatrix[6] = 2 * (yz - xw);
	rotMatrix[8] = 2 * (xz - yw);
	rotMatrix[9] = 2 * (yz + xw);
	rotMatrix[10] = 1 - 2 * (xx + yy);
	rotMatrix[3] = rotMatrix[7] = rotMatrix[11] = rotMatrix[12] = rotMatrix[13] = rotMatrix[14] = 0;
	rotMatrix[15] = 1;

	result.setMyMatrix(rotMatrix);
	return result;
}