Blender V2.61 - r43446

KX_SCA_DynamicActuator.cpp

Go to the documentation of this file.
00001 
00004 //
00005 // Adjust dynamics settins for this object
00006 //
00007 //
00008 // ***** BEGIN GPL LICENSE BLOCK *****
00009 //
00010 // This program is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public License
00012 // as published by the Free Software Foundation; either version 2
00013 // of the License, or (at your option) any later version.
00014 //
00015 // This program is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with this program; if not, write to the Free Software Foundation,
00022 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00023 //
00024 // The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00025 // All rights reserved.
00026 //
00027 // The Original Code is: all of this file.
00028 //
00029 // Contributor(s): none yet.
00030 //
00031 // ***** END GPL LICENSE BLOCK *****
00032 
00033 //
00034 // Previously existed as:
00035 
00036 // \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
00037 
00038 // Please look here for revision history.
00039 
00040 #include "KX_SCA_DynamicActuator.h"
00041 
00042 #ifdef WITH_PYTHON
00043 
00044 /* ------------------------------------------------------------------------- */
00045 /* Python functions                                                          */
00046 /* ------------------------------------------------------------------------- */
00047 
00048 /* Integration hooks ------------------------------------------------------- */
00049 
00050 PyTypeObject KX_SCA_DynamicActuator::Type = {
00051     PyVarObject_HEAD_INIT(NULL, 0)
00052     "KX_SCA_DynamicActuator",
00053     sizeof(PyObjectPlus_Proxy),
00054     0,
00055     py_base_dealloc,
00056     0,
00057     0,
00058     0,
00059     0,
00060     py_base_repr,
00061     0,0,0,0,0,0,0,0,0,
00062     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00063     0,0,0,0,0,0,0,
00064     Methods,
00065     0,
00066     0,
00067     &SCA_IActuator::Type,
00068     0,0,0,0,0,0,
00069     py_base_new
00070 };
00071 
00072 PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
00073     {NULL,NULL} //Sentinel
00074 };
00075 
00076 PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
00077     KX_PYATTRIBUTE_SHORT_RW("mode",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation),
00078     KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,FLT_MAX,KX_SCA_DynamicActuator,m_setmass),
00079     { NULL }    //Sentinel
00080 };
00081 
00082 #endif // WITH_PYTHON
00083 
00084 /* ------------------------------------------------------------------------- */
00085 /* Native functions                                                          */
00086 /* ------------------------------------------------------------------------- */
00087 
00088 KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
00089                                                        short dyn_operation,
00090                                                        float setmass) :
00091 
00092     SCA_IActuator(gameobj, KX_ACT_DYNAMIC),
00093     m_dyn_operation(dyn_operation),
00094     m_setmass(setmass)
00095 {
00096 } /* End of constructor */
00097 
00098 
00099 KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
00100 { 
00101     // there's nothing to be done here, really....
00102 } /* end of destructor */
00103 
00104 
00105 
00106 bool KX_SCA_DynamicActuator::Update()
00107 {
00108     // bool result = false; /*unused*/
00109     KX_GameObject *obj = (KX_GameObject*) GetParent();
00110     bool bNegativeEvent = IsNegativeEvent();
00111     KX_IPhysicsController* controller;
00112     RemoveAllEvents();
00113 
00114     if (bNegativeEvent)
00115         return false; // do nothing on negative events
00116     
00117     if (!obj)
00118         return false; // object not accessible, shouldnt happen
00119     controller = obj->GetPhysicsController();
00120     if (!controller)
00121         return false;   // no physic object
00122 
00123     switch (m_dyn_operation)
00124     {
00125         case 0:         
00126             obj->RestoreDynamics(); 
00127             break;
00128         case 1:
00129             obj->SuspendDynamics();
00130             break;
00131         case 2:
00132             controller->setRigidBody(true); 
00133             break;
00134         case 3:
00135             controller->setRigidBody(false);
00136             break;
00137         case 4:
00138             controller->SetMass(m_setmass);
00139             break;
00140     }
00141 
00142     return false;
00143 }
00144 
00145 
00146 
00147 CValue* KX_SCA_DynamicActuator::GetReplica()
00148 {
00149     KX_SCA_DynamicActuator* replica = 
00150         new KX_SCA_DynamicActuator(*this);
00151 
00152     if (replica == NULL)
00153         return NULL;
00154 
00155     replica->ProcessReplica();
00156     return replica;
00157 };
00158 
00159 
00160 /* eof */