1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_CAMERA3D_H
#define HPL_CAMERA3D_H
#include "hpl1/engine/math/Frustum.h"
#include "hpl1/engine/math/MathTypes.h"
#include "hpl1/engine/scene/Camera.h"
#include "hpl1/engine/scene/Node3D.h"
namespace hpl {
enum eCameraMoveMode {
eCameraMoveMode_Walk,
eCameraMoveMode_Fly,
eCameraMoveMode_LastEnum
};
enum eCameraRotateMode {
eCameraRotateMode_EulerAngles,
eCameraRotateMode_Matrix,
eCameraRotateMode_LastEnum
};
class iLowLevelGraphics;
class iEntity3D;
class cCamera3D : public iCamera {
public:
cCamera3D();
virtual ~cCamera3D();
const cVector3f &GetPosition() const { return mvPosition; }
void SetPosition(const cVector3f &avPos);
/**
* Move forward (or back) according to the move mode.
* \param afDist
*/
void MoveForward(float afDist);
/**
* Move right (or left) according to the move mode.
* \param afDist
*/
void MoveRight(float afDist);
/**
* Move up (or down) according to the move mode.
* \param afDist
*/
void MoveUp(float afDist);
void SetFOV(float afAngle) {
mfFOV = afAngle;
mbProjectionUpdated = true;
}
float GetFOV() { return mfFOV; }
void SetAspect(float afAngle) {
mfAspect = afAngle;
mbProjectionUpdated = true;
}
float GetAspect() { return mfAspect; }
void SetFarClipPlane(float afX) {
mfFarClipPlane = afX;
mbProjectionUpdated = true;
}
float GetFarClipPlane() { return mfFarClipPlane; }
void SetNearClipPlane(float afX) {
mfNearClipPlane = afX;
mbProjectionUpdated = true;
}
float GetNearClipPlane() { return mfNearClipPlane; }
/**
* This sets the far plane so that no far clipping is made.
* The FarClipPlane is still used for creating bounding box and frustum and
* should be set to some value.
*/
void SetInifintiveFarPlane(bool abX) {
mbInfFarPlane = abX;
mbProjectionUpdated = true;
}
bool GetInifintiveFarPlane() { return mbInfFarPlane; }
cFrustum *GetFrustum();
eCameraRotateMode GetRotateMode() { return mRotateMode; }
eCameraMoveMode GetMoveMode() { return mMoveMode; }
/**
* Set the mode to calculate the rotation angles.
* EulerAngles: Yaw, Pitch and Roll are used.
* Matrix: The matrix is changed directly.
*/
void SetRotateMode(eCameraRotateMode aMode);
/**
* Set the mode to calculate movement.
* Walk: only moving in the XZ plane
* Fly: moving in the dir the camera is facing.
*/
void SetMoveMode(eCameraMoveMode aMode);
/**
* Resets all rotation
*/
void ResetRotation();
/**
* Unproject the screen coordinate to world space.
*/
cVector3f UnProject(const cVector2f &avScreenPos, iLowLevelGraphics *apLowLevel);
void AttachEntity(iEntity3D *apEntity);
void RemoveEntity(iEntity3D *apEntity);
cNode3D *GetAttachmentNode() { return &mNode; }
void ClearAttachedEntities();
//////////////////////////////////////////////////
////////// EULER ANGLES ROTATION /////////////////
//////////////////////////////////////////////////
void SetPitch(float afAngle);
void SetYaw(float afAngle);
void SetRoll(float afAngle);
void AddPitch(float afAngle);
void AddYaw(float afAngle);
void AddRoll(float afAngle);
float GetPitch() const { return mfPitch; }
float GetYaw() const { return mfYaw; }
float GetRoll() const { return mfRoll; }
/**
* Set the limits within the pitch can move
* \param avLimits x = high limt and y low.If both are 0 limits are disabled.
*/
void SetPitchLimits(cVector2f avLimits) { mvPitchLimits = avLimits; }
const cVector2f &GetPitchLimits() { return mvPitchLimits; }
/**
* Set the limits within the yaw can move
* \param avLimits x = high limt and y low. If both are 0 limits are disabled.
*/
void SetYawLimits(cVector2f avLimits) { mvYawLimits = avLimits; }
const cVector2f &GetYawLimits() { return mvYawLimits; }
//////////////////////////////////////////////////
////////// EULER ANGLES ROTATION /////////////////
//////////////////////////////////////////////////
const cMatrixf &GetViewMatrix();
const cMatrixf &GetProjectionMatrix();
const cMatrixf &GetMoveMatrix();
// iCamera stuff:
void SetModelViewMatrix(iLowLevelGraphics *apLowLevel);
void SetProjectionMatrix(iLowLevelGraphics *apLowLevel);
cVector3f GetEyePosition();
eCameraType GetType() { return eCameraType_3D; }
cVector3f GetForward();
cVector3f GetRight();
cVector3f GetUp();
//////////////////////////////////////////////////
////////// RENDER SPECIFIC ///////////////////////
//////////////////////////////////////////////////
void SetPrevView(const cMatrixf &a_mtxA) { m_mtxPrevView = a_mtxA; }
void SetPrevProjection(const cMatrixf &a_mtxA) { m_mtxPrevProjection = a_mtxA; }
cMatrixf &GetPrevView() { return m_mtxPrevView; }
cMatrixf &GetPrevProjection() { return m_mtxPrevProjection; }
private:
void UpdateMoveMatrix();
cVector3f mvPosition;
float mfFOV;
float mfAspect;
float mfFarClipPlane;
float mfNearClipPlane;
float mfPitch;
float mfYaw;
float mfRoll;
cVector2f mvPitchLimits;
cVector2f mvYawLimits;
eCameraRotateMode mRotateMode;
eCameraMoveMode mMoveMode;
cMatrixf m_mtxView;
cMatrixf m_mtxProjection;
cMatrixf m_mtxMove;
cMatrixf m_mtxPrevView;
cMatrixf m_mtxPrevProjection;
cNode3D mNode;
cFrustum mFrustum;
bool mbInfFarPlane;
bool mbViewUpdated;
bool mbProjectionUpdated;
bool mbMoveUpdated;
};
} // namespace hpl
#endif // HPL_CAMERA3D_H
|