22package main .tut08 ;
33
44import 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-
165import com .jogamp .opengl .GL3 ;
17- import com .jogamp .opengl .util .glsl .ShaderCode ;
18- import com .jogamp .opengl .util .glsl .ShaderProgram ;
196import glm .mat .Mat4x4 ;
207import glm .quat .Quat ;
8+ import glm .vec ._3 .Vec3 ;
219import glm .vec ._4 .Vec4 ;
2210import main .framework .Framework ;
2311import main .framework .component .Mesh ;
24- import glm .mat .Mat4x4 ;
25- import glm .vec ._3 .Vec3 ;
12+ import org .xml .sax .SAXException ;
2613import uno .glm .MatrixStack ;
14+ import uno .time .Timer ;
2715
16+ import javax .xml .parsers .ParserConfigurationException ;
2817import java .io .IOException ;
2918import java .net .URISyntaxException ;
3019import java .util .logging .Level ;
3120import 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 ;
3725import static glm .GlmKt .glm ;
3826import 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