Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/util/track/action_box.cc

Last change on this file was 10767, checked in by snellen, 17 years ago

removed trackdraw, actionbox, draw ,position output in spaceship

File size: 4.4 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//   glPopAttrib();
85//   glPopMatrix();
86}
87
88/**
89 * create a new action box. you must not create more than one action box
90 * @param _track track to assign actionbox to
91 * @param width_2 width/2 of near plane
92 * @param height_2 height/2 of near plane
93 * @param depth distance between near and far plane
94 * @param stretch far plane will be stretched by this factor
95 */
96ActionBox::ActionBox( Track* _track, float width_2, float height_2, float depth, float stretch )
97{
98  assert( _track );
99  assert( State::getActionBox() == NULL );
100
101  State::setActionBox( this );
102
103  this->width_2 = width_2;
104  this->height_2 = height_2;
105  this->depth = depth;
106  this->stretch = stretch;
107  this->track = _track;
108
109  setParent( _track->getTrackNode() );
110
111  toList( OM_COMMON );
112}
113
114/**
115 * destructor
116 */
117ActionBox::~ActionBox( )
118{
119  assert( State::getActionBox() );
120  State::setActionBox( NULL );
121}
122
123/**
124 * checks wether a point is inside this box
125 * @param pos point to check (absCoor)
126 * @return true if inside
127 */
128bool ActionBox::isPointInBox( const Vector & pos )
129{
130  for ( int i = 0; i<6; i++ )
131  {
132    if ( planes[i].distancePoint( pos ) < 0 )
133    {
134      return false;
135    }
136  }
137  return true;
138}
139
140/**
141 * update planes with new coordiantes. nomals must point to the inside
142 */
143void ActionBox::updatePlanes( )
144{
145  Vector p[7];
146
147  p[0] = Vector( 0.0, height_2, -width_2 );
148  p[1] = Vector( 0.0, height_2, width_2 );
149  p[2] = Vector( 0.0, -height_2, -width_2 );
150  p[3] = Vector( depth, height_2, -width_2 );
151  p[4] = Vector( depth, height_2, width_2 );
152  p[5] = Vector( depth, -height_2, width_2 );
153  p[6] = Vector( depth, -height_2, -width_2 );
154
155  for ( int i = 0; i<7; i++ )
156  {
157    p[i] = track->getTrackNode()->getAbsDir().apply( p[i] );
158    p[i] += track->getTrackNode()->getAbsCoor();
159  }
160
161  planes[0] = Plane( p[1], p[0], p[2] );
162  planes[1] = Plane( p[3], p[4], p[5] );
163  planes[2] = Plane( p[5], p[4], p[1] );
164  planes[3] = Plane( p[2], p[0], p[3] );
165  planes[4] = Plane( p[3], p[0], p[1] );
166  planes[5] = Plane( p[2], p[6], p[5] );
167}
168
169
170
Note: See TracBrowser for help on using the repository browser.