Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/util/track/action_box.cc @ 10667

Last change on this file since 10667 was 10667, checked in by rennerc, 18 years ago

ActionboxEnemy

File size: 4.3 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2006 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12
13   the actual playing shoult take place within this box
14
15   main-programmer: Christoph Renner
16*/
17
18#include "action_box.h"
19#include "track.h"
20#include "state.h"
21
22/**
23 * this function is called each frame. update your state here
24 * @param time time since last tick
25 */
26void ActionBox::tick( float time )
27{
28  updatePlanes();
29}
30
31/**
32 * draws the box for debugging
33 */
34void ActionBox::draw( ) const
35{
36  glMatrixMode(GL_MODELVIEW);
37  glPushMatrix();
38
39  glPushAttrib(GL_ENABLE_BIT);
40
41  glDisable(GL_LIGHTING);
42  glDisable(GL_TEXTURE_2D);
43  glDisable(GL_BLEND);
44  glLineWidth(2.0);
45  glTranslatef ( track->getTrackNode()->getAbsCoor ().x,
46                track->getTrackNode()->getAbsCoor ().y,
47                track->getTrackNode()->getAbsCoor ().z);
48  Vector tmpRot = track->getTrackNode()->getAbsDir().getSpacialAxis();
49  glRotatef (track->getTrackNode()->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
50
51
52  glColor3f(1.0, 1.0, 0.0);
53  glBegin(GL_LINE_STRIP);
54    glVertex3f(0, height_2, width_2);
55    glVertex3f(0, -height_2, width_2);
56    glVertex3f(0, -height_2, -width_2);
57    glVertex3f(0, height_2, -width_2);
58    glVertex3f(0, height_2, width_2);
59  glEnd();
60
61  glColor3f(1.0, 0.0, 0.0 );
62  glBegin(GL_LINE_STRIP);
63    glVertex3f(depth, height_2 * stretch, width_2 * stretch);
64    glVertex3f(depth, -height_2 * stretch, width_2 * stretch);
65    glVertex3f(depth, -height_2 * stretch, -width_2 * stretch);
66    glVertex3f(depth, height_2 * stretch, -width_2 * stretch);
67    glVertex3f(depth, height_2 * stretch, width_2 * stretch);
68  glEnd();
69
70  glBegin(GL_LINE_STRIP);
71    glVertex3f(depth, height_2 * stretch, width_2 * stretch);
72    glVertex3f(0, height_2, width_2);
73    glVertex3f(0, -height_2, width_2);
74    glVertex3f(depth, -height_2 * stretch, width_2 * stretch);
75  glEnd();
76
77  glBegin(GL_LINE_STRIP);
78    glVertex3f(depth, height_2 * stretch, -width_2 * stretch);
79    glVertex3f(0, height_2, -width_2);
80    glVertex3f(0, -height_2, -width_2);
81    glVertex3f(depth, -height_2 * stretch, -width_2 * stretch);
82  glEnd();
83
84  glPopMatrix();
85}
86
87/**
88 * create a new action box. you must not create more than one action box
89 * @param _track track to assign actionbox to
90 * @param width_2 width/2 of near plane
91 * @param height_2 height/2 of near plane
92 * @param depth distance between near and far plane
93 * @param stretch far plane will be stretched by this factor
94 */
95ActionBox::ActionBox( Track* _track, float width_2, float height_2, float depth, float stretch )
96{
97  assert( _track );
98  assert( State::getActionBox() == NULL );
99 
100  State::setActionBox( this );
101 
102  this->width_2 = width_2;
103  this->height_2 = height_2;
104  this->depth = depth;
105  this->stretch = stretch;
106  this->track = _track;
107 
108  setParent( _track->getTrackNode() );
109   
110  toList( OM_COMMON );
111}
112
113/**
114 * destructor
115 */
116ActionBox::~ActionBox( )
117{
118  assert( State::getActionBox() );
119  State::setActionBox( NULL );
120}
121
122/**
123 * checks wether a point is inside this box
124 * @param pos point to check (absCoor)
125 * @return true if inside
126 */
127bool ActionBox::isPointInBox( const Vector & pos )
128{
129  for ( int i = 0; i<6; i++ )
130  {
131    if ( planes[i].distancePoint( pos ) < 0 )
132    {
133      return false;
134    }
135  }
136  return true;
137}
138
139/**
140 * update planes with new coordiantes. nomals must point to the inside
141 */
142void ActionBox::updatePlanes( )
143{
144  Vector p[7];
145
146  p[0] = Vector( 0.0, height_2, -width_2 );
147  p[1] = Vector( 0.0, height_2, width_2 );
148  p[2] = Vector( 0.0, -height_2, -width_2 );
149  p[3] = Vector( depth, height_2, -width_2 );
150  p[4] = Vector( depth, height_2, width_2 );
151  p[5] = Vector( depth, -height_2, width_2 );
152  p[6] = Vector( depth, -height_2, -width_2 );
153
154  for ( int i = 0; i<7; i++ )
155  {
156    p[i] = track->getTrackNode()->getAbsDir().apply( p[i] );
157    p[i] += track->getTrackNode()->getAbsCoor();
158  }
159
160  planes[0] = Plane( p[1], p[0], p[2] );
161  planes[1] = Plane( p[3], p[4], p[5] );
162  planes[2] = Plane( p[5], p[4], p[1] );
163  planes[3] = Plane( p[2], p[0], p[3] );
164  planes[4] = Plane( p[3], p[0], p[1] );
165  planes[5] = Plane( p[2], p[6], p[5] );
166}
167
168
169
Note: See TracBrowser for help on using the repository browser.