Line data Source code
1 : /**
2 : * @file ModelGameObject.h
3 : * @brief A game object represented by a model.
4 : *
5 : * Game object model.
6 : */
7 : #ifndef _MODEL_GAME_OBJECT_H_
8 : #define _MODEL_GAME_OBJECT_H_
9 :
10 : #include <GL/glut.h>
11 : #include <map>
12 : #include <string>
13 :
14 : #include "Object.h"
15 :
16 : class Terrain;
17 :
18 : struct Triangle {
19 : GLuint vertices[3]; // index into model's vertex array
20 : GLfloat colors[3][3]; // [vertex][rgb]
21 : };
22 :
23 : struct Edge {
24 : int vertices[2];
25 : int triangleIndex[2];
26 : };
27 :
28 : struct TransformedEdge {
29 : Vector p1, p2;
30 : };
31 :
32 : struct ModelStorage {
33 : GLuint numVertices; // number of vertices in the model
34 : GLuint numTriangles; // number of triangles in the model
35 : GLfloat initalScale; // the scaleFactor that was used to scale the vertices
36 : GLfloat** baseVertex; // list of base vertices ( not transformed )
37 : Vector* normal; // list of normals that comprise the model
38 : Triangle* triangle;
39 :
40 : void load(char[]);
41 : };
42 :
43 : class ModelGameObject : public Object {
44 : public:
45 : ModelGameObject();
46 : virtual ~ModelGameObject();
47 : void load(std::string);
48 : void unload(void);
49 :
50 : // overridden virtual functions ////////////
51 : virtual void draw(Object*) override;
52 : virtual void drawOutline(Object*) override;
53 : virtual void drawShadow (Vector*) override;
54 :
55 : virtual void handleCollision(Object*) override;
56 :
57 : virtual void update(Vector*) override;
58 : virtual void animate(const float&, Object*) override;
59 :
60 : virtual void orientOnTerrain(Terrain *temp, const Quaternion &baseRotation) override;
61 : virtual void setHeightFromTerrain(Terrain *temp, const float &offset) override;
62 :
63 0 : virtual void printTypeName() override {}
64 : ///////////////////////////////////////////
65 :
66 : void buildEdges();
67 :
68 : static std::map <std::string, ModelStorage*> modelHash;
69 :
70 : protected:
71 : std::string modelKey_;
72 :
73 : // transformed data //
74 : GLfloat *lightIntensity; // light intensity due to each normal, updated per cycle
75 : GLfloat **updatedVertex; // list of vertices that comprise the model
76 :
77 : // TODO: Determine if this data is included for shadows (which is not fully
78 : // implemented).
79 : int numEdges;
80 : Edge *edges;
81 :
82 : TransformedEdge *sEdge;
83 : int numSEdge;
84 : };
85 : #endif
|