Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/camera.cc @ 2624

Last change on this file since 2624 was 2115, checked in by chris, 20 years ago

orxonox/branches/chris: Managed to apply all that rotating and translating so that you now actually see the debug player following the track. You can even steer the spaceship via the keys now… unfortunately the coordinate transformations are still a mess. Even though mapping from Locations to Placements seems to work in general, applying the finetuned position and rotation still messes up the whole damn thing…

File size: 3.8 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 ()
30{
31        bound = NULL;
32}
33
34/**
35   \brief default destructor
36*/
37Camera::~Camera ()
38{
39}
40
41/**
42   \brief time based actualisation of camera parameters
43   \param deltaT: The amount of time that has passed in milliseconds
44   
45   This is called by the World in every time_slice, use it to do fancy time dependant effects (such
46   as smooth camera movement or swaying).
47*/
48void Camera::time_slice (Uint32 deltaT)
49{
50        update_desired_place ();
51        jump (NULL);
52}
53
54/**
55  \brief this calculates the location where the track wants the camera to be
56   
57        This refreshes the placement the camera should have according to the bound entity's position on the track.
58*/
59void Camera::update_desired_place ()
60{
61                Orxonox *orx = Orxonox::getInstance();
62                Location lookat;
63               
64                if( bound != NULL)
65                {
66                        bound->get_lookat (&lookat);
67                        orx->get_world()->calc_camera_pos (&lookat, &desired_place);
68                }
69                else
70                {
71                        desired_place.r = Vector (0,0,0);
72                        desired_place.w = Quaternion (); 
73                }
74}
75
76/**
77  \brief initialize rendering perspective according to this camera
78   
79        This is called immediately before the a rendering cycle starts, it sets all global rendering options as
80        well as the GL_PROJECTION matrix according to the camera.
81*/
82void Camera::apply ()
83{
84        glMatrixMode (GL_PROJECTION);
85  glLoadIdentity ();
86                // view
87                // TO DO: implement options for frustum generation
88        glFrustum( -1.0,1.0,-1.0,1.0,1.5,250.0);
89//Vector up(0,0,1);
90//Vector dir(1,0,0);
91//Quaternion q(dir,up);
92//float matrix[4][4];
93//q.conjugate().matrix (matrix);
94//glMultMatrixf ((float*)matrix);
95//glTranslatef (10,0,-5);
96//
97//dir = Vector(-1,-1,0);
98//q = Quaternion( dir, up);
99//glMatrixMode (GL_MODELVIEW);
100//glLoadIdentity ();
101//q.matrix (matrix);
102//glMultMatrixf ((float*)matrix);
103//glTranslatef (2,2,0);
104//
105//glBegin(GL_TRIANGLES);
106//glColor3f(1,0,0);
107//glVertex3f(0,0,0.5);
108//glColor3f(0,1,0);
109//glVertex3f(-0.5,0,-1);
110//glColor3f(0,0,1);
111//glVertex3f(0.5,0,-1);
112//glEnd();     
113
114        // rotation
115  float matrix[4][4];
116  actual_place.w.conjugate().matrix (matrix);
117  glMultMatrixf ((float*)matrix);
118        // translation
119  glTranslatef (-actual_place.r.x, -actual_place.r.y,- actual_place.r.z);
120 
121  glMatrixMode (GL_MODELVIEW);
122  glLoadIdentity ();
123 
124  printf("Camera@%f/%f/%f\n",actual_place.r.x,actual_place.r.y,actual_place.r.z);
125  Vector unique(1,0,0);
126  Vector test = actual_place.w.apply (unique);
127  printf("Camera&%f/%f/%f\n", test.x, test.y, test.z);
128}
129
130/**
131  \brief set the camera position
132  \param plc: The Placement to set the camera to
133       
134        This will set the actual and desired placement of the camera to plc
135*/
136void Camera::jump (Placement* plc = NULL)
137{
138        if( plc == NULL)
139        {
140                actual_place = desired_place;
141        }
142        else
143        {
144                desired_place = *plc;
145                actual_place = *plc;
146        }
147}
148
149/**
150  \brief bind the camera to an entity
151  \param entity: The enitity to bind the camera to
152       
153        This sets the focus of the camera to the given entity. This means that it will use the given WorldEntity's
154        Location and get_lookat() to determine the viewpoint the camera will render from.
155        Note that you cannot bind a camera to a free entity.
156*/
157void Camera::bind (WorldEntity* entity)
158{
159        if( entity != NULL)
160        {
161                if( entity->isFree ()) printf("Cannot bind camera to free entity");
162                else bound = entity;
163        } 
164}
Note: See TracBrowser for help on using the repository browser.