Changeset 3028 in orxonox.OLD for orxonox/branches/bezierTrack
- Timestamp:
- Nov 30, 2004, 2:50:59 PM (20 years ago)
- Location:
- orxonox/branches/bezierTrack/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/bezierTrack/src/Makefile.am
r3023 r3028 31 31 coordinates.cc 32 32 33 noinst_HEADERS= ability.h \33 noinst_HEADERS= ability.h \ 34 34 data_tank.h \ 35 35 npc.h \ -
orxonox/branches/bezierTrack/src/camera.cc
r3023 r3028 44 44 actual_place.pos.y = 10.0; 45 45 actual_place.pos.z = -5.0; 46 47 // Initializing Target 48 target = new CameraTarget (Vector (0,0,0)); 49 46 50 } 47 51 … … 79 83 switch(cameraMode) 80 84 { 81 82 case ELLIPTICAL: 83 { 84 //r = actual_place.r 85 Orxonox *orx = Orxonox::getInstance(); 86 Location lookat; 87 Placement plFocus; 88 if( bound != NULL) 89 { 90 bound->get_lookat (&lookat); 91 orx->get_world()->calc_camera_pos (&lookat, &plFocus); 92 Quaternion *fr; 93 if(t < 20.0) 94 { 95 Vector *start = new Vector(0.0, 1.0, 0.0); 96 //r = /*actual_place.r*/ *start - plFocus.r; 97 r = *(new Vector(0.0, 5.0, 0.0)); 98 99 Vector up(0.0, 0.0, 1.0); 100 101 Vector op(1.0, 0.0, 0.0); 102 float angle = angle_deg(op, *start); 103 printf("angle is: %f\n", angle); 104 105 //if in one plane 106 from = new Quaternion(angle, up); 107 108 //from = new Quaternion(*start, *up); 109 //&from = &plFocus.w; 110 //fr = &plFocus.w; real quaternion use 111 112 113 114 Vector vDirection(1.0, 0.0, 0.0); 115 //vDirection = plFocus.w.apply(vDirection); 116 to = new Quaternion(vDirection, *start); 117 res = new Quaternion(); 118 } 119 //printf("vector r = %f, %f, %f\n",r.x, r.y, r.z ); 120 rAbs = r.len(); 121 if(t < 30.0) /* FIXME!!*/ 122 { 123 ka = rAbs / deltaTime*deltaTime; 124 } 125 /* this is the new length of the vector */ 126 //float len = ka * powf((deltaTime - t), 2); 127 128 /* calc the rotation */ 129 /* 130 Vector axis(0.0, 0.0, 1.0); 131 if(t < 30.0) 132 a0 = PI/4 - atanf(fabs(r.x) / fabs(r.y)); 133 printf("a0 = %f\n", a0); 134 float angle = a0/deltaTime * (deltaTime - t); 135 printf("angle is: %f\n", angle); 136 Quaternion q(angle, axis); 137 */ 138 //r = q.apply(r); 139 //r = r * (len/r.len()); 140 141 //res->quatSlerp(from, to, t/deltaTime, res); 142 res->quatSlerp(to, from, t/deltaTime, res); 143 144 Vector ursp(0.0, 0.0, 0.0); 145 desired_place.pos = /*plFocus.r -*/ ursp - res->apply(r); 146 147 printf("desired place is: %f, %f, %f\n", desired_place.pos.x, desired_place.pos.y, desired_place.pos.z); 148 //plLastBPlace = *bound->get_placement(); 149 } 150 } 151 break; 152 case SMOTH_FOLLOW: 153 { 154 Placement *plBound = bound->get_placement(); 155 Location lcBound; 156 if(bound != null) 157 { 158 bound->get_lookat(&lcBound); 159 Vector vDirection(0.0, 0.0, 1.0); 160 vDirection = plBound->rot.apply(vDirection); 161 desired_place.pos = (vDirection * ((lcBound.dist-10.0)/* / l*/)) + Vector(0,0,5.0); 162 } 163 break; 164 } 165 /* this is a camera mode that tries just to follow the entity. */ 166 case STICKY: 167 { 168 if(bound != null) 169 { 170 Placement *plBound = bound->get_placement(); 171 Vector vDirection(0.0, 0.0, 1.0); 172 Vector eclipticOffset(0.0, 0.0, 5.0); 173 vDirection = plBound->rot.apply(vDirection); 174 desired_place.pos = plBound->pos - vDirection*10 + eclipticOffset; 175 } 176 break; 177 } 178 /* the camera is handled like an entity and rolls on the track */ 85 179 86 case NORMAL: 180 Location lookat; 87 this->setPosition(world->track->getPos() - world->track->getDir() *10 +Vector (0,0,5), WORLD); 88 target->setPosition(world->track->getPos(), WORLD); 89 90 Location lookat; 181 91 if( bound != NULL && world != NULL ) 182 92 { … … 206 116 // TO DO: implement options for frustum generation 207 117 glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0); 208 //Vector up(0,0,1);209 //Vector dir(1,0,0);210 //Quaternion q(dir,up);211 //float matrix[4][4];212 //q.conjugate().matrix (matrix);213 //glMultMatrixf ((float*)matrix);214 //glTranslatef (10,0,-5);215 //216 //dir = Vector(-1,-1,0);217 //q = Quaternion( dir, up);218 //glMatrixMode (GL_MODELVIEW);219 //glLoadIdentity ();220 //q.matrix (matrix);221 //glMultMatrixf ((float*)matrix);222 //glTranslatef (2,2,0);223 //224 //glBegin(GL_TRIANGLES);225 //glColor3f(1,0,0);226 //glVertex3f(0,0,0.5);227 //glColor3f(0,1,0);228 //glVertex3f(-0.5,0,-1);229 //glColor3f(0,0,1);230 //glVertex3f(0.5,0,-1);231 //glEnd();232 118 233 119 // ===== first camera control calculation option 234 120 // rotation 121 Vector eye = this->getPosition(WORLD); 122 Vector targetV = target->getPosition(WORLD); 123 124 gluLookAt (eye.x, eye.y, eye.z, 125 targetV.x, targetV.y, targetV.z, 126 0,0,1); 127 235 128 float matrix[4][4]; 236 129 actual_place.rot.conjugate().matrix (matrix); 237 130 /* orientation and */ 238 glMultMatrixf ((float*)matrix);131 // glMultMatrixf ((float*)matrix); 239 132 /* translation */ 240 glTranslatef (-actual_place.pos.x, -actual_place.pos.y,- actual_place.pos.z);133 // glTranslatef (-actual_place.pos.x, -actual_place.pos.y,- actual_place.pos.z); 241 134 //Placement *plBound = bound->get_placement(); 242 135 … … 297 190 this->world = world; 298 191 } 192 193 194 195 CameraTarget::CameraTarget () 196 { 197 198 199 } 200 201 CameraTarget::CameraTarget (Vector pos) 202 { 203 this->setPosition (pos, WORLD); 204 } -
orxonox/branches/bezierTrack/src/camera.h
r3023 r3028 11 11 class WorldEntity; 12 12 class World; 13 class CameraTarget; 13 14 14 15 //! Camera … … 30 31 Placement desired_place; //!< where the Camera should be according to calculations 31 32 World* world; 33 CameraTarget* target; 32 34 33 35 /* physical system - not needed yet */ … … 69 71 }; 70 72 73 //! A Class to handle the Target of a Camera. 74 class CameraTarget : public Coordinate 75 { 76 private: 77 WorldEntity* lookAt; 78 79 80 public: 81 CameraTarget (); 82 CameraTarget (Vector pos); //!< a target only needs a Position and no Rotation 83 84 void setLookAt (WorldEntity* lookat); 85 86 }; 87 71 88 #endif -
orxonox/branches/bezierTrack/src/coordinates.h
r3023 r3028 46 46 } Coord; 47 47 48 //! A class to handle coordinates of Objects. 48 49 class Coordinate 49 50 { … … 56 57 void setPosition (Vector position, COORD_TYPE cType); 57 58 void setRotation (Quaternion rotation, COORD_TYPE cType); 59 60 void move (Vector, COORD_TYPE cType); // just move a Object 58 61 59 62 Coord getCoord (COORD_TYPE cType) const; -
orxonox/branches/bezierTrack/src/curve.cc
r3023 r3028 130 130 ret.normalize(); 131 131 132 return Vector (0,0,0);//ret;132 return ret; 133 133 } 134 135 Quaternion BezierCurve::calcQuat (float t) 136 { 137 return Quaternion (calcDir(t), Vector(0,0,1)); 138 } 139 134 140 135 141 /** … … 155 161 return ret; 156 162 } 163 -
orxonox/branches/bezierTrack/src/curve.h
r3023 r3028 49 49 BezierCurve (void); 50 50 ~BezierCurve (void); 51 virtual Vector calcPos (float t); 52 virtual Vector calcDir (float t); 51 Vector calcPos (float t); 52 Vector calcDir (float t); 53 Quaternion calcQuat (float t); 54 53 55 54 56 Vector getPos () const; -
orxonox/branches/bezierTrack/src/track.cc
r3018 r3028 17 17 18 18 #include "track.h" 19 float t = .0;20 19 21 20 using namespace std; … … 28 27 this->next = NULL; 29 28 this->previous = NULL; 29 mainTime = .0; 30 30 31 31 32 curve = BezierCurve(); … … 62 63 } 63 64 65 Vector Track::getPos (void) 66 { 67 return curve.calcPos (mainTime); 68 } 64 69 65 70 Vector Track::getPos (float t) … … 67 72 return curve.calcPos (t); 68 73 } 74 75 Vector Track::getDir (void) 76 { 77 return curve.calcDir (mainTime); 78 } 79 69 80 Vector Track::getDir (float t) 70 81 { 71 82 return curve.calcDir (t); 83 } 84 85 Quaternion Track::getQuat (void) 86 { 87 return curve.calcQuat (mainTime); 88 } 89 Quaternion Track::getQuat (float t) 90 { 91 return curve.calcQuat (t); 72 92 } 73 93 … … 88 108 // float r = (lookat->dist)*PI / l; 89 109 // camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); 90 camplc->pos = curve.calcPos(t) + (curve.calcDir(t)* ((lookat->dist-10.0)/t)) + Vector(-5,0,5); 91 110 111 // camplc->pos = curve.calcPos(t) + (curve.calcDir(t)* ((lookat->dist-10.0)/t)) + Vector(-5,0,5); 112 camplc->pos = curve.calcPos(mainTime) + (curve.calcDir(mainTime) * 5) + Vector (0,0,5); 113 92 114 Vector w(0.0,0.0,0.0); 93 115 // w=Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r)); 94 w = Vector(0,0,0) - (((curve.calcPos( t)) + ((curve.calcDir(t)) * ((lookat->dist) / t)) - camplc->pos));116 w = Vector(0,0,0) - (((curve.calcPos(mainTime)) + ((curve.calcDir(mainTime)) * ((lookat->dist) / mainTime)) - camplc->pos)); 95 117 //Vector up(0.0,sin(r),cos(r)); // corrupt... 96 118 Vector up(0.0, 0.0, 1.0); … … 118 140 bool Track::map_coords (Location* loc, Placement* plc) 119 141 { 120 t+=.0001; 121 // printf ("%f\n", t); 122 // if (t > 1) t =0; 123 // printf ("Pos: %f, %f, %f\n", curve.calcPos(t).x, curve.calcPos(t).y, curve.calcPos(t).z); 124 //Line trace(*offset, *end - *offset); 125 // float l = trace.len (); 126 127 /* change to the next track? */ 128 // if( loc->dist > l) 129 //{ 130 // loc->dist -= l; 131 // loc->part = nextID; 132 //FIXME: loc->track = this; 133 //return true; 134 //} 135 142 this->setPosition (curve.calcPos (mainTime), WORLD); 143 this->setRotation (curve.calcQuat (mainTime), WORLD); 144 // printf ("x: %f; y:%f; z:%f\n", getRotation(WORLD).v.x, getRotation(WORLD).v.y, getRotation(WORLD).v.z); 145 136 146 /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of 137 147 * the track */ 138 Quaternion dir(curve.calcDir( t), Vector(0,0,1));148 Quaternion dir(curve.calcDir(mainTime), Vector(0,0,1)); 139 149 140 plc->pos = curve.calcPos(t) + (curve.calcDir(t) * ((loc->dist) / t)) + /*dir.apply*/(loc->pos);141 plc->rot = dir * loc->rot;150 plc->pos = this->getPosition(WORLD);// curve.calcPos(t) + (curve.calcDir(t) * ((loc->dist) / t)) + /*dir.apply*/(loc->pos); 151 plc->rot = this->getRotation(WORLD);dir * loc->rot; 142 152 143 153 return false; … … 174 184 void Track::tick (float deltaT) 175 185 { 186 mainTime += deltaT/10; 176 187 } 177 188 -
orxonox/branches/bezierTrack/src/track.h
r3018 r3028 15 15 To create special levels with special camera movement, rules or whatever, derive from this base class. 16 16 */ 17 class Track 17 class Track : public Coordinate 18 18 { 19 19 private: … … 22 22 Vector* end; 23 23 BezierCurve curve; 24 25 float mainTime; 24 26 // Vector* direction; // unity direction vector: it is costy to always recalculate it 25 27 //Vector* up; // direction where up is ment to be - diffuse in space, eh? … … 39 41 void addHotPoint (Vector hotPoint); 40 42 43 Vector getPos(void); 41 44 Vector getPos(float t); 45 Vector getDir (void); 42 46 Vector getDir (float t); 47 Quaternion getQuat (void); 48 Quaternion getQuat (float t); 49 Coord getCoord (void); 50 Coord getCoord (float t); 43 51 44 52 -
orxonox/branches/bezierTrack/src/vector.cc
r3018 r3028 257 257 { 258 258 Vector z = dir; 259 z.normalize(); 259 z.normalize(); // not necesarry 260 260 Vector x = up.cross(z); 261 261 x.normalize(); -
orxonox/branches/bezierTrack/src/world.cc
r3023 r3028 18 18 #include "world_entity.h" 19 19 #include "collision.h" 20 #include "track.h"21 20 #include "player.h" 22 21 #include "command_node.h" … … 423 422 } 424 423 424 track->tick(seconds); 425 425 // for( int i = 0; i < tracklen; i++) track[i].tick (seconds); 426 426 } -
orxonox/branches/bezierTrack/src/world.h
r2822 r3028 9 9 #include "stdincl.h" 10 10 #include "story_entity.h" 11 #include "track.h" 11 12 12 13
Note: See TracChangeset
for help on using the changeset viewer.