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