Blender  V2.59
KX_Camera.h
Go to the documentation of this file.
00001 /*
00002  * $Id: KX_Camera.h 35063 2011-02-22 10:33:14Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #ifndef __KX_CAMERA
00036 #define __KX_CAMERA
00037 
00038 
00039 #include "MT_Transform.h"
00040 #include "MT_Matrix3x3.h"
00041 #include "MT_Matrix4x4.h"
00042 #include "MT_Vector3.h"
00043 #include "MT_Point3.h"
00044 #include "KX_GameObject.h"
00045 #include "IntValue.h"
00046 #include "RAS_CameraData.h"
00047 
00048 #ifdef WITH_PYTHON
00049 /* utility conversion function */
00050 bool ConvertPythonToCamera(PyObject * value, KX_Camera **object, bool py_none_ok, const char *error_prefix);
00051 #endif
00052 
00053 class KX_Camera : public KX_GameObject
00054 {
00055         Py_Header;
00056 protected:
00057         friend class KX_Scene;
00063         RAS_CameraData  m_camdata;
00064 
00065         // Never used, I think...
00066 //      void MoveTo(const MT_Point3& movevec)
00067 //      {
00068                 /*MT_Transform camtrans;
00069                 camtrans.invert(m_trans1);
00070                 MT_Matrix3x3 camorient = camtrans.getBasis();
00071                 camtrans.translate(camorient.inverse()*movevec);
00072                 m_trans1.invert(camtrans);
00073                 */
00074 //      }
00075 
00079         MT_Matrix4x4 m_projection_matrix;
00080         //MT_Matrix4x4 m_projection_matrix1;
00081 
00085         MT_Matrix4x4 m_modelview_matrix;
00086         
00092         bool         m_dirty;
00096         bool         m_normalized;
00097         
00101         MT_Vector4   m_planes[6];
00102         
00107         bool         m_frustum_culling;
00108         
00112         bool         m_set_projection_matrix;
00113         
00117         MT_Point3    m_frustum_center;
00118         MT_Scalar    m_frustum_radius;
00119         bool         m_set_frustum_center;
00120 
00124         bool             m_delete_node;
00125 
00129         void ExtractClipPlanes();
00133         void NormalizeClipPlanes();
00137         void ExtractFrustumSphere();
00141         MT_Vector4 *GetNormalizedClipPlanes()
00142         {
00143                 ExtractClipPlanes();
00144                 NormalizeClipPlanes();
00145                 return m_planes;
00146         }
00147 
00148 public:
00149 
00150         enum { INSIDE, INTERSECT, OUTSIDE } ;
00151 
00152         KX_Camera(void* sgReplicationInfo,SG_Callbacks callbacks,const RAS_CameraData& camdata, bool frustum_culling = true, bool delete_node = false);
00153         virtual ~KX_Camera();
00154         
00160         virtual CValue*                         
00161         GetReplica(
00162         );
00163         virtual void ProcessReplica();
00164 
00165         MT_Transform            GetWorldToCamera() const;
00166         MT_Transform            GetCameraToWorld() const;
00167 
00171         void                            CorrectLookUp(MT_Scalar speed);
00172         const MT_Point3         GetCameraLocation() const;
00173 
00174         /* I want the camera orientation as well. */
00175         const MT_Quaternion GetCameraOrientation() const;
00176                 
00178         void                            SetProjectionMatrix(const MT_Matrix4x4 & mat);
00179 
00181         void                            SetModelviewMatrix(const MT_Matrix4x4 & mat);
00182                 
00184         const MT_Matrix4x4&             GetProjectionMatrix() const;
00185         
00187         bool                            hasValidProjectionMatrix() const;
00188         
00193         void                            InvalidateProjectionMatrix(bool valid = false);
00194         
00198         const MT_Matrix4x4&             GetModelviewMatrix() const;
00199 
00201         float                           GetLens() const;
00203         float                           GetScale() const;
00205         float                           GetCameraNear() const;
00207         float                           GetCameraFar() const;
00209         float                           GetFocalLength() const;
00211         RAS_CameraData*         GetCameraData();
00212         
00220         int SphereInsideFrustum(const MT_Point3& center, const MT_Scalar &radius);
00227         int BoxInsideFrustum(const MT_Point3 *box);
00232         bool PointInsideFrustum(const MT_Point3& x);
00233         
00237         bool GetFrustumCulling() const;
00238         
00242         void EnableViewport(bool viewport);
00243         
00247         void SetViewport(int left, int bottom, int right, int top);
00248         
00252         bool GetViewport() const;
00253         
00257         int GetViewportLeft() const;
00258         
00262         int GetViewportBottom() const;
00263         
00267         int GetViewportRight() const;
00268         
00272         int GetViewportTop() const;
00273 
00274         virtual int GetGameObjectType() { return OBJ_CAMERA; }
00275 
00276 #ifdef WITH_PYTHON
00277         KX_PYMETHOD_DOC_VARARGS(KX_Camera, sphereInsideFrustum);
00278         KX_PYMETHOD_DOC_O(KX_Camera, boxInsideFrustum);
00279         KX_PYMETHOD_DOC_O(KX_Camera, pointInsideFrustum);
00280         
00281         KX_PYMETHOD_DOC_NOARGS(KX_Camera, getCameraToWorld);
00282         KX_PYMETHOD_DOC_NOARGS(KX_Camera, getWorldToCamera);
00283         
00284         KX_PYMETHOD_DOC_VARARGS(KX_Camera, setViewport);        
00285         KX_PYMETHOD_DOC_NOARGS(KX_Camera, setOnTop);    
00286 
00287         KX_PYMETHOD_DOC_O(KX_Camera, getScreenPosition);
00288         KX_PYMETHOD_DOC_VARARGS(KX_Camera, getScreenVect);
00289         KX_PYMETHOD_DOC_VARARGS(KX_Camera, getScreenRay);
00290         
00291         static PyObject*        pyattr_get_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00292         static int                      pyattr_set_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00293 
00294         static PyObject*        pyattr_get_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00295         static int                      pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00296         static PyObject*        pyattr_get_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00297         static int                      pyattr_set_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00298         static PyObject*        pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00299         static int                      pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00300         static PyObject*        pyattr_get_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00301         static int                      pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00302         
00303         static PyObject*        pyattr_get_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00304         static int                      pyattr_set_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00305         
00306         static PyObject*        pyattr_get_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00307         static int                      pyattr_set_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00308         
00309         static PyObject*        pyattr_get_modelview_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00310         static PyObject*        pyattr_get_camera_to_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00311         static PyObject*        pyattr_get_world_to_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00312         
00313         static PyObject*        pyattr_get_INSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00314         static PyObject*        pyattr_get_OUTSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00315         static PyObject*        pyattr_get_INTERSECT(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00316 #endif
00317 };
00318 
00319 #endif //__KX_CAMERA
00320