Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_SteeringActuator.cpp
| Show All 35 Lines | |||||
| #include "KX_PythonInit.h" | #include "KX_PythonInit.h" | ||||
| #include "KX_PyMath.h" | #include "KX_PyMath.h" | ||||
| #include "Recast.h" | #include "Recast.h" | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj, | KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj, | ||||
| int mode, | int mode, | ||||
| KX_GameObject *target, | KX_GameObject *target, | ||||
| KX_GameObject *navmesh, | KX_GameObject *navmesh, | ||||
| float distance, | float distance, | ||||
| float velocity, | float velocity, | ||||
| float acceleration, | float acceleration, | ||||
| float turnspeed, | float turnspeed, | ||||
| bool isSelfTerminated, | bool isSelfTerminated, | ||||
| int pathUpdatePeriod, | int pathUpdatePeriod, | ||||
| KX_ObstacleSimulation* simulation, | KX_ObstacleSimulation* simulation, | ||||
| short facingmode, | short facingmode, | ||||
| bool normalup, | bool normalup, | ||||
| bool enableVisualization) | bool enableVisualization, | ||||
| float velzfactor) | |||||
| : SCA_IActuator(gameobj, KX_ACT_STEERING), | : SCA_IActuator(gameobj, KX_ACT_STEERING), | ||||
| m_target(target), | m_target(target), | ||||
| m_mode(mode), | m_mode(mode), | ||||
| m_distance(distance), | m_distance(distance), | ||||
| m_velocity(velocity), | m_velocity(velocity), | ||||
| m_acceleration(acceleration), | m_acceleration(acceleration), | ||||
| m_turnspeed(turnspeed), | m_turnspeed(turnspeed), | ||||
| m_simulation(simulation), | m_simulation(simulation), | ||||
| m_updateTime(0), | m_updateTime(0), | ||||
| m_obstacle(NULL), | m_obstacle(NULL), | ||||
| m_isActive(false), | m_isActive(false), | ||||
| m_isSelfTerminated(isSelfTerminated), | m_isSelfTerminated(isSelfTerminated), | ||||
| m_enableVisualization(enableVisualization), | m_enableVisualization(enableVisualization), | ||||
| m_facingMode(facingmode), | m_facingMode(facingmode), | ||||
| m_normalUp(normalup), | m_normalUp(normalup), | ||||
| m_pathLen(0), | m_pathLen(0), | ||||
| m_pathUpdatePeriod(pathUpdatePeriod), | m_pathUpdatePeriod(pathUpdatePeriod), | ||||
| m_velzfactor(velzfactor), | |||||
| m_wayPointIdx(-1), | m_wayPointIdx(-1), | ||||
| m_steerVec(MT_Vector3(0, 0, 0)) | m_steerVec(MT_Vector3(0, 0, 0)) | ||||
| { | { | ||||
| m_navmesh = static_cast<KX_NavMeshObject*>(navmesh); | m_navmesh = static_cast<KX_NavMeshObject*>(navmesh); | ||||
| if (m_navmesh) | if (m_navmesh) | ||||
| m_navmesh->RegisterActuator(this); | m_navmesh->RegisterActuator(this); | ||||
| if (m_target) | if (m_target) | ||||
| m_target->RegisterActuator(this); | m_target->RegisterActuator(this); | ||||
| ▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | if (apply_steerforce) | ||||
| } | } | ||||
| HandleActorFace(newvel); | HandleActorFace(newvel); | ||||
| if (isdyna) | if (isdyna) | ||||
| { | { | ||||
| //temporary solution: set 2D steering velocity directly to obj | //temporary solution: set 2D steering velocity directly to obj | ||||
| //correct way is to apply physical force | //correct way is to apply physical force | ||||
| MT_Vector3 curvel = obj->GetLinearVelocity(); | MT_Vector3 curvel = obj->GetLinearVelocity(); | ||||
| newvel.z() = curvel.z(); | newvel.z() = curvel.z() * m_velzfactor; | ||||
| obj->setLinearVelocity(newvel, false); | obj->setLinearVelocity(newvel, false); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| MT_Vector3 movement = delta*newvel; | MT_Vector3 movement = delta*newvel; | ||||
| obj->ApplyMovement(movement, false); | obj->ApplyMovement(movement, false); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 336 Lines • Show Last 20 Lines | |||||