[10642] | 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 | */ |
---|
| 26 | void ActionBox::tick( float time ) |
---|
| 27 | { |
---|
| 28 | updatePlanes(); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * draws the box for debugging |
---|
| 33 | */ |
---|
| 34 | void ActionBox::draw( ) const |
---|
| 35 | { |
---|
[10767] | 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(); |
---|
[10642] | 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 | */ |
---|
| 96 | ActionBox::ActionBox( Track* _track, float width_2, float height_2, float depth, float stretch ) |
---|
| 97 | { |
---|
| 98 | assert( _track ); |
---|
| 99 | assert( State::getActionBox() == NULL ); |
---|
[10728] | 100 | |
---|
[10642] | 101 | State::setActionBox( this ); |
---|
[10728] | 102 | |
---|
[10642] | 103 | this->width_2 = width_2; |
---|
| 104 | this->height_2 = height_2; |
---|
| 105 | this->depth = depth; |
---|
| 106 | this->stretch = stretch; |
---|
| 107 | this->track = _track; |
---|
[10728] | 108 | |
---|
[10642] | 109 | setParent( _track->getTrackNode() ); |
---|
[10728] | 110 | |
---|
[10642] | 111 | toList( OM_COMMON ); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * destructor |
---|
| 116 | */ |
---|
| 117 | ActionBox::~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 | */ |
---|
| 128 | bool ActionBox::isPointInBox( const Vector & pos ) |
---|
| 129 | { |
---|
| 130 | for ( int i = 0; i<6; i++ ) |
---|
| 131 | { |
---|
| 132 | if ( planes[i].distancePoint( pos ) < 0 ) |
---|
| 133 | { |
---|
[10667] | 134 | return false; |
---|
[10642] | 135 | } |
---|
| 136 | } |
---|
[10667] | 137 | return true; |
---|
[10642] | 138 | } |
---|
| 139 | |
---|
| 140 | /** |
---|
| 141 | * update planes with new coordiantes. nomals must point to the inside |
---|
| 142 | */ |
---|
| 143 | void ActionBox::updatePlanes( ) |
---|
| 144 | { |
---|
| 145 | Vector p[7]; |
---|
[10645] | 146 | |
---|
[10642] | 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 ); |
---|
[10645] | 154 | |
---|
[10642] | 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 | } |
---|
[10645] | 160 | |
---|
[10642] | 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 | |
---|