forked from bartvdbraak/blender
BGE: Fix for bugs T42520 and T42097 (mouse look actuator related).
With this fix the mouse actuator movement works well as with even screen resolutions as odd screen resolutions. Also it fixed the movement when the border of the blenderplayer window is out of the screen limits. Reviewed By: moguri Differential Revision: https://developer.blender.org/D946
This commit is contained in:
parent
2d2bfd416b
commit
ee58d44945
@ -126,24 +126,33 @@ bool KX_MouseActuator::Update()
|
||||
float movement[2];
|
||||
MT_Vector3 rotation;
|
||||
float setposition[2] = {0.0};
|
||||
float center_x = 0.5, center_y = 0.5;
|
||||
|
||||
getMousePosition(position);
|
||||
|
||||
movement[0] = position[0];
|
||||
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.
|
||||
if ((m_oldposition[0] <= -0.9) && (m_oldposition[1] <= -0.9)) {
|
||||
|
||||
if (m_reset_x) {
|
||||
m_oldposition[0] = 0.5;
|
||||
m_oldposition[0] = center_x;
|
||||
}
|
||||
else {
|
||||
m_oldposition[0] = position[0];
|
||||
}
|
||||
|
||||
if (m_reset_y) {
|
||||
m_oldposition[1] = 0.5;
|
||||
m_oldposition[1] = center_y;
|
||||
}
|
||||
else {
|
||||
m_oldposition[1] = position[1];
|
||||
@ -156,8 +165,8 @@ bool KX_MouseActuator::Update()
|
||||
if (m_use_axis_x) {
|
||||
|
||||
if (m_reset_x) {
|
||||
setposition[0] = 0.5;
|
||||
movement[0] -= 0.5;
|
||||
setposition[0] = center_x;
|
||||
movement[0] -= center_x;
|
||||
}
|
||||
else {
|
||||
setposition[0] = position[0];
|
||||
@ -166,12 +175,10 @@ bool KX_MouseActuator::Update()
|
||||
|
||||
movement[0] *= -1.0;
|
||||
|
||||
/* Don't apply the rotation when width resolution is odd (+ little movement) to
|
||||
avoid undesired drifting or when we are under a certain threshold for mouse
|
||||
/* Don't apply the rotation when we are under a certain threshold for mouse
|
||||
movement */
|
||||
|
||||
if (!((m_canvas->GetWidth() % 2 != 0) && MT_abs(movement[0]) < 0.01) &&
|
||||
((movement[0] > (m_threshold[0] / 10.0)) ||
|
||||
if (((movement[0] > (m_threshold[0] / 10.0)) ||
|
||||
((movement[0] * (-1.0)) > (m_threshold[0] / 10.0)))) {
|
||||
|
||||
movement[0] *= m_sensitivity[0];
|
||||
@ -209,15 +216,15 @@ bool KX_MouseActuator::Update()
|
||||
}
|
||||
}
|
||||
else {
|
||||
setposition[0] = 0.5;
|
||||
setposition[0] = center_x;
|
||||
}
|
||||
|
||||
//Calculating Y axis.
|
||||
if (m_use_axis_y) {
|
||||
|
||||
if (m_reset_y) {
|
||||
setposition[1] = 0.5;
|
||||
movement[1] -= 0.5;
|
||||
setposition[1] = center_y;
|
||||
movement[1] -= center_y;
|
||||
}
|
||||
else {
|
||||
setposition[1] = position[1];
|
||||
@ -226,12 +233,10 @@ bool KX_MouseActuator::Update()
|
||||
|
||||
movement[1] *= -1.0;
|
||||
|
||||
/* Don't apply the rotation when height resolution is odd (+ little movement) to
|
||||
avoid undesired drifting or when we are under a certain threshold for mouse
|
||||
/* Don't apply the rotation when we are under a certain threshold for mouse
|
||||
movement */
|
||||
|
||||
if (!((m_canvas->GetHeight() % 2 != 0) && MT_abs(movement[1]) < 0.01) &&
|
||||
((movement[1] > (m_threshold[1] / 10.0)) ||
|
||||
if (((movement[1] > (m_threshold[1] / 10.0)) ||
|
||||
((movement[1] * (-1.0)) > (m_threshold[1] / 10.0)))) {
|
||||
|
||||
movement[1] *= m_sensitivity[1];
|
||||
@ -270,7 +275,7 @@ bool KX_MouseActuator::Update()
|
||||
}
|
||||
}
|
||||
else {
|
||||
setposition[1] = 0.5;
|
||||
setposition[1] = center_y;
|
||||
}
|
||||
|
||||
setMousePosition(setposition[0], setposition[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user