Skip to content

Commit a97a54d

Browse files
committed
Format changes.
1 parent 5c54a63 commit a97a54d

File tree

1 file changed

+113
-97
lines changed

1 file changed

+113
-97
lines changed

src/main/java/workspace/FirstPersonView.java

Lines changed: 113 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,132 +10,148 @@
1010

1111
public class FirstPersonView {
1212

13-
private boolean enabled;
14-
private boolean left;
15-
private boolean right;
16-
private boolean forward;
17-
private boolean back;
18-
private boolean up;
19-
private boolean down;
20-
private float pitch = Mathf.PI;
21-
private float yaw = 0;
22-
private Vector3f eye = new Vector3f(-1000, 0, 1000);
23-
private float speed = 10;
24-
private PApplet context;
25-
26-
public FirstPersonView(PApplet context) {
27-
this.context = context;
28-
context.registerMethod("pre", this);
29-
context.registerMethod("keyEvent", this);
30-
}
31-
32-
public void pre() {
33-
if (!enabled)
34-
return;
35-
yaw = Mathf.map(context.mouseX, 0, context.width, Mathf.PI, -Mathf.PI);
36-
pitch = Mathf.map(context.mouseY, 0, context.height, -Mathf.PI, Mathf.PI);
13+
private boolean enabled;
14+
15+
private boolean left;
16+
17+
private boolean right;
18+
19+
private boolean forward;
20+
21+
private boolean back;
22+
23+
private boolean up;
24+
25+
private boolean down;
26+
27+
private float pitch = Mathf.PI;
28+
29+
private float yaw = 0;
30+
31+
private Vector3f eye = new Vector3f(-1000, 0, 1000);
32+
33+
private float speed = 10;
34+
35+
private PApplet context;
36+
37+
public FirstPersonView(PApplet context) {
38+
this.context = context;
39+
context.registerMethod("pre", this);
40+
context.registerMethod("keyEvent", this);
41+
}
42+
43+
public void pre() {
44+
if (!enabled)
45+
return;
46+
yaw = Mathf.map(context.mouseX, 0, context.width, Mathf.PI, -Mathf.PI);
47+
pitch = Mathf
48+
.map(context.mouseY, 0, context.height, -Mathf.PI, Mathf.PI);
3749

3850
// if (pitch > 89)
3951
// pitch = 89;
4052
// if (pitch < -89)
4153
// pitch = -89;
4254

43-
Vector3f front = new Vector3f();
44-
float x = Mathf.cos(Mathf.toRadians(yaw)) * Mathf.cos(Mathf.toRadians(pitch));
45-
float y = Mathf.sin(Mathf.toRadians(pitch));
46-
float z = Mathf.cos(Mathf.toRadians(yaw)) * Mathf.cos(Mathf.toRadians(pitch));
47-
front.set(x, y, z);
55+
Vector3f front = new Vector3f();
56+
float x = Mathf.cos(Mathf.toRadians(yaw))
57+
* Mathf.cos(Mathf.toRadians(pitch));
58+
float y = Mathf.sin(Mathf.toRadians(pitch));
59+
float z = Mathf.cos(Mathf.toRadians(yaw))
60+
* Mathf.cos(Mathf.toRadians(pitch));
61+
front.set(x, y, z);
4862

49-
Vector3f velocity = new Vector3f();
63+
Vector3f velocity = new Vector3f();
5064

51-
if (left) {
52-
velocity.addLocal(-1, 0, 0);
53-
}
65+
if (left) {
66+
velocity.addLocal(-1, 0, 0);
67+
}
5468

55-
if (right) {
56-
velocity.addLocal(1, 0, 0);
57-
}
69+
if (right) {
70+
velocity.addLocal(1, 0, 0);
71+
}
5872

59-
if (back) {
60-
velocity.addLocal(0, 0, 1);
61-
}
73+
if (back) {
74+
velocity.addLocal(0, 0, 1);
75+
}
6276

63-
if (forward) {
64-
velocity.addLocal(0, 0, -1);
65-
}
77+
if (forward) {
78+
velocity.addLocal(0, 0, -1);
79+
}
6680

67-
velocity.multLocal(getRotationMatrix(yaw));
81+
velocity.multLocal(getRotationMatrix(yaw));
6882

69-
eye.addLocal(velocity.mult(speed));
70-
eye.setY(-300);
71-
}
83+
eye.addLocal(velocity.mult(speed));
84+
eye.setY(-300);
85+
}
7286

73-
public void apply() {
74-
Matrix4f m = Matrix4f.fpsViewRH(eye, pitch, yaw).transpose();
75-
PMatrix matrix = context.getMatrix();
76-
matrix.set(m.getValues());
77-
context.setMatrix(matrix);
78-
}
87+
public void apply() {
88+
Matrix4f m = Matrix4f.fpsViewRH(eye, pitch, yaw).transpose();
89+
PMatrix matrix = context.getMatrix();
90+
matrix.set(m.getValues());
91+
context.setMatrix(matrix);
92+
}
7993

80-
public void keyEvent(KeyEvent key) {
81-
if (key.getAction() == KeyEvent.PRESS)
82-
onKeyPressed(key.getKey());
83-
if (key.getAction() == KeyEvent.RELEASE)
84-
onKeyReleased(key.getKey());
85-
}
94+
public void keyEvent(KeyEvent key) {
95+
if (key.getAction() == KeyEvent.PRESS)
96+
onKeyPressed(key.getKey());
97+
if (key.getAction() == KeyEvent.RELEASE)
98+
onKeyReleased(key.getKey());
99+
}
86100

87-
public void onKeyPressed(char key) {
88-
if (key == 'w' || key == 'W')
89-
forward = true;
101+
public void onKeyPressed(char key) {
102+
if (key == 'w' || key == 'W')
103+
forward = true;
90104

91-
if (key == 's' || key == 'S')
92-
back = true;
105+
if (key == 's' || key == 'S')
106+
back = true;
93107

94-
if (key == 'a' || key == 'A')
95-
left = true;
108+
if (key == 'a' || key == 'A')
109+
left = true;
96110

97-
if (key == 'd' || key == 'D')
98-
right = true;
111+
if (key == 'd' || key == 'D')
112+
right = true;
99113

100-
if (key == ' ')
101-
up = true;
114+
if (key == ' ')
115+
up = true;
102116

103-
if (key == 'c' || key == 'C')
104-
down = true;
105-
}
117+
if (key == 'c' || key == 'C')
118+
down = true;
119+
}
106120

107-
public void onKeyReleased(char key) {
108-
if (key == 'w' || key == 'W')
109-
forward = false;
121+
public void onKeyReleased(char key) {
122+
if (key == 'w' || key == 'W')
123+
forward = false;
110124

111-
if (key == 's' || key == 'S')
112-
back = false;
125+
if (key == 's' || key == 'S')
126+
back = false;
113127

114-
if (key == 'a' || key == 'A')
115-
left = false;
128+
if (key == 'a' || key == 'A')
129+
left = false;
116130

117-
if (key == 'd' || key == 'D')
118-
right = false;
131+
if (key == 'd' || key == 'D')
132+
right = false;
119133

120-
if (key == ' ')
121-
up = false;
134+
if (key == ' ')
135+
up = false;
122136

123-
if (key == 'c' || key == 'C')
124-
down = false;
125-
}
137+
if (key == 'c' || key == 'C')
138+
down = false;
139+
}
126140

127-
public Matrix3f getRotationMatrix(float angle) {
128-
Matrix3f m = new Matrix3f(Mathf.cos(angle), 0, Mathf.sin(angle), 0, 1, 0, -Mathf.sin(angle), 0,
129-
Mathf.cos(angle));
130-
return m;
131-
}
141+
public Matrix3f getRotationMatrix(float angle) {
142+
Matrix3f m = new Matrix3f(
143+
Mathf.cos(angle), 0, Mathf.sin(angle), 0, 1, 0,
144+
-Mathf.sin(angle), 0, Mathf.cos(angle)
145+
);
146+
return m;
147+
}
132148

133-
public boolean isEnabled() {
134-
return enabled;
135-
}
149+
public boolean isEnabled() {
150+
return enabled;
151+
}
136152

137-
public void setEnabled(boolean enabled) {
138-
this.enabled = enabled;
139-
}
153+
public void setEnabled(boolean enabled) {
154+
this.enabled = enabled;
155+
}
140156

141157
}

0 commit comments

Comments
 (0)