Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_ObjectActuator.cpp
| Context not available. | |||||
| * \ingroup ketsji | * \ingroup ketsji | ||||
| */ | */ | ||||
| #include <stdio.h> | |||||
| #include "KX_ObjectActuator.h" | #include "KX_ObjectActuator.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "KX_PyMath.h" // For PyVecTo - should this include be put in PyObjectPlus? | #include "KX_PyMath.h" // For PyVecTo - should this include be put in PyObjectPlus? | ||||
| Context not available. | |||||
| #include "PHY_ICharacter.h" | #include "PHY_ICharacter.h" | ||||
| #include "PHY_IPhysicsEnvironment.h" | #include "PHY_IPhysicsEnvironment.h" | ||||
| #include "CM_Message.h" | |||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| Context not available. | |||||
| if (!character) | if (!character) | ||||
| { | { | ||||
| printf("Character motion enabled on non-character object (%s), falling back to simple motion.\n", parent->GetName().Ptr()); | CM_LogicBrickWarning(this, "character motion enabled on non-character object, falling back to simple motion."); | ||||
| m_bitLocalFlag.CharacterMotion = false; | m_bitLocalFlag.CharacterMotion = false; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| MT_Vector3 v = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity); | MT_Vector3 v = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity); | ||||
| if (m_reference) | if (m_reference) | ||||
| { | { | ||||
| const MT_Point3& mypos = parent->NodeGetWorldPosition(); | const MT_Vector3& mypos = parent->NodeGetWorldPosition(); | ||||
| const MT_Point3& refpos = m_reference->NodeGetWorldPosition(); | const MT_Vector3& refpos = m_reference->NodeGetWorldPosition(); | ||||
| MT_Point3 relpos; | MT_Vector3 relpos; | ||||
| relpos = (mypos-refpos); | relpos = (mypos-refpos); | ||||
| MT_Vector3 vel= m_reference->GetVelocity(relpos); | MT_Vector3 vel= m_reference->GetVelocity(relpos); | ||||
| if (m_bitLocalFlag.LinearVelocity) | if (m_bitLocalFlag.LinearVelocity) | ||||
| Context not available. | |||||
| { | { | ||||
| if (m_bitLocalFlag.AddOrSetLinV) { | if (m_bitLocalFlag.AddOrSetLinV) { | ||||
| parent->addLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0); | parent->addLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0); | ||||
| } else { | } | ||||
| else { | |||||
| m_active_combined_velocity = true; | m_active_combined_velocity = true; | ||||
| if (m_damping > 0) { | if (m_damping > 0) { | ||||
| MT_Vector3 linV; | MT_Vector3 linV; | ||||
| Context not available. | |||||
| // delta and the start speed (depends on the existing speed in that direction) | // delta and the start speed (depends on the existing speed in that direction) | ||||
| linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity); | linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity); | ||||
| // keep only the projection along the desired direction | // keep only the projection along the desired direction | ||||
| m_current_linear_factor = linV.dot(m_linear_velocity)/m_linear_length2; | m_current_linear_factor = linV.dot(m_linear_velocity) / m_linear_length2; | ||||
| m_linear_damping_active = true; | m_linear_damping_active = true; | ||||
| } | } | ||||
| if (m_current_linear_factor < 1.0f) | if (m_current_linear_factor < 1.0f) | ||||
| m_current_linear_factor += 1.0f/m_damping; | m_current_linear_factor += 1.0f / m_damping; | ||||
| if (m_current_linear_factor > 1.0f) | if (m_current_linear_factor > 1.0f) | ||||
| m_current_linear_factor = 1.0f; | m_current_linear_factor = 1.0f; | ||||
| linV = m_current_linear_factor * m_linear_velocity; | linV = m_current_linear_factor * m_linear_velocity; | ||||
| parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0); | parent->setLinearVelocity(linV, (m_bitLocalFlag.LinearVelocity) != 0); | ||||
| } else { | } | ||||
| parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0); | else { | ||||
| parent->setLinearVelocity(m_linear_velocity, (m_bitLocalFlag.LinearVelocity) != 0); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| m_current_angular_factor = angV.dot(m_angular_velocity)/m_angular_length2; | m_current_angular_factor = angV.dot(m_angular_velocity)/m_angular_length2; | ||||
| m_angular_damping_active = true; | m_angular_damping_active = true; | ||||
| } | } | ||||
| if (m_current_angular_factor < 1.0f) | if (m_current_angular_factor < 1.0) | ||||
| m_current_angular_factor += 1.0f/m_damping; | m_current_angular_factor += 1.0/m_damping; | ||||
| if (m_current_angular_factor > 1.0f) | if (m_current_angular_factor > 1.0) | ||||
| m_current_angular_factor = 1.0f; | m_current_angular_factor = 1.0; | ||||
| angV = m_current_angular_factor * m_angular_velocity; | angV = m_current_angular_factor * m_angular_velocity; | ||||
| parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0); | parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0); | ||||
| } else { | } else { | ||||
| Context not available. | |||||
| return false; | return false; | ||||
| } | } | ||||
| void KX_ObjectActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map) | void KX_ObjectActuator::Relink(std::map<void *, void *>& obj_map) | ||||
| { | { | ||||
| void **h_obj = (*obj_map)[m_reference]; | void *h_obj = obj_map[m_reference]; | ||||
| if (h_obj) { | if (h_obj) { | ||||
| if (m_reference) | if (m_reference) | ||||
| m_reference->UnregisterActuator(this); | m_reference->UnregisterActuator(this); | ||||
| m_reference = (KX_GameObject*)(*h_obj); | m_reference = (KX_GameObject *)h_obj; | ||||
| m_reference->RegisterActuator(this); | m_reference->RegisterActuator(this); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| KX_PYATTRIBUTE_RW_FUNCTION("forceLimitZ", KX_ObjectActuator, pyattr_get_forceLimitZ, pyattr_set_forceLimitZ), | KX_PYATTRIBUTE_RW_FUNCTION("forceLimitZ", KX_ObjectActuator, pyattr_get_forceLimitZ, pyattr_set_forceLimitZ), | ||||
| KX_PYATTRIBUTE_VECTOR_RW_CHECK("pid", -100, 200, true, KX_ObjectActuator, m_pid, PyCheckPid), | KX_PYATTRIBUTE_VECTOR_RW_CHECK("pid", -100, 200, true, KX_ObjectActuator, m_pid, PyCheckPid), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("reference", KX_ObjectActuator,pyattr_get_reference,pyattr_set_reference), | KX_PYATTRIBUTE_RW_FUNCTION("reference", KX_ObjectActuator,pyattr_get_reference,pyattr_set_reference), | ||||
| { NULL } //Sentinel | KX_PYATTRIBUTE_NULL //Sentinel | ||||
| }; | }; | ||||
| /* Attribute get/set functions */ | /* Attribute get/set functions */ | ||||
| Context not available. | |||||