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
SpaceStation.cpp
Go to the documentation of this file.
1 
6 #include "SpaceStation.h"
7 #include "Plane.h"
8 
10 
17 SpaceStation::SpaceStation( float r, GLuint displayList ) : SpinningObject( ), ModelObject( r, displayList ) {
18 }
19 
21 
28 SpaceStation::SpaceStation( Vector3 position, float r, GLuint displayList ) : SpinningObject( position ), ModelObject( r, displayList ) {
29 }
30 
32 
41 SpaceStation::SpaceStation( float x, float y, float z, float r, GLuint displayList ) : SpinningObject( x, y, z ), ModelObject( r, displayList ) {
42 }
43 
48 
49 }
50 
52  glPushMatrix();
53  glTranslatef( getPos().x, getPos().y, getPos().z );
54  this->spin();
56 
57  // zeichne nur viereck
58  //float factor = 0.01;
59  //glColor3fv( colorRed );
60  //glDisable( GL_TEXTURE_2D );
61  //glBegin( GL_QUADS );
62  //glVertex3f( -10 * factor, 30 * factor, 160 * factor);
63  //glVertex3f( -10 * factor,-30 * factor, 160 * factor);
64  //glVertex3f(10 * factor,-30 * factor, 160 * factor);
65  //glVertex3f(10 * factor, 30 * factor, 160 * factor);
66  //glEnd();
67 
68  glEnable( GL_TEXTURE_2D );
69  glPopMatrix();
70 }
71 
73  float factor = 0.01;
74  Vector3 ant = Vector3( -10*factor,30*factor, 160*factor );
75  Vector3 bnt = Vector3( +10*factor,30*factor, 160*factor );
76  Vector3 cnt = Vector3( -10*factor, -30*factor, 160*factor );
77 
78  GLfloat m[4][4];// define memory space for a single matrix
79  glPushMatrix();
80  glLoadIdentity();
81  glTranslatef( getPos().x, getPos().y, getPos().z );
82  this->spin();
83  glGetFloatv( GL_MODELVIEW_MATRIX, &m[0][0] );// get the matrix
84  glPopMatrix();
85 
86  float vectStart[4];
87  float vectResult[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
88 
89  vectStart[0] = ant.x;
90  vectStart[1] = ant.y;
91  vectStart[2] = ant.z;
92  vectStart[3] = 1.0f;
93  for( int j =0; j<4; j++ ) {
94  float val = 0;
95  for( int i = 0; i<4; i++) {
96  val+= m[i][j] * vectStart[i];
97  }
98  vectResult[j] = val;
99  }
100  Vector3 a = Vector3( vectResult[0], vectResult[1], vectResult[2] );
101 
102  vectStart[0] = bnt.x;
103  vectStart[1] = bnt.y;
104  vectStart[2] = bnt.z;
105  vectStart[3] = 1.0f;
106  for( int j =0; j<4; j++ ) {
107  float val = 0;
108  for( int i = 0; i<4; i++) {
109  val+= m[i][j] * vectStart[i];
110  }
111  vectResult[j] = val;
112  }
113  Vector3 b = Vector3( vectResult[0], vectResult[1], vectResult[2] );
114 
115  vectStart[0] = cnt.x;
116  vectStart[1] = cnt.y;
117  vectStart[2] = cnt.z;
118  vectStart[3] = 1.0f;
119  for( int j =0; j<4; j++ ) {
120  float val = 0;
121  for( int i = 0; i<4; i++) {
122  val+= m[i][j] * vectStart[i];
123  }
124  vectResult[j] = val;
125  }
126  Vector3 c = Vector3( vectResult[0], vectResult[1], vectResult[2] );
127 
128  Plane p = Plane( a, c, b );
129  Vector3 ret = p.getNormal();
130  ret.normalize();
131  return ret;
132 }
133 
135  float factor = 0.01;
136 
137  Vector3 cnt = Vector3( 0,0, 160*factor );
138 
139  GLfloat m[4][4];// define memory space for a single matrix
140  glPushMatrix();
141  glLoadIdentity();
142  glTranslatef( getPos().x, getPos().y, getPos().z );
143  this->spin();
144  glGetFloatv( GL_MODELVIEW_MATRIX, &m[0][0] );// get the matrix
145  glPopMatrix();
146 
147  float vectStart[4];
148  float vectResult[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
149 
150  vectStart[0] = cnt.x;
151  vectStart[1] = cnt.y;
152  vectStart[2] = cnt.z;
153  vectStart[3] = 1.0f;
154  for( int j =0; j<4; j++ ) {
155  float val = 0;
156  for( int i = 0; i<4; i++) {
157  val+= m[i][j] * vectStart[i];
158  }
159  vectResult[j] = val;
160  }
161  Vector3 c = Vector3( vectResult[0], vectResult[1], vectResult[2] );
162 
163  // c is the point in the center of the coriolis station
164 
165  return c + this->getOutVector() * this->getRadius();
166 }
167 
168 bool SpaceStation::test( const Vector3 &position ) {
169  float factor = 0.01;
170  Vector3 ant = Vector3( -10*factor,30*factor, 160*factor );
171  Vector3 bnt = Vector3( +10*factor,30*factor, 160*factor );
172  Vector3 cnt = Vector3( -10*factor, -30*factor, 160*factor );
173  Vector3 dnt = Vector3( +10*factor, -30*factor, 160*factor );
174  Vector3 ant2 = Vector3( -10*factor,30*factor, -160*factor );
175  Vector3 bnt2 = Vector3( +10*factor,30*factor, -160*factor );
176  Vector3 cnt2 = Vector3( -10*factor, -30*factor, -160*factor );
177  //Vector3 dnt2 = Vector3( +10*factor, -30*factor, -160*factor );
178 
179  GLfloat m[4][4];// define memory space for a single matrix
180  glPushMatrix();
181  glLoadIdentity();
182  glTranslatef( getPos().x, getPos().y, getPos().z );
183  this->spin();
184  glGetFloatv( GL_MODELVIEW_MATRIX, &m[0][0] );// get the matrix
185  glPopMatrix();
186 
187  float vectStart[4];
188  float vectResult[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
189 
190  vectStart[0] = ant.x;
191  vectStart[1] = ant.y;
192  vectStart[2] = ant.z;
193  vectStart[3] = 1.0f;
194  for( int j =0; j<4; j++ ) {
195  float val = 0;
196  for( int i = 0; i<4; i++) {
197  val+= m[i][j] * vectStart[i];
198  }
199  vectResult[j] = val;
200  }
201  Vector3 a = Vector3( vectResult[0], vectResult[1], vectResult[2] );
202 
203  vectStart[0] = bnt.x;
204  vectStart[1] = bnt.y;
205  vectStart[2] = bnt.z;
206  vectStart[3] = 1.0f;
207  for( int j =0; j<4; j++ ) {
208  float val = 0;
209  for( int i = 0; i<4; i++) {
210  val+= m[i][j] * vectStart[i];
211  }
212  vectResult[j] = val;
213  }
214  Vector3 b = Vector3( vectResult[0], vectResult[1], vectResult[2] );
215 
216  vectStart[0] = cnt.x;
217  vectStart[1] = cnt.y;
218  vectStart[2] = cnt.z;
219  vectStart[3] = 1.0f;
220  for( int j =0; j<4; j++ ) {
221  float val = 0;
222  for( int i = 0; i<4; i++) {
223  val+= m[i][j] * vectStart[i];
224  }
225  vectResult[j] = val;
226  }
227  Vector3 c = Vector3( vectResult[0], vectResult[1], vectResult[2] );
228 
229  vectStart[0] = dnt.x;
230  vectStart[1] = dnt.y;
231  vectStart[2] = dnt.z;
232  vectStart[3] = 1.0f;
233  for( int j =0; j<4; j++ ) {
234  float val = 0;
235  for( int i = 0; i<4; i++) {
236  val+= m[i][j] * vectStart[i];
237  }
238  vectResult[j] = val;
239  }
240  Vector3 d = Vector3( vectResult[0], vectResult[1], vectResult[2] );
241 
242 
243 
244 
245  vectStart[0] = ant2.x;
246  vectStart[1] = ant2.y;
247  vectStart[2] = ant2.z;
248  vectStart[3] = 1.0f;
249  for( int j =0; j<4; j++ ) {
250  float val = 0;
251  for( int i = 0; i<4; i++) {
252  val+= m[i][j] * vectStart[i];
253  }
254  vectResult[j] = val;
255  }
256  Vector3 a2 = Vector3( vectResult[0], vectResult[1], vectResult[2] );
257 
258  vectStart[0] = bnt2.x;
259  vectStart[1] = bnt2.y;
260  vectStart[2] = bnt2.z;
261  vectStart[3] = 1.0f;
262  for( int j =0; j<4; j++ ) {
263  float val = 0;
264  for( int i = 0; i<4; i++) {
265  val+= m[i][j] * vectStart[i];
266  }
267  vectResult[j] = val;
268  }
269  Vector3 b2 = Vector3( vectResult[0], vectResult[1], vectResult[2] );
270 
271  vectStart[0] = cnt2.x;
272  vectStart[1] = cnt2.y;
273  vectStart[2] = cnt2.z;
274  vectStart[3] = 1.0f;
275  for( int j =0; j<4; j++ ) {
276  float val = 0;
277  for( int i = 0; i<4; i++) {
278  val+= m[i][j] * vectStart[i];
279  }
280  vectResult[j] = val;
281  }
282  Vector3 c2 = Vector3( vectResult[0], vectResult[1], vectResult[2] );
283 
284 
285  // works without rotating ;)
286  //Vector3 actPos( m[3][0], m[3][1], m[3][2] );// position of the zero vector
287  //Vector3 a = ant + actPos;
288  //Vector3 b = bnt + actPos;
289  //Vector3 c = cnt + actPos;
290  //Vector3 d = dnt + actPos;
291 
292  bool in = true;
293  float distance;
294 
295  Plane plinks;
296  plinks.setPlane(d-c, c);
297  distance = plinks.distance( position );
298  if( distance < 0 )
299  in = false;
300 
301  Plane prechts;
302  plinks.setPlane(a-b, b);
303  distance = plinks.distance( position );
304  if( distance < 0 )
305  in = false;
306 
307  Plane poben;
308  plinks.setPlane(c-a, a);
309  distance = plinks.distance( position );
310  if( distance < 0 )
311  in = false;
312 
313  Plane punten;
314  plinks.setPlane(b-d, d);
315  distance = plinks.distance( position );
316  if( distance < 0 )
317  in = false;
318 
319  // check now if the player is inside the object
320  Plane pfront;
321  pfront.setPlane( a, b, c );
322  distance = pfront.distance( position);
323  if( distance < 0 )
324  in = false;
325 
326  Plane pback;
327  pfront.setPlane( a2, c2, b2 );
328  distance = pfront.distance( position);
329  if( distance < 0 )
330  in = false;
331 
332  return in;
333 
334 }