Mouse Movement: Difference between revisions

From Minecraft Parkour Wiki
Content added Content deleted
(formatting)
(Marked this version for translation)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<!--T:1-->
Mouse movement represents the instant displacement of the cursor on the screen (in pixels) : (<math display="inline">dx,dy</math>).
Mouse movement represents the instant displacement of the cursor on the screen (in pixels) : (<math display="inline">dx,dy</math>).


<!--T:2-->
When it comes to Minecraft, mouse movement represents the instant rotation of the camera (in degrees) : (<math display="inline">\Delta x , \Delta y</math>).
When it comes to Minecraft, mouse movement represents the instant rotation of the camera (in degrees) : (<math display="inline">\Delta x , \Delta y</math>).


<!--T:3-->
<br />
<br />



== Sensitivity ==
== Sensitivity == <!--T:4-->

<!--T:5-->
Sensitivity ('''s''') is a parameter that changes how fast the camera should turn.
Sensitivity ('''s''') is a parameter that changes how fast the camera should turn.


<!--T:6-->
This setting can be changed in the Controls menu.
This setting can be changed in the Controls menu.


<!--T:7-->
* The default sensitivity is "100%" (<math display="inline">s=0.5</math>)
* The default sensitivity is "100%" (<math display="inline">s=0.5</math>)


<!--T:8-->
* The lowest vanilla sensitivity is "0%" (<math display="inline">s=0.0</math>)
* The lowest vanilla sensitivity is "0%" (<math display="inline">s=0.0</math>)
* The highest vanilla sensitivity is "200%" (<math display="inline">s=2.0</math>)
* The highest vanilla sensitivity is "200%" (<math display="inline">s=1.0</math>)




<!--T:9-->
In 1.8, <math display="inline">\Delta x</math> is calculated as:
In 1.8, <math display="inline">\Delta x</math> is calculated as:


<!--T:10-->
<math>\Delta x = 1.2dx \times (0.6s + 0.2)^{3}</math>
<math>\Delta x = 1.2dx \times (0.6s + 0.2)^{3}</math>


<!--T:11-->
<math display="inline">\Delta y</math> is obtained in the same way, and is multiplied by -1 if "Invert Mouse" is ON.
<math display="inline">\Delta y</math> is obtained in the same way, and is multiplied by -1 if "Invert Mouse" is ON.




<!--T:12-->
With default sensitivity (<math display="inline">s=0.5</math>), one pixel of mouse movement translates into 0.15° of rotation.
With default sensitivity (<math display="inline">s=0.5</math>), one pixel of mouse movement translates into 0.15° of rotation.


<!--T:13-->
This means that the camera moves in increments of 0.15°: to turn 45°, you would need to move your mouse by 300px.
This means that the camera moves in increments of 0.15°: to turn 45°, you would need to move your mouse by 300px.






<!--T:14-->
Furthermore, '''s''' isn't technically bounded by [0,1], and can take any value (even negative).
Furthermore, '''s''' isn't technically bounded by [0,1], and can take any value (even negative).


<!--T:15-->
You can manually edit the value of mouseSensitivity in the options.txt file (found in the .minecraft folder)
You can manually edit the value of mouseSensitivity in the options.txt file (found in the .minecraft folder)


<!--T:16-->
Be warned that modifying the options.txt file may or may not be allowed on servers.
Be warned that modifying the options.txt file may or may not be allowed on servers.






== Remarkable values ==
Since it's possible to set the sensitivity to any value we want, it might be interesting to adjust the sensitivity to match specific rotation increments.


== Remarkable values == <!--T:17-->


<!--T:18-->
Since it's possible to set the sensitivity to any value we want, it might be interesting to adjust the sensitivity to match specific rotation increments.


<!--T:19-->
To get the required sensitivity for the desired increment <math display="inline">\delta</math>, we can use the inverse formula:
To get the required sensitivity for the desired increment <math display="inline">\delta</math>, we can use the inverse formula:


<!--T:20-->
<math>s = \frac{\sqrt[3]{\frac{\delta}{1.2}} - 0.2}{0.6}</math>
<math>s = \frac{\sqrt[3]{\frac{\delta}{1.2}} - 0.2}{0.6}</math>
<br />
<br />


<!--T:21-->
This table lists remarkable increments of rotation, and the corresponding values of '''s'''.
This table lists remarkable increments of rotation, and the corresponding values of '''s'''.
{| class="wikitable"
{| class="wikitable"
Line 76: Line 99:
|8.5221547
|8.5221547
|}<br />
|}<br />
== Yaw and Pitch ==
Yaw (horizontal rotation) and pitch (vertical rotation) are [https://en.wikipedia.org/wiki/Floating-point_arithmetic floats] that keep track of an entity's spatial rotation.


== Yaw and Pitch == <!--T:22-->
[[Facing and Angles|Facing]] is the restriction of the yaw to [-180, 180], as it is represented in [[Debug Screen|F3]]. Pitch is naturally restricted to [-90, 90].


<!--T:23-->
Yaw (horizontal rotation) and pitch (vertical rotation) are [https://en.wikipedia.org/wiki/Floating-point_arithmetic floats] that keep track of an entity's head rotation.


<!--T:24-->
Mouse movement directly modifies the Player's yaw and pitch:<syntaxhighlight lang="java">
[[Special:MyLanguage/Facing and Angles|Facing]] is the restriction of the yaw to [-180, 180], as it is represented in [[Special:MyLanguage/Debug Screen|F3]]. Pitch is naturally clamped between [-90, 90].

<!--T:25-->
Mouse movement directly modifies the player's yaw and pitch:<syntaxhighlight lang="java">
/* In EntityRenderer.java */
/* In EntityRenderer.java */
public void updateMouseMovement(...)
public void updateMouseMovement(...)
Line 88: Line 115:
... //previous code ignored
... //previous code ignored


<!--T:26-->
float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
float mult = f * f * f * 8.0F;
float mult = f * f * f * 8.0F;
float dX = (float)this.mc.mouseHelper.deltaX * mult;
float dX = (float)this.mc.mouseHelper.deltaX * mult;
float dY = (float)this.mc.mouseHelper.deltaY * mult;
float dY = (float)this.mc.mouseHelper.deltaY * mult;


int i = 1;
<!--T:27-->
int i = 1;
if (this.mc.gameSettings.invertMouse)
if (this.mc.gameSettings.invertMouse)
i = -1;
i = -1;


<!--T:28-->
... //Applies filters if smooth camera
... //Applies filters if smooth camera


<!--T:29-->
this.mc.thePlayer.rotateEntity(dX, dY*i);
this.mc.thePlayer.rotateEntity(dX, dY*i);
}
}




<!--T:30-->
/* In Entity.java */
/* In Entity.java */
public void rotateEntity(float dX, float dY)
public void rotateEntity(float dX, float dY)
Line 113: Line 145:




While the pitch is clamped between -90° and 90°, yaw is not clamped between -180° and 180° as would be expected.


<!--T:31-->
While the pitch is clamped between -90° and 90°, yaw is not restricted between -180° and 180° as would be expected.

<!--T:32-->
This means that '''yaw is unbounded''', which has some unintended consequences if you deliberately turn in one direction for long enough.
This means that '''yaw is unbounded''', which has some unintended consequences if you deliberately turn in one direction for long enough.




<!--T:33-->
By nature of being a float, its precision becomes worse the bigger it gets, to the point where it becomes noticeably jittery at large values.
By nature of being a float, its precision becomes worse the bigger it gets, to the point where it becomes noticeably jittery at large values.


<!--T:34-->
* When <math>|yaw| > 4194304</math> (<math display="inline">2^{22}</math>) it can only increase in increments of 0.5°.
* When <math>|yaw| > 4194304</math> (<math display="inline">2^{22}</math>) it can only increase in increments of 0.5°.
* When <math>|yaw| > 8388608</math> (<math display="inline">2^{23}</math>) it can only increase in increments of 1°.
* When <math>|yaw| > 8388608</math> (<math display="inline">2^{23}</math>) it can only increase in increments of 1°.
Line 125: Line 162:




<!--T:35-->
At some point, yaw can even [https://youtu.be/DEI_CeFlatM mess with movement and stop the player in place].
At some point, yaw can even [https://youtu.be/DEI_CeFlatM mess with movement and stop the player in place].


<!--T:36-->
This is because the yaw gets too large to be converted to a proper angle (see [[Angles]]).
This is because the yaw gets too large to be converted to a proper angle (see [[Special:MyLanguage/Angles|Angles]]).


<!--T:37-->
This phenomenon happens when <math>|yaw| \geq 11796480 = 360 \times 2^{15}</math>.
This phenomenon happens when <math>|yaw| \geq 11796480 = 360 \times 2^{15}</math>.




<!--T:38-->
Turning even further can crash the game, when <math display="inline">|yaw| > 8.59 \times 10^9</math>
Turning even further can crash the game, when <math display="inline">|yaw| > 8.59 \times 10^9</math>
</translate>

Latest revision as of 11:16, 1 October 2021

Other languages:

Mouse movement represents the instant displacement of the cursor on the screen (in pixels) : ().

When it comes to Minecraft, mouse movement represents the instant rotation of the camera (in degrees) : ().



Sensitivity

Sensitivity (s) is a parameter that changes how fast the camera should turn.

This setting can be changed in the Controls menu.

  • The default sensitivity is "100%" ()
  • The lowest vanilla sensitivity is "0%" ()
  • The highest vanilla sensitivity is "200%" ()


In 1.8, is calculated as:

is obtained in the same way, and is multiplied by -1 if "Invert Mouse" is ON.


With default sensitivity (), one pixel of mouse movement translates into 0.15° of rotation.

This means that the camera moves in increments of 0.15°: to turn 45°, you would need to move your mouse by 300px.


Furthermore, s isn't technically bounded by [0,1], and can take any value (even negative).

You can manually edit the value of mouseSensitivity in the options.txt file (found in the .minecraft folder)

Be warned that modifying the options.txt file may or may not be allowed on servers.



Remarkable values

Since it's possible to set the sensitivity to any value we want, it might be interesting to adjust the sensitivity to match specific rotation increments.

To get the required sensitivity for the desired increment , we can use the inverse formula:


This table lists remarkable increments of rotation, and the corresponding values of s.

s
-0.3333333
0.1° 0.3946504
0.15° 0.5
0.25° 0.6546926
0.5° 0.9115013
1.2350600
45° 5.2452746
180° 8.5221547


Yaw and Pitch

Yaw (horizontal rotation) and pitch (vertical rotation) are floats that keep track of an entity's head rotation.

Facing is the restriction of the yaw to [-180, 180], as it is represented in F3. Pitch is naturally clamped between [-90, 90].

Mouse movement directly modifies the player's yaw and pitch:

/* In EntityRenderer.java */
public void updateMouseMovement(...)
{
    ... //previous code ignored

    float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
    float mult = f * f * f * 8.0F;
    float dX = (float)this.mc.mouseHelper.deltaX * mult;
    float dY = (float)this.mc.mouseHelper.deltaY * mult;

    int i = 1;
    if (this.mc.gameSettings.invertMouse)
        i = -1;

    ... //Applies filters if smooth camera

    this.mc.thePlayer.rotateEntity(dX, dY*i);
}


/* In Entity.java */
public void rotateEntity(float dX, float dY)
{
    this.rotationYaw = this.rotationYaw + dX*0.15);
    this.rotationPitch = this.rotationPitch - dY*0.15;
    this.rotationPitch = MathHelper.clamp(this.rotationPitch, -90.0, 90.0);
}


While the pitch is clamped between -90° and 90°, yaw is not restricted between -180° and 180° as would be expected.

This means that yaw is unbounded, which has some unintended consequences if you deliberately turn in one direction for long enough.


By nature of being a float, its precision becomes worse the bigger it gets, to the point where it becomes noticeably jittery at large values.

  • When () it can only increase in increments of 0.5°.
  • When () it can only increase in increments of 1°.


At some point, yaw can even mess with movement and stop the player in place.

This is because the yaw gets too large to be converted to a proper angle (see Angles).

This phenomenon happens when .


Turning even further can crash the game, when