Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: functions to set gluPerspective-options

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