source: branches/VUT/0.2/chcdemo/Geometry.h @ 10

Revision 10, 3.5 KB checked in by gametools, 20 years ago (diff)

vienna university of technology first files

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