Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/camera.cc @ 3638

Last change on this file since 3638 was 3638, checked in by bensch, 19 years ago

orxonox/trunk: camera now banks together with the TrackManager

File size: 2.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
20#include "world.h"
21#include "world_entity.h"
22#include "vector.h"
23
24using namespace std;
25
26////////////
27// CAMERA //
28////////////
29
30/**
31   \brief creates a Camera
32*/
33Camera::Camera(void)
34{
35  this->target = new CameraTarget();
36
37  this->setFovy(60);
38  this->setAspectRatio(1.2f);
39  this->setClipRegion(.1, 2000);
40}
41
42/**
43   \brief default destructor
44*/
45Camera::~Camera(void)
46{
47
48}
49
50/**
51   \brief focuses the Camera onto a Target
52   \param target the new PNode the Camera should look at.
53*/
54void Camera::lookAt(PNode* target)
55{
56  this->target->setParent(target);
57}
58
59/**
60   \returns The PNode of the Target (from there you can get position and so on
61*/
62PNode* Camera::getTarget(void)
63{
64  return (PNode*)this->target;
65}
66
67
68/**
69   \brief sets a new AspectRatio
70   \param aspectRatio the new aspect ratio to set (width / height)
71*/
72void Camera::setAspectRatio(float aspectRatio)
73{
74  this->aspectRatio = aspectRatio;
75}
76
77/**
78   \brief sets the Field of View to fofy
79   \param fovy new field of view factor (in degrees)
80*/
81void Camera::setFovy(float fovy)
82{
83  this->fovy = fovy;
84}
85
86/**
87  \brief Sets a new clipping region
88  \param nearClip The near clip plane
89  \param farClip The far clip plane
90*/
91void Camera::setClipRegion(float nearClip, float farClip)
92{
93  this->nearClip = nearClip;
94  this->farClip = farClip;
95}
96
97/**
98   \brief initialize rendering perspective according to this camera
99   
100   This is called immediately before the rendering cycle starts, it sets all global
101   rendering options as well as the GL_PROJECTION matrix according to the camera.
102*/
103void Camera::apply ()
104{
105  // switching to Projection Matrix
106  glMatrixMode (GL_PROJECTION);
107  glLoadIdentity ();
108
109  // setting up the perspective
110  gluPerspective(this->fovy,
111                 this->aspectRatio,
112                 this->nearClip,
113                 this->farClip);
114
115  // speed-up feature
116  Vector cameraPosition = this->getAbsCoor();
117  Vector targetPosition = this->target->getAbsCoor();
118  Vector up = Vector(0, 1, 0);
119  up = this->getAbsDir().apply(up);
120
121  // Setting the Camera Eye, lookAt and up Vectors
122  gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
123            targetPosition.x, targetPosition.y, targetPosition.z,
124            up.x, up.y, up.z);
125
126  // switching back to Modeling Matrix
127  glMatrixMode (GL_MODELVIEW);
128}
129
130
131
132///////////////////
133// CAMERA-TARGET //
134///////////////////
135
136
137CameraTarget::CameraTarget()
138{
139  this->setMode(PNODE_MOVEMENT);
140}
141
142CameraTarget::~CameraTarget()
143{
144
145}
Note: See TracBrowser for help on using the repository browser.