public :
Mesh3D ( const char * theName = "" );
Mesh3D ( const char * theName, Vector3D * theVertices, Vector3D * theNormals, int theNumVertices, Vector2D * theTexCoords, int theNumTexCoords, Face * theFaces, int theNumFaces, Texture * theTexture, Vector4D * theColors = NULL );
~Mesh3D ();
virtual bool isOk () const
return vertices != NULL && faces != NULL;
const BoundingBoxS getBoundingBox () const return boundingBox;
const Vector3D * getVertices () const {
return vertices;
int getNumVertices () const return numVertices;
void setTexture ( Texture * theTexture ),-void draw ( Views view, const Cameras camera,
const Vector4D& color, Fog * fog. Texture * txt = NULL, bool transparent = false ) const; void apply ( const Transform3D& );
void computeNormals (); void buildBoundingBox () ;
static MetaClass classlnstance;
protected:
void rebuildFaces ( Face * theFaces, Vector2D *
theTexCoords, int nTexCoords );
} ;

Метод computeNormals служит для вычисления значений нормалей в вершинах модели. Для этого сперва вычисляются значения вектора нормали для каждой грани модели (как векторное произведение ребер), а затем для каждой вершины находится сумма нормалей граней, проходящих через эту вершину, и значением нормали в вершине становится эта нормированная сумма.

Добавляем модели

'9
void Mesh3D :: computeNormals () {
Vector3D normal, v [3];
if ( normals != NULL ) // reallocate normals delete normals;
normals = new Vector3D [numVertices];
// face normals Vector 3D * tempNormals = new Vector3D [numFaces] ,-
// process all faces of mesh
for ( int i = 0; i < numFaces; i++ ) {
// extract the 3 points of this face v [0] = vertices [faces [i].index [0]] v [1] = vertices [faces [i].index [1]] v [2] = vertices [faces [i].index [2]]
// compute face normal normal = (v [2] -v [0]) " (v [2] -v [1]);
tempNormals [i] = normal.normalize ();

⇐ Предыдущая| |Следующая ⇒