33import com .google .common .collect .HashBiMap ;
44import net .minecraft .client .KeyMapping ;
55import net .minecraft .client .Minecraft ;
6+ import net .minecraft .util .Mth ;
67import net .minecraft .util .profiling .Profiler ;
78import org .joml .Matrix4f ;
9+ import org .joml .Matrix4fc ;
810import org .joml .Vector2f ;
911import org .joml .Vector3f ;
1012import org .lwjgl .PointerBuffer ;
2830import org .vivecraft .client_vr .provider .openxr .control .ControllerMapping ;
2931import org .vivecraft .client_vr .provider .openxr .control .XRInputAction ;
3032import org .vivecraft .client_vr .settings .VRSettings ;
33+ import org .vivecraft .common .utils .MathUtils ;
3134import oshi .util .tuples .Pair ;
3235
3336import java .io .FileNotFoundException ;
@@ -318,6 +321,22 @@ private void updatePose() {
318321 }
319322 }
320323
324+ if (this .controllerTracking [RIGHT_CONTROLLER ]) {
325+ Matrix4fc tip = this .controllerRotation [RIGHT_CONTROLLER ];
326+ Matrix4fc hand = this .handRotation [RIGHT_CONTROLLER ];
327+
328+ Vector3f tipVec = tip .transformDirection (MathUtils .BACK , new Vector3f ());
329+ Vector3f handVec = hand .transformDirection (MathUtils .BACK , new Vector3f ());
330+
331+ float dot = Math .abs (tipVec .dot (handVec ));
332+
333+ float angleRad = (float ) Math .acos (dot );
334+ float angleDeg = Mth .RAD_TO_DEG * angleRad ;
335+
336+ this .gunStyle = angleDeg > 10.0F ;
337+ this .gunAngle = angleDeg ;
338+ }
339+
321340 this .updateAim ();
322341 }
323342 }
@@ -881,20 +900,26 @@ private void initializeOpenXRSwapChain() {
881900 error = XR10 .xrEnumerateSwapchainFormats (this .session , intBuf , swapchainFormats );
882901 logError (error , "xrEnumerateSwapchainFormats" , "get formats" );
883902
884- long [] desiredSwapchainFormats = {
885- // SRGB formats
886- GL21 .GL_SRGB8_ALPHA8 ,
887- GL21 .GL_SRGB8 ,
888- // others
889- GL11 .GL_RGB10_A2 ,
890- GL30 .GL_RGBA16F ,
891- GL30 .GL_RGB16F ,
892-
893- // The two below should only be used as a fallback, as they are linear color formats without enough bits for color
894- // depth, thus leading to banding.
895- GL11 .GL_RGBA8 ,
896- GL31 .GL_RGBA8_SNORM ,
897- };
903+ long [] desiredSwapchainFormats ;
904+ if (this .device .getClass () == DeviceCompat .Desktop .class ) {
905+ desiredSwapchainFormats = new long [] {
906+ // SRGB formats
907+ GL21 .GL_SRGB8_ALPHA8 ,
908+ GL21 .GL_SRGB8 ,
909+ // others
910+ GL11 .GL_RGB10_A2 ,
911+ GL30 .GL_RGBA16F ,
912+ GL30 .GL_RGB16F ,
913+
914+ // The two below should only be used as a fallback, as they are linear color formats without enough bits for color
915+ // depth, thus leading to banding.
916+ GL11 .GL_RGBA8 ,
917+ GL31 .GL_RGBA8_SNORM
918+ };
919+ } else {
920+ // Mobile runtimes tend to over-correct SRGB for some reason
921+ desiredSwapchainFormats = new long [] {GL11 .GL_RGBA8 };
922+ }
898923
899924 // Choose format
900925 long chosenFormat = 0 ;
@@ -1181,17 +1206,22 @@ private void loadBindings() {
11811206 VRSettings .LOGGER .warn ("Input action '{}' not found" , "/actions/" + set .getKey () + "/in/" + action .action ());
11821207 continue ;
11831208 }
1184- long handle = this .mappedBindings .get (new ActionBind (inputAction .actionSet , source .path ()));
1185- ActionType buttonType = ControllerMapping .getMapping (headsetPath ).get (source .path ());
11861209
1210+ Long handle = this .mappedBindings .get (new ActionBind (inputAction .actionSet , source .path ()));
1211+ if (handle == null ) {
1212+ VRSettings .LOGGER .error ("Cannot find button for path {}, are you sure this is the correct path?" , source .path ());
1213+ continue ;
1214+ }
1215+
1216+ ActionType buttonType = ControllerMapping .getMapping (headsetPath ).get (source .path ());
11871217 inputAction .addHandle (
11881218 headsetPath ,
11891219 handle ,
11901220 source .path ().contains ("/left/" ) ? ControllerType .LEFT : ControllerType .RIGHT ,
11911221 buttonType
11921222 );
1193- inputAction .setType (action .type ());
11941223
1224+ inputAction .setType (action .type ());
11951225 if (inputAction .getHandle (headsetPath ).isEmpty () || handle == 0L ) {
11961226 VRSettings .LOGGER .error ("Handle for '{}'/'{}' is null" , "/actions/" + set .getKey () + "/in/" + action .action (), source .path ());
11971227 continue ;
@@ -1202,8 +1232,6 @@ private void loadBindings() {
12021232 new XrAction (handle , new XrActionSet (this .actionSetHandles .get (inputAction .actionSet ), this .instance )),
12031233 getPath (source .path ())
12041234 ));
1205-
1206- VRSettings .LOGGER .info ("Mapped action '{}' to button '{}'" , this .getInputActionByName ("/actions/" + set .getKey () + "/in/" + action .action ()).name , source .path ());
12071235 }
12081236 }
12091237
0 commit comments