Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
cdb644ea
Commit
cdb644ea
authored
Nov 06, 2023
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix billboard rotation to always face player, and ignore camera pitch/yaw.
parent
bbba1c18
Pipeline
#11647
passed with stage
in 20 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
16 deletions
+14
-16
ClientInit.java
src/client/java/com/owlmaddie/ClientInit.java
+14
-16
No files found.
src/client/java/com/owlmaddie/ClientInit.java
View file @
cdb644ea
...
@@ -198,33 +198,31 @@ public class ClientInit implements ClientModInitializer {
...
@@ -198,33 +198,31 @@ public class ClientInit implements ClientModInitializer {
// Calculate the difference vector (from entity to camera)
// Calculate the difference vector (from entity to camera)
Vec3d
difference
=
cameraEntity
.
getPos
().
subtract
(
entity
.
getPos
());
Vec3d
difference
=
cameraEntity
.
getPos
().
subtract
(
entity
.
getPos
());
// Calculate the yaw angle
(just like before)
// Calculate the yaw angle
double
yaw
=
-(
Math
.
atan2
(
difference
.
z
,
difference
.
x
)
+
Math
.
PI
/
2
D
);
double
yaw
=
-(
Math
.
atan2
(
difference
.
z
,
difference
.
x
)
+
Math
.
PI
/
2
D
);
// Calculate the pitch difference (using y component)
// Convert yaw to Quaternion
double
pitch
=
Math
.
atan2
(
difference
.
y
,
Math
.
sqrt
(
difference
.
x
*
difference
.
x
+
difference
.
z
*
difference
.
z
));
// Clamp the pitch to the desired range (in this case, ±X degrees converted to radians)
pitch
=
MathHelper
.
clamp
(
pitch
,
-
Math
.
toRadians
(
20
),
Math
.
toRadians
(
20
));
// Convert yaw and pitch to Quaternionf
float
halfYaw
=
(
float
)
yaw
*
0.5f
;
float
halfYaw
=
(
float
)
yaw
*
0.5f
;
double
sinHalfYaw
=
MathHelper
.
sin
(
halfYaw
);
double
sinHalfYaw
=
MathHelper
.
sin
(
halfYaw
);
double
cosHalfYaw
=
MathHelper
.
cos
(
halfYaw
);
double
cosHalfYaw
=
MathHelper
.
cos
(
halfYaw
);
Quaternionf
yawRotation
=
new
Quaternionf
(
0
,
sinHalfYaw
,
0
,
cosHalfYaw
);
// Apply the yaw rotation to the matrix stack
matrices
.
multiply
(
yawRotation
);
// Obtain the horizontal distance to the entity
double
horizontalDistance
=
Math
.
sqrt
(
difference
.
x
*
difference
.
x
+
difference
.
z
*
difference
.
z
);
// Calculate the pitch angle based on the horizontal distance and the y difference
double
pitch
=
Math
.
atan2
(
difference
.
y
,
horizontalDistance
);
// Convert pitch to Quaternion
float
halfPitch
=
(
float
)
pitch
*
0.5f
;
float
halfPitch
=
(
float
)
pitch
*
0.5f
;
double
sinHalfPitch
=
MathHelper
.
sin
(
halfPitch
);
double
sinHalfPitch
=
MathHelper
.
sin
(
halfPitch
);
double
cosHalfPitch
=
MathHelper
.
cos
(
halfPitch
);
double
cosHalfPitch
=
MathHelper
.
cos
(
halfPitch
);
// Constructing the Quaternionf for yaw (around Y axis) and pitch (around X axis)
Quaternionf
yawRotation
=
new
Quaternionf
(
0
,
sinHalfYaw
,
0
,
cosHalfYaw
);
Quaternionf
pitchRotation
=
new
Quaternionf
(
sinHalfPitch
,
0
,
0
,
cosHalfPitch
);
Quaternionf
pitchRotation
=
new
Quaternionf
(
sinHalfPitch
,
0
,
0
,
cosHalfPitch
);
// Combine the rotations
// Apply the pitch rotation to the matrix stack
yawRotation
.
mul
(
pitchRotation
);
matrices
.
multiply
(
pitchRotation
);
// Now when you want to render, apply the combined rotation:
matrices
.
multiply
(
yawRotation
);
// Determine max line length
// Determine max line length
float
linesDisplayed
=
ending_line
-
starting_line
;
float
linesDisplayed
=
ending_line
-
starting_line
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment