00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __CAMERA__H__
00013 #define __CAMERA__H__
00014
00015 #include "common.h"
00016 #include "bvolumes.h"
00017 #include "scenenode.h"
00018 #include "scene.h"
00019
00020
00021 namespace VRUT
00022 {
00023 class Scene;
00024
00026 class Camera : public SceneNode
00027 {
00028 private:
00030 MATRIX projMat;
00032 PLANE frustumPlanes[6];
00034 BSphere bSphere;
00036 float nearPlane;
00038 float farPlane;
00040 float fov;
00042 unsigned lastWidth;
00044 unsigned lastHeight;
00046 float centerDist;
00047
00049 void extractFrustum();
00051 void updateProjection();
00052
00053 public:
00055 enum VFC_RESULT
00056 {
00057 OUTSIDE = 0,
00058 INSIDE,
00059 INTERSECT
00060 };
00061
00063 enum FRUSTUM_PLANE
00064 {
00065 FRUSTUM_NEAR = 0,
00066 FRUSTUM_FAR,
00067 FRUSTUM_LEFT,
00068 FRUSTUM_RIGHT,
00069 FRUSTUM_TOP,
00070 FRUSTUM_BOTTOM
00071 };
00072
00074 Camera(const wxString & _uid, const wxString & _name);
00076 Camera(const Camera & c)
00077 : SceneNode(c), projMat(c.projMat), bSphere(c.bSphere),
00078 nearPlane(c.nearPlane), farPlane(c.farPlane), fov(c.fov),
00079 lastWidth(c.lastWidth), lastHeight(c.lastHeight), centerDist(c.centerDist)
00080 {
00081 for (int i = 0; i < 6; i++)
00082 frustumPlanes[i] = c.frustumPlanes[i];
00083 }
00085 virtual ~Camera();
00086
00088 VECTOR3 GetCenterPoint() const
00089 {
00090 return GetWorldTransMatrix()->ExtractTranslation() + GetCenterDist() * GetView();
00091 }
00092
00094 float GetCenterDist() const
00095 {
00096 return centerDist;
00097 }
00098
00100 void SetCenterDist(float dist)
00101 {
00102 centerDist = dist;
00103 }
00104
00106 float GetFOV() const
00107 {
00108 return fov;
00109 }
00110
00112 float GetFarPlane() const
00113 {
00114 return farPlane;
00115 }
00116
00118 float GetNearPlane() const
00119 {
00120 return nearPlane;
00121 }
00122
00124 VECTOR3 GetView() const
00125 {
00126 return (GetWorldTransMatrix()->TransformNormal(VECTOR3(0,0,-1)));
00127 }
00128
00130 VECTOR3 GetUp() const
00131 {
00132 return (GetWorldTransMatrix()->TransformNormal(VECTOR3(0,1,0)));
00133 }
00134
00136 const BSphere * GetBSphere() const
00137 {
00138 return &bSphere;
00139 }
00140
00142 void GetWidthHeight(unsigned * width, unsigned * height) const
00143 {
00144 *width = lastWidth;
00145 *height = lastHeight;
00146 }
00147
00149 const MATRIX * GetProjectionMatrix() const
00150 {
00151 if (!IsValid())
00152 LOGWARNING(wxT("<Camera>Getting invalid projection matrix - update first"));
00153 return &projMat;
00154 }
00155
00162 VFC_RESULT InFrustum(const AABB & aabb, int * lastOut, unsigned * planeMask) const;
00163
00165 virtual wxString ToString() const
00166 {
00167 wxString ret = SceneNode::ToString();
00168 ret << wxString::Format(wxT("Projection: \n%s\n"), projMat.ToString().c_str());
00169 for (int i = 0; i < 6; i++)
00170 ret << wxString::Format(wxT("Frustum plane %i: %s\n"), i, frustumPlanes[i].ToString().c_str());
00171 ret << wxString::Format(wxT("Bound sphere:\n%s\n"), bSphere.ToString().c_str());
00172 ret << wxString::Format(wxT("Near plane: %f\nFar plane: %f\nCenter distance: %f\n"), nearPlane, farPlane, centerDist);
00173 return ret;
00174 }
00175
00177 virtual SceneNode * Clone() const
00178 {
00179 return new Camera(*this);
00180 }
00181
00182 friend class Scene;
00183 };
00184 };
00185
00186 #endif