Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #ifndef __KX_CAMERA 00034 #define __KX_CAMERA 00035 00036 00037 #include "MT_Transform.h" 00038 #include "MT_Matrix3x3.h" 00039 #include "MT_Matrix4x4.h" 00040 #include "MT_Vector3.h" 00041 #include "MT_Point3.h" 00042 #include "KX_GameObject.h" 00043 #include "IntValue.h" 00044 #include "RAS_CameraData.h" 00045 00046 #ifdef WITH_PYTHON 00047 /* utility conversion function */ 00048 bool ConvertPythonToCamera(PyObject * value, KX_Camera **object, bool py_none_ok, const char *error_prefix); 00049 #endif 00050 00051 class KX_Camera : public KX_GameObject 00052 { 00053 Py_Header 00054 protected: 00055 friend class KX_Scene; 00061 RAS_CameraData m_camdata; 00062 00063 // Never used, I think... 00064 // void MoveTo(const MT_Point3& movevec) 00065 // { 00066 /*MT_Transform camtrans; 00067 camtrans.invert(m_trans1); 00068 MT_Matrix3x3 camorient = camtrans.getBasis(); 00069 camtrans.translate(camorient.inverse()*movevec); 00070 m_trans1.invert(camtrans); 00071 */ 00072 // } 00073 00077 MT_Matrix4x4 m_projection_matrix; 00078 //MT_Matrix4x4 m_projection_matrix1; 00079 00083 MT_Matrix4x4 m_modelview_matrix; 00084 00090 bool m_dirty; 00094 bool m_normalized; 00095 00099 MT_Vector4 m_planes[6]; 00100 00105 bool m_frustum_culling; 00106 00110 bool m_set_projection_matrix; 00111 00115 MT_Point3 m_frustum_center; 00116 MT_Scalar m_frustum_radius; 00117 bool m_set_frustum_center; 00118 00122 bool m_delete_node; 00123 00127 void ExtractClipPlanes(); 00131 void NormalizeClipPlanes(); 00135 void ExtractFrustumSphere(); 00139 MT_Vector4 *GetNormalizedClipPlanes() 00140 { 00141 ExtractClipPlanes(); 00142 NormalizeClipPlanes(); 00143 return m_planes; 00144 } 00145 00146 public: 00147 00148 enum { INSIDE, INTERSECT, OUTSIDE } ; 00149 00150 KX_Camera(void* sgReplicationInfo,SG_Callbacks callbacks,const RAS_CameraData& camdata, bool frustum_culling = true, bool delete_node = false); 00151 virtual ~KX_Camera(); 00152 00158 virtual CValue* 00159 GetReplica( 00160 ); 00161 virtual void ProcessReplica(); 00162 00163 MT_Transform GetWorldToCamera() const; 00164 MT_Transform GetCameraToWorld() const; 00165 00169 void CorrectLookUp(MT_Scalar speed); 00170 const MT_Point3 GetCameraLocation() const; 00171 00172 /* I want the camera orientation as well. */ 00173 const MT_Quaternion GetCameraOrientation() const; 00174 00176 void SetProjectionMatrix(const MT_Matrix4x4 & mat); 00177 00179 void SetModelviewMatrix(const MT_Matrix4x4 & mat); 00180 00182 const MT_Matrix4x4& GetProjectionMatrix() const; 00183 00185 bool hasValidProjectionMatrix() const; 00186 00191 void InvalidateProjectionMatrix(bool valid = false); 00192 00196 const MT_Matrix4x4& GetModelviewMatrix() const; 00197 00199 float GetLens() const; 00201 float GetScale() const; 00203 float GetSensorWidth() const; 00205 float GetSensorHeight() const; 00207 short GetSensorFit() const; 00209 float GetCameraNear() const; 00211 float GetCameraFar() const; 00213 float GetFocalLength() const; 00215 RAS_CameraData* GetCameraData(); 00216 00224 int SphereInsideFrustum(const MT_Point3& center, const MT_Scalar &radius); 00231 int BoxInsideFrustum(const MT_Point3 *box); 00236 bool PointInsideFrustum(const MT_Point3& x); 00237 00241 bool GetFrustumCulling() const; 00242 00246 void EnableViewport(bool viewport); 00247 00251 void SetViewport(int left, int bottom, int right, int top); 00252 00256 bool GetViewport() const; 00257 00261 int GetViewportLeft() const; 00262 00266 int GetViewportBottom() const; 00267 00271 int GetViewportRight() const; 00272 00276 int GetViewportTop() const; 00277 00278 virtual int GetGameObjectType() { return OBJ_CAMERA; } 00279 00280 #ifdef WITH_PYTHON 00281 KX_PYMETHOD_DOC_VARARGS(KX_Camera, sphereInsideFrustum); 00282 KX_PYMETHOD_DOC_O(KX_Camera, boxInsideFrustum); 00283 KX_PYMETHOD_DOC_O(KX_Camera, pointInsideFrustum); 00284 00285 KX_PYMETHOD_DOC_NOARGS(KX_Camera, getCameraToWorld); 00286 KX_PYMETHOD_DOC_NOARGS(KX_Camera, getWorldToCamera); 00287 00288 KX_PYMETHOD_DOC_VARARGS(KX_Camera, setViewport); 00289 KX_PYMETHOD_DOC_NOARGS(KX_Camera, setOnTop); 00290 00291 KX_PYMETHOD_DOC_O(KX_Camera, getScreenPosition); 00292 KX_PYMETHOD_DOC_VARARGS(KX_Camera, getScreenVect); 00293 KX_PYMETHOD_DOC_VARARGS(KX_Camera, getScreenRay); 00294 00295 static PyObject* pyattr_get_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00296 static int pyattr_set_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00297 00298 static PyObject* pyattr_get_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00299 static int pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00300 static PyObject* pyattr_get_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00301 static int pyattr_set_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00302 static PyObject* pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00303 static int pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00304 static PyObject* pyattr_get_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00305 static int pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00306 00307 static PyObject* pyattr_get_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00308 static int pyattr_set_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00309 00310 static PyObject* pyattr_get_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00311 static int pyattr_set_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00312 00313 static PyObject* pyattr_get_modelview_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00314 static PyObject* pyattr_get_camera_to_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00315 static PyObject* pyattr_get_world_to_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00316 00317 static PyObject* pyattr_get_INSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00318 static PyObject* pyattr_get_OUTSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00319 static PyObject* pyattr_get_INTERSECT(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00320 #endif 00321 }; 00322 00323 #endif //__KX_CAMERA 00324