예제 #1
0
///////////////////////////////////////////////////////////////////////////////////////////////////
// Calculate the tangent basis for a triangle on the surface of a model
// This vector is needed for most normal mapping shaders 
void m3dCalculateTangentBasis(M3DVector3f vTangent, const M3DVector3f vTriangle[3], const M3DVector2f vTexCoords[3], const M3DVector3f N)
{
	M3DVector3f dv2v1, dv3v1;
	float dc2c1t, dc2c1b, dc3c1t, dc3c1b;
	float M;
	
	m3dSubtractVectors3(dv2v1, vTriangle[1], vTriangle[0]);
	m3dSubtractVectors3(dv3v1, vTriangle[2], vTriangle[0]);
	
	dc2c1t = vTexCoords[1][0] - vTexCoords[0][0];
	dc2c1b = vTexCoords[1][1] - vTexCoords[0][1];
	dc3c1t = vTexCoords[2][0] - vTexCoords[0][0];
	dc3c1b = vTexCoords[2][1] - vTexCoords[0][1];
	
	M = (dc2c1t * dc3c1b) - (dc3c1t * dc2c1b);
	M = 1.0f / M;
	
	m3dScaleVector3(dv2v1, dc3c1b);
	m3dScaleVector3(dv3v1, dc2c1b);
	
	m3dSubtractVectors3(vTangent, dv2v1, dv3v1);
	m3dScaleVector3(vTangent, M);  // This potentially changes the direction of the vector
	m3dNormalizeVector3(vTangent);

	M3DVector3f B;
	m3dCrossProduct3(B, N, vTangent);
	m3dCrossProduct3(vTangent, B, N);
	m3dNormalizeVector3(vTangent);
	}
예제 #2
0
void SetUpFrame(GLFrame &frame,const M3DVector3f origin, const M3DVector3f forward, const M3DVector3f up) {
	frame.SetOrigin(origin);
	frame.SetForwardVector(forward);
	M3DVector3f side,oUp;
	m3dCrossProduct3(side,forward,up);
	m3dCrossProduct3(oUp,side,forward);
	frame.SetUpVector(oUp);
	frame.Normalize();
}
예제 #3
0
void SetUpFrame(GLFrame &cameraFrame,const M3DVector3f origin,
				const M3DVector3f forward,
				const M3DVector3f cameraUpDirection) {
					cameraFrame.SetOrigin(origin);
					cameraFrame.SetForwardVector(forward);
	M3DVector3f side,oUp;
	m3dCrossProduct3(side,forward,cameraUpDirection);
	m3dCrossProduct3(oUp,side,forward);
	cameraFrame.SetUpVector(oUp);
	cameraFrame.Normalize();
};
예제 #4
0
void normal(float result[], const float A[], const float B[], const float C[]) {
   float C_min_B[3], A_min_B[3];
   m3dSubtractVectors3(C_min_B, C, B);
   m3dSubtractVectors3(A_min_B, A, B);
   m3dCrossProduct3(result, C_min_B, A_min_B);
   m3dNormalizeVector3(result);
}
예제 #5
0
//----------------------------------------------------
void TriangleFace(M3DVector3f a, M3DVector3f b, M3DVector3f c) {
   M3DVector3f normal, bMa, cMa;
   m3dSubtractVectors3(bMa, b, a);
   m3dSubtractVectors3(cMa, c, a);
   m3dCrossProduct3(normal, bMa, cMa);
   m3dNormalizeVector3(normal);
   glVertexAttrib3fv(GLT_ATTRIBUTE_NORMAL, normal);
   glVertex3fv(a);
   glVertex3fv(b);
   glVertex3fv(c);
}
예제 #6
0
void Camerak::strafeRight(){
	
	M3DVector3f temp,fwd,up,right;
	Vec3 thisMove;
	cam.GetOrigin(temp);
	lastPos.fromM3D(temp);
	cam.GetForwardVector(fwd);
	cam.GetUpVector(up);
	m3dCrossProduct3(right,fwd,up);
	thisMove.fromM3D(right);
	thisMove*= movement_rate;
	move+=thisMove;
}
예제 #7
0
// Ditto above, but for doubles
void m3dFindNormal(M3DVector3d result, const M3DVector3d point1, const M3DVector3d point2, 
							const M3DVector3d point3)
	{
	M3DVector3d v1,v2;		// Temporary vectors

	// Calculate two vectors from the three points. Assumes counter clockwise
	// winding!
	v1[0] = point1[0] - point2[0];
	v1[1] = point1[1] - point2[1];
	v1[2] = point1[2] - point2[2];

	v2[0] = point2[0] - point3[0];
	v2[1] = point2[1] - point3[1];
	v2[2] = point2[2] - point3[2];

	// Take the cross product of the two vectors to get
	// the normal vector.
	m3dCrossProduct3(result, v1, v2);
	}
예제 #8
0
// Ditto above, but for doubles
void m3dGetPlaneEquation(M3DVector4d planeEq, const M3DVector3d p1, const M3DVector3d p2, const M3DVector3d p3)
{
	// Get two vectors... do the cross product
	M3DVector3d v1, v2;

	// V1 = p3 - p1
	v1[0] = p3[0] - p1[0];
	v1[1] = p3[1] - p1[1];
	v1[2] = p3[2] - p1[2];

	// V2 = P2 - p1
	v2[0] = p2[0] - p1[0];
	v2[1] = p2[1] - p1[1];
	v2[2] = p2[2] - p1[2];

	// Unit normal to plane - Not sure which is the best way here
	m3dCrossProduct3(planeEq, v1, v2);
	m3dNormalizeVector3(planeEq);
	// Back substitute to get D
	planeEq[3] = -(planeEq[0] * p3[0] + planeEq[1] * p3[1] + planeEq[2] * p3[2]);
}
예제 #9
0
파일: main.cpp 프로젝트: wdlove58/WcgCube
void MouseMoveEvent(int x, int y)
{

	if (isStartTrackBall)
	{
		GLfloat theta;
		M3DVector3f p1, p2, n;
		int width = glutGet(GLUT_WINDOW_WIDTH);
		int height = glutGet(GLUT_WINDOW_HEIGHT);

		MousePtToSphereVec(p1, mMouseX, mMouseY, width, height);
		MousePtToSphereVec(p2, x, y, width, height);

		mMouseX = x;
		mMouseY = y;

		m3dNormalizeVector3(p1);
		m3dNormalizeVector3(p2);
		theta = acos(m3dDotProduct3(p1, p2)) ;

		//theta = m3dGetAngleBetweenVectors3(p1, p2);

		m3dCrossProduct3(n, p1, p2);
		m3dNormalizeVector3(n);

		M3DMatrix44f tempRotation;
		m3dLoadIdentity44(tempRotation);
		GLfloat dis = m3dGetDistance3(p1, p2);
		if (dis != 0.0f)
		{
			m3dRotationMatrix44(tempRotation, theta, m3dGetVectorX(n), m3dGetVectorY(n), m3dGetVectorZ(n));
		}
		m3dMatrixMultiply44(mRotation, tempRotation, mRotation);

		glutPostRedisplay();

		
	}
	
}