forked from nekonaute/WorldOfCells
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLandscape.java
710 lines (564 loc) · 24.1 KB
/
Landscape.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// ### WORLD OF CELLS ###
// created by nicolas.bredeche(at)upmc.fr
// date of creation: 2013-1-12
package graphics;
import applications.simpleworld.Ville;
import applications.simpleworld.WorldOfTrees;
import util.Case;
import util.Couleur;
import worlds.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.ArrayList;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.fixedfunc.*;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.gl2.GLUT;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import objects.CommonObject;
import objects.Monolith;
import landscapegenerator.LoadFromFileLandscape;
import landscapegenerator.PerlinNoiseLandscapeGenerator;
import static util.Couleur.heureToCouleur;
import static util.Couleur.world;
/*
* TODO
* - clean code
* - add objects + CA_objects
* - add agents
* - add my-agent + move + modify heights
* - water flowing ; snow (same, with evaporation)
*
* technical issues:
* - antialias
* - go fast -- cf. "GO FAST" COMMENTS TO CHECK DOUBLE BUFFERING TRICK
*
*
*/
/**
* Self-contained code
* displaying a landscape generated with Perlin noise
*/
public class Landscape implements GLEventListener, KeyListener, MouseListener{
private WorldOfTrees _myWorld;
private static GLCapabilities caps; // GO FAST ???
static boolean MY_LIGHT_RENDERING = true; // true: nicer but slower
final static boolean SMOOTH_AT_BORDER = false; // nicer (but wrong) rendering at border (smooth altitudes)
//final static double landscapeAltitudeRatio = 0.6; // 0.5: half mountain, half water ; 0.3: fewer water
static boolean VIEW_FROM_ABOVE = false; // also deactivate altitudes
static boolean DISPLAY_OBJECTS = true; // useful to deactivate if view_from_above
final static boolean DISPLAY_FPS = true; // on-screen display
/*
* benchmarking
* Airbook (w/wo visible display) :
* true: frame per second : frames per second : 59 ; polygons per second: 966656 --- frames per second : 82 ; polygons per second: 1343488
* false: frames per second : 61 ; polygons per second: 999424 --- frames per second : 254 ; polygons per second: 4161536 (!!!)
*
*
* Bonnes pratiques:
* - gl.Begin() ... gl.glEnd(); : faire un minimum d'appel, idealement un par iteration. (gain de 50% a 100% ici)
* - gl.glCullFace(GL.GL_FRONT); ... gl.glEnable(GL.GL_CULL_FACE); : si la scene le permet, reduit le nb de polyg a afficher.
* - TRIANGLE SPLIT permet de reduire le nombre d'appels a OpenGL (gl.begin et end)
* - each call to gl.glColor3f costs a lot (speed is down by two if no call!)
*/
static Animator animator;
// https://sites.google.com/site/justinscsstuff/jogl-tutorial-3
// if you use a regular Animator object instead of the FPSAnimator, your program will render as fast as possible. You can, however, limit the framerate of a regular Animator by asking the graphics driver to synchronize with the refresh rate of the display (v-sync). Because the target framerate is often the same as the refresh rate, which is often 60-75 or so, this method is a great choice as it lets the driver do the work of limiting frame changes.
// However, some Intel GPUs may ignore this setting. In the init method, active v-sync as follows:
// add : drawable.getGL().setSwapInterval(1); in the init method
// then: in the main method, replace the FPSAnimator with a regular Animator.
private float rotateX = 0.0f;
private float rotateY = 0.0f;
private float rotationVelocity = 0.0f; // 0.2f
int it = 0;
int movingIt = 0;
int dxView;
int dyView;
double[][] landscape;
int lastFpsValue = 0;
public static int lastItStamp = 0;
public static long lastTimeStamp = 0;
// visualization parameters
float heightFactor; //64.0f; // was: 32.0f;
double heightBooster; // applied to landscape values. increase heights.
// -- NOTE that this could also be achieved using heighFactor but is decomposed to enable further pre-calc of height values
// heightFactor deals with visualization
// heigBooster will impact landscape array content
float offset;
float stepX;
float stepY;
float lenX;
float lenY;
float zoom;
float smoothFactor[];
int smoothingDistanceThreshold;
int movingX = 0;
int movingY = 0;
/**
*
*/
public Landscape (WorldOfTrees __myWorld, int __dx, int __dy, double scaling, double landscapeAltitudeRatio)
{
_myWorld = __myWorld;
int nombreDeVilles = 60;
landscape = PerlinNoiseLandscapeGenerator.generatePerlinNoiseLandscape(__dx,__dy,scaling,landscapeAltitudeRatio,10); // 11
//landscape = PolynomialLandscapeGenerator.generatePolynomialLandscape(__dx,__dy,scaling,landscapeAltitudeRatio,nombreDeVilles); // 11
initLandscape();
// placer villes
ArrayList<Case> surterrain = new ArrayList<>();
// recuperer liste de cases au dessus de l'eau
for (int i = 2; i < __dx-3; i++) {
for (int j = 2; j < __dy-3; j++) {
if (landscape[i][j] >= 0.0) {
surterrain.add(new Case(i, j,true));
}
}
}
for (int i = 0; i < nombreDeVilles; i++) {
int index = (int)(Math.random() * surterrain.size());
float color[] = new float[3];
color[0] = 1.f; color[1] = 0.2f; color[2] = 1.0f;
_myWorld.cellsColorValues.setCellState(surterrain.get(index).x, surterrain.get(index).y, color);
_myWorld.setCellValue(surterrain.get(index).x, surterrain.get(index).y, (i+1)*100+10);
_myWorld.uniqueDynamicObjects.add(new Ville(i+1,surterrain.get(index).x, surterrain.get(index).y, _myWorld));
}
}
/**
*
*/
public Landscape (WorldOfTrees __myWorld, String __filename, double scaling, double landscapeAltitudeRatio)
{
_myWorld = __myWorld;
landscape = LoadFromFileLandscape.load(__filename,scaling,landscapeAltitudeRatio);
initLandscape();
}
/**
*
*/
private void initLandscape()
{
dxView = landscape.length;
dyView = landscape[0].length;
System.out.println("Landscape contains " + dxView*dyView + " tiles. (" + dxView + "x" + dyView +")");
_myWorld.init(dxView,dyView,landscape);
heightFactor = 16.0f; //64.0f; // was: 32.0f;
heightBooster = 3.0; // default: 2.0 // 6.0 makes nice high mountains.
offset = -200.0f; // was: -40.
stepX = (-offset*2.0f) / dxView;
stepY = (-offset*2.0f) / dxView;
lenX = stepX / 2f;
lenY = stepY / 2f;
zoom = 1.f;
rotateY = -70.f;
smoothFactor = new float[4];
for ( int i = 0 ; i < 4 ; i++ )
smoothFactor[i] = 1.0f;
smoothingDistanceThreshold = 30; //30;
}
/**
*
*/
public static Landscape run(Landscape __landscape)
{
caps = new GLCapabilities(GLProfile.getMaximum(true)); //!n
System.out.println(GLProfile.glAvailabilityToString());
//20210202-caps.setDoubleBuffered(true); //!n
final GLCanvas canvas = new GLCanvas(caps); // original
final Frame frame = new Frame("World Of Cells");
animator = new Animator(canvas);
//Landscape myLandscape = new Landscape(dx,dy,myWorld);
canvas.addGLEventListener(__landscape);
canvas.addMouseListener(__landscape);// register mouse callback functions
canvas.addKeyListener(__landscape);// register keyboard callback functions
frame.add(canvas);
frame.setSize(800, 800);
//frame.setSize(1280, 960);
frame.setResizable(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
animator.stop();
frame.dispose();
System.exit(0);
}
});
frame.setVisible(true);
//animator.setRunAsFastAsPossible(true); // GO FAST! --- DOES It WORK?
animator.start();
canvas.requestFocus();
return __landscape;
}
/**
* OpenGL Init method
*/
//@Override
public void init(GLAutoDrawable glDrawable) {
GL2 gl = glDrawable.getGL().getGL2();
// double buffer
gl.glEnable(GL2.GL_DOUBLEBUFFER);
glDrawable.setAutoSwapBufferMode(true);
gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
// Culling - display only triangles facing the screen
//gl.glCullFace(GL.GL_FRONT);
//gl.glEnable(GL.GL_CULL_FACE);
// trucs d'alex
gl.glEnable(GL.GL_DITHER);
}
/**
*
*/
//@Override
public void display(GLAutoDrawable gLDrawable) {
DecimalFormat df = new DecimalFormat("#.00");
// ** compute FPS
if ( System.currentTimeMillis() - lastTimeStamp >= 1000 )
{
int fps = ( it - lastItStamp ) / 1;
if ( Math.random() < 0.10 ) // display in console every ~10 updates
{
System.out.print("frames per second : "+fps+" ; ");
System.out.println();
}
lastItStamp = it;
lastTimeStamp = System.currentTimeMillis();
lastFpsValue = fps;
}
// ** clean screen
final GL2 gl = gLDrawable.getGL().getGL2();
double heure = _myWorld.getHeure();
// color le ciel
Couleur ciel = Couleur.heureToCouleur(heure);
gl.glClearColor(ciel.r, ciel.g, ciel.b, 1.f);
//gl.glClearColor(0.2f, 0.6f, 0.8f, 1.f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
// ** display FPS on screen
if ( DISPLAY_FPS )
{
gl.glPushMatrix();
gl.glColor3f((float)Math.random(),(float)Math.random(),(float)Math.random()); // do this before calling glWindowsPos2d
gl.glWindowPos2d(0, 728);
GLUT glut = new GLUT();
gl.glTranslatef(0, 0, 0);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "fps: " + lastFpsValue + " heure: " + new DecimalFormat("##.##").format(_myWorld.getHeure()));
gl.glPopMatrix();
}
// ** render all
// *** ADD LIGHT
if ( MY_LIGHT_RENDERING )
{
// Prepare light parameters.
float SHINE_ALL_DIRECTIONS = 1;
//float[] lightPos = {120.f, 120.f, -200.f, SHINE_ALL_DIRECTIONS};
//float[] lightPos = {40.f, 0.f, -300.f, SHINE_ALL_DIRECTIONS};
float[] lightPos = {0.f, 40.f, -100.f, SHINE_ALL_DIRECTIONS};
//float[] lightColorAmbient = {0.2f, 0.2f, 0.2f, 1f};
float intensite = ((ciel.r + ciel.g + ciel.b) / 3.f) + 0.4f;
//float intensite = 0.45f;
//if (VIEW_FROM_ABOVE)
// intensite *= 0.6;
float[] lightColorAmbient = {intensite, intensite, intensite, 1f};
float[] lightColorSpecular = {intensite*0.6f, intensite*0.6f, intensite*0.6f, 1f};
// Set light parameters.
gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_POSITION, lightPos, 0);
gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_AMBIENT, lightColorAmbient, 0);
gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_SPECULAR, lightColorSpecular, 0);
// Enable lighting in GL.
gl.glEnable(GL2.GL_LIGHT1);
gl.glEnable(GL2.GL_LIGHTING);
}
// ***
////gl.glTranslatef(0.0f, 0.0f, -100.0f); // 0,0,-5
// rotate on the three axis
////gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
////gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
//gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
// gl.glPushMatrix(); gl.glPopMatrix();
/* DEBUG: as seen from above *
gl.glTranslatef(0.0f, 0.0f, -500.0f); // 0,0,-5
gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
// DEBUG
/**/
/*
// DEBUG
gl.glTranslatef(0.0f, 0.0f, -500.0f); // 0,0,-5
//gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
//gl.glRotatef(-90.f, 1.0f, 0.0f, 0.0f);
gl.glRotatef(-90.f, 0.0f, 0.0f, 1.0f);
// DEBUG
/**/
if ( VIEW_FROM_ABOVE == true )
{
// as seen from above, no rotation (debug mode)
gl.glTranslatef(0.0f, 0.0f, -500.0f); // 0,0,-5
gl.glRotatef(1.0f, 0.0f, 1.0f, 0.0f);
}
else
{
// continuous rotation (default view)
gl.glTranslatef(0.0f, -50.f * zoom, -400.0f * zoom); // 0,0,-5
gl.glRotatef(rotateX, 0.0f, 1.0f, 0.0f);
gl.glRotatef(rotateY, 1.0f, 0.0f, 0.0f);
}
//System.out.println("rotateT = " + rotateT );
it++;
// ** update Cellular Automata
_myWorld.step();
// ** draw everything
gl.glBegin(GL2.GL_QUADS);
//movingX = movingIt;// it; // was: it
//movingY = 0; // was: it
for ( int x = 0 ; x < dxView ; x++ )
for ( int y = 0 ; y < dyView ; y++ )
{
double height = _myWorld.getCellHeight(x+movingX,y+movingY);
int cellState = _myWorld.getCellValue(x+movingX,y+movingY);
float[] color = _myWorld.getCellColorValue(x+movingX,y+movingY);
// compute CA-based coloring
gl.glColor3f(color[0],color[1],color[2]);
// * if light is on
if ( MY_LIGHT_RENDERING )
{
gl.glMaterialfv( GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, color, 0 );
gl.glMaterialfv( GL.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, color, 0 );
gl.glMaterialfv( GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, color, 0 );
gl.glMateriali( GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 2 );
float[] colorBlack = {0.0f,0.0f,0.0f,1.0f};
gl.glMaterialfv( GL.GL_FRONT_AND_BACK, GL2.GL_EMISSION, colorBlack, 0 );
}
// Border visual smoothing : smooth altitudes near border (i.e. nicer rendering)
if ( SMOOTH_AT_BORDER == true && VIEW_FROM_ABOVE != true)
{
if ( Math.min(Math.min(x, dxView-x-1),Math.min(y, dyView-y-1)) < smoothingDistanceThreshold )
{
for ( int i = 0 ; i < 4 ; i++ )
{
int xIt = i==1||i==2?1:0;
int yIt = i==0||i==1?1:0;
float xSign = i==1||i==2?1.f:-1.f;
float ySign = i==0||i==1?1.f:-1.f;
smoothFactor[i] = (float)
Math.min(
Math.min( 1.0 , (double)Math.min(x+xIt,dxView-x+xIt)/(double)smoothingDistanceThreshold ) , // check x-axis
Math.min( 1.0 , (double)Math.min(y+yIt,dyView-y+yIt)/(double)smoothingDistanceThreshold ) // check y-axis
);
}
}
else
{
for ( int i = 0 ; i < 4 ; i++ )
smoothFactor[i] = 1.0f;
}
}
// use dxCA instead of dxView to keep synchronization with CA states
for ( int i = 0 ; i < 4 ; i++ )
{
int xIt = i==1||i==2?1:0;
int yIt = i==0||i==1?1:0;
float xSign = i==1||i==2?1.f:-1.f;
float ySign = i==0||i==1?1.f:-1.f;
float zValue = 0.f;
if ( VIEW_FROM_ABOVE == false )
{
//double altitude = landscape[(x+xIt+movingX)%(dxCA][(y+yIt+movingY)%dyCA] * heightBooster;
double altitude = landscape[(x+xIt+movingX)%(dxView-1)][(y+yIt+movingY)%(dyView-1)] * heightBooster;
if ( altitude < 0 )
zValue = 0;
else
zValue = heightFactor*(float)altitude * smoothFactor[i];
}
gl.glVertex3f( offset+x*stepX+xSign*lenX, offset+y*stepY+ySign*lenY, zValue);
}
/**/
// * display objects
// TODO+: diplayObjectAt(x,y,...) ==> on y gagne quoi? les smoothFactors. C'est tout. Donc on externalise?
if ( DISPLAY_OBJECTS == true) // calls my world with the enough info to display anything at this location.
{
float normalizeHeight = ( smoothFactor[0] + smoothFactor[1] + smoothFactor[2] + smoothFactor[3] ) / 4.f * (float)heightBooster * heightFactor;
//gl.glColor3f(color[0],color[1],color[2]);
_myWorld.displayObjectAt(_myWorld,gl,cellState, x, y, height, offset, stepX, stepY, lenX, lenY, normalizeHeight);
_myWorld.displayWaterAt(_myWorld,gl,_myWorld.getWaterValue(x+movingX, y+movingY), x, y, height, offset, stepX, stepY, lenX, lenY, normalizeHeight);
}
}
/**/
// TODO+: displayObjects()
if ( DISPLAY_OBJECTS == true) // calls my world with enough info to display anything anywhere
{
float normalizeHeight = (float)heightBooster * heightFactor;
_myWorld.displayUniqueObjects(_myWorld,gl,movingX,movingY,offset,stepX,stepY,lenX,lenY,normalizeHeight);
}
gl.glEnd();
// increasing rotation for the next iteration
rotateX += rotationVelocity;
//gl.glFlush(); // GO FAST ???
//gLDrawable.swapBuffers(); // GO FAST ??? // should be done at the end (http://stackoverflow.com/questions/1540928/jogl-double-buffering)
}
/**
*
*/
//@Override
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
if ( this.it == 0 )
System.out.println( "W"+"o"+"r"+"l"+"d"+" "+"O"+
"f"+" "+"C"+"e"+"l"+"l"+"s"+" "+"-"+" "+"n"+"i"+
"c"+"o"+"l"+"a"+"s"+"."+"b"+"r"+"e"+"d"+"e"+"c"+
"h"+"e"+(char)(0x40)+"u"+"p"+"m"+"c"+"."+"f"+"r"+
","+" "+"2"+"0"+"1"+"3"+"\n");
GL2 gl = gLDrawable.getGL().getGL2();
final float aspect = (float) width / (float) height;
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
final float fh = 0.5f;
final float fw = fh * aspect;
gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
}
/**
*
*/
//@Override
public void dispose(GLAutoDrawable gLDrawable) {
}
@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
//landscape = PerlinNoiseLandscapeGenerator.generatePerlinNoiseLandscape(dxView,dyView,1,0.25,1); // 11
//initLandscape();
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent mouse)
{
/* example from doublebuf.java
switch (mouse.getButton()) {
case MouseEvent.BUTTON1:
spinDelta = 2f;
break;
case MouseEvent.BUTTON2:
case MouseEvent.BUTTON3:
spinDelta = 0f;
break;
}
/**/
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent key) {
switch (key.getKeyCode()) {
case KeyEvent.VK_ESCAPE:
new Thread()
{
public void run() { animator.stop();}
}.start();
System.exit(0);
break;
case KeyEvent.VK_V:
VIEW_FROM_ABOVE = !VIEW_FROM_ABOVE ;
break;
case KeyEvent.VK_R:
MY_LIGHT_RENDERING = !MY_LIGHT_RENDERING;
break;
case KeyEvent.VK_O:
DISPLAY_OBJECTS = !DISPLAY_OBJECTS;
break;
case KeyEvent.VK_2:
heightBooster++;
break;
case KeyEvent.VK_1:
if ( heightBooster > 0 )
heightBooster--;
break;
case KeyEvent.VK_UP:
movingX = ( movingX + 1 ) % (dxView-1);
break;
case KeyEvent.VK_DOWN:
movingX = ( movingX - 1 + dxView-1 ) % (dxView-1);
break;
case KeyEvent.VK_RIGHT:
movingY = ( movingY - 1 + dyView-1 ) % (dyView-1);
break;
case KeyEvent.VK_LEFT:
movingY = ( movingY + 1 ) % (dyView-1);
break;
case KeyEvent.VK_Q:
//rotationVelocity-=0.1;
rotateX-=1.f;
break;
case KeyEvent.VK_D:
//rotationVelocity+=0.1;
rotateX+=1.f;
break;
case KeyEvent.VK_Z:
break;
case KeyEvent.VK_S:
break;
case KeyEvent.VK_H:
System.out.println(
"Help:\n" +
" [v] change view\n" +
" [o] objects display on/off\n" +
" [1] decrease altitude booster\n" +
" [2] increase altitude booster\n" +
" [cursor keys] navigate in the landscape\n" +
" [q/d] rotation wrt landscape\n" +
" [9/0] zoom out/in\n" +
" [7/8] slow down / speed up time\n" +
" [space] toggle pause/play of simulation\n" +
" [cursor keys] navigate\n"
);
break;
case KeyEvent.VK_SPACE:
this._myWorld.togglePause();
break;
case KeyEvent.VK_0:
zoom*=1.05;
break;
case KeyEvent.VK_9:
zoom/=1.05;
break;
case KeyEvent.VK_8:
this._myWorld.setRate(this._myWorld.getRate() * 1.10);
break;
case KeyEvent.VK_7:
this._myWorld.setRate(this._myWorld.getRate() * 0.90);
break;
case KeyEvent.VK_6:
rotateY+=1.f;
break;
case KeyEvent.VK_5:
rotateY-=1.f;
break;
default:
break;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}