GivensParameters .java

com.mojang.math.GivensParameters (record): members: sinHalf, cosHalf, fromPositiveAngle, fromUnnormalized, aroundX, aroundY, aroundZ, cos, sin, inverse.

com.mojang.mathrecord88 linescommon2.0 KB

API Surface (12)

record GivensParameters(float sinHalf, float cosHalf)
GivensParameters fromUnnormalized(final float sinHalf, final float cosHalf)
GivensParameters fromPositiveAngle(final float angle)
GivensParameters inverse()
Quaternionf aroundX(final Quaternionf input)
Quaternionf aroundY(final Quaternionf input)
Quaternionf aroundZ(final Quaternionf input)
float cos()
float sin()
Matrix3f aroundX(final Matrix3f input)
Matrix3f aroundY(final Matrix3f input)
Matrix3f aroundZ(final Matrix3f input)

Full Source

GivensParameters.java88 lines · Minecraft 26.3 · verbatim
1
package com.mojang.math;
2
3
import org.joml.Math;
4
import org.joml.Matrix3f;
5
import org.joml.Quaternionf;
6
7
public record GivensParameters(float sinHalf, float cosHalf) {
8
	public static GivensParameters fromUnnormalized(final float sinHalf, final float cosHalf) {
9
		float w = Math.invsqrt(sinHalf * sinHalf + cosHalf * cosHalf);
10
		return new GivensParameters(w * sinHalf, w * cosHalf);
11
	}
12
13
	public static GivensParameters fromPositiveAngle(final float angle) {
14
		float sin = Math.sin(angle / 2.0F);
15
		float cos = Math.cosFromSin(sin, angle / 2.0F);
16
		return new GivensParameters(sin, cos);
17
	}
18
19
	public GivensParameters inverse() {
20
		return new GivensParameters(-this.sinHalf, this.cosHalf);
21
	}
22
23
	public Quaternionf aroundX(final Quaternionf input) {
24
		return input.set(this.sinHalf, 0.0F, 0.0F, this.cosHalf);
25
	}
26
27
	public Quaternionf aroundY(final Quaternionf input) {
28
		return input.set(0.0F, this.sinHalf, 0.0F, this.cosHalf);
29
	}
30
31
	public Quaternionf aroundZ(final Quaternionf input) {
32
		return input.set(0.0F, 0.0F, this.sinHalf, this.cosHalf);
33
	}
34
35
	public float cos() {
36
		return this.cosHalf * this.cosHalf - this.sinHalf * this.sinHalf;
37
	}
38
39
	public float sin() {
40
		return 2.0F * this.sinHalf * this.cosHalf;
41
	}
42
43
	public Matrix3f aroundX(final Matrix3f input) {
44
		input.m01 = 0.0F;
45
		input.m02 = 0.0F;
46
		input.m10 = 0.0F;
47
		input.m20 = 0.0F;
48
		float c = this.cos();
49
		float s = this.sin();
50
		input.m11 = c;
51
		input.m22 = c;
52
		input.m12 = s;
53
		input.m21 = -s;
54
		input.m00 = 1.0F;
55
		return input;
56
	}
57
58
	public Matrix3f aroundY(final Matrix3f input) {
59
		input.m01 = 0.0F;
60
		input.m10 = 0.0F;
61
		input.m12 = 0.0F;
62
		input.m21 = 0.0F;
63
		float c = this.cos();
64
		float s = this.sin();
65
		input.m00 = c;
66
		input.m22 = c;
67
		input.m02 = -s;
68
		input.m20 = s;
69
		input.m11 = 1.0F;
70
		return input;
71
	}
72
73
	public Matrix3f aroundZ(final Matrix3f input) {
74
		input.m02 = 0.0F;
75
		input.m12 = 0.0F;
76
		input.m20 = 0.0F;
77
		input.m21 = 0.0F;
78
		float c = this.cos();
79
		float s = this.sin();
80
		input.m00 = c;
81
		input.m11 = c;
82
		input.m01 = s;
83
		input.m10 = -s;
84
		input.m22 = 1.0F;
85
		return input;
86
	}
87
}
88

Decompiled Minecraft 26.3 source of GivensParameters (com/mojang/math/GivensParameters.java) with Mojang official mappings, stored verbatim on the site.