4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
28 * General KX game object.
31 #ifndef __KX_GAMEOBJECT
32 #define __KX_GAMEOBJECT
35 // get rid of this stupid "warning 'this' used in initialiser list", generated by VC when including Solid/Sumo
36 #pragma warning (disable : 4355)
40 #include "ListValue.h"
41 #include "SCA_IObject.h"
43 #include "MT_Transform.h"
44 #include "MT_CmMatrix4x4.h"
46 #include "GEN_HashedPtr.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
55 //Forward declarations.
56 struct KX_ClientObjectInfo;
59 class KX_IPhysicsController;
60 class PHY_IPhysicsEnvironment;
64 * KX_GameObject is the main class for dynamic objects.
66 class KX_GameObject : public SCA_IObject
72 KX_ClientObjectInfo* m_pClient_info;
76 std::vector<RAS_MeshObject*> m_meshes;
77 struct Object* m_pBlenderObject;
78 struct Object* m_pBlenderGroupObject;
80 bool m_bSuspendDynamics;
81 bool m_bUseObjectColor;
82 bool m_bIsNegativeScaling;
83 MT_Vector4 m_objectColor;
85 // visible = user setting
86 // culled = while rendering, depending on camera
90 KX_IPhysicsController* m_pPhysicsController1;
91 // used for ray casting
92 PHY_IPhysicsEnvironment* m_pPhysicsEnvironment;
93 STR_String m_testPropName;
95 KX_GameObject* m_pHitObject;
99 MT_CmMatrix4x4 m_OpenGL_4x4Matrix;
104 virtual void /* This function should be virtual - derived classed override it */
106 GEN_Map<GEN_HashedPtr, void*> *map
110 * Compute an OpenGl compatable 4x4 matrix. Has the
111 * side effect of storing the result internally. The
112 * memory for the matrix remains the property of this class.
119 * Return a pointer to a MT_CmMatrix4x4 storing the
120 * opengl transformation for this object. This is updated
121 * by a call to GetOpenGLMatrix(). This class owns the
122 * memory for the returned matrix.
128 return &m_OpenGL_4x4Matrix;
132 * Get a pointer to the game object that is the parent of
133 * this object. Or NULL if there is no parent. The returned
134 * object is part of a reference counting scheme. Calling
135 * this function ups the reference count on the returned
136 * object. It is the responsibility of the caller to decrement
137 * the reference count when you have finished with it.
144 * Sets the parent of this object to a game object
146 void SetParent(KX_Scene *scene, KX_GameObject *obj);
149 * Removes the parent of this object to a game object
151 void RemoveParent(KX_Scene *scene);
154 * Construct a game object. This class also inherits the
155 * default constructors - use those with care!
159 void* sgReplicationInfo,
160 SG_Callbacks callbacks,
161 PyTypeObject* T=&Type
170 /* temporarily to find memleaks */ return CValue::AddRef();
174 * @section Stuff which is here due to poor design.
175 * Inherited from CValue and needs an implementation.
176 * Do not expect these functions do to anything sensible.
180 * Inherited from CValue -- does nothing!
189 * Inherited from CValue -- does nothing!
193 VALUE_DATA_TYPE dtype,
199 * Inherited from CValue -- does nothing!
207 * Inherited from CValue -- does nothing!
214 * @section Inherited from CValue. These are the useful
215 * part of the CValue interface that this class implements.
219 * Inherited from CValue -- returns the name of this object.
226 * Inherited from CValue -- set the name of this object.
234 * Inherited from CValue -- does nothing.
242 * Inherited from CValue -- return a new copy of this
243 * instance allocated on the heap. Ownership of the new
244 * object belongs with the caller.
251 * Inherited from CValue -- Makes sure any internal
252 * data owned by this class is deep copied. Called internally
256 KX_GameObject* replica
260 * Return the linear velocity of the game object.
268 * Return the mass of the object
274 * Return the angular velocity of the game object.
282 * Align the object to a given normal.
286 const MT_Vector3& vect,
292 * Quick'n'dirty obcolor ipo stuff
297 const MT_Vector4& rgbavec
302 ResolveCombinedVelocities(
303 const MT_Vector3 & lin_vel,
304 const MT_Vector3 & ang_vel,
311 * @return a pointer to the physics environment in use during the game, for rayCasting
313 PHY_IPhysicsEnvironment* GetPhysicsEnvironment()
315 return m_pPhysicsEnvironment;
318 void SetPhysicsEnvironment(PHY_IPhysicsEnvironment* physicsEnvironment)
320 m_pPhysicsEnvironment = physicsEnvironment;
324 * @return a pointer to the physics controller owned by this class.
327 KX_IPhysicsController* GetPhysicsController() ;
329 void SetPhysicsController(KX_IPhysicsController* physicscontroller,bool isDynamic)
332 m_pPhysicsController1 = physicscontroller;
337 * @section Coordinate system manipulation functions
340 void NodeSetLocalPosition(const MT_Point3& trans );
342 void NodeSetLocalOrientation(const MT_Matrix3x3& rot );
344 void NodeSetLocalScale( const MT_Vector3& scale );
346 void NodeSetRelativeScale( const MT_Vector3& scale );
348 // adapt local position so that world position is set to desired position
349 void NodeSetWorldPosition(const MT_Point3& trans);
359 NodeGetWorldOrientation(
369 NodeGetWorldPosition(
374 * @section scene graph node accessor functions.
377 SG_Node* GetSGNode( )
382 const SG_Node* GetSGNode( ) const
388 * @section blender object accessor functions.
391 struct Object* GetBlenderObject( )
393 return m_pBlenderObject;
396 void SetBlenderObject( struct Object* obj)
398 m_pBlenderObject = obj;
401 struct Object* GetBlenderGroupObject( )
403 return m_pBlenderGroupObject;
406 void SetBlenderGroupObject( struct Object* obj)
408 m_pBlenderGroupObject = obj;
413 return (m_pBlenderObject &&
414 (m_pBlenderObject->transflag & OB_DUPLIGROUP) &&
415 m_pBlenderObject->dup_group != NULL) ? true : false;
419 * Set the Scene graph node for this game object.
420 * warning - it is your responsibility to make sure
421 * all controllers look at this new node. You must
422 * also take care of the memory associated with the
423 * old node. This class takes ownership of the new
426 void SetSGNode(SG_Node* node )
431 //Is it a dynamic/physics object ?
432 bool IsDynamic() const
438 * Check if this object has a vertex parent relationship
440 bool IsVertexParent( )
442 return (m_pSGNode && m_pSGNode->GetSGParent() && m_pSGNode->GetSGParent()->IsVertexParent());
445 bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
446 bool NeedRayCast(KX_ClientObjectInfo* client);
450 * @section Physics accessors for this node.
452 * All these calls get passed directly to the physics controller
453 * owned by this object.
454 * This is real interface bloat. Why not just use the physics controller
455 * directly? I think this is because the python interface is in the wrong
461 const MT_Vector3& force, bool local
466 const MT_Vector3& torque,
472 const MT_Vector3& drot,
478 const MT_Vector3& dloc,
484 const MT_Vector3& lin_vel,
490 const MT_Vector3& lin_vel,
496 const MT_Vector3& ang_vel,
501 * Update the physics object transform based upon the current SG_Node
508 static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
511 * Only update the transform if it's a non-dynamic object
518 * Function to set IPO option at start of IPO
528 * Odd function to update an ipo. ???
536 * Updates Material Ipo data
551 * @section Mesh accessor functions.
555 * Update buckets to indicate that there is a new
556 * user of this object's meshes.
563 * Update buckets with data about the mesh after
564 * creating or duplicating the object, changing
565 * visibility, object color, .. .
573 * Clear the meshes associated with this class
574 * and remove from the bucketing system.
575 * Don't think this actually deletes any of the meshes.
582 * Add a mesh to the set of meshes associated with this
583 * node. Meshes added in this way are not deleted by this class.
584 * Make sure you call RemoveMeshes() before deleting the
591 m_meshes.push_back(mesh);
595 * Pick out a mesh associated with the integer 'num'.
601 return m_meshes[num];
605 * Return the number of meshes currently associated with this
611 return m_meshes.size();
615 * Set the debug color of the meshes associated with this
616 * class. Does this still work?
624 * Reset the debug color of meshes associated with this class.
631 * Was this object marked visible? (only for the explicit
632 * visibility system).
640 * Set visibility flag of this object
649 * Was this object culled?
657 * Set culled flag of this object
665 * Change the layer of the object (when it is added in another layer
666 * than the original layer)
674 * Get the object layer
682 * Get the negative scaling state
687 ) { return m_bIsNegativeScaling; }
698 * @section Logic bubbling methods.
702 * Stop making progress
707 * Resume making progress
711 void SuspendDynamics(void) {
712 if (m_bSuspendDynamics)
717 if (m_pPhysicsController1)
719 m_pPhysicsController1->SuspendDynamics();
721 m_bSuspendDynamics = true;
724 void RestoreDynamics(void) {
725 if (!m_bSuspendDynamics)
730 if (m_pPhysicsController1)
732 m_pPhysicsController1->RestoreDynamics();
734 m_bSuspendDynamics = false;
737 KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
739 * @section Python interface functions.
745 const STR_String& attr
751 const STR_String& attr,
753 ); // _setattr method
755 KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
756 KX_PYMETHOD_O(KX_GameObject,SetPosition);
757 KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
758 KX_PYMETHOD_VARARGS(KX_GameObject,GetLinearVelocity);
759 KX_PYMETHOD_VARARGS(KX_GameObject,SetLinearVelocity);
760 KX_PYMETHOD_VARARGS(KX_GameObject,GetAngularVelocity);
761 KX_PYMETHOD_VARARGS(KX_GameObject,SetAngularVelocity);
762 KX_PYMETHOD_VARARGS(KX_GameObject,GetVelocity);
763 KX_PYMETHOD_NOARGS(KX_GameObject,GetMass);
764 KX_PYMETHOD_NOARGS(KX_GameObject,GetReactionForce);
765 KX_PYMETHOD_NOARGS(KX_GameObject,GetOrientation);
766 KX_PYMETHOD_O(KX_GameObject,SetOrientation);
767 KX_PYMETHOD_NOARGS(KX_GameObject,GetVisible);
768 KX_PYMETHOD_VARARGS(KX_GameObject,SetVisible);
769 KX_PYMETHOD_NOARGS(KX_GameObject,GetState);
770 KX_PYMETHOD_O(KX_GameObject,SetState);
771 KX_PYMETHOD_VARARGS(KX_GameObject,AlignAxisToVect);
772 KX_PYMETHOD_O(KX_GameObject,GetAxisVect);
773 KX_PYMETHOD_NOARGS(KX_GameObject,SuspendDynamics);
774 KX_PYMETHOD_NOARGS(KX_GameObject,RestoreDynamics);
775 KX_PYMETHOD_NOARGS(KX_GameObject,EnableRigidBody);
776 KX_PYMETHOD_NOARGS(KX_GameObject,DisableRigidBody);
777 KX_PYMETHOD_VARARGS(KX_GameObject,ApplyImpulse);
778 KX_PYMETHOD_O(KX_GameObject,SetCollisionMargin);
779 KX_PYMETHOD_NOARGS(KX_GameObject,GetParent);
780 KX_PYMETHOD_O(KX_GameObject,SetParent);
781 KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent);
782 KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren);
783 KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive);
784 KX_PYMETHOD_VARARGS(KX_GameObject,GetMesh);
785 KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId);
786 KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames);
787 KX_PYMETHOD_NOARGS(KX_GameObject,EndObject);
788 KX_PYMETHOD_DOC(KX_GameObject,rayCastTo);
789 KX_PYMETHOD_DOC(KX_GameObject,rayCast);
790 KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo);
791 KX_PYMETHOD_DOC(KX_GameObject,getVectTo);
796 * Random internal function to convert python function arguments
798 * @return true if conversion was possible.
802 ConvertPythonVectorArgs(
810 /* utility conversion function */
811 bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok);
813 #endif //__KX_GAMEOBJECT