Skip to content

Commit 03407aa

Browse files
authored
East/West Camera rotation, relative to current position (#25)
* New Feature: Relative Camera rotation * Removed debug print statements. Reverted auto changes to the import statements * Per request, removed README additions and reset the version number
1 parent e9cb315 commit 03407aa

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/main/java/com/compassCameraControl/CompassCameraControlConfig.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,33 @@ default Keybind lookEastKey() {
135135
default Keybind lookWestKey() {
136136
return new Keybind(KeyEvent.VK_UNDEFINED, 0);
137137
}
138+
139+
140+
141+
@ConfigItem(
142+
keyName = "rotateWestKey",
143+
name = "Rotate West Key",
144+
description = "Rotate camera West, based on user configuration (Default 90°)",
145+
position = 12,
146+
section = cardinalKeybindingSnap
147+
)
148+
default Keybind rotateWestKey() { return new Keybind(KeyEvent.VK_UNDEFINED, 0);}
149+
150+
@ConfigItem(
151+
keyName = "rotateEastKey",
152+
name = "Rotate East Key",
153+
description = "Rotate camera East, based on user configuration (Default 90°)",
154+
position = 13,
155+
section = cardinalKeybindingSnap
156+
)
157+
default Keybind rotateEastKey() { return new Keybind(KeyEvent.VK_UNDEFINED, 0);}
158+
159+
@ConfigItem(
160+
keyName = "rotateDegree",
161+
name = "Rotation Degree",
162+
description = "How many degrees to rotate",
163+
position = 14,
164+
section = cardinalKeybindingSnap
165+
)
166+
default int rotateDegree(){ return 90; }
138167
}

src/main/java/com/compassCameraControl/CompassCameraControlPlugin.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,36 @@ private void facingYaw()
217217
client.setCameraYawTarget(targetYaw);
218218
}
219219

220+
private int degreesToYaw(int degrees) {
221+
return (int) Math.round(degrees * 2048.0 / 360.0);
222+
}
223+
224+
private void rotateWestYaw()
225+
{
226+
int currentYaw = client.getCameraYaw();
227+
int userInputDegree = config.rotateDegree();
228+
int shift = degreesToYaw(userInputDegree);
229+
230+
int targetYaw = currentYaw + shift;
231+
// Wraps yaw into camera range [0,2048)
232+
targetYaw &= 2047;
233+
234+
client.setCameraYawTarget(targetYaw);
235+
}
236+
237+
private void rotateEastYaw()
238+
{
239+
int currentYaw = client.getCameraYaw();
240+
int userInputDegree = config.rotateDegree();
241+
int shift = degreesToYaw(userInputDegree);
242+
243+
int targetYaw = currentYaw - shift;
244+
// Wraps yaw into camera range [0,2048)
245+
targetYaw &= 2047;
246+
247+
client.setCameraYawTarget(targetYaw);
248+
}
249+
220250
private final KeyListener keyListener = new KeyListener() {
221251
@Override
222252
public void keyTyped(KeyEvent event) { }
@@ -241,6 +271,10 @@ public void keyPressed(KeyEvent event) {
241271
client.setCameraYawTarget(EAST_YAW);}
242272
else if (config.lookWestKey().matches(event)) {
243273
client.setCameraYawTarget(WEST_YAW);
274+
} else if (config.rotateWestKey().matches(event)) {
275+
rotateWestYaw();
276+
} else if (config.rotateEastKey().matches(event)) {
277+
rotateEastYaw();
244278
} else {
245279
handledEvent = false;
246280
}

0 commit comments

Comments
 (0)