Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_MouseActuator.cpp
| Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | switch (m_type) { | ||||
| case KX_ACT_MOUSE_LOOK: | case KX_ACT_MOUSE_LOOK: | ||||
| { | { | ||||
| if (m_mouse) { | if (m_mouse) { | ||||
| float position[2]; | float position[2]; | ||||
| float movement[2]; | float movement[2]; | ||||
| MT_Vector3 rotation; | MT_Vector3 rotation; | ||||
| float setposition[2] = {0.0}; | float setposition[2] = {0.0}; | ||||
| float center_x = 0.5, center_y = 0.5; | |||||
| getMousePosition(position); | getMousePosition(position); | ||||
| movement[0] = position[0]; | movement[0] = position[0]; | ||||
| movement[1] = position[1]; | movement[1] = position[1]; | ||||
| //preventing undesired drifting when resolution is odd | |||||
| if ((m_canvas->GetWidth() % 2) != 0) { | |||||
| center_x = ((m_canvas->GetWidth() - 1.0) / 2.0) / (m_canvas->GetWidth()); | |||||
| } | |||||
| if ((m_canvas->GetHeight() % 2) != 0) { | |||||
| center_y = ((m_canvas->GetHeight() - 1.0) / 2.0) / (m_canvas->GetHeight()); | |||||
| } | |||||
| //preventing initial skipping. | //preventing initial skipping. | ||||
| if ((m_oldposition[0] <= -0.9) && (m_oldposition[1] <= -0.9)) { | if ((m_oldposition[0] <= -0.9) && (m_oldposition[1] <= -0.9)) { | ||||
| if (m_reset_x) { | if (m_reset_x) { | ||||
| m_oldposition[0] = 0.5; | m_oldposition[0] = center_x; | ||||
| } | } | ||||
| else { | else { | ||||
| m_oldposition[0] = position[0]; | m_oldposition[0] = position[0]; | ||||
| } | } | ||||
| if (m_reset_y) { | if (m_reset_y) { | ||||
| m_oldposition[1] = 0.5; | m_oldposition[1] = center_y; | ||||
| } | } | ||||
| else { | else { | ||||
| m_oldposition[1] = position[1]; | m_oldposition[1] = position[1]; | ||||
| } | } | ||||
| setMousePosition(m_oldposition[0], m_oldposition[1]); | setMousePosition(m_oldposition[0], m_oldposition[1]); | ||||
| break; | break; | ||||
| } | } | ||||
| //Calculating X axis. | //Calculating X axis. | ||||
| if (m_use_axis_x) { | if (m_use_axis_x) { | ||||
| if (m_reset_x) { | if (m_reset_x) { | ||||
| setposition[0] = 0.5; | setposition[0] = center_x; | ||||
| movement[0] -= 0.5; | movement[0] -= center_x; | ||||
| } | } | ||||
| else { | else { | ||||
| setposition[0] = position[0]; | setposition[0] = position[0]; | ||||
| movement[0] -= m_oldposition[0]; | movement[0] -= m_oldposition[0]; | ||||
| } | } | ||||
| movement[0] *= -1.0; | movement[0] *= -1.0; | ||||
| /* Don't apply the rotation when width resolution is odd (+ little movement) to | /* Don't apply the rotation when we are under a certain threshold for mouse | ||||
| avoid undesired drifting or when we are under a certain threshold for mouse | |||||
| movement */ | movement */ | ||||
| if (!((m_canvas->GetWidth() % 2 != 0) && MT_abs(movement[0]) < 0.01) && | if (((movement[0] > (m_threshold[0] / 10.0)) || | ||||
| ((movement[0] > (m_threshold[0] / 10.0)) || | |||||
| ((movement[0] * (-1.0)) > (m_threshold[0] / 10.0)))) { | ((movement[0] * (-1.0)) > (m_threshold[0] / 10.0)))) { | ||||
| movement[0] *= m_sensitivity[0]; | movement[0] *= m_sensitivity[0]; | ||||
| if ((m_limit_x[0] != 0.0) && ((m_angle[0] + movement[0]) <= m_limit_x[0])) { | if ((m_limit_x[0] != 0.0) && ((m_angle[0] + movement[0]) <= m_limit_x[0])) { | ||||
| movement[0] = m_limit_x[0] - m_angle[0]; | movement[0] = m_limit_x[0] - m_angle[0]; | ||||
| } | } | ||||
| Show All 21 Lines | case KX_ACT_MOUSE_LOOK: | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| parent->ApplyRotation(rotation, m_local_x); | parent->ApplyRotation(rotation, m_local_x); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| setposition[0] = 0.5; | setposition[0] = center_x; | ||||
| } | } | ||||
| //Calculating Y axis. | //Calculating Y axis. | ||||
| if (m_use_axis_y) { | if (m_use_axis_y) { | ||||
| if (m_reset_y) { | if (m_reset_y) { | ||||
| setposition[1] = 0.5; | setposition[1] = center_y; | ||||
| movement[1] -= 0.5; | movement[1] -= center_y; | ||||
| } | } | ||||
| else { | else { | ||||
| setposition[1] = position[1]; | setposition[1] = position[1]; | ||||
| movement[1] -= m_oldposition[1]; | movement[1] -= m_oldposition[1]; | ||||
| } | } | ||||
| movement[1] *= -1.0; | movement[1] *= -1.0; | ||||
| /* Don't apply the rotation when height resolution is odd (+ little movement) to | /* Don't apply the rotation when we are under a certain threshold for mouse | ||||
| avoid undesired drifting or when we are under a certain threshold for mouse | |||||
| movement */ | movement */ | ||||
| if (!((m_canvas->GetHeight() % 2 != 0) && MT_abs(movement[1]) < 0.01) && | if (((movement[1] > (m_threshold[1] / 10.0)) || | ||||
| ((movement[1] > (m_threshold[1] / 10.0)) || | |||||
| ((movement[1] * (-1.0)) > (m_threshold[1] / 10.0)))) { | ((movement[1] * (-1.0)) > (m_threshold[1] / 10.0)))) { | ||||
| movement[1] *= m_sensitivity[1]; | movement[1] *= m_sensitivity[1]; | ||||
| if ((m_limit_y[0] != 0.0) && ((m_angle[1] + movement[1]) <= m_limit_y[0])) { | if ((m_limit_y[0] != 0.0) && ((m_angle[1] + movement[1]) <= m_limit_y[0])) { | ||||
| movement[1] = m_limit_y[0] - m_angle[1]; | movement[1] = m_limit_y[0] - m_angle[1]; | ||||
| } | } | ||||
| Show All 22 Lines | case KX_ACT_MOUSE_LOOK: | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| parent->ApplyRotation(rotation, m_local_y); | parent->ApplyRotation(rotation, m_local_y); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| setposition[1] = 0.5; | setposition[1] = center_y; | ||||
| } | } | ||||
| setMousePosition(setposition[0], setposition[1]); | setMousePosition(setposition[0], setposition[1]); | ||||
| m_oldposition[0] = position[0]; | m_oldposition[0] = position[0]; | ||||
| m_oldposition[1] = position[1]; | m_oldposition[1] = position[1]; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines | |||||