1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_CAMERA_SCENE_NODE_H_INCLUDED__
6
#define __C_CAMERA_SCENE_NODE_H_INCLUDED__
8
#include "ICameraSceneNode.h"
9
#include "SViewFrustum.h"
16
class CCameraSceneNode : public ICameraSceneNode
21
CCameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
22
const core::vector3df& position = core::vector3df(0,0,0),
23
const core::vector3df& lookat = core::vector3df(0,0,100));
25
//! Sets the projection matrix of the camera.
26
/** The core::matrix4 class has some methods
27
to build a projection matrix. e.g: core::matrix4::buildProjectionMatrixPerspectiveFovLH.
28
Note that the matrix will only stay as set by this method until one of
29
the following Methods are called: setNearValue, setFarValue, setAspectRatio, setFOV.
30
\param projection The new projection matrix of the camera.
31
\param isOrthogonal Set this to true if the matrix is an orthogonal one (e.g.
32
from matrix4::buildProjectionMatrixOrthoLH(). */
33
virtual void setProjectionMatrix(const core::matrix4& projection, bool isOrthogonal = false);
35
//! Gets the current projection matrix of the camera
36
//! \return Returns the current projection matrix of the camera.
37
virtual const core::matrix4& getProjectionMatrix() const;
39
//! Gets the current view matrix of the camera
40
//! \return Returns the current view matrix of the camera.
41
virtual const core::matrix4& getViewMatrix() const;
43
//! Sets a custom view matrix affector.
44
/** \param affector: The affector matrix. */
45
virtual void setViewMatrixAffector(const core::matrix4& affector);
47
//! Gets the custom view matrix affector.
48
virtual const core::matrix4& getViewMatrixAffector() const;
50
//! It is possible to send mouse and key events to the camera. Most cameras
51
//! may ignore this input, but camera scene nodes which are created for
52
//! example with scene::ISceneManager::addMayaCameraSceneNode or
53
//! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input
54
//! for changing their position, look at target or whatever.
55
virtual bool OnEvent(const SEvent& event);
57
//! Sets the look at target of the camera
58
/** If the camera's target and rotation are bound ( @see bindTargetAndRotation() )
59
then calling this will also change the camera's scene node rotation to match the target.
60
\param pos: Look at target of the camera. */
61
virtual void setTarget(const core::vector3df& pos);
63
//! Sets the rotation of the node.
64
/** This only modifies the relative rotation of the node.
65
If the camera's target and rotation are bound ( @see bindTargetAndRotation() )
66
then calling this will also change the camera's target to match the rotation.
67
\param rotation New rotation of the node in degrees. */
68
virtual void setRotation(const core::vector3df& rotation);
70
//! Gets the current look at target of the camera
71
/** \return The current look at target of the camera */
72
virtual const core::vector3df& getTarget() const;
74
//! Sets the up vector of the camera.
75
//! \param pos: New upvector of the camera.
76
virtual void setUpVector(const core::vector3df& pos);
78
//! Gets the up vector of the camera.
79
//! \return Returns the up vector of the camera.
80
virtual const core::vector3df& getUpVector() const;
82
//! Gets distance from the camera to the near plane.
83
//! \return Value of the near plane of the camera.
84
virtual f32 getNearValue() const;
86
//! Gets the distance from the camera to the far plane.
87
//! \return Value of the far plane of the camera.
88
virtual f32 getFarValue() const;
90
//! Get the aspect ratio of the camera.
91
//! \return The aspect ratio of the camera.
92
virtual f32 getAspectRatio() const;
94
//! Gets the field of view of the camera.
95
//! \return Field of view of the camera
96
virtual f32 getFOV() const;
98
//! Sets the value of the near clipping plane. (default: 1.0f)
99
virtual void setNearValue(f32 zn);
101
//! Sets the value of the far clipping plane (default: 2000.0f)
102
virtual void setFarValue(f32 zf);
104
//! Sets the aspect ratio (default: 4.0f / 3.0f)
105
virtual void setAspectRatio(f32 aspect);
107
//! Sets the field of view (Default: PI / 3.5f)
108
virtual void setFOV(f32 fovy);
111
virtual void OnRegisterSceneNode();
114
virtual void render();
116
//! Returns the axis aligned bounding box of this node
117
virtual const core::aabbox3d<f32>& getBoundingBox() const;
119
//! Returns the view area. Sometimes needed by bsp or lod render nodes.
120
virtual const SViewFrustum* getViewFrustum() const;
122
//! Disables or enables the camera to get key or mouse inputs.
123
//! If this is set to true, the camera will respond to key inputs
125
virtual void setInputReceiverEnabled(bool enabled);
127
//! Returns if the input receiver of the camera is currently enabled.
128
virtual bool isInputReceiverEnabled() const;
130
//! Writes attributes of the scene node.
131
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
133
//! Reads attributes of the scene node.
134
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
136
//! Returns type of the scene node
137
virtual ESCENE_NODE_TYPE getType() const { return ESNT_CAMERA; }
139
//! Binds the camera scene node's rotation to its target position and vice vera, or unbinds them.
140
virtual void bindTargetAndRotation(bool bound);
142
//! Queries if the camera scene node's rotation and its target position are bound together.
143
virtual bool getTargetAndRotationBinding(void) const;
145
//! Creates a clone of this scene node and its children.
146
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0);
150
void recalculateProjectionMatrix();
151
void recalculateViewArea();
153
core::vector3df Target;
154
core::vector3df UpVector;
156
f32 Fovy; // Field of view, in radians.
157
f32 Aspect; // Aspect ratio.
158
f32 ZNear; // value of the near view-plane.
159
f32 ZFar; // Z-value of the far view-plane.
161
SViewFrustum ViewArea;
162
core::matrix4 Affector;
164
bool InputReceiverEnabled;
165
bool TargetAndRotationAreBound;