bool ModelClass::CalculateBNT(ID3D11Device* device) { if(!m_vertexBuffer) { return false; } for(int i=0; i < m_vertexCount; i+=3) { CalculateTangentBinormal(i, i+1, i+2); CalculateNormal(i, i+1, i+2); } InitializeBuffers(device); return true; }
void ModelClass::CalculateModelVectors() { int faceCount, index; TempVertexType vertex[3]; XMFLOAT3 tangent, binormal, normal; faceCount = mVertexCount / 3; index = 0; for (int i = 0; i < faceCount; ++i) { for (int z = 0; z < 3; ++z) { vertex[z].x = mModel[index].x; vertex[z].y = mModel[index].y; vertex[z].z = mModel[index].z; vertex[z].tu = mModel[index].tu; vertex[z].tv = mModel[index].tv; vertex[z].nx = mModel[index].nx; vertex[z].ny = mModel[index].ny; vertex[z].nz = mModel[index].nz; ++index; } CalculateTangentBinormal(vertex[0], vertex[1], vertex[2], tangent, binormal); CalculateNormal(tangent, binormal, normal); for (int z = 0; z < 3; ++z) { mModel[index - 1 - z].nx = normal.x; mModel[index - 1 - z].ny = normal.y; mModel[index - 1 - z].nz = normal.z; mModel[index - 1 - z].tx = tangent.x; mModel[index - 1 - z].ty = tangent.y; mModel[index - 1 - z].tz = tangent.z; mModel[index - 1 - z].bx = binormal.x; mModel[index - 1 - z].by = binormal.y; mModel[index - 1 - z].bz = binormal.z; } } }
void ModelClass::CalculateModelVectors() { int faceCount, i, index; TempVertexType vertex1, vertex2, vertex3; VectorType tangent, binormal, normal; faceCount = m_vertexCount / 3; index = 0; for (i = 0; i != faceCount; ++i) { loadStruct(vertex1, m_Model, index++); loadStruct(vertex2, m_Model, index++); loadStruct(vertex3, m_Model, index++); CalculateTangentBinormal(vertex1, vertex2, vertex3, tangent, binormal); CalculateNormal(tangent, binormal, normal); loadModel(m_Model, index, tangent, binormal, normal); } }
void BumpModelClass::CalculateModelVectors() { int faceCount, i, index; TempVertexType vertex1, vertex2, vertex3; VectorType tangent, binormal; // Calculate the number of faces in the model. faceCount = m_vertexCount / 3; // Initialize the index to the model data. index = 0; // Go through all the faces and calculate the the tangent, binormal, and normal vectors. for(i=0; i<faceCount; i++) { // Get the three vertices for this face from the model. vertex1.x = m_model[index].x; vertex1.y = m_model[index].y; vertex1.z = m_model[index].z; vertex1.tu = m_model[index].tu; vertex1.tv = m_model[index].tv; vertex1.nx = m_model[index].nx; vertex1.ny = m_model[index].ny; vertex1.nz = m_model[index].nz; index++; vertex2.x = m_model[index].x; vertex2.y = m_model[index].y; vertex2.z = m_model[index].z; vertex2.tu = m_model[index].tu; vertex2.tv = m_model[index].tv; vertex2.nx = m_model[index].nx; vertex2.ny = m_model[index].ny; vertex2.nz = m_model[index].nz; index++; vertex3.x = m_model[index].x; vertex3.y = m_model[index].y; vertex3.z = m_model[index].z; vertex3.tu = m_model[index].tu; vertex3.tv = m_model[index].tv; vertex3.nx = m_model[index].nx; vertex3.ny = m_model[index].ny; vertex3.nz = m_model[index].nz; index++; // Calculate the tangent and binormal of that face. CalculateTangentBinormal(vertex1, vertex2, vertex3, tangent, binormal); // Store the tangent and binormal for this face back in the model structure. m_model[index-1].tx = tangent.x; m_model[index-1].ty = tangent.y; m_model[index-1].tz = tangent.z; m_model[index-1].bx = binormal.x; m_model[index-1].by = binormal.y; m_model[index-1].bz = binormal.z; m_model[index-2].tx = tangent.x; m_model[index-2].ty = tangent.y; m_model[index-2].tz = tangent.z; m_model[index-2].bx = binormal.x; m_model[index-2].by = binormal.y; m_model[index-2].bz = binormal.z; m_model[index-3].tx = tangent.x; m_model[index-3].ty = tangent.y; m_model[index-3].tz = tangent.z; m_model[index-3].bx = binormal.x; m_model[index-3].by = binormal.y; m_model[index-3].bz = binormal.z; } return; }