67 #ifndef _graphicsproceduralvertexnormalsmodifier_cpp
68 #define _graphicsproceduralvertexnormalsmodifier_cpp
70 #include "Graphics/Procedural/Mesh/vertexnormalsmodifier.h"
94 for(
Whole Index = 0 ; Index < Indices.size() ; Index += 3 )
96 Vector3 v1 = Vertices[Indices[Index]].Position;
97 Vector3 v2 = Vertices[Indices[Index+1]].Position;
98 Vector3 v3 = Vertices[Indices[Index+2]].Position;
100 Vertices[Indices[Index]].Normal = VertNormal;
101 Vertices[Indices[Index+1]].Normal = VertNormal;
102 Vertices[Indices[Index+2]].Normal = VertNormal;
105 std::vector< std::vector<Vector3> > TempNormals;
106 TempNormals.resize(Vertices.size());
107 for(
Whole Index = 0 ; Index < Indices.size() ; Index += 3 )
109 Vector3 v1 = Vertices[Indices[Index]].Position;
110 Vector3 v2 = Vertices[Indices[Index+1]].Position;
111 Vector3 v3 = Vertices[Indices[Index+2]].Position;
112 Vector3 VertNormal = (v2-v1).CrossProduct(v3-v1);
113 TempNormals[Indices[Index]].push_back(VertNormal);
114 TempNormals[Indices[Index+1]].push_back(VertNormal);
115 TempNormals[Indices[Index+2]].push_back(VertNormal);
117 for(
Whole CurrVertex = 0 ; CurrVertex < Vertices.size() ; ++CurrVertex )
119 Vector3 VertNormal(0.0,0.0,0.0);
120 for(
Whole CurrNormal = 0 ; CurrNormal < TempNormals[CurrVertex].size() ; ++CurrNormal )
122 VertNormal += TempNormals[CurrVertex][CurrNormal];
124 Vertices[CurrVertex].Normal = VertNormal.
GetNormal();
130 {
return "VertexNormalsModifier"; }
std::vector< Vertex > VertexContainer
Basic container type for Vertex storage.
IndexContainer & GetIndices()
Gets a modifiable reference to Indices.
ComputeMode
An enum used to determine how normals are calculated.
Vector3 GetNormal() const
This returns the normal for this relative to the origin.
A convenience buffer that stores vertices and indices of a mesh to be generated.
ComputeMode Compute
The mode in which normals are calculated for each vertex.
VertexContainer & GetVertices()
Gets a modifiable reference to Vertices.
virtual String GetName() const
Gets the name of this modifier.
std::vector< Integer > IndexContainer
A container of Integers used to represent the indicies of a shape.
VertexNormalsModifier & SetComputerMode(const VertexNormalsModifier::ComputeMode Mode)
Sets how the normals for each vertex is to be calculated.
The normal for each vertex is the average of the normals for each triangle it belongs to...
VertexNormalsModifier()
Blank constructor.
The normal for each vertex is the same as the normal for the last triangle it belongs to...
virtual ~VertexNormalsModifier()
Class destructor.
This is used to represent a point in space, or a vector through space.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
virtual void Modify(TriangleBuffer &Buffer)
Alters the generated pixels in a TriangleBuffer.
std::string String
A datatype used to a series of characters.