Skip to content

Commit f18ec27

Browse files
author
micheal65536
committed
automatically detect which way the player is sitting in the boat and swap paddle hands accordingly
1 parent 2329f12 commit f18ec27

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

  • common/src/main/java/org/vivecraft/client_vr/gameplay/trackers

common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class RowTracker extends Tracker {
1818
private final Vec3[] lastUWPs = new Vec3[2];
1919
public Vec3[] paddleAngles = new Vec3[]{null, null};
2020
public boolean[] paddleInWater = new boolean[]{false, false};
21+
private int[] hands = new int[2];
2122

2223
public RowTracker(Minecraft mc, ClientDataHolderVR dh) {
2324
super(mc, dh);
@@ -64,12 +65,22 @@ public void doProcess(LocalPlayer player) {
6465
Mth.DEG_TO_RAD * boat.getXRot(),
6566
0.0F).normalize();
6667

68+
Vector3f hand0 = boatRot.transformInverse(MathUtils.subtractToVector3f(this.getAbsArmPos(0), boat.position()));
69+
Vector3f hand1 = boatRot.transformInverse(MathUtils.subtractToVector3f(this.getAbsArmPos(1), boat.position()));
70+
if (hand0.x > hand1.x) {
71+
hands[0] = 0;
72+
hands[1] = 1;
73+
} else {
74+
hands[0] = 1;
75+
hands[1] = 0;
76+
}
77+
6778
for (int paddle = 0; paddle <= 1; paddle++) {
68-
Vec3 arm2Pad = this.getArmToPaddleVector(paddle, boat);
79+
Vec3 arm2Pad = this.getArmToPaddleVector(paddle, hands[paddle], boat);
6980
this.paddleAngles[paddle] = MathUtils.toMcVec3(boatRot.transformInverse(new Vector3f((float) arm2Pad.x, (float) arm2Pad.y, (float) arm2Pad.z)));
7081

7182
boolean inWater;
72-
if (this.isPaddleUnderWater(paddle, boat)) {
83+
if (this.isPaddleUnderWater(paddle, hands[paddle], boat)) {
7384
inWater = true;
7485

7586
Vec3 attach = this.getAttachmentPoint(paddle, boat);
@@ -101,27 +112,27 @@ public void doProcess(LocalPlayer player) {
101112

102113
if (inWater) {
103114
if (!this.paddleInWater[paddle]) {
104-
this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, 0.8F);
115+
this.dh.vr.triggerHapticPulse(ControllerType.values()[hands[paddle]], 0.05F, 100.0F, 0.8F);
105116
} else {
106117
float strength = (float) (Math.abs(this.forces[paddle]) / 0.1D);
107118
if (strength > 0.05F) {
108119
strength = strength * 0.7F + 0.3F;
109-
this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, strength);
120+
this.dh.vr.triggerHapticPulse(ControllerType.values()[hands[paddle]], 0.05F, 100.0F, strength);
110121
}
111122
}
112123
} else {
113124
if (this.paddleInWater[paddle]) {
114-
this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, 0.2F);
125+
this.dh.vr.triggerHapticPulse(ControllerType.values()[hands[paddle]], 0.05F, 100.0F, 0.2F);
115126
}
116127
}
117128

118129
this.paddleInWater[paddle] = inWater;
119130
}
120131
}
121132

122-
private Vec3 getArmToPaddleVector(int paddle, Boat boat) {
133+
private Vec3 getArmToPaddleVector(int paddle, int hand, Boat boat) {
123134
Vec3 attachAbs = this.getAttachmentPoint(paddle, boat);
124-
Vec3 armAbs = this.getAbsArmPos(paddle == 0 ? 1 : 0);
135+
Vec3 armAbs = this.getAbsArmPos(hand);
125136
return attachAbs.subtract(armAbs);
126137
}
127138

@@ -141,9 +152,9 @@ private Vec3 getAbsArmPos(int side) {
141152
return this.dh.vrPlayer.roomOrigin.add(arm.x, arm.y, arm.z);
142153
}
143154

144-
private boolean isPaddleUnderWater(int paddle, Boat boat) {
155+
private boolean isPaddleUnderWater(int paddle, int hand, Boat boat) {
145156
Vec3 attachAbs = this.getAttachmentPoint(paddle, boat);
146-
Vec3 armToPaddle = this.getArmToPaddleVector(paddle, boat).normalize();
157+
Vec3 armToPaddle = this.getArmToPaddleVector(paddle, hand, boat).normalize();
147158
Vec3 blockPos = attachAbs.add(armToPaddle);
148159
return blockPos.subtract(boat.position()).y < 0.2F;
149160
}

0 commit comments

Comments
 (0)