Skip to content

Commit 547562e

Browse files
committed
world scene
1 parent bc8847a commit 547562e

File tree

16 files changed

+342
-3712
lines changed

16 files changed

+342
-3712
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ dependencies {
2222

2323
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
2424

25-
compile 'com.github.elect86:glm:406cea2811a788326610bd0776ebace6db6956a8'
26-
compile 'com.github.elect86:uno-sdk:aec9b89741bba36f2671c05f3df9d1925794eb86'
25+
compile 'com.github.elect86:glm:c64070b8452cf1fa4f23fd2d5a1f913b724abc43'
26+
compile 'com.github.elect86:uno-sdk:925235b75fa5f9d68868c50ce3c658c00e3dc361'
2727
compile 'one.util:streamex:0.6.5'
2828

2929
def jogl = '2.3.2'

src/main/java/main/tut08/Interpolation.java

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,26 @@
22
package main.tut08;
33

44
import com.jogamp.newt.event.KeyEvent;
5-
6-
import static com.jogamp.opengl.GL.GL_BACK;
7-
import static com.jogamp.opengl.GL.GL_CULL_FACE;
8-
import static com.jogamp.opengl.GL.GL_CW;
9-
import static com.jogamp.opengl.GL.GL_DEPTH_TEST;
10-
import static com.jogamp.opengl.GL.GL_LEQUAL;
11-
import static com.jogamp.opengl.GL2ES2.GL_FRAGMENT_SHADER;
12-
import static com.jogamp.opengl.GL2ES2.GL_VERTEX_SHADER;
13-
import static com.jogamp.opengl.GL2ES3.GL_COLOR;
14-
import static com.jogamp.opengl.GL2ES3.GL_DEPTH;
15-
165
import com.jogamp.opengl.GL3;
17-
import com.jogamp.opengl.util.glsl.ShaderCode;
18-
import com.jogamp.opengl.util.glsl.ShaderProgram;
196
import glm.mat.Mat4x4;
207
import glm.quat.Quat;
8+
import glm.vec._3.Vec3;
219
import glm.vec._4.Vec4;
2210
import main.framework.Framework;
2311
import main.framework.component.Mesh;
24-
import glm.mat.Mat4x4;
25-
import glm.vec._3.Vec3;
12+
import org.xml.sax.SAXException;
2613
import uno.glm.MatrixStack;
14+
import uno.time.Timer;
2715

16+
import javax.xml.parsers.ParserConfigurationException;
2817
import java.io.IOException;
2918
import java.net.URISyntaxException;
3019
import java.util.logging.Level;
3120
import java.util.logging.Logger;
32-
import javax.xml.parsers.ParserConfigurationException;
33-
34-
import org.xml.sax.SAXException;
35-
import uno.time.Timer;
3621

22+
import static com.jogamp.opengl.GL.*;
23+
import static com.jogamp.opengl.GL2ES3.GL_COLOR;
24+
import static com.jogamp.opengl.GL2ES3.GL_DEPTH;
3725
import static glm.GlmKt.glm;
3826
import static uno.glsl.UtilKt.programOf;
3927

@@ -62,6 +50,7 @@ private float calcFrustumScale(float fovDeg) {
6250
}
6351

6452
private Mat4x4 cameraToClipMatrix = new Mat4x4(0.0f);
53+
6554
private Orientation orient = new Orientation();
6655

6756
@Override
@@ -160,17 +149,14 @@ public void keyPressed(KeyEvent e) {
160149
break;
161150
}
162151

163-
for (int i = 0; i < orientKeys.length; i++) {
164-
if (e.getKeyCode() == orientKeys[i]) {
152+
for (int i = 0; i < orientKeys.length; i++)
153+
if (e.getKeyCode() == orientKeys[i])
165154
applyOrientation(i);
166-
}
167-
}
168155
}
169156

170157
private void applyOrientation(int index) {
171-
if (!orient.isAnimating()) {
158+
if (!orient.isAnimating())
172159
orient.animateToOrient(index);
173-
}
174160
}
175161

176162
private final short[] orientKeys = {
@@ -204,11 +190,10 @@ public boolean toggleSlerp() {
204190
}
205191

206192
public Quat getOrient() {
207-
if (isAnimating) {
193+
if (isAnimating)
208194
return anim.getOrient(orients[currentOrient], slerp);
209-
} else {
195+
else
210196
return orients[currentOrient];
211-
}
212197
}
213198

214199
public boolean isAnimating() {
@@ -226,9 +211,9 @@ public void updateTime() {
226211
}
227212

228213
public void animateToOrient(int destination) {
229-
if (currentOrient == destination) {
214+
if (currentOrient == destination)
230215
return;
231-
}
216+
232217
anim.startAnimation(destination, 1.0f);
233218
isAnimating = true;
234219
}
@@ -243,11 +228,10 @@ public boolean updateTime() {
243228
}
244229

245230
public Quat getOrient(Quat initial, boolean slerp) {
246-
if (slerp) {
231+
if (slerp)
247232
return slerp(initial, orients[finalOrient], currTimer.getAlpha());
248-
} else {
233+
else
249234
return lerp(initial, orients[finalOrient], currTimer.getAlpha());
250-
}
251235
}
252236

253237
public void startAnimation(int destination, float duration) {
@@ -265,49 +249,38 @@ private Quat slerp(Quat v0, Quat v1, float alpha) {
265249

266250
float dot = glm.dot(v0, v1);
267251
final float DOT_THRESHOLD = 0.9995f;
268-
if (dot > DOT_THRESHOLD) {
252+
if (dot > DOT_THRESHOLD)
269253
return lerp(v0, v1, alpha);
270-
}
271-
glm.clamp(dot, -1.0f, 1.0f);
272-
float theta0 = (float) Math.acos(dot);
254+
255+
dot = glm.clamp(dot, -1.0f, 1.0f);
256+
float theta0 = glm.acos(dot);
273257
float theta = theta0 * alpha;
274258

275259
Quat v2 = v1.minus(v0.times(dot));
276-
v2.normalize();
260+
v2.normalize_();
277261

278262
return v0.times(glm.cos(theta)).plus(v2.times(glm.sin(theta)));
279263
}
280264

265+
// TODO check lerp thinkness
281266
private Quat lerp(Quat v0, Quat v1, float alpha) {
282267

283-
Vec4 start = vectorize(v0);
284-
Vec4 end = vectorize(v1);
268+
Vec4 start = v0.vectorize();
269+
Vec4 end = v1.vectorize();
285270
Vec4 interp = glm.mix(start, end, alpha);
286271

287272
System.out.println("alpha: " + alpha + ", " + interp);
288273

289-
interp.normalize();
290-
return new Quat(interp.w, interp.x, interp.y, interp.z);
291-
}
292-
293-
private Vec4 vectorize(Quat theQuat) {
294-
295-
Vec4 ret = new Vec4();
296-
297-
ret.x = theQuat.x;
298-
ret.y = theQuat.y;
299-
ret.z = theQuat.z;
300-
ret.w = theQuat.w;
301-
302-
return ret;
274+
interp.normalize_();
275+
return new Quat(interp);
303276
}
304277

305278
private final Quat[] orients = {
306279
new Quat(0.7071f, 0.7071f, 0.0f, 0.0f),
307280
new Quat(0.5f, 0.5f, -0.5f, 0.5f),
308281
new Quat(-0.4895f, -0.7892f, -0.3700f, -0.02514f),
309282
new Quat(0.4895f, 0.7892f, 0.3700f, 0.02514f),
310-
//
283+
311284
new Quat(0.3840f, -0.1591f, -0.7991f, -0.4344f),
312285
new Quat(0.5537f, 0.5208f, 0.6483f, 0.0410f),
313286
new Quat(0.0f, 0.0f, 1.0f, 0.0f)};

0 commit comments

Comments
 (0)