fix for bug #18898: GE perspective 3D View not working properly (missing LENS)
[blender.git] / source / gameengine / Ketsji / KX_GameObject.h
index 6051cf850b5f2bfbd94c8d39cd97f089370086d0..dbdea97031d2e3663d119935d593e539fe55065a 100644 (file)
 #include "KX_KetsjiEngine.h" /* for m_anim_framerate */
 #include "KX_IPhysicsController.h" /* for suspend/resume */
 #include "DNA_object_types.h"
+#include "SCA_LogicManager.h" /* for ConvertPythonToGameObject to search object names */
 #define KX_OB_DYNAMIC 1
 
-
 //Forward declarations.
 struct KX_ClientObjectInfo;
+class KX_RayCast;
 class RAS_MeshObject;
 class KX_IPhysicsController;
+class PHY_IGraphicController;
 class PHY_IPhysicsEnvironment;
 struct Object;
 
+/* utility conversion function */
+bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok, const char *error_prefix);
+
 /**
  * KX_GameObject is the main class for dynamic objects.
  */
@@ -72,21 +77,27 @@ protected:
        STR_String                                                      m_text;
        int                                                                     m_layer;
        std::vector<RAS_MeshObject*>            m_meshes;
+       SG_QList                                                        m_meshSlots;    // head of mesh slots of this 
        struct Object*                                          m_pBlenderObject;
+       struct Object*                                          m_pBlenderGroupObject;
        
        bool                                                            m_bSuspendDynamics;
        bool                                                            m_bUseObjectColor;
        bool                                                            m_bIsNegativeScaling;
        MT_Vector4                                                      m_objectColor;
 
-       // Is this object set to be visible? Only useful for the
-       // visibility subsystem right now.
-       bool       m_bVisible; 
+       // visible = user setting
+       // culled = while rendering, depending on camera
+       bool                                                            m_bVisible; 
+       bool                                                            m_bCulled; 
+       bool                                                            m_bOccluder;
 
        KX_IPhysicsController*                          m_pPhysicsController1;
+       PHY_IGraphicController*                         m_pGraphicController;
        // used for ray casting
        PHY_IPhysicsEnvironment*                        m_pPhysicsEnvironment;
        STR_String                                                      m_testPropName;
+       bool                                                            m_xray;
        KX_GameObject*                                          m_pHitObject;
 
        SG_Node*                                                        m_pSGNode;
@@ -96,6 +107,28 @@ protected:
 public:
        bool                                                            m_isDeformable;
 
+       /**
+        * Helper function for modules that can't include KX_ClientObjectInfo.h
+        */
+       static KX_GameObject* GetClientObject(KX_ClientObjectInfo* info);
+
+       // Python attributes that wont convert into CValue
+       // 
+       // there are 2 places attributes can be stored, in the CValue,
+       // where attributes are converted into BGE's CValue types
+       // these can be used with property actuators
+       //
+       // For the python API, For types that cannot be converted into CValues (lists, dicts, GameObjects)
+       // these will be put into "m_attr_dict", logic bricks cannot access them.
+       // 
+       // rules for setting attributes.
+       // 
+       // * there should NEVER be a CValue and a m_attr_dict attribute with matching names. get/sets make sure of this.
+       // * if CValue conversion fails, use a PyObject in "m_attr_dict"
+       // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attr_dict" and set the CValue
+       // 
+       PyObject*                                                       m_attr_dict; 
+
        virtual void    /* This function should be virtual - derived classed override it */
        Relink(
                GEN_Map<GEN_HashedPtr, void*> *map
@@ -138,7 +171,7 @@ public:
        /** 
         * Sets the parent of this object to a game object
         */                     
-       void SetParent(KX_Scene *scene, KX_GameObject *obj);
+       void SetParent(KX_Scene *scene, KX_GameObject *obj, bool addToCompound=true, bool ghost=true);
 
        /** 
         * Removes the parent of this object to a game object
@@ -160,11 +193,6 @@ public:
        ~KX_GameObject(
        );
 
-               CValue*                         
-       AddRef() { 
-               /* temporarily to find memleaks */ return CValue::AddRef(); 
-       }
-
        /** 
         * @section Stuff which is here due to poor design.
         * Inherited from CValue and needs an implementation. 
@@ -201,7 +229,7 @@ public:
        /**
         * Inherited from CValue -- does nothing!
         */
-               float                           
+               double
        GetNumber(
        );
 
@@ -213,7 +241,7 @@ public:
        /**
         * Inherited from CValue -- returns the name of this object.
         */
-               STR_String                      
+               STR_String&                     
        GetName(
        );
 
@@ -222,15 +250,7 @@ public:
         */
                void                            
        SetName(
-               STR_String name
-       );
-
-       /**
-        * Inherited from CValue -- does nothing.
-        */
-               void                            
-       ReplicaSetName(
-               STR_String name
+               const char *name
        );
 
        /** 
@@ -247,9 +267,7 @@ public:
         * data owned by this class is deep copied. Called internally
         */
        virtual void                            
-       ProcessReplica(
-               KX_GameObject* replica
-       );
+       ProcessReplica();
 
        /** 
         * Return the linear velocity of the game object.
@@ -259,12 +277,27 @@ public:
                bool local=false
        );
 
+       /** 
+        * Return the linear velocity of a given point in world coordinate
+        * but relative to center of object ([0,0,0]=center of object)
+        */
+               MT_Vector3 
+       GetVelocity(
+               const MT_Point3& position
+       );
+
        /**
         * Return the mass of the object
         */
                MT_Scalar       
        GetMass();
 
+       /**
+        * Return the local inertia vector of the object
+        */
+               MT_Vector3
+       GetLocalInertia();
+
        /** 
         * Return the angular velocity of the game object.
         */
@@ -327,6 +360,31 @@ public:
                m_pPhysicsController1 = physicscontroller;
        }
 
+       virtual class RAS_Deformer* GetDeformer()
+       {
+               return 0;
+       }
+       virtual void    SetDeformer(class RAS_Deformer* deformer)
+       {
+
+       }
+
+       /**
+        * @return a pointer to the graphic controller owner by this class 
+        */
+       PHY_IGraphicController* GetGraphicController()
+       {
+               return m_pGraphicController;
+       }
+
+       void SetGraphicController(PHY_IGraphicController* graphiccontroller) 
+       { 
+               m_pGraphicController = graphiccontroller;
+       }
+       /*
+        * @add/remove the graphic controller to the physic system
+        */
+       void ActivateGraphicController(bool recurse);
 
        /**
         * @section Coordinate system manipulation functions
@@ -345,8 +403,7 @@ public:
 
                void                                            
        NodeUpdateGS(
-               double time,
-               bool bInitiator
+               double time
        );
 
        const 
@@ -392,6 +449,16 @@ public:
        {
                m_pBlenderObject = obj;
        }
+
+       struct Object* GetBlenderGroupObject( )
+       {
+               return m_pBlenderGroupObject;
+       }
+
+       void SetBlenderGroupObject( struct Object* obj)
+       {
+               m_pBlenderGroupObject = obj;
+       }
        
        bool IsDupliGroup()
        { 
@@ -427,7 +494,8 @@ public:
                return (m_pSGNode && m_pSGNode->GetSGParent() && m_pSGNode->GetSGParent()->IsVertexParent());
        }
 
-       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
+       bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
+       bool NeedRayCast(KX_ClientObjectInfo* client);
 
 
        /**
@@ -492,11 +560,11 @@ public:
        static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
 
        /**
-        * Only update the transform if it's a non-dynamic object
+        * only used for sensor objects
         */
-               void 
-       UpdateNonDynas(
-       );
+       void SynchronizeTransform();
+
+       static void SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene);
 
        /**
         * Function to set IPO option at start of IPO
@@ -521,6 +589,7 @@ public:
         */
                void 
        UpdateMaterialData(
+               dword matname_hash,
                MT_Vector4 rgba,
                MT_Vector3 specrgb,
                MT_Scalar hard,
@@ -533,18 +602,23 @@ public:
        /**
         * @section Mesh accessor functions.
         */
+
+       /**     
+        * Update buckets to indicate that there is a new
+        * user of this object's meshes.
+        */
+               void                                            
+       AddMeshUser(
+       );
        
        /**     
-        * Run through the meshes associated with this
-        * object and bucketize them. See RAS_Mesh for
-        * more details on this function. Interesting to 
-        * note that polygon bucketizing seems to happen on a per
-        * object basis. Which may explain why there is such
-        * a big performance gain when all static objects
-        * are joined into 1.
+        * Update buckets with data about the mesh after
+        * creating or duplicating the object, changing
+        * visibility, object color, .. .
         */
                void                                            
-       Bucketize(
+       UpdateBuckets(
+               bool recursive
        );
 
        /**
@@ -605,25 +679,8 @@ public:
        ResetDebugColor(
        );
 
-       /** 
-        * Set the visibility of the meshes associated with this
-        * object.
-        */
-               void                                            
-       MarkVisible(
-               bool visible
-       );
-
-       /** 
-        * Set the visibility according to the visibility flag.
-        */
-               void                                            
-       MarkVisible(
-               void
-       );
-
        /**
-        * Was this object marked visible? (only for the ewxplicit
+        * Was this object marked visible? (only for the explicit
         * visibility system).
         */
                bool
@@ -636,9 +693,43 @@ public:
         */
                void
        SetVisible(
-               bool b
+               bool b,
+               bool recursive
        );
 
+       /**
+        * Was this object culled?
+        */
+       inline bool
+       GetCulled(
+               void
+       ) { return m_bCulled; }
+
+       /**
+        * Set culled flag of this object
+        */
+       inline void
+       SetCulled(
+               bool c
+       ) { m_bCulled = c; }
+       
+       /**
+        * Is this object an occluder?
+        */
+       inline bool
+       GetOccluder(
+               void
+       ) { return m_bOccluder; }
+
+       /**
+        * Set occluder flag of this object
+        */
+       void
+       SetOccluder(
+               bool v,
+               bool recursive
+       );
+       
        /**
         * Change the layer of the object (when it is added in another layer
         * than the original layer)
@@ -664,6 +755,14 @@ public:
                void
        ) { return m_bIsNegativeScaling; }
 
+       /**
+        * Is this a light?
+        */
+               virtual bool
+       IsLight(
+               void
+       ) { return false; }
+
        /**
         * @section Logic bubbling methods.
         */
@@ -705,56 +804,123 @@ public:
        }
        
        KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
+       
+       CListValue* GetChildren();
+       CListValue* GetChildrenRecursive();
+       
        /**
         * @section Python interface functions.
         */
-
-       virtual 
-               PyObject*                       
-       _getattr(
-               const STR_String& attr
-       );
-       virtual 
-               int 
-       _setattr(
-               const STR_String& attr, 
-               PyObject *value
-       );              // _setattr method
-
+       
+       virtual PyObject* py_getattro(PyObject *attr);
+       virtual PyObject* py_getattro_dict();
+       virtual int py_setattro(PyObject *attr, PyObject *value);               // py_setattro method
+       virtual int                             py_delattro(PyObject *attr);
+       virtual PyObject* py_repr(void)
+       {
+               return PyString_FromString(GetName().ReadPtr());
+       }
+       
+       
+       /* quite annoying that we need these but the bloody 
+        * py_getattro_up and py_setattro_up macro's have a returns in them! */
+       PyObject* py_getattro__internal(PyObject *attr);
+       int py_setattro__internal(PyObject *attr, PyObject *value);             // py_setattro method
+       
+               
        KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
        KX_PYMETHOD_O(KX_GameObject,SetPosition);
-       KX_PYMETHOD(KX_GameObject,GetLinearVelocity);
-       KX_PYMETHOD(KX_GameObject,SetLinearVelocity);
-       KX_PYMETHOD(KX_GameObject,GetVelocity);
+       KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyForce);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyTorque);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyRotation);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyMovement);
+       KX_PYMETHOD_VARARGS(KX_GameObject,GetLinearVelocity);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SetLinearVelocity);
+       KX_PYMETHOD_VARARGS(KX_GameObject,GetAngularVelocity);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SetAngularVelocity);
+       KX_PYMETHOD_VARARGS(KX_GameObject,GetVelocity);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetMass);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetReactionForce);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetOrientation);
        KX_PYMETHOD_O(KX_GameObject,SetOrientation);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetVisible);
-       KX_PYMETHOD_O(KX_GameObject,SetVisible);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SetVisible);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SetOcclusion);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetState);
        KX_PYMETHOD_O(KX_GameObject,SetState);
-       KX_PYMETHOD(KX_GameObject,AlignAxisToVect);
+       KX_PYMETHOD_VARARGS(KX_GameObject,AlignAxisToVect);
        KX_PYMETHOD_O(KX_GameObject,GetAxisVect);
        KX_PYMETHOD_NOARGS(KX_GameObject,SuspendDynamics);
        KX_PYMETHOD_NOARGS(KX_GameObject,RestoreDynamics);
        KX_PYMETHOD_NOARGS(KX_GameObject,EnableRigidBody);
        KX_PYMETHOD_NOARGS(KX_GameObject,DisableRigidBody);
-       KX_PYMETHOD(KX_GameObject,ApplyImpulse);
+       KX_PYMETHOD_VARARGS(KX_GameObject,ApplyImpulse);
        KX_PYMETHOD_O(KX_GameObject,SetCollisionMargin);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetParent);
-       KX_PYMETHOD_O(KX_GameObject,SetParent);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SetParent);
        KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren);  
        KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive);
-       KX_PYMETHOD(KX_GameObject,GetMesh);
+       KX_PYMETHOD_VARARGS(KX_GameObject,GetMesh);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames);
+       KX_PYMETHOD_O(KX_GameObject,ReplaceMesh);
        KX_PYMETHOD_NOARGS(KX_GameObject,EndObject);
        KX_PYMETHOD_DOC(KX_GameObject,rayCastTo);
        KX_PYMETHOD_DOC(KX_GameObject,rayCast);
-       KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo);
+       KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo);
+       KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo);
+       KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage);
+       
+       /* Dict access */
+       KX_PYMETHOD_VARARGS(KX_GameObject,get);
+       KX_PYMETHOD_O(KX_GameObject,has_key);
+       
+       /* attributes */
+       static PyObject*        pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+
+       static PyObject*        pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_children(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_children_recursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       
+       /* Experemental! */
+       static PyObject*        pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       
+       /* getitem/setitem */
+       static Py_ssize_t                       Map_Len(PyObject* self);
+       static PyMappingMethods Mapping;
+       static PyObject*                        Map_GetItem(PyObject *self_v, PyObject *item);
+       static int                                      Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val);
        
 private :
 
@@ -773,5 +939,7 @@ private :
 
 };
 
+
+
 #endif //__KX_GAMEOBJECT