Ejemplo n.º 1
0
// Inner function to rotate a vector around another vector by angle
Rvector3 Camera::RotateAround(Rvector3 vector, Real angle, Rvector3 axis){
   // Store the old x,y,z values
   Real oldX = vector[0], oldY = vector[1], oldZ = vector[2];
   // Store the cos and sin values, for convenience
   Real c = cos(angle), s = sin(angle);
   // Store the x,y,z values of the axis, for convenience
   axis.Normalize();
   Real x = axis[0], y = axis[1], z = axis[2];
   // Rotate the vector around the axis
   vector.Set((1+(1-c)*(x*x-1))*oldX + (-z*s+(1-c)*x*y)*oldY + (y*s+(1-c)*x*z)*oldZ,
      (z*s+(1-c)*x*y)*oldX + (1+(1-c)*(y*y-1))*oldY + (-x*s+(1-c)*y*z)*oldZ,
      (-y*s+(1-c)*x*z)*oldX + (x*s+(1-c)*y*z)*oldY + (1+(1-c)*(z*z-1))*oldZ);
   // Make sure the direction vectors are still orthogonal to each other
   //ReorthogonalizeVectors();
   return vector;
}
Ejemplo n.º 2
0
//--------------------------------------------------------------------
void SurfaceMesh::BuildNormals ()
// Create the normal vectors for the faces
   {
   for (Integer i=0;  i<=FacesSize-1;  ++i)
      {
      ZFace& face (Faces[i]);
      Rvector3 x = Vectors[face.VertexIndex[0]].WrtBody.ConvertToRvector3();
      Rvector3 y = Vectors[face.VertexIndex[1]].WrtBody.ConvertToRvector3();
      Rvector3 z = Vectors[face.VertexIndex[2]].WrtBody.ConvertToRvector3();
      Rvector3 xy = y-x;
      Rvector3 yz = z-y;
      Rvector3 n = Cross(xy,yz);
      if (n.GetMagnitude() != 0)
         n = n.Normalize();
      int index = MakeVector (n,false);
      for (Integer j=0;  j<=3-1;  ++j)
         face.NormalIndex[j] = index;
      }
   }
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------
bool PolyhedronBody::FaceNormals()
{
	PolygonFace face;
   Rvector3 n;
	Rvector3 r1, r2, A, B, C;

	fn.clear();

	// Create normal vector list based on facesList:
	Real x, y, z;
	for (UnsignedInt i = 0; i < facesList.size(); ++i)
	{
		// Get indices of triangle ith:
		face = facesList[i];
		A.Set(verticesList[face[0]].Get(0), verticesList[face[0]].Get(1), verticesList[face[0]].Get(2));		// vertex A of triangle ABC
		B.Set(verticesList[face[1]].Get(0), verticesList[face[1]].Get(1), verticesList[face[1]].Get(2));		// vertex B of triangle ABC
		C.Set(verticesList[face[2]].Get(0), verticesList[face[2]].Get(1), verticesList[face[2]].Get(2));		// vertex C of triangle ABC
		r1 = B - A;						// vector AB
		r2 = C - B;						// vector BC
		x = r1[1]*r2[2] - r1[2]*r2[1];
		y = r1[2]*r2[0] - r1[0]*r2[2];
		z = r1[0]*r2[1] - r1[1]*r2[0];
      n.Set(x,y,z);		         // n = AB x BC
		if (n.Norm() < 1.0e-15)
			return false;

		n.Normalize();					// normal vector of triangle ABC
		fn.push_back(n);				// add normal vector to the normal vectors list
	}

#ifdef DEBUG_FACENORMALS_CALCULATION
	MessageInterface::ShowMessage("List of normal vectors:\n");
	for (UnsignedInt i = 0; i < fn.size(); ++i)
	{
		MessageInterface::ShowMessage("%.15lf   %.15lf   %.15lf\n", fn[i][0], fn[i][1], fn[i][2]);
	}
#endif
	return true;
}