BGE: Occlusion culling and other performance improvements.
[blender-staging.git] / source / gameengine / Ketsji / KX_GameObject.h
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  * General KX game object.
29  */
30
31 #ifndef __KX_GAMEOBJECT
32 #define __KX_GAMEOBJECT
33
34 #ifdef WIN32
35 // get rid of this stupid "warning 'this' used in initialiser list", generated by VC when including Solid/Sumo
36 #pragma warning (disable : 4355) 
37 #endif 
38
39
40 #include "ListValue.h"
41 #include "SCA_IObject.h"
42 #include "SG_Node.h"
43 #include "MT_Transform.h"
44 #include "MT_CmMatrix4x4.h"
45 #include "GEN_Map.h"
46 #include "GEN_HashedPtr.h"
47 #include "KX_Scene.h"
48 #include "KX_KetsjiEngine.h" /* for m_anim_framerate */
49 #include "KX_IPhysicsController.h" /* for suspend/resume */
50 #include "DNA_object_types.h"
51 #include "SCA_LogicManager.h" /* for ConvertPythonToGameObject to search object names */
52 #define KX_OB_DYNAMIC 1
53
54
55 //Forward declarations.
56 struct KX_ClientObjectInfo;
57 class KX_RayCast;
58 class RAS_MeshObject;
59 class KX_IPhysicsController;
60 class PHY_IGraphicController;
61 class PHY_IPhysicsEnvironment;
62 struct Object;
63
64 /**
65  * KX_GameObject is the main class for dynamic objects.
66  */
67 class KX_GameObject : public SCA_IObject
68 {
69         Py_Header;
70 protected:
71
72         bool                                                            m_bDyna;
73         KX_ClientObjectInfo*                            m_pClient_info;
74         STR_String                                                      m_name;
75         STR_String                                                      m_text;
76         int                                                                     m_layer;
77         std::vector<RAS_MeshObject*>            m_meshes;
78         struct Object*                                          m_pBlenderObject;
79         struct Object*                                          m_pBlenderGroupObject;
80         
81         bool                                                            m_bSuspendDynamics;
82         bool                                                            m_bUseObjectColor;
83         bool                                                            m_bIsNegativeScaling;
84         MT_Vector4                                                      m_objectColor;
85
86         // visible = user setting
87         // culled = while rendering, depending on camera
88         bool                                                            m_bVisible; 
89         bool                                                            m_bCulled; 
90         bool                                                            m_bOccluder;
91
92         KX_IPhysicsController*                          m_pPhysicsController1;
93         PHY_IGraphicController*                         m_pGraphicController;
94         // used for ray casting
95         PHY_IPhysicsEnvironment*                        m_pPhysicsEnvironment;
96         STR_String                                                      m_testPropName;
97         bool                                                            m_xray;
98         KX_GameObject*                                          m_pHitObject;
99
100         SG_Node*                                                        m_pSGNode;
101
102         MT_CmMatrix4x4                                          m_OpenGL_4x4Matrix;
103         
104 public:
105         bool                                                            m_isDeformable;
106
107         /**
108          * Helper function for modules that can't include KX_ClientObjectInfo.h
109          */
110         static KX_GameObject* GetClientObject(KX_ClientObjectInfo* info);
111
112         // Python attributes that wont convert into CValue
113         // 
114         // there are 2 places attributes can be stored, in the CValue,
115         // where attributes are converted into BGE's CValue types
116         // these can be used with property actuators
117         //
118         // For the python API, For types that cannot be converted into CValues (lists, dicts, GameObjects)
119         // these will be put into "m_attrlist", logic bricks cannot access them.
120         // 
121         // rules for setting attributes.
122         // 
123         // * there should NEVER be a CValue and a m_attrlist attribute with matching names. get/sets make sure of this.
124         // * if CValue conversion fails, use a PyObject in "m_attrlist"
125         // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attrlist" and set the CValue
126         // 
127         PyObject*                                                       m_attrlist; 
128
129         virtual void    /* This function should be virtual - derived classed override it */
130         Relink(
131                 GEN_Map<GEN_HashedPtr, void*> *map
132         );
133
134         /**
135          * Compute an OpenGl compatable 4x4 matrix. Has the
136          * side effect of storing the result internally. The
137          * memory for the matrix remains the property of this class.
138          */ 
139                 double*                                         
140         GetOpenGLMatrix(
141         );
142
143         /**
144          * Return a pointer to a MT_CmMatrix4x4 storing the 
145          * opengl transformation for this object. This is updated
146          * by a call to GetOpenGLMatrix(). This class owns the 
147          * memory for the returned matrix.
148          */
149
150                 MT_CmMatrix4x4*                         
151         GetOpenGLMatrixPtr(
152         ) { 
153                 return &m_OpenGL_4x4Matrix;
154         };
155
156         /** 
157          * Get a pointer to the game object that is the parent of 
158          * this object. Or NULL if there is no parent. The returned
159          * object is part of a reference counting scheme. Calling
160          * this function ups the reference count on the returned 
161          * object. It is the responsibility of the caller to decrement
162          * the reference count when you have finished with it.
163          */
164                 KX_GameObject*                          
165         GetParent(
166         );
167
168         /** 
169          * Sets the parent of this object to a game object
170          */                     
171         void SetParent(KX_Scene *scene, KX_GameObject *obj);
172
173         /** 
174          * Removes the parent of this object to a game object
175          */                     
176         void RemoveParent(KX_Scene *scene);
177
178         /**
179          * Construct a game object. This class also inherits the 
180          * default constructors - use those with care!
181          */
182
183         KX_GameObject(
184                 void* sgReplicationInfo,
185                 SG_Callbacks callbacks,
186                 PyTypeObject* T=&Type
187         );
188
189         virtual 
190         ~KX_GameObject(
191         );
192
193                 CValue*                         
194         AddRef() { 
195                 /* temporarily to find memleaks */ return CValue::AddRef(); 
196         }
197
198         /** 
199          * @section Stuff which is here due to poor design.
200          * Inherited from CValue and needs an implementation. 
201          * Do not expect these functions do to anything sensible.
202          */
203
204         /**
205          * Inherited from CValue -- does nothing!
206          */
207                 CValue*                         
208         Calc(
209                 VALUE_OPERATOR op,
210                 CValue *val
211         );
212
213         /**
214          * Inherited from CValue -- does nothing!
215          */
216                 CValue*                         
217         CalcFinal(
218                 VALUE_DATA_TYPE dtype,
219                 VALUE_OPERATOR op,
220                 CValue *val
221         );
222
223         /**
224          * Inherited from CValue -- does nothing!
225          */
226         const 
227                 STR_String &    
228         GetText(
229         );
230
231         /**
232          * Inherited from CValue -- does nothing!
233          */
234                 double
235         GetNumber(
236         );
237
238         /**
239          * @section Inherited from CValue. These are the useful
240          * part of the CValue interface that this class implements. 
241          */
242
243         /**
244          * Inherited from CValue -- returns the name of this object.
245          */
246                 STR_String                      
247         GetName(
248         );
249
250         /**
251          * Inherited from CValue -- set the name of this object.
252          */
253                 void                            
254         SetName(
255                 STR_String name
256         );
257
258         /**
259          * Inherited from CValue -- does nothing.
260          */
261                 void                            
262         ReplicaSetName(
263                 STR_String name
264         );
265
266         /** 
267          * Inherited from CValue -- return a new copy of this
268          * instance allocated on the heap. Ownership of the new 
269          * object belongs with the caller.
270          */
271         virtual CValue*                         
272         GetReplica(
273         );
274         
275         /**
276          * Inherited from CValue -- Makes sure any internal 
277          * data owned by this class is deep copied. Called internally
278          */
279         virtual void                            
280         ProcessReplica(
281                 KX_GameObject* replica
282         );
283
284         /** 
285          * Return the linear velocity of the game object.
286          */
287                 MT_Vector3 
288         GetLinearVelocity(
289                 bool local=false
290         );
291
292         /** 
293          * Return the linear velocity of a given point in world coordinate
294          * but relative to center of object ([0,0,0]=center of object)
295          */
296                 MT_Vector3 
297         GetVelocity(
298                 const MT_Point3& position
299         );
300
301         /**
302          * Return the mass of the object
303          */
304                 MT_Scalar       
305         GetMass();
306
307         /**
308          * Return the local inertia vector of the object
309          */
310                 MT_Vector3
311         GetLocalInertia();
312
313         /** 
314          * Return the angular velocity of the game object.
315          */
316                 MT_Vector3 
317         GetAngularVelocity(
318                 bool local=false
319         );
320
321         /** 
322          * Align the object to a given normal.
323          */
324                 void 
325         AlignAxisToVect(
326                 const MT_Vector3& vect,
327                 int axis = 2,
328                 float fac = 1.0
329         );
330
331         /** 
332          * Quick'n'dirty obcolor ipo stuff
333          */
334
335                 void                            
336         SetObjectColor(
337                 const MT_Vector4& rgbavec
338         );
339
340
341                 void 
342         ResolveCombinedVelocities(
343                 const MT_Vector3 & lin_vel,
344                 const MT_Vector3 & ang_vel,
345                 bool lin_vel_local,
346                 bool ang_vel_local
347         );
348
349
350         /**
351          * @return a pointer to the physics environment in use during the game, for rayCasting
352          */
353         PHY_IPhysicsEnvironment* GetPhysicsEnvironment()
354         {
355                 return m_pPhysicsEnvironment;
356         }
357
358         void SetPhysicsEnvironment(PHY_IPhysicsEnvironment* physicsEnvironment)
359         {
360                 m_pPhysicsEnvironment = physicsEnvironment;
361         }
362
363         /**
364          * @return a pointer to the physics controller owned by this class.
365          */
366
367         KX_IPhysicsController* GetPhysicsController() ;
368
369         void    SetPhysicsController(KX_IPhysicsController*     physicscontroller,bool isDynamic) 
370         { 
371                 m_bDyna = isDynamic;
372                 m_pPhysicsController1 = physicscontroller;
373         }
374
375         virtual class RAS_Deformer* GetDeformer()
376         {
377                 return 0;
378         }
379         virtual void    SetDeformer(class RAS_Deformer* deformer)
380         {
381
382         }
383
384         /**
385          * @return a pointer to the graphic controller owner by this class 
386          */
387         PHY_IGraphicController* GetGraphicController()
388         {
389                 return m_pGraphicController;
390         }
391
392         void SetGraphicController(PHY_IGraphicController* graphiccontroller) 
393         { 
394                 m_pGraphicController = graphiccontroller;
395         }
396
397         /**
398          * @section Coordinate system manipulation functions
399          */
400
401         void    NodeSetLocalPosition(const MT_Point3& trans     );
402
403         void    NodeSetLocalOrientation(const MT_Matrix3x3& rot );
404
405         void    NodeSetLocalScale(      const MT_Vector3& scale );
406
407         void    NodeSetRelativeScale(   const MT_Vector3& scale );
408
409         // adapt local position so that world position is set to desired position
410         void    NodeSetWorldPosition(const MT_Point3& trans);
411
412                 void                                            
413         NodeUpdateGS(
414                 double time
415         );
416
417         const 
418                 MT_Matrix3x3&                   
419         NodeGetWorldOrientation(
420         ) const;
421
422         const 
423                 MT_Vector3&                     
424         NodeGetWorldScaling(
425         ) const;
426
427         const 
428                 MT_Point3&                      
429         NodeGetWorldPosition(
430         ) const;
431
432
433         /**
434          * @section scene graph node accessor functions.
435          */
436
437         SG_Node*        GetSGNode(      ) 
438         { 
439                 return m_pSGNode;
440         }
441
442         const   SG_Node* GetSGNode(     ) const 
443         { 
444                 return m_pSGNode;
445         }
446
447         /**
448          * @section blender object accessor functions.
449          */
450
451         struct Object* GetBlenderObject( )
452         {
453                 return m_pBlenderObject;
454         }
455
456         void SetBlenderObject( struct Object* obj)
457         {
458                 m_pBlenderObject = obj;
459         }
460
461         struct Object* GetBlenderGroupObject( )
462         {
463                 return m_pBlenderGroupObject;
464         }
465
466         void SetBlenderGroupObject( struct Object* obj)
467         {
468                 m_pBlenderGroupObject = obj;
469         }
470         
471         bool IsDupliGroup()
472         { 
473                 return (m_pBlenderObject &&
474                                 (m_pBlenderObject->transflag & OB_DUPLIGROUP) &&
475                                 m_pBlenderObject->dup_group != NULL) ? true : false;
476         }
477
478         /**
479          * Set the Scene graph node for this game object.
480          * warning - it is your responsibility to make sure
481          * all controllers look at this new node. You must
482          * also take care of the memory associated with the
483          * old node. This class takes ownership of the new
484          * node.
485          */
486                 void    SetSGNode(SG_Node* node )
487                 { 
488                         m_pSGNode = node; 
489                 }
490         
491         //Is it a dynamic/physics object ?
492         bool    IsDynamic() const 
493         { 
494                 return m_bDyna; 
495         }
496
497         /**
498          * Check if this object has a vertex parent relationship
499          */
500         bool IsVertexParent( )
501         {
502                 return (m_pSGNode && m_pSGNode->GetSGParent() && m_pSGNode->GetSGParent()->IsVertexParent());
503         }
504
505         bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
506         bool NeedRayCast(KX_ClientObjectInfo* client);
507
508
509         /**
510          * @section Physics accessors for this node.
511          *
512          * All these calls get passed directly to the physics controller 
513          * owned by this object.
514          * This is real interface bloat. Why not just use the physics controller
515          * directly? I think this is because the python interface is in the wrong
516          * place.
517          */
518
519                 void                                            
520         ApplyForce(
521                 const MT_Vector3& force,        bool local
522         );
523
524                 void                                            
525         ApplyTorque(
526                 const MT_Vector3& torque,
527                 bool local
528         );
529
530                 void                                            
531         ApplyRotation(
532                 const MT_Vector3& drot,
533                 bool local
534         );
535
536                 void                                            
537         ApplyMovement(
538                 const MT_Vector3& dloc,
539                 bool local
540         );
541
542                 void                                            
543         addLinearVelocity(
544                 const MT_Vector3& lin_vel,
545                 bool local
546         );
547
548                 void                                            
549         setLinearVelocity(
550                 const MT_Vector3& lin_vel,
551                 bool local
552         );
553
554                 void                                            
555         setAngularVelocity(
556                 const MT_Vector3& ang_vel,
557                 bool local
558         );
559
560         /**     
561          * Update the physics object transform based upon the current SG_Node
562          * position.
563          */
564                 void
565         UpdateTransform(
566         );
567
568         static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
569
570         /**
571          * Function to set IPO option at start of IPO
572          */ 
573                 void    
574         InitIPO(
575                 bool ipo_as_force,
576                 bool ipo_add,
577                 bool ipo_local
578         );
579
580         /**
581          * Odd function to update an ipo. ???
582          */ 
583                 void    
584         UpdateIPO(
585                 float curframetime,
586                 bool recurse
587         );
588         /**
589          * Updates Material Ipo data 
590          */
591                 void 
592         UpdateMaterialData(
593                 dword matname_hash,
594                 MT_Vector4 rgba,
595                 MT_Vector3 specrgb,
596                 MT_Scalar hard,
597                 MT_Scalar spec,
598                 MT_Scalar ref,
599                 MT_Scalar emit,
600                 MT_Scalar alpha
601         );
602
603         /**
604          * @section Mesh accessor functions.
605          */
606
607         /**     
608          * Update buckets to indicate that there is a new
609          * user of this object's meshes.
610          */
611                 void                                            
612         AddMeshUser(
613         );
614         
615         /**     
616          * Update buckets with data about the mesh after
617          * creating or duplicating the object, changing
618          * visibility, object color, .. .
619          */
620                 void                                            
621         UpdateBuckets(
622                 bool recursive
623         );
624
625         /**
626          * Clear the meshes associated with this class
627          * and remove from the bucketing system.
628          * Don't think this actually deletes any of the meshes.
629          */
630                 void                                            
631         RemoveMeshes(
632         );
633
634         /**
635          * Add a mesh to the set of meshes associated with this
636          * node. Meshes added in this way are not deleted by this class.
637          * Make sure you call RemoveMeshes() before deleting the
638          * mesh though,
639          */
640                 void                                            
641         AddMesh(
642                 RAS_MeshObject* mesh
643         ){ 
644                 m_meshes.push_back(mesh);
645         }
646
647         /**
648          * Pick out a mesh associated with the integer 'num'.
649          */
650                 RAS_MeshObject*                         
651         GetMesh(
652                 int num
653         ) const { 
654                 return m_meshes[num]; 
655         }
656
657         /**
658          * Return the number of meshes currently associated with this
659          * game object.
660          */
661                 int                                                     
662         GetMeshCount(
663         ) const { 
664                 return m_meshes.size(); 
665         }
666         
667         /**     
668          * Set the debug color of the meshes associated with this
669          * class. Does this still work?
670          */
671                 void                                            
672         SetDebugColor(
673                 unsigned int bgra
674         );
675
676         /** 
677          * Reset the debug color of meshes associated with this class.
678          */
679                 void                                            
680         ResetDebugColor(
681         );
682
683         /**
684          * Was this object marked visible? (only for the explicit
685          * visibility system).
686          */
687                 bool
688         GetVisible(
689                 void
690         );
691
692         /**
693          * Set visibility flag of this object
694          */
695                 void
696         SetVisible(
697                 bool b,
698                 bool recursive
699         );
700
701         /**
702          * Was this object culled?
703          */
704         inline bool
705         GetCulled(
706                 void
707         ) { return m_bCulled; }
708
709         /**
710          * Set culled flag of this object
711          */
712         inline void
713         SetCulled(
714                 bool c
715         ) { m_bCulled = c; }
716         
717         /**
718          * Is this object an occluder?
719          */
720         inline bool
721         GetOccluder(
722                 void
723         ) { return m_bOccluder; }
724
725         /**
726          * Set occluder flag of this object
727          */
728         void
729         SetOccluder(
730                 bool v,
731                 bool recursive
732         );
733         
734         /**
735          * Change the layer of the object (when it is added in another layer
736          * than the original layer)
737          */
738                 void
739         SetLayer(
740                 int l
741         );
742
743         /**
744          * Get the object layer
745          */
746                 int
747         GetLayer(
748                 void
749         );
750                 
751         /**
752          * Get the negative scaling state
753          */
754                 bool
755         IsNegativeScaling(
756                 void
757         ) { return m_bIsNegativeScaling; }
758
759         /**
760          * Is this a light?
761          */
762                 virtual bool
763         IsLight(
764                 void
765         ) { return false; }
766
767         /**
768          * @section Logic bubbling methods.
769          */
770
771         /**
772          * Stop making progress
773          */
774         void Suspend(void);
775
776         /**
777          * Resume making progress
778          */
779         void Resume(void);
780         
781         void SuspendDynamics(void) {
782                 if (m_bSuspendDynamics)
783                 {
784                         return;
785                 }
786         
787                 if (m_pPhysicsController1)
788                 {
789                         m_pPhysicsController1->SuspendDynamics();
790                 }
791                 m_bSuspendDynamics = true;
792         }
793         
794         void RestoreDynamics(void) {    
795                 if (!m_bSuspendDynamics)
796                 {
797                         return;
798                 }
799         
800                 if (m_pPhysicsController1)
801                 {
802                         m_pPhysicsController1->RestoreDynamics();
803                 }
804                 m_bSuspendDynamics = false;
805         }
806         
807         KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
808         /**
809          * @section Python interface functions.
810          */
811         
812         virtual PyObject* py_getattro(PyObject *attr);
813         virtual int py_setattro(PyObject *attr, PyObject *value);               // py_setattro method
814         virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); }
815         
816         /* we need our own getattr and setattr types */
817         /* See m_attrlist definition for rules on how this works */
818         static PyObject *py_base_getattro_gameobject(PyObject * self, PyObject *attr)
819         {
820                 PyObject *object= ((KX_GameObject *) self)->py_getattro(attr);
821                 
822                 if (object==NULL && ((KX_GameObject *) self)->m_attrlist) {
823                         /* backup the exception incase the attr doesnt exist in the dict either */
824                         PyObject *err_type, *err_value, *err_tb;
825                         PyErr_Fetch(&err_type, &err_value, &err_tb);
826                         
827                         object= PyDict_GetItem(((KX_GameObject *) self)->m_attrlist, attr);
828                         if (object) {
829                                 Py_INCREF(object);
830                                 
831                                 PyErr_Clear();
832                                 Py_XDECREF( err_type );
833                                 Py_XDECREF( err_value );
834                                 Py_XDECREF( err_tb );
835                         }
836                         else {
837                                 PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */
838                         }
839                 }
840                 return object;
841         }
842         
843         static int py_base_setattro_gameobject(PyObject * self, PyObject *attr, PyObject *value)
844         {
845                 int ret;
846                 
847                 /* Delete the item */
848                 if (value==NULL)
849                 {
850                         ret= ((PyObjectPlus*) self)->py_delattro(attr);
851                         
852                         if (ret != 0) /* CValue attribute failed, try KX_GameObject m_attrlist dict */
853                         {
854                                 if (((KX_GameObject *) self)->m_attrlist)
855                                 {
856                                         /* backup the exception incase the attr doesnt exist in the dict either */
857                                         PyObject *err_type, *err_value, *err_tb;
858                                         PyErr_Fetch(&err_type, &err_value, &err_tb);
859                                         
860                                         if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) == 0)
861                                         {
862                                                 ret= 0;
863                                                 PyErr_Clear();
864                                                 Py_XDECREF( err_type );
865                                                 Py_XDECREF( err_value );
866                                                 Py_XDECREF( err_tb );
867                                         }
868                                         else { 
869                                                 PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */
870                                         }
871                                 }
872                         }
873                         return ret;
874                 }
875                 
876                 
877                 ret= ((PyObjectPlus*) self)->py_setattro(attr, value);
878                 
879                 if (ret==PY_SET_ATTR_SUCCESS) {
880                         /* remove attribute in our own dict to avoid double ups */
881                         if (((KX_GameObject *) self)->m_attrlist) {
882                                 if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) != 0)
883                                         PyErr_Clear();
884                         }
885                 }
886                 
887                 if (ret==PY_SET_ATTR_COERCE_FAIL) {
888                         /* CValue attribute exists, remove and add dict value */
889                         ((KX_GameObject *) self)->RemoveProperty(STR_String(PyString_AsString(attr)));
890                         ret= PY_SET_ATTR_MISSING;
891                 }
892                 
893                 if (ret==PY_SET_ATTR_MISSING) {
894                         /* Lazy initialization */
895                         if (((KX_GameObject *) self)->m_attrlist==NULL)
896                                 ((KX_GameObject *) self)->m_attrlist = PyDict_New();
897                         
898                         if (PyDict_SetItem(((KX_GameObject *) self)->m_attrlist, attr, value)==0) {
899                                 PyErr_Clear();
900                                 ret= PY_SET_ATTR_SUCCESS;
901                         }
902                         else {
903                                 PyErr_Format(PyExc_AttributeError, "failed assigning value to KX_GameObject internal dictionary");
904                                 ret= PY_SET_ATTR_FAIL;
905                         }
906                 }
907                 
908                 return ret;
909         }
910         
911         
912         
913         KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
914         KX_PYMETHOD_O(KX_GameObject,SetPosition);
915         KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
916         KX_PYMETHOD_VARARGS(KX_GameObject, ApplyForce);
917         KX_PYMETHOD_VARARGS(KX_GameObject, ApplyTorque);
918         KX_PYMETHOD_VARARGS(KX_GameObject, ApplyRotation);
919         KX_PYMETHOD_VARARGS(KX_GameObject, ApplyMovement);
920         KX_PYMETHOD_VARARGS(KX_GameObject,GetLinearVelocity);
921         KX_PYMETHOD_VARARGS(KX_GameObject,SetLinearVelocity);
922         KX_PYMETHOD_VARARGS(KX_GameObject,GetAngularVelocity);
923         KX_PYMETHOD_VARARGS(KX_GameObject,SetAngularVelocity);
924         KX_PYMETHOD_VARARGS(KX_GameObject,GetVelocity);
925         KX_PYMETHOD_NOARGS(KX_GameObject,GetMass);
926         KX_PYMETHOD_NOARGS(KX_GameObject,GetReactionForce);
927         KX_PYMETHOD_NOARGS(KX_GameObject,GetOrientation);
928         KX_PYMETHOD_O(KX_GameObject,SetOrientation);
929         KX_PYMETHOD_NOARGS(KX_GameObject,GetVisible);
930         KX_PYMETHOD_VARARGS(KX_GameObject,SetVisible);
931         KX_PYMETHOD_VARARGS(KX_GameObject,SetOcclusion);
932         KX_PYMETHOD_NOARGS(KX_GameObject,GetState);
933         KX_PYMETHOD_O(KX_GameObject,SetState);
934         KX_PYMETHOD_VARARGS(KX_GameObject,AlignAxisToVect);
935         KX_PYMETHOD_O(KX_GameObject,GetAxisVect);
936         KX_PYMETHOD_NOARGS(KX_GameObject,SuspendDynamics);
937         KX_PYMETHOD_NOARGS(KX_GameObject,RestoreDynamics);
938         KX_PYMETHOD_NOARGS(KX_GameObject,EnableRigidBody);
939         KX_PYMETHOD_NOARGS(KX_GameObject,DisableRigidBody);
940         KX_PYMETHOD_VARARGS(KX_GameObject,ApplyImpulse);
941         KX_PYMETHOD_O(KX_GameObject,SetCollisionMargin);
942         KX_PYMETHOD_NOARGS(KX_GameObject,GetParent);
943         KX_PYMETHOD_O(KX_GameObject,SetParent);
944         KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent);
945         KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren);  
946         KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive);
947         KX_PYMETHOD_VARARGS(KX_GameObject,GetMesh);
948         KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId);
949         KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames);
950         KX_PYMETHOD_O(KX_GameObject,ReplaceMesh);
951         KX_PYMETHOD_NOARGS(KX_GameObject,EndObject);
952         KX_PYMETHOD_DOC(KX_GameObject,rayCastTo);
953         KX_PYMETHOD_DOC(KX_GameObject,rayCast);
954         KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo);
955         KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo);
956         KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage);
957         /* attributes */
958         static PyObject*        pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
959         static PyObject*        pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
960
961         static PyObject*        pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
962         static int                      pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
963         static PyObject*        pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
964         static int                      pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
965         static PyObject*        pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
966         static int                      pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
967         static PyObject*        pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
968         static int                      pyattr_set_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
969         static PyObject*        pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
970         static int                      pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
971         static PyObject*        pyattr_get_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
972         static int                      pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
973         static PyObject*        pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
974         static int                      pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
975         static PyObject*        pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
976         static int                      pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
977         static PyObject*        pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
978         
979         /* for dir(), python3 uses __dir__() */
980         static PyObject*        pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
981         
982         /* Experemental! */
983         static PyObject*        pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
984         static PyObject*        pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
985         static PyObject*        pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
986         
987         /* getitem/setitem */
988         static Py_ssize_t                       Map_Len(PyObject* self);
989         static PyMappingMethods Mapping;
990         static PyObject*                        Map_GetItem(PyObject *self_v, PyObject *item);
991         static int                                      Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val);
992         
993         
994 private :
995
996         /**     
997          * Random internal function to convert python function arguments
998          * to 2 vectors.
999          * @return true if conversion was possible.
1000          */
1001
1002                 bool                                            
1003         ConvertPythonVectorArgs(
1004                 PyObject* args,
1005                 MT_Vector3& pos,
1006                 MT_Vector3& pos2
1007         );      
1008
1009 };
1010
1011 /* utility conversion function */
1012 bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok);
1013
1014 #endif //__KX_GAMEOBJECT
1015