2222
2323package io .github .axolotlclient .waypoints .waypoints ;
2424
25+ import java .lang .Math ;
2526import java .util .concurrent .atomic .AtomicReference ;
2627
2728import com .mojang .blaze3d .systems .RenderSystem ;
3738import net .minecraft .client .renderer .RenderType ;
3839import net .minecraft .world .phys .Vec3 ;
3940import org .jetbrains .annotations .Nullable ;
40- import org .joml .Matrix4f ;
41- import org .joml .Quaternionf ;
42- import org .joml .Vector3f ;
43- import org .joml .Vector4f ;
41+ import org .joml .*;
4442
4543public class WaypointRenderer {
4644
@@ -78,15 +76,16 @@ private void renderWaypoint(Waypoint waypoint, PoseStack stack, Vec3 camPos, Cam
7876 int width = textWidth + Waypoint .displayXOffset () * 2 ;
7977 int textHeight = minecraft .font .lineHeight ;
8078 int height = textHeight + Waypoint .displayYOffset () * 2 ;
81- var displayStart = projectToScreen (cam , fov , width , height , waypoint .x () - ( width / 2f * 0.04 ), waypoint . y () - ( height / 2f * 0.04 ), waypoint . z ( ));
79+ var displayStart = projectToScreen (cam , fov , width , height , waypoint .x (), waypoint . y (), waypoint . z (), new Vector2f (-( width / 2f * 0.04f ), ( height / 2f * 0.04f ) ));
8280 if (displayStart == null ) return ;
83- var displayEnd = projectToScreen (cam , fov , width , height , waypoint .x () + ( width / 2f * 0.04 ), waypoint . y () + ( height / 2f * 0.04 ), waypoint . z ( ));
81+ var displayEnd = projectToScreen (cam , fov , width , height , waypoint .x (), waypoint . y (), waypoint . z (), new Vector2f ( width / 2f * 0.04f , -( height / 2f * 0.04f ) ));
8482 if (displayEnd == null ) return ;
8583 float projWidth = Math .abs (displayEnd .x () - displayStart .x ());
8684 float projHeight = Math .abs (displayEnd .y () - displayStart .y ());
87- if (projWidth / width <= 1 && projHeight / height <= 1 ) {
85+ if (projWidth < width && projHeight < height ) {
8886 return ;
8987 }
88+
9089 stack .pushPose ();
9190 stack .translate (waypoint .x () - camPos .x (), waypoint .y () - camPos .y (), waypoint .z () - camPos .z ());
9291 stack .mulPose (cam .rotation ());
@@ -133,7 +132,7 @@ public void renderWaypoints(GuiGraphics graphics, float delta) {
133132 }
134133
135134 private void renderWaypoint (Waypoint waypoint , GuiGraphics graphics , float tick , Camera camera , AtomicReference <Runnable > positionDrawn ) {
136- var fov = ((GameRendererAccessor ) minecraft .gameRenderer ).invokeGetFov (camera , tick , true );
135+ var fov = ((GameRendererAccessor ) minecraft .gameRenderer ).invokeGetFov (camera , tick , false );
137136 var pose = graphics .pose ();
138137
139138 var textWidth = minecraft .font .width (waypoint .display ());
@@ -142,27 +141,44 @@ private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, float tick,
142141 int height = textHeight + Waypoint .displayYOffset () * 2 ;
143142 var camPos = camera .getPosition ();
144143
145- var displayStart = projectToScreen (camera , fov , width , height , waypoint .x () - (width / 2f * 0.04 ), waypoint .y () - (height / 2f * 0.04 ), waypoint .z ());
146- if (displayStart == null ) return ;
147- var displayEnd = projectToScreen (camera , fov , width , height , waypoint .x () + (width / 2f * 0.04 ), waypoint .y () + (height / 2f * 0.04 ), waypoint .z ());
148- if (displayEnd == null ) return ;
149- float projWidth = Math .abs (displayEnd .x () - displayStart .x ());
150- float projHeight = Math .abs (displayEnd .y () - displayStart .y ());
151- Result result = projectToScreen (camera , fov , width , height , waypoint .x (), waypoint .y (), waypoint .z ());
144+ var displayStart = projectToScreen (camera , fov , width , height , waypoint .x (), waypoint .y (), waypoint .z (), new Vector2f (-(width / 2f * 0.04f ), (height / 2f * 0.04f )));
145+ var displayEnd = projectToScreen (camera , fov , width , height , waypoint .x (), waypoint .y (), waypoint .z (), new Vector2f ((width / 2f * 0.04f ), -(height / 2f * 0.04f )));
146+ Result result = projectToScreen (camera , fov , width , height , waypoint .x (), waypoint .y (), waypoint .z (), null );
152147 if (result == null ) return ;
148+ float projWidth ;
149+ float projHeight ;
150+ if (displayStart != null && displayEnd != null ) {
151+ projWidth = Math .abs (displayEnd .x () - displayStart .x ());
152+ projHeight = Math .abs (displayEnd .y () - displayStart .y ());
153+ } else {
154+ projWidth = 0 ;
155+ projHeight = 0 ;
156+ }
153157
154158 pose .translate (result .x (), result .y (), 0 );
155-
156- if (!AxolotlClientWaypoints .renderOutOfViewWaypointsOnScreenEdge .get () && (result .x () < -width / 2f || result .x () > graphics .guiWidth () + width / 2f || result .y () < -height / 2f || result .y () > graphics .guiHeight () + height / 2f )) {
157- return ;
158- }
159- if (projWidth / width > 1 || projHeight / height > 1 ) {
159+ boolean outOfView = result .x () < -width / 2f || result .x () > graphics .guiWidth () + width / 2f || result .y () < -height / 2f || result .y () > graphics .guiHeight () + height / 2f ;
160+ if (!AxolotlClientWaypoints .renderOutOfViewWaypointsOnScreenEdge .get () && outOfView ) {
160161 return ;
161162 }
162163
163- if (positionDrawn .get () == null && Math .abs (result .x () - graphics .guiWidth () / 2f ) < width / 2f && Math .abs (result .y () - graphics .guiHeight () / 2f ) < height / 2f ) {
164+ boolean _3dOnScreen ;
165+ if (displayEnd != null && displayStart != null ) {
166+ float minX = displayStart .x ();
167+ float minY = displayStart .y ();
168+ float maxX = displayEnd .x ();
169+ float maxY = displayEnd .y ();
170+ int guiWidth = graphics .guiWidth ();
171+ int guiHeight = graphics .guiHeight ();
172+ _3dOnScreen = minX > 0 && minY > 0 && minX < guiWidth && minY < guiHeight ||
173+ minX > 0 && maxY > 0 && minX < guiWidth && maxY < guiHeight ||
174+ maxX > 0 && maxY > 0 && maxX < guiWidth && maxY < guiHeight ||
175+ maxX > 0 && minY > 0 && maxX < guiWidth && minY < guiHeight ;
176+ } else {
177+ _3dOnScreen = false ;
178+ }
179+ if (positionDrawn .get () == null && Math .abs (result .x () - graphics .guiWidth () / 2f ) < (_3dOnScreen ? Math .max (projWidth , width ) : width ) / 2f && Math .abs (result .y () - graphics .guiHeight () / 2f ) < (_3dOnScreen ? Math .max (height , projHeight ) : height ) / 2f ) {
164180 pose .pushPose ();
165- pose .translate (0 , height / 2f + 2 , 0 );
181+ pose .translate (0 , Math . max ( height , projHeight + 4 ) / 2f + 4 , 0 );
166182 var pos = pose .last ().pose ().transformPosition (new Vector3f ());
167183 positionDrawn .set (() -> {
168184 var line1 = waypoint .name ();
@@ -182,20 +198,32 @@ private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, float tick,
182198 pose .popPose ();
183199 }
184200
201+ if ((projWidth >= width || projHeight >= height ) && _3dOnScreen ) {
202+ return ;
203+ }
204+
185205 graphics .fill (-width / 2 , -height / 2 , width / 2 , height / 2 , waypoint .color ().toInt ());
186206 graphics .drawString (minecraft .font , waypoint .display (), -textWidth / 2 , -textHeight / 2 , -1 , false );
187207 }
188208
189- private @ Nullable Result projectToScreen (Camera camera , double fov , int width , int height , double x , double y , double z ) {
209+ private @ Nullable Result projectToScreen (Camera camera , double fov , int width , int height , double x , double y , double z , Vector2f orthoOffset ) {
190210 viewProj .set (x , y , z , 1 );
211+ if (orthoOffset != null ) {
212+ var vec = new Matrix4f ();
213+ var camRot = camera .rotation ().rotateY ((float ) -(Math .PI ), new Quaternionf ()).invert ();
214+ vec .rotate (camRot .invert (new Quaternionf ()));
215+ vec .translate (orthoOffset .x (), orthoOffset .y (), 0 );
216+ vec .rotate (camRot );
217+ vec .transform (viewProj );
218+ }
191219 view .rotation (camera .rotation ().rotateY ((float ) -(Math .PI ), new Quaternionf ()).invert ()).translate (camera .getPosition ().toVector3f ().negate ());
192220
193221 Matrix4f projection = minecraft .gameRenderer .getProjectionMatrix (fov );
194222 projection .mul (view );
195223 viewProj .mul (projection );
196224
197225
198- if (AxolotlClientWaypoints .renderOutOfViewWaypointsOnScreenEdge .get ()) {
226+ if (orthoOffset == null && AxolotlClientWaypoints .renderOutOfViewWaypointsOnScreenEdge .get ()) {
199227 viewProj .w = Math .max (Math .abs (viewProj .x ()), Math .max (Math .abs (viewProj .y ()), viewProj .w ()));
200228 }
201229
0 commit comments