Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/bezierTrack/src/camera.cc @ 3028

Last change on this file since 3028 was 3028, checked in by bensch, 20 years ago

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

File size: 4.6 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Christian Meyer
15   co-programmer: ...
16*/
17
18#include "camera.h"
19#include "world.h"
20#include "world_entity.h"
21
22using namespace std;
23
24/**
25   \brief creates a Camera
26   
27   This standard constructor sets all parameters to zero
28*/
29Camera::Camera (World* world)
30{
31  this->world = world;
32  bound = NULL;
33  /* give it some physical live */
34  mass = 10;
35  acceleration = new Vector(0.0, 0.0, 0.0);
36  velocity = new Vector(0.0, 0.0, 0.0);
37  cameraMode = NORMAL;
38  deltaTime = 3000.0;
39  cameraOffset = 1.0;
40  cameraOffsetZ = 10.0;
41  t = 0.0;
42
43  actual_place.pos.x = 0.0;
44  actual_place.pos.y = 10.0;
45  actual_place.pos.z = -5.0;
46 
47  // Initializing Target
48  target = new CameraTarget (Vector (0,0,0));
49 
50}
51
52/**
53   \brief default destructor
54*/
55Camera::~Camera ()
56{
57}
58
59/**
60   \brief time based actualisation of camera parameters
61   \param deltaT: The amount of time that has passed in milliseconds
62   
63   This is called by the World in every time_slice, use it to do fancy time dependant effects (such
64   as smooth camera movement or swaying).
65*/
66void Camera::time_slice (Uint32 deltaT)
67{
68  if(t <= deltaTime)
69    {t += deltaT;}
70  //printf("time is: t=%f\n", t );
71  update_desired_place ();
72  jump (NULL);
73}
74
75/**
76   \brief this calculates the location where the track wants the camera to be
77   
78   This refreshes the placement the camera should have according to the
79   bound entity's position on the track.
80*/
81void Camera::update_desired_place ()
82{
83  switch(cameraMode)
84    {
85
86    case NORMAL:
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;
91      if( bound != NULL && world != NULL )
92        {
93          bound->get_lookat (&lookat);
94          world->calc_camera_pos (&lookat, &desired_place);
95        } 
96      else
97        {
98          desired_place.pos = Vector (0,0,0);
99          desired_place.rot = Quaternion (); 
100        }
101      break;
102    }
103}
104
105/**
106   \brief initialize rendering perspective according to this camera
107   
108   This is called immediately before the rendering cycle starts, it sets all global
109   rendering options as well as the GL_PROJECTION matrix according to the camera.
110*/
111void Camera::apply ()
112{
113  glMatrixMode (GL_PROJECTION);
114  glLoadIdentity ();
115  // view
116  // TO DO: implement options for frustum generation
117  glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0);
118
119  // ===== first camera control calculation option
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
128  float matrix[4][4];
129  actual_place.rot.conjugate().matrix (matrix);
130  /* orientation and */
131  //  glMultMatrixf ((float*)matrix);
132  /*  translation */
133  //  glTranslatef (-actual_place.pos.x, -actual_place.pos.y,- actual_place.pos.z);
134  //Placement *plBound = bound->get_placement();
135
136  // ===== second camera control calculation option
137  /*
138    gluLookAt(actual_place.pos.x, actual_place.pos.y, actual_place.pos.z,
139              bound->pos.x, bound->pos.y, bound->pos.z,
140              0.0, 0.0, 1.0);
141  */   
142
143  glMatrixMode (GL_MODELVIEW);
144  glLoadIdentity ();
145}
146
147/**
148  \brief set the camera position
149  \param plc: The Placement to set the camera to
150       
151        This will set the actual and desired placement of the camera to plc
152*/
153void Camera::jump (Placement* plc = NULL)
154{
155  if( plc == NULL)
156    {
157      actual_place = desired_place;
158      //printf("Camera|jump: camer@ %f, %f, %f\n\n", actual_place.r.x, actual_place.r.y, actual_place.r.z);
159    }
160  else
161    {
162      desired_place = *plc;
163      actual_place = *plc;
164    }
165}
166
167/**
168  \brief bind the camera to an entity
169  \param entity: The enitity to bind the camera to
170       
171        This sets the focus of the camera to the given entity. This means that it will use the given WorldEntity's
172        Location and get_lookat() to determine the viewpoint the camera will render from.
173        Note that you cannot bind a camera to a free entity.
174*/
175void Camera::bind (WorldEntity* entity)
176{
177  if( entity != NULL)
178    {
179      if( entity->isFree ()) printf("Cannot bind camera to free entity");
180      else 
181        {
182          bound = entity;
183        }
184    } 
185}
186
187
188void Camera::setWorld(World* world)
189{
190  this->world = world;
191}
192
193
194
195CameraTarget::CameraTarget ()
196{
197 
198
199}
200
201CameraTarget::CameraTarget (Vector pos)
202{
203  this->setPosition (pos, WORLD);
204}
Note: See TracBrowser for help on using the repository browser.