Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3028 in orxonox.OLD for orxonox/branches/bezierTrack


Ignore:
Timestamp:
Nov 30, 2004, 2:50:59 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/bezierTrack: now Camera follows Path. heavy cleanUp of not used stuff like elyptical Camera and so on…

Location:
orxonox/branches/bezierTrack/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/bezierTrack/src/Makefile.am

    r3023 r3028  
    3131                coordinates.cc
    3232
    33 noinst_HEADERS=ability.h \
     33noinst_HEADERS= ability.h \
    3434                data_tank.h \
    3535                npc.h \
  • orxonox/branches/bezierTrack/src/camera.cc

    r3023 r3028  
    4444  actual_place.pos.y = 10.0;
    4545  actual_place.pos.z = -5.0;
     46 
     47  // Initializing Target
     48  target = new CameraTarget (Vector (0,0,0));
     49 
    4650}
    4751
     
    7983  switch(cameraMode)
    8084    {
    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
    17986    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;
    18191      if( bound != NULL && world != NULL )
    18292        {
     
    206116  // TO DO: implement options for frustum generation
    207117  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();   
    232118
    233119  // ===== first camera control calculation option
    234120  // 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
    235128  float matrix[4][4];
    236129  actual_place.rot.conjugate().matrix (matrix);
    237130  /* orientation and */
    238   glMultMatrixf ((float*)matrix);
     131  //  glMultMatrixf ((float*)matrix);
    239132  /*  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);
    241134  //Placement *plBound = bound->get_placement();
    242135
     
    297190  this->world = world;
    298191}
     192
     193
     194
     195CameraTarget::CameraTarget ()
     196{
     197 
     198
     199}
     200
     201CameraTarget::CameraTarget (Vector pos)
     202{
     203  this->setPosition (pos, WORLD);
     204}
  • orxonox/branches/bezierTrack/src/camera.h

    r3023 r3028  
    1111class WorldEntity;
    1212class World;
     13class CameraTarget;
    1314
    1415//! Camera
     
    3031  Placement desired_place;        //!< where the Camera should be according to calculations
    3132  World* world;
     33  CameraTarget* target;
    3234 
    3335  /* physical system - not needed yet */
     
    6971};
    7072
     73//! A Class to handle the Target of a Camera.
     74class 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
    7188#endif
  • orxonox/branches/bezierTrack/src/coordinates.h

    r3023 r3028  
    4646} Coord;
    4747
     48//! A class to handle coordinates of Objects.
    4849class Coordinate
    4950{
     
    5657  void setPosition (Vector position, COORD_TYPE cType);
    5758  void setRotation (Quaternion rotation, COORD_TYPE cType);
     59
     60  void move (Vector, COORD_TYPE cType); // just move a Object
    5861
    5962  Coord getCoord (COORD_TYPE cType) const;
  • orxonox/branches/bezierTrack/src/curve.cc

    r3023 r3028  
    130130  ret.normalize();
    131131
    132   return Vector (0,0,0);//ret;
     132  return ret;
    133133}
     134
     135Quaternion BezierCurve::calcQuat (float t)
     136{
     137  return Quaternion (calcDir(t), Vector(0,0,1));
     138}
     139
    134140
    135141/**
     
    155161  return ret;
    156162}
     163
  • orxonox/branches/bezierTrack/src/curve.h

    r3023 r3028  
    4949  BezierCurve (void);
    5050  ~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 
    5355 
    5456  Vector getPos () const;
  • orxonox/branches/bezierTrack/src/track.cc

    r3018 r3028  
    1717
    1818#include "track.h"
    19   float t = .0;
    2019
    2120using namespace std;
     
    2827  this->next = NULL;
    2928  this->previous = NULL;
     29  mainTime = .0;
     30
    3031
    3132  curve = BezierCurve();
     
    6263}
    6364
     65Vector Track::getPos (void)
     66{
     67  return curve.calcPos (mainTime);
     68}
    6469
    6570Vector Track::getPos (float t)
     
    6772  return curve.calcPos (t);
    6873}
     74
     75Vector Track::getDir (void)
     76{
     77  return curve.calcDir (mainTime);
     78}
     79
    6980Vector Track::getDir (float t)
    7081{
    7182  return curve.calcDir (t);
     83}
     84
     85Quaternion Track::getQuat (void)
     86{
     87  return curve.calcQuat (mainTime);
     88}
     89Quaternion Track::getQuat (float t)
     90{
     91  return curve.calcQuat (t);
    7292}
    7393
     
    88108  //  float r = (lookat->dist)*PI / l;
    89109  // 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 
    92114  Vector w(0.0,0.0,0.0);
    93115  //  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));
    95117  //Vector up(0.0,sin(r),cos(r)); // corrupt...
    96118  Vector up(0.0, 0.0, 1.0);
     
    118140bool Track::map_coords (Location* loc, Placement* plc)
    119141{
    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
    136146        /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of
    137147         * the track */
    138         Quaternion dir(curve.calcDir(t), Vector(0,0,1));
     148        Quaternion dir(curve.calcDir(mainTime), Vector(0,0,1));
    139149
    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;
    142152       
    143153        return false;
     
    174184void Track::tick (float deltaT)
    175185{
     186  mainTime += deltaT/10;
    176187}
    177188
  • orxonox/branches/bezierTrack/src/track.h

    r3018 r3028  
    1515   To create special levels with special camera movement, rules or whatever, derive from this base class.
    1616*/
    17 class Track
     17class Track : public Coordinate
    1818{
    1919 private:
     
    2222  Vector* end;
    2323  BezierCurve curve;
     24
     25  float mainTime;
    2426  // Vector* direction; // unity direction vector: it is costy to always recalculate it
    2527  //Vector* up; // direction where up is ment to be - diffuse in space, eh?
     
    3941  void addHotPoint (Vector hotPoint);
    4042 
     43  Vector getPos(void);
    4144  Vector getPos(float t);
     45  Vector getDir (void);
    4246  Vector getDir (float t);
     47  Quaternion getQuat (void);
     48  Quaternion getQuat (float t);
     49  Coord getCoord (void);
     50  Coord getCoord (float t);
    4351
    4452 
  • orxonox/branches/bezierTrack/src/vector.cc

    r3018 r3028  
    257257{
    258258  Vector z = dir;
    259   z.normalize();
     259  z.normalize(); // not necesarry
    260260  Vector x = up.cross(z);
    261261  x.normalize();
  • orxonox/branches/bezierTrack/src/world.cc

    r3023 r3028  
    1818#include "world_entity.h"
    1919#include "collision.h"
    20 #include "track.h"
    2120#include "player.h"
    2221#include "command_node.h"
     
    423422    }
    424423
     424  track->tick(seconds);
    425425  //  for( int i = 0; i < tracklen; i++) track[i].tick (seconds);
    426426}
  • orxonox/branches/bezierTrack/src/world.h

    r2822 r3028  
    99#include "stdincl.h"
    1010#include "story_entity.h"
     11#include "track.h"
    1112
    1213
Note: See TracChangeset for help on using the changeset viewer.