Чтобы не вычислять значения середин граней каждый раз, удобно их также хранить в отдельном массиве (centers).

Версия класса Mesh3D с учетом всех этим изменений приводится ниже.

class Mesh3D : public Object {
public:
struct Face // triangular face
{
int vertexlndex [3];
// indexes to array of vertices int texCoordlndex [3];
// indexes to array of texture coordinates
};
struct FaceVa // triangular face struct for
// usage with vertex arrays
{
int index [3];
};
private:

struct FaceOrderinglnfо // struct used to keep info

// for ordering transparent // meshes
{
float key; // distance
int index; // facet #
};

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

int numVertices; int numTexCoords;
int numFaces; Vector3D * vertices;
Vector3D * normals;
Vector2D * texCoords;
Vector4D * colors;
FaceVa * faces;
Texture * texture;
BoundingBox boundingBox; Bool smooth; FaceOrderinglnfo * indices;
Vector3D * centers; // faces center poins
Vector4D * tempColors;
// temp array for color values when in
// call to draw color is not ( 1, 1, 1, ) and
// colors array is present
mutable Vector4D cachedColor;
// color for which tempColors is
// computed, declared mutable since it
// can be modified in const method draw
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 BoundingBox& getBoundingBox () const return boundingBox;
const Vector3D * getVertices () const return vertices;
intgetNumVertices () const return numVertices;
void setSmooth ( bool flag ) smooth = flag;
bool getSmooth () const return smooth;
void setTexture ( Texture * theTexture );

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