Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_GameObject.h

Go to the documentation of this file.
00001 #ifndef __KX_GAMEOBJECT
00002 #define __KX_GAMEOBJECT
00003 
00004 
00005 #ifdef WIN32
00006 // get rid of this stupid "warning 'this' used in initialiser list", generated by VC when including Solid/Sumo
00007 #pragma warning (disable : 4355) 
00008 #endif 
00009 
00010 
00011 #include "ListValue.h"
00012 #include "SCA_IObject.h"
00013 #include "SG_Node.h"
00014 #include "MT_Transform.h"
00015 
00016 #define KX_FIXED_FRAME_PER_SEC 25.0f
00017 #define KX_FIXED_SEC_PER_FRAME (1.0f / KX_FIXED_FRAME_PER_SEC)
00018 #define KX_OB_DYNAMIC 1
00019 
00020 
00021 
00022 // defined on bottom of this headerfile
00023 
00024 class SM_Object;
00025 
00026 #include "KX_Matrix4x4.h"
00027 
00028 
00029 class KX_GameObject : public SCA_IObject
00030 {
00031         Py_Header;
00032 
00033         bool                            m_bDyna;
00034         struct  SM_ClientObjectInfo* m_pClient_info;
00035         MT_Vector3                      m_DynamicsScaling;
00036         CCString                        m_name;
00037         CCString                        m_text;
00038         std::vector                             <class RAS_MeshObject*>         m_meshes;
00039         bool                            m_bInLayer;
00040         bool                            m_bSuspendDynamics;
00041         
00042         // in future get/find next (m_pPhysicsController) 
00043         // from Node info etc.
00044         class KX_PhysicsController*     m_pPhysicsController;
00045 
00046          SG_Node*               m_pSGNode;
00047 
00048 protected:
00049         CMatrix4x4                      m_OpenGL_4x4Matrix;
00050         double*                         GetOpenGLMatrix();
00051 public:
00052 
00053         KX_GameObject(void* sgReplicationInfo,SG_Callbacks callbacks,PyTypeObject* T=&Type);
00054         virtual ~KX_GameObject();
00055         virtual CValue*         AddRef()

00056         {
00057                 // temporarily to find memleaks
00058                 return CValue::AddRef();
00059         }
00060         // Add a reference to this value
00061         virtual CValue*         Calc(VALUE_OPERATOR op, CValue *val) ;
00062         virtual CValue*         CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
00063         virtual const CCString &        GetText();
00064         virtual float           GetNumber();
00065         virtual CCString        GetName();
00066         
00067         virtual void            SetName(CCString name);                                                         // Set the name of the value
00068         virtual void            ReplicaSetName(CCString name);
00069         virtual CValue*         GetReplica();
00070 
00071         void    RelativeTransform(const MT_Transform& trans);
00072         
00073         // Sumo Physics methods
00074         virtual void RegisterSumoObject(class SM_Scene* sumoScene,class SM_Object* sumoObj,const char* matname,bool isDynamic,bool isActor,bool addghost);
00075         SM_Object*              GetSumoObject();
00076 
00077 
00078 
00079         void                                                    NodeSetLocalPosition(const MT_Point3& trans);
00080         void                                                    NodeSetLocalOrientation(const MT_Matrix3x3& rot);
00081         void                                                    NodeSetLocalScale(const MT_Vector3& scale);
00082         void                                                    NodeUpdateGS(double time,bool bInitiator);
00083         const MT_Matrix3x3&                             NodeGetWorldOrientation() const;
00084         const MT_Vector3&                               NodeGetWorldScaling() const;
00085         const MT_Point3&                                NodeGetWorldPosition() const;
00086         void                                                    NodeAddChild(class SG_Spatial* child);
00087         void                                                    NodeSetVertexParent(bool isvertexparent);
00088 
00089         SG_Node*                                                GetSGNode()

00090         {       
00091                 return m_pSGNode;
00092         }
00093         void    SetSGNode(SG_Node* node) {
00094                         m_pSGNode = node;
00095 
00096         }
00097 
00098         const SG_Node*                                          GetSGNode() const

00099         {       
00100                 return m_pSGNode;
00101         }
00102 
00103 
00104         bool    IsDynamic()             { 
00105                 return m_bDyna; 
00106         }
00107         bool    IsInLayer()     {       return m_bInLayer;};
00108         void    ApplyForce(const MT_Vector3& force,bool local);
00109         void    ApplyTorque(const MT_Vector3& torque,bool local);
00110         void    ApplyRotation(const MT_Vector3& drot,bool local);
00111         void    ApplyMovement(const MT_Vector3& dloc,bool local);
00112 
00113 <<<<<<< KX_GameObject.h
00114         /*void Move(const MT_Vector3& movevec)

00115         {

00116                 //MT_Vector3 newpos = m_trans1.getOrigin()- movevec;

00117                 //m_trans1.setOrigin(newpos.getValue());

00118         }

00119         */
00120 =======
00121 >>>>>>> 1.55
00122 
00123         MT_Matrix3x3 RotateWorld (const MT_Vector3& v, MT_Scalar angle)

00124         {
00125                   MT_Vector3 u = v.normalized();
00126                   MT_Scalar ca, sa;
00127                   ca = cos (angle);
00128                   sa = sin (angle);
00129                   return MT_Matrix3x3   (
00130                                          ca+(1-ca)*u.x()*u.x(), u.x()*u.y()*(1-ca)-u.z()*sa, u.x()*u.z()*(1-ca)+u.y()*sa,
00131                                  u.x()*u.y()*(1-ca)+u.z()*sa,     ca+(1-ca)*u.y()*u.y(), u.y()*u.z()*(1-ca)-u.x()*sa,
00132                                  u.x()*u.z()*(1-ca)-u.y()*sa, u.y()*u.z()*(1-ca)+u.x()*sa,     ca+(1-ca)*u.z()*u.z());
00133         }
00134 
00135 
00136 <<<<<<< KX_GameObject.h
00137         
00138 =======
00139 >>>>>>> 1.55
00140         void    Bucketize();
00141         void    RemoveMeshes();
00142         void    AddMesh(RAS_MeshObject* mesh)

00143         {
00144                 m_meshes.push_back(mesh);
00145         }
00146         RAS_MeshObject* GetMesh(int num) { return m_meshes[num];}
00147         int     GetMeshCount() { return m_meshes.size();};
00148         
00149         void    SetMeshScaling(const MT_Vector3& scale) {
00150                 //m_ipo_xform.SetScaling(scale);
00151         };
00152 
00153 <<<<<<< KX_GameObject.h
00154 =======
00155 
00156 >>>>>>> 1.55
00157         void    SetDynamicsScaling(const MT_Vector3& scale) {
00158                 m_DynamicsScaling = scale;
00159         };
00160         const MT_Vector3& GetDynamicScaling() const {
00161                 return m_DynamicsScaling;
00162         }
00163 
00164         
00165         void    UpdateTransform(bool i_am_ipo = true);
00166         void    UpdateIPO(float curframetime);
00167         void    SetSumoMotionState();
00168         
00169         void    SetDebugColor(unsigned int bgra);
00170         void    ResetDebugColor();
00171 
00172         void    MarkVisible(bool visible);
00173         
00174         virtual PyObject*  _getattr(char *attr);
00175 
00176         PyObject* PySetPosition(PyObject* self, 
00177                                PyObject* args, 
00178                                PyObject* kwds) {
00179                 //futureMove(10,0,0)
00180                 // make a general function for this, it's needed many times
00181                 MT_Point3 pos;
00182                 PyObject* pylist;
00183                 bool    error = false;
00184                 
00185                 PyArg_ParseTuple(args,"O",&pylist);
00186                 
00187                 if (pylist->ob_type == &CListValue::Type)
00188                 {
00189                         CListValue* listval = (CListValue*) pylist;
00190                         if (listval->GetCount() == 3)
00191                         {
00192                                 int index;
00193                                 for (index=0;index<3;index++)
00194                                 {
00195                                         pos[index] = listval->GetValue(index)->GetNumber();
00196                                 }
00197                         }       else
00198                         {
00199                                 error = true;
00200                         }
00201                         
00202                 } else
00203                 {
00204                         
00205                         // assert the list is long enough...
00206                         int numitems = PyList_Size(pylist);
00207                         if (numitems == 3)
00208                         {
00209                                 int index;
00210                                 for (index=0;index<3;index++)
00211                                 {
00212                                         pos[index] = PyFloat_AsDouble(PyList_GetItem(pylist,index));
00213                                 }
00214                         }
00215                         else
00216                         {
00217                                 error = true;
00218                         }
00219                 }
00220                 
00221                 if (!error)
00222                         NodeSetLocalPosition(pos);
00223                 
00224                 Py_INCREF(Py_None);
00225             return Py_None;
00226         }
00227         
00228         static PyObject* sPySetPosition(PyObject* self, 
00229                                                                         PyObject* args, 
00230                                                                         PyObject* kwds)

00231                 {
00232 //          printf("sPySetPosition\n");
00233                         return ((KX_GameObject*) self)->PySetPosition(self, args, kwds);
00234                 }
00235         
00236         KX_PYMETHOD(KX_GameObject,GetPosition);
00237         KX_PYMETHOD(KX_GameObject,GetLinearVelocity);
00238         KX_PYMETHOD(KX_GameObject,GetVelocity);
00239         KX_PYMETHOD(KX_GameObject,GetMass);
00240         KX_PYMETHOD(KX_GameObject,GetReactionForce);
00241 
00242         KX_PYMETHOD(KX_GameObject,GetOrientation);
00243         KX_PYMETHOD(KX_GameObject,SetOrientation);
00244 
00245 //      KX_PYMETHOD(KX_GameObject,SetMass);
00246         KX_PYMETHOD(KX_GameObject,SetVisible);
00247         KX_PYMETHOD(KX_GameObject,SuspendDynamics);
00248         KX_PYMETHOD(KX_GameObject,RestoreDynamics);
00249 
00250         virtual void setLinearVelocity(const MT_Vector3& lin_vel,bool local);
00251         virtual void setAngularVelocity(const MT_Vector3& ang_vel,bool local);
00252         
00253 
00254 };
00255 
00256 
00257 #endif //__KX_GAMEOBJECT
00258 

Generated at Thu Feb 1 13:03:04 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000