Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/chris: Implemented basic track and spawning functionality. Added a function to convert a Rotation into a glmatrix. Implemented operator* in Rotation. Refined World, made World friend class of world_entity. Implemented camera functionality (can now be bound to the worldentity it should focus on).

File size: 1.7 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
19#include "camera.h"
20
21using namespace std;
22
23Camera::Camera ()
24{
25        bound = NULL;
26        desired_place.r = Vector (0,0,0);
27        desired_place.w = Rotation (0,0,0);
28        actual_place.r = Vector (0,0,0);
29        actual_place.w = Rotation (0,0,0);
30}
31
32Camera::~Camera ()
33{
34}
35
36void Camera::time_slice (Uint32 deltaT)
37{
38        update_desired_place ();
39}
40
41void Camera::update_desired_place ()
42{
43                Orxonox *orx = Orxonox::getInstance();
44                Location lookat;
45               
46                if( bound != NULL)
47                {
48                        bound->get_lookat (&lookat);
49                        orx->get_world()->calc_camera_pos (&lookat, &desired_place);
50                }
51                else
52                {
53                        desired_place.r = Vector (0,0,0);
54                        desired_place.w = Rotation (0,0,0); 
55                }
56}
57
58void Camera::apply ()
59{
60        glMatrixMode (GL_PROJECTION);
61                // view
62                // TO DO: implement options for frustum generation
63        glFrustum( -1.0,1.0,-1.0,1.0,1.5,20.0);
64        // rotation
65  float matrix[16];
66  actual_place.w.glmatrix (matrix);
67  glLoadMatrixf (matrix);
68        // translation
69  glTranslatef (actual_place.v.x, actual_place.v.y, actual_place.v.z);
70 
71  glMatrixMode (GL_MODELVIEW);
72  glLoadIdentity ();
73}
74
75void Camera::jump (Placement* plc = NULL)
76{
77        if( plc == NULL)
78        {
79                actual_place = desired_place;
80        }
81        else
82        {
83                desired_place = *plc;
84                actual_place = *plc;
85        }
86}
87
88void Camera::bind (WorldEntity* entity)
89{
90        if( entity != NULL)
91        {
92                if( entity->bFree) printf("Cannot bind camera to free entity");
93                else bound = entity;
94        } 
95}
Note: See TracBrowser for help on using the repository browser.