source: GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.h @ 2642

Revision 2642, 3.6 KB checked in by mattausch, 17 years ago (diff)

new demo

Line 
1#ifndef GEOMETRY_H
2#define GEOMETRY_H
3
4extern "C"
5{
6        #include "MathStuff.h"
7}
8
9/** Represents a drawable geometry. It can draw simple objects (teapot,
10        torus, shere. It also contains the object transformation and
11        the material .An AAB is used as bouning volume.
12*/
13class Geometry
14{
15public:
16        Geometry();
17        Geometry(Vector3 translation, float xRot, float yRot, float zRot, float scale, int objectType);
18        //! renders this geometry
19        void Render();
20       
21        //! sets rotations in degree : executed in the order x, y, and z rotation
22        void SetRotations(float xRot, float yRot, float zRot);
23        //! sets the rotation matrix
24        void SetTranslation(Vector3 translation);
25        //! a uniform scale
26        void SetScale(float scale);
27        //! returns current scale
28        float GetScale();
29
30        //! returns translation
31        void GetTranslation(Vector3 translation);
32        //! returns rotation
33        void GetRotations(float &xRot, float &yRot, float &zRot);
34
35        // --- material settings
36        void SetAmbientColor(float ambientR,   float ambientG,  float ambientB);
37        void SetDiffuseColor(float diffuseR,   float diffuseG,  float diffuseB);
38        void SetSpecularColor(float specularR, float specularG, float specularB);
39
40        const AABox& GetBoundingVolume();
41               
42        //! last visited flag, important for rendering each geometry only once
43        void SetLastVisited(int lastVisited);
44        //! returns lastvisited flag
45        int GetLastVisited();
46
47        // --- sets the object type to one of teapot, torus, sphere
48        void SetObjectType(int type);
49
50        enum{TEAPOT, TORUS, SPHERE, NUM_OBJECTS};
51       
52        static int sDisplayList[NUM_OBJECTS];
53       
54        //! cleans static members
55        static void CleanUp();
56        //! returns the triangle count of the specified object type
57        static int CountTriangles(int objectType);
58        //! initialises display lists
59        static void ResetLists();
60
61protected:
62        //! generates the display list this a object
63        void GenerateList();
64
65        //! calculates accumulated transformation matrix
66        void CalcTransform();
67        //! applies tranformations
68        void Transform();
69
70        // --- statistics
71        static int CountTorusTriangles();
72        static int CountSphereTriangles();
73        static int CountTeapotTriangles();
74
75        //!
76        static void CreateTorus(float innerRadius, float outerRadius, int precision);
77
78        //! calculates the bounding volume of this geometry
79        void CalcBoundingVolume();
80        // the size of the bounging box is calculated using the radius of the sphere
81        void CalcSphereBoundingVolume();
82        // the standard bounding volume calculation having an array of vertices
83        void CalcBoundingVolume(float *vertices, const int num_vertices);
84
85        // initialises static members
86        static bool Init();
87
88        // --- drawing routines
89        static void RenderTeapot();
90        static void RenderSphere();
91        static void RenderTorus();
92
93        // --- transformations
94        float mXRotation;
95        float mYRotation;
96        float mZRotation;
97       
98        float mScale;
99
100        Vector3 mTranslation;
101       
102        //! accumulated transform matrix
103        Matrix4x4 mTransform;
104
105        // --- material
106        float mAmbientColor[3];
107        float mDiffuseColor[3];
108        float mSpecularColor[3];
109
110        AABox mBoundingBox;
111        //! type of the rendered object (teapot, sphere ...)
112        int mObjectType;
113       
114        int mLastVisited;
115
116        // --- static members
117
118        static bool sIsInitialised;
119
120        static float const sphere_radius;
121       
122        static int num_torus_indices;
123        static int num_torus_vertices;
124        static int num_torus_normals;
125
126        static float *torus_vertices;
127        static float *torus_normals;
128        static int *torus_indices;
129
130        static const int torus_precision;
131        static const int sphere_precision;
132        static const float torus_inner_radius;
133        static const float torus_outer_radius;
134};
135
136
137#endif // GEOMETRY_H
Note: See TracBrowser for help on using the repository browser.