Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_MouseActuator.cpp
| Show All 24 Lines | |||||
| #include "SCA_MouseManager.h" | #include "SCA_MouseManager.h" | ||||
| #include "SCA_IInputDevice.h" | #include "SCA_IInputDevice.h" | ||||
| #include "RAS_ICanvas.h" | #include "RAS_ICanvas.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "MT_Vector3.h" | #include "MT_Vector3.h" | ||||
| #include "MT_Scalar.h" | #include "MT_Scalar.h" | ||||
| #include "MT_assert.h" | #include "MT_assert.h" | ||||
| #include "limits.h" | #include "limits.h" | ||||
| #include "PHY_ICharacter.h" | |||||
| #include "PHY_IPhysicsEnvironment.h" | |||||
| #include "PHY_IPhysicsController.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | ||||
| #include <config.h> | #include <config.h> | ||||
| #endif | #endif | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | bool KX_MouseActuator::Update() | ||||
| bool bNegativeEvent = IsNegativeEvent(); | bool bNegativeEvent = IsNegativeEvent(); | ||||
| RemoveAllEvents(); | RemoveAllEvents(); | ||||
| if (bNegativeEvent) | if (bNegativeEvent) | ||||
| return false; // do nothing on negative events | return false; // do nothing on negative events | ||||
| KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent()); | KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent()); | ||||
| PHY_ICharacter *character = parent->GetScene()->GetPhysicsEnvironment()->GetCharacterController(parent); | |||||
| m_mouse = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice(); | m_mouse = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice(); | ||||
| switch (m_type) { | switch (m_type) { | ||||
| case KX_ACT_MOUSE_VISIBILITY: | case KX_ACT_MOUSE_VISIBILITY: | ||||
| { | { | ||||
| if (m_visible) { | if (m_visible) { | ||||
| if (m_canvas) { | if (m_canvas) { | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | case KX_ACT_MOUSE_LOOK: | ||||
| rotation = MT_Vector3(0.0, 0.0, movement[0]); | rotation = MT_Vector3(0.0, 0.0, movement[0]); | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| parent->ApplyRotation(rotation, m_local_x); | parent->ApplyRotation(rotation, m_local_x); | ||||
| } | } | ||||
| else { | |||||
| // Asigning unit vector for calculating walk direction if there is no X axis movement | |||||
| if (character) { | |||||
| rotation = MT_Vector3(0.0, 0.0, 0.0); | |||||
| rotation[m_object_axis[0] - KX_ACT_MOUSE_OBJECT_AXIS_X] = 1.0; | |||||
| } | |||||
| } | |||||
| // Calculating walk direction if character physics exists | |||||
| if (character) { | |||||
| MT_Vector3 character_dir = character->GetWalkDirection(); | |||||
| character_dir = rotation * character_dir; | |||||
| character->SetWalkDirection(character_dir / parent->GetScene()->GetPhysicsEnvironment()->GetNumTimeSubSteps()); | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| setposition[0] = center_x; | setposition[0] = center_x; | ||||
| } | } | ||||
| //Calculating Y axis. | //Calculating Y axis. | ||||
| if (m_use_axis_y) { | if (m_use_axis_y) { | ||||
campbellbarton: Can't this be simplified?
rotation = MT_Vector3(0, 0, 0)
rotation… | |||||
| if (m_reset_y) { | if (m_reset_y) { | ||||
| setposition[1] = center_y; | setposition[1] = center_y; | ||||
| movement[1] -= center_y; | movement[1] -= center_y; | ||||
| } | } | ||||
| else { | else { | ||||
| setposition[1] = position[1]; | setposition[1] = position[1]; | ||||
| movement[1] -= m_oldposition[1]; | movement[1] -= m_oldposition[1]; | ||||
| Show All 36 Lines | case KX_ACT_MOUSE_LOOK: | ||||
| rotation = MT_Vector3(0.0, 0.0, movement[1]); | rotation = MT_Vector3(0.0, 0.0, movement[1]); | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| parent->ApplyRotation(rotation, m_local_y); | parent->ApplyRotation(rotation, m_local_y); | ||||
| } | } | ||||
| else { | |||||
| // Asigning unit vector for calculating walk direction if there is no Y axis movement | |||||
| if (character) { | |||||
| rotation = MT_Vector3(0.0, 0.0, 0.0); | |||||
| rotation[m_object_axis[1] - KX_ACT_MOUSE_OBJECT_AXIS_X] = 1.0; | |||||
| } | |||||
| } | |||||
| // Calculating walk direction if character physics exists | |||||
| if (character) { | |||||
| MT_Vector3 character_dir = character->GetWalkDirection(); | |||||
| character_dir = rotation * character_dir; | |||||
| character->SetWalkDirection(character_dir / parent->GetScene()->GetPhysicsEnvironment()->GetNumTimeSubSteps()); | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| setposition[1] = center_y; | setposition[1] = center_y; | ||||
| } | } | ||||
| setMousePosition(setposition[0], setposition[1]); | setMousePosition(setposition[0], setposition[1]); | ||||
| m_oldposition[0] = position[0]; | m_oldposition[0] = position[0]; | ||||
| ▲ Show 20 Lines • Show All 253 Lines • Show Last 20 Lines | |||||
Can't this be simplified?
same below