/* BaseMeshVertexModifiers.cpp Written by Matthew Fisher BaseMesh is an abstract mesh class that defines basic mesh functionality. It also includes source for most of the manipulation (shape generation, file loading, etc.) that is possible under this generic structure. Each mesh must be associated with a graphics device before most operations can be performed. Because there are so many associated functions, they are grouped into various files. BaseMeshVertexModifiers.cpp contains all the vertex coloring, texturing, and transformation functions. */ Vec3f BaseMesh::EvaluateBarycentricPos(UINT FaceIndex, float u, float v) const { const MeshVertex *V = Vertices(); const DWORD *I = Indices(); Vec3f V0 = V[I[FaceIndex * 3 + 0]].Pos; Vec3f V1 = V[I[FaceIndex * 3 + 1]].Pos; Vec3f V2 = V[I[FaceIndex * 3 + 2]].Pos; return V0 + u * (V1 - V0) + v * (V2 - V0); } void BaseMesh::SetColor(RGBColor Color) { MeshVertex *V = Vertices(); UINT vc = VertexCount(); // // rgba to bgra // Color = Color.FlipBlueAndRed(); for(UINT i = 0; i < vc; i++) { V[i].Color = Color; } } void BaseMesh::SetAlpha(BYTE Alpha) { MeshVertex *V = Vertices(); UINT vc = VertexCount(); for(UINT i = 0; i < vc; i++) { V[i].Color.a = Alpha; } } void BaseMesh::RandomizeColors() { int i,vc=VertexCount(); MeshVertex *V = Vertices(); for(i=0;i r) r = g; if(b > r) r = b; } else { r = (r + g + b) / 3; //merge the 3 values into one value via some method } V[i].Color = RGBColor(r / 255.0f * Vec3f(Color)); } } void BaseMesh::SetRadius(float Size) { Stretch(Size / Radius()); } void BaseMesh::Stretch(float ScaleFactor) { Stretch(Vec3f(ScaleFactor, ScaleFactor, ScaleFactor)); } void BaseMesh::Stretch(const Vec3f &v) { UINT vc = VertexCount(); MeshVertex *V = Vertices(); for(UINT i = 0; i < vc; i++) { V[i].Pos.x *= v.x; V[i].Pos.y *= v.y; V[i].Pos.z *= v.z; } } void BaseMesh::Translate(const Vec3f &v) { UINT vc = VertexCount(); MeshVertex *V = Vertices(); for(UINT i = 0; i < vc; i++) { V[i].Pos += v; } } void BaseMesh::ApplyMatrix(const Matrix4 &M) { UINT vc = VertexCount(); MeshVertex *V = Vertices(); for(UINT i = 0; i < vc; i++) { V[i].Pos = M.TransformPoint(V[i].Pos); V[i].Normal = M.TransformNormal(V[i].Normal); } } void BaseMesh::TextureMapToNormals(int variable) { int i,vc = VertexCount(); MeshVertex *V = Vertices(); //remap the normals into texture coordinates //there are three normal components (x, y, z) and only two texture coordinates (x, y), //so variable tells us which normal component not to map. for(i=0;i