Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3635 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Mar 23, 2005, 12:24:48 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: reimplemented the Camera.
Camera is now a PNode and not a WorldEntity. I have taken out all the unnecessary stuff like ELLIPTIC_CAMERA and so on, and now it is more like it should be in the new Framework

Location:
orxonox/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/camera.cc

    r3608 r3635  
    2424using namespace std;
    2525
     26////////////
     27// CAMERA //
     28////////////
     29
    2630/**
    2731   \brief creates a Camera
    28    
    29    This standard constructor sets all parameters to zero
    3032*/
    31 Camera::Camera (World* world)
     33Camera::Camera(void)
    3234{
    33   this->world = world;
    34   this->bound = NULL;
    35   /* give it some physical live */
    36   this->m = 10;
    37   this->a = new Vector(0.0, 0.0, 0.0);
    38   this->v = new Vector(0.0, 0.0, 0.0);
    39   this->fs = new Vector(0.0, 0.0, 0.0);
    40   this->cameraMode = NORMAL;
    41   this->deltaTime = 3000.0;
    42   this->cameraOffset = 1.0;
    43   this->cameraOffsetZ = 10.0;
    44   this->t = 0.0;
    45 
    46 
    47   this->setDrawable (false);
     35  this->target = new CameraTarget();
    4836}
    4937
     
    5139   \brief default destructor
    5240*/
    53 Camera::~Camera ()
     41Camera::~Camera(void)
    5442{
    55   this->bound = NULL;
    56   this->world = NULL;
    5743
    5844}
    5945
    6046/**
    61    \brief time based actualisation of camera parameters
    62    \param deltaT: The amount of time that has passed in milliseconds
    63    
    64    This is called by the World in every time_slice, use it to do fancy time dependant effects (such
    65    as smooth camera movement or swaying).
     47   \brief focuses the Camera onto a Target
     48   \param target the new PNode the Camera should look at.
    6649*/
    67 void Camera::tick (Uint32 deltaT)
     50void Camera::lookAt(PNode* target)
    6851{
    69   if( this->t <= deltaTime)
    70     {this->t += deltaT;}
    71   //printf("time is: t=%f\n", t );
    72   updateDesiredPlace();
    73   //jump(NULL);
     52  this->target->setParent(target);
    7453}
    7554
    76 /**
    77    \brief this calculates the location where the track wants the camera to be
    78    
    79    This refreshes the placement the camera should have according to the
    80    bound entity's position on the track.
    81 */
    82 void Camera::updateDesiredPlace ()
     55PNode* Camera::getTarget(void)
    8356{
    84   switch(cameraMode)
    85     {
    86      
    87     case ELLIPTICAL:
    88       {
    89         /*
    90         //r = actual_place.r
    91         Orxonox *orx = Orxonox::getInstance();
    92         Location lookat; 
    93         Placement plFocus;
    94         if( bound != NULL)
    95           {
    96             bound->getLookat (&lookat);
    97             orx->getWorld()->calcCameraPos (&lookat, &plFocus);
    98             Quaternion *fr;
    99             if(t < 20.0)
    100               {
    101                 Vector *start = new Vector(0.0, 1.0, 0.0);
    102                 r = *(new Vector(0.0, 5.0, 0.0));
    103 
    104                 Vector up(0.0, 0.0, 1.0);
    105                
    106                 Vector op(1.0, 0.0, 0.0);
    107                 float angle = angleDeg(op, *start);
    108                 printf("angle is: %f\n", angle);
    109 
    110                 //if in one plane
    111                 from = new Quaternion(angle, up);
    112 
    113                 //from = new Quaternion(*start, *up);
    114                 //&from = &plFocus.w;
    115                 //fr = &plFocus.w; real quaternion use
    116                
    117 
    118 
    119                 Vector vDirection(1.0, 0.0, 0.0);
    120                 //vDirection = plFocus.w.apply(vDirection);
    121                 to = new Quaternion(vDirection, *start);
    122                 res = new Quaternion();
    123               }
    124             //printf("vector r = %f, %f, %f\n",r.x, r.y, r.z );
    125             rAbs = r.len();
    126             if(t < 30)
    127               {
    128                 ka = rAbs / deltaTime*deltaTime;
    129               }
    130 
    131             res->quatSlerp(to, from, t/deltaTime, res);
    132 
    133             Vector ursp(0.0, 0.0, 0.0);
    134             desiredPlace.r =  ursp - res->apply(r);
    135 
    136             printf("desired place is: %f, %f, %f\n", desiredPlace.r.x, desiredPlace.r.y, desiredPlace.r.z);
    137             //plLastBPlace = *bound->get_placement();
    138            
    139           }
    140       */
    141       }
    142       break;
    143     case SMOTH_FOLLOW:
    144       {
    145         /*
    146         Placement *plBound = bound->getPlacement();
    147         Location lcBound;
    148         if(bound != null)
    149           {
    150             bound->getLookat(&lcBound);
    151             Vector vDirection(0.0, 0.0, 1.0);
    152             vDirection = plBound->w.apply(vDirection);
    153             desiredPlace.r = (vDirection * ((lcBound.dist-10.0))) + Vector(0,0,5.0);
    154           }
    155         */
    156         break;
    157       }
    158       /* this is a camera mode that tries just to follow the entity. */
    159     case STICKY:
    160       {
    161         /*
    162         if(bound != null)
    163           {
    164             Placement *plBound = bound->getPlacement();
    165             Vector vDirection(0.0, 0.0, 1.0);
    166             Vector eclipticOffset(0.0, 0.0, 5.0);
    167             vDirection = plBound->w.apply(vDirection);
    168             desiredPlace.r = plBound->r - vDirection*10 + eclipticOffset;
    169           }
    170         */
    171         break;
    172       }
    173       /* the camera is handled like an entity and rolls on the track */
    174     case NORMAL:
    175       if( bound != NULL && world != NULL )
    176         {
    177           //FIXME: camera should be made via relative coordinates
    178           Vector* cameraOffset = new Vector (-10, 5, 0);
    179           this->setRelCoor (cameraOffset);
    180         }
    181       else
    182         {
    183           /*
    184           desiredPlace.r = Vector (0,0,0);
    185           desiredPlace.w = Quaternion ();
    186           */
    187         }
    188       break;
    189     }
     57  return (PNode*)this->target;
    19058}
    19159
     
    20068  glMatrixMode (GL_PROJECTION);
    20169  glLoadIdentity ();
    202   // view
    203   // TO DO: implement options for frustum generation
    204   //glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0);
     70
    20571  gluPerspective(60, 1.2f, 0.1, 2000);
    206  
    207   //Vector up(0,0,1);
    208   //Vector dir(1,0,0);
    209   //Quaternion q(dir,up);
    210   //float matrix[4][4];
    211   //q.conjugate().matrix (matrix);
    212   //glMultMatrixf ((float*)matrix);
    213   //glTranslatef (10,0,-5);
    214   //
    215   //dir = Vector(-1,-1,0);
    216   //q = Quaternion( dir, up);
    217   //glMatrixMode (GL_MODELVIEW);
    218   //glLoadIdentity ();
    219   //q.matrix (matrix);
    220   //glMultMatrixf ((float*)matrix);
    221   //glTranslatef (2,2,0);
    222   //
    223   //glBegin(GL_TRIANGLES);
    224   //glColor3f(1,0,0);
    225   //glVertex3f(0,0,0.5);
    226   //glColor3f(0,1,0);
    227   //glVertex3f(-0.5,0,-1);
    228   //glColor3f(0,0,1);
    229   //glVertex3f(0.5,0,-1);
    230   //glEnd();   
     72  float matrix[4][4];
    23173
    232   // ===== first camera control calculation option
    233   // rotation
    234   float matrix[4][4];
    235   //this->absDirection.conjugate().matrix (matrix);
    236   /* orientation and */
    237   //glMultMatrixf ((float*)matrix);
     74  Vector cameraPosition = this->getAbsCoor();
     75  Vector targetPosition = this->target->getAbsCoor();
    23876
    239   /*  translation */
    240   //glTranslatef (this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z );
    241 
    242 
    243   // ===== second camera control calculation option
    244 
    245   Vector r = this->getAbsCoor();
    246   gluLookAt(r.x, r.y, r.z,
    247             this->parent->getAbsCoor ().x, this->parent->getAbsCoor ().y, this->parent->getAbsCoor ().z,
     77  gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
     78            targetPosition.x, targetPosition.y, targetPosition.z,
    24879            0.0, 1.0, 0.0);
    249  
    250 
    25180  glMatrixMode (GL_MODELVIEW);
    25281  glLoadIdentity ();
     
    25584
    25685
    257 /**
    258   \brief bind the camera to an entity
    259   \param entity: The enitity to bind the camera to
    260        
    261   This sets the focus of the camera to the given entity. This means that it will use the given WorldEntity's
    262   Location and get_lookat() to determine the viewpoint the camera will render from.
    263   Note that you cannot bind a camera to a free entity.
    264 */
    265 void Camera::bind (WorldEntity* entity)
     86///////////////////
     87// CAMERA-TARGET //
     88///////////////////
     89
     90
     91CameraTarget::CameraTarget()
    26692{
    267   if( entity != NULL)
    268     {
    269       if( entity->isFree()) printf("Cannot bind camera to free entity");
    270       else
    271         {
    272           this->bound = entity;
    273         }
    274     }
     93 
    27594}
    27695
     96CameraTarget::~CameraTarget()
     97{
    27798
    278 void Camera::setWorld(World* world)
    279 {
    280   this->world = world;
    28199}
    282 
    283 
  • orxonox/trunk/src/camera.h

    r3608 r3635  
    77#define _CAMERA_H
    88
    9 #include "world_entity.h"
     9#include "p_node.h"
    1010
    1111class World;
     12class CameraTarget;
     13
    1214
    1315//! Camera
    1416/**
    15    This class controls the viewpoint from which the World is rendered. To use the
    16    Camera it has to be bound to a WorldEntity which serves as the reference focus
    17    point. The Camera itself calls the WorldEntity::get_lookat() and
    18    World::calc_camera_pos() functions to calculate the position it currently should
    19    be in.
     17   This class controls the viewpoint from which the World is rendered.
    2018*/
    21 
    22 enum CAMERA_MODE {NORMAL, SMOTH_FOLLOW, STICKY, ELLIPTICAL};
    23 
    24 class Camera : public WorldEntity {
     19class Camera : public PNode
     20{
    2521 private:
    26   WorldEntity* bound;           //!< the WorldEntity the Camera is bound to
    27   World* world;
    28  
    29   /* physical system - not needed yet */
    30   float m; //!< mass
    31   Vector *fs; //!< seil-kraft
    32   Vector *a;  //!< acceleration
    33   Vector *v;  //!< velocity
    34  
    35   /* elliptical camera mode variables */
    36   float cameraOffset;
    37   float cameraOffsetZ;
    38   float deltaTime;
    39   float t;
    40   Vector* r;
    41   float rAbs;
    42   float ka;
    43   float a0;
    44 
    45   Quaternion *from;
    46   Quaternion *to;
    47   Quaternion *res;
    48  
    49  
    50   CAMERA_MODE cameraMode; //!< saves the camera mode: how the camera follows the entity
    51  
    52   void updateDesiredPlace ();
     22  CameraTarget* target;
    5323 
    5424 public:
    55   Camera (World* world);
    56   virtual ~Camera ();
     25  Camera(void);
     26  virtual ~Camera(void);
     27
     28  void lookAt(PNode* target);
    5729 
    58   void tick (Uint32 deltaT);
     30  PNode* getTarget();
    5931  void apply ();
    60   void bind (WorldEntity* entity);
    61 
    62   void setWorld(World* world); 
    63 
    6432};
    6533
     34//! A CameraTarget is where the Camera is looking at.
     35class CameraTarget : public PNode
     36{
     37  friend class Camera; //!
     38 
     39 private:
     40  CameraTarget(void);
     41 
     42 public:
     43  virtual ~CameraTarget(void);
     44};
     45
     46
    6647#endif /* _CAMERA_H */
  • orxonox/trunk/src/story_entities/world.cc

    r3634 r3635  
    302302           
    303303            // bind camera
    304             this->localCamera = new Camera(this);
     304            this->localCamera = new Camera();
    305305            this->localCamera->setName ("camera");
    306             this->localCamera->bind (this->localPlayer);
     306            this->localCamera->lookAt(this->localPlayer);
     307
    307308            /*monitor progress*/
    308309            this->glmis->step();           
     
    366367           
    367368            // bind camera
    368             this->localCamera = new Camera (this);
     369            this->localCamera = new Camera ();
    369370            this->localCamera->setName ("camera");
    370             this->localCamera->bind (myPlayer);
     371            this->localCamera->lookAt(this->localPlayer);
    371372            this->localPlayer->addChild (this->localCamera);
    372373
     
    749750     
    750751      /* update tick the rest */
    751       this->localCamera->tick(dt);
    752752      this->trackManager->tick(dt);
    753753    }
Note: See TracChangeset for help on using the changeset viewer.