Ejemplo n.º 1
0
// Up is along the positive Y axis (vUp in global coordinates)
// Forward is along the NEGATIVE Z axis (negative, remember! Its the opengl standard, its what the camera uses, and so it can be what objects use)
// Right is along the positive X axis.
void mlMatrixUtility::MatrixFromDirection(mlMatrix3x3 & result, const mlVector3D & vForward, const mlVector3D & vUp)
{
	// This produces an identity matrix when vForward is along the Z axis, and vUp is along the Y axis.
	// Alternative - an identity matrix when vForward is along the -ve Z axis, and vUp is along the Y axis.

	// Compute our new look at vector, which will be
	//   the new negative Z axis of our transformed object.
	result.K = vForward;
	result.K.Normalise();

	// Cross product of the new look at vector and the current
	//   up vector will produce a vector which is the new
	//   positive X axis of our transformed object.
	result.I = mlVectorCross(result.K, vUp);
	//result.I = mlVectorCross(vUp, result.K); // new
	result.I.Normalise();

	// Calculate the new up vector, which will be the
	//   positive Y axis of our transformed object. Note
	//   that it will lie in the same plane as the new
	//   look at vector and the old up vector.
	result.J = mlVectorCross(result.I, result.K);
	//result.J = mlVectorCross(result.K, result.I); // new

	// Account for the fact that the geometry will be defined to
	//   point along the negative Z axis.
	result.K *= -1.0f;
}
Ejemplo n.º 2
0
void mlMatrixUtility::MatrixFromVectorRotation(mlMatrix3x3 & result, const mlVector3D & normalisedVectorA, const mlVector3D & normalisedVectorB)
{
	mlVector3D v = mlVectorCross(normalisedVectorA, normalisedVectorB);
	mlFloat vSquared = v.MagnitudeSquared();

	if (vSquared > mlFloatMin)
	{
		mlFloat e = normalisedVectorA * normalisedVectorB;
		mlFloat h = (1.0f - e) / vSquared;

		result.I.x = e + h * (v.x * v.x);
		result.I.y = h * v.x * v.y + v.z;
		result.I.z = h * v.x * v.z - v.y;
		result.J.x = h * v.x * v.y - v.z;
		result.J.y = e + h * (v.y * v.y);
		result.J.z = h * v.y * v.z + v.x;
		result.K.x = h * v.x * v.z + v.y;
		result.K.y = h * v.y * v.z - v.x;
		result.K.z = e + h * (v.z * v.z);
	}
	else
	{
		result.SetIdentity();
	}
}
Ejemplo n.º 3
0
mlVector3D Face::getNormal()
{
	mlVector3D p1 = v1->getPosition();
	mlVector3D p2 = v2->getPosition();
	mlVector3D p3 = v3->getPosition();
	
	mlVector3D xy = p2 - p1;
	mlVector3D xz = p3 - p1;

	//xy.Normalise();
	//xz.Normalise();
	
	mlVector3D normal = mlVectorCross(xy, xz);
	normal.Normalise();
	
	return normal;
}