Пример #1
0
void ModelClass::CalculateTangentBinormal(TempVertexType vt1, TempVertexType vt2, TempVertexType vt3, VectorType &tangent, VectorType &binormal)
{
	float vec1[3], vec2[3];
	float tuVec[2], tvVec[2];
	float den;
	float length;

	vec1[0] = vt2.pos_x - vt1.pos_x;
	vec1[1] = vt2.pos_y - vt2.pos_y;
	vec1[2] = vt2.pos_z - vt1.pos_z;

	vec2[0] = vt3.pos_x - vt1.pos_x;
	vec2[1] = vt3.pos_y - vt1.pos_y;
	vec2[2] = vt3.pos_z - vt1.pos_z;

	tuVec[0] = vt2.tex_u - vt1.tex_u;
	tvVec[0] = vt2.tex_v - vt1.tex_v;

	tuVec[1] = vt3.tex_u - vt1.tex_u;
	tvVec[1] = vt3.tex_v - vt1.tex_v;

	den = 1.0f / (tuVec[0] * tvVec[1] - tuVec[1] * tvVec[0]);

	tangent.x = (tvVec[1] * vec1[0] - tvVec[0] * vec2[0]) * den;
	tangent.y = (tvVec[1] * vec1[1] - tvVec[0] * vec2[1]) *den;
	tangent.z = (tvVec[1] * vec1[2] - tvVec[0] * vec2[2]) *den;

	binormal.x = (tuVec[0] * vec2[0] - tuVec[1] * vec1[0]) * den;
	binormal.y = (tuVec[0] * vec2[1] - tuVec[1] * vec1[1])*den;
	binormal.z = (tuVec[0] * vec2[2] - tuVec[1] * vec1[2])*den;

	normalizeVertex(tangent);
	normalizeVertex(binormal);
}
Пример #2
0
void ModelClass::CalculateNormal(VectorType tangent, VectorType binormal, VectorType &normal)
{
	float length;

	normal.x = tangent.y*binormal.z - tangent.z*binormal.y;
	normal.y = tangent.z*binormal.x - tangent.x*binormal.z;
	normal.z = tangent.x*binormal.y - tangent.y*binormal.x;

	normalizeVertex(normal);
}
Пример #3
0
 void Mesh::end()
 {
   switch ((m_blocks.end()-1)->normal) {
   case VERTEX:
     normalizeVertex(*(m_blocks.end()-1));
     break;
   case FACE:
     normalizeFaces(*(m_blocks.end()-1));
     break;
   default:
     break;
   }
 }