mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Planet.cpp
Go to the documentation of this file.
1 
6 #include "Planet.h"
7 #include "Shapes.h"
8 #include "Textures.h"
9 #include "ColorConstants.h"
10 
12 
18 Planet::Planet( float planetRadius, float crashRadius, GLuint textureName )
19 : SpinningObject( ),
20 QuadricObject( textureName ),
21 GameObject( ),
22 GraphicsObject( crashRadius ) {
23  m_planetRadius = planetRadius;
24  m_rotateAngle = 0;
25  m_rotateSpeed = 0;
26  m_drawRadiusLine = false;
27 }
28 
30 
36 Planet::Planet( float x, float y, float z, float bothRadiuses, GLuint textureName )
37 : SpinningObject( x, y, z ),
38 QuadricObject( textureName ),
39 GameObject( x, y, z ),
40 GraphicsObject( bothRadiuses ) {
41  m_planetRadius = bothRadiuses;
42  m_rotateAngle = 0;
43  m_drawRadiusLine = false;
44 }
45 
47 
53 Planet::Planet( float x, float y, float z, float planetRadius, float crashRadius, GLuint textureName )
54 : SpinningObject( x, y, z ),
55 QuadricObject( textureName ),
56 GameObject( x, y, z ),
57 GraphicsObject( crashRadius ) {
58  m_planetRadius = planetRadius;
59 }
60 
65 }
66 
68 
76 GLvoid Planet::draw() {
78  glColor4f( getColor().x, getColor().y, getColor().z, getColor().a );
79 
80  glPushMatrix();
81  glRotatef( m_rotateAngle, 0.0, 1.0, 0.0 ); // rotation about a certain angle --> startposition
82  glRotatef( (glutGet(GLUT_ELAPSED_TIME)*m_rotateSpeed * 0.001), 0.0, 1.0, 0.0 ); // jahresdrehung
83  //Vector3 pos1 = Vector3( getPos().x, getPos().y, getPos().z );
85  Vector3 pos = pos2;
86  glTranslatef( pos.x, pos.y, pos.z );// translate to supposed position
87  this->spin();// spin the planet
88  glRotatef( -90, 1.0, 0.0, 0.0 );// rotate because the planet should run xz-space
89 
90  // this is not perfect, object is created everytime it's drawn
91  GLUquadricObj *quadObj = gluNewQuadric();
92  gluQuadricDrawStyle( quadObj, GLU_FILL );
93  gluQuadricTexture( quadObj, GL_TRUE );
94  gluSphere( quadObj, m_planetRadius, 32, 32 );
95  gluDeleteQuadric( quadObj );
96  glPopMatrix();
97 
98  // try to draw radius line
99  if( m_drawRadiusLine ) {
100  glPushMatrix();
101  glRotatef( -90, 1.0, 0.0, 0.0 );
103  Shapes::drawCircleShape(0, 0, 0, 300, radius, colorWhite );
104  glPopMatrix();
105  }
106 }
107 
109 
113  GLfloat m[4][4];// define memory space for a single matrix
114  glPushMatrix();
115  glLoadIdentity();
116  glRotatef( m_rotateAngle, 0.0, 1.0, 0.0 ); // rotation about a certain angle --> startposition
117  glRotatef( (glutGet(GLUT_ELAPSED_TIME)*m_rotateSpeed * 0.001), 0.0, 1.0, 0.0 ); // jahresdrehung
118  //Vector3 pos1 = Vector3( getPos().x, getPos().y, getPos().z );
120  Vector3 pos = pos2;
121  glTranslatef( pos.x, pos.y, pos.z );// translate to supposed position
122  this->spin();// spin the planet
123  glGetFloatv( GL_MODELVIEW_MATRIX, &m[0][0] );// get the matrix
124  glPopMatrix();
125  // the vector is (0,0,0,1) and therefore we can directly access the needed values!
126  // the components in the 4th column are used as the 4th component of the vector contains the only non-zero-value
127  Vector3 actPos( m[3][0], m[3][1], m[3][2] );
128 
129  return actPos;
130 }
131 
132 
136 float Planet::getRotateSpeed( void ) {
137  return m_rotateSpeed;
138 }
139 
141 
146 void Planet::setRotateAngle( float angle ) {
147  m_rotateAngle = angle;
148 }
149 
154 void Planet::setRotateSpeed( float speed ) {
155  m_rotateSpeed = speed;
156 }
157 
162 void Planet::setRadiusLineDrawing( bool draw ) {
163  m_drawRadiusLine = draw;
164 }