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
|
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.GL11.*;
public class Test extends Thread {
public static void main(String[] args){
// Creation de la fenetre d'affichage
int width=800;
int height=600;
int depth=16;
try {
DisplayMode modes[] = Display.getAvailableDisplayModes();
for(DisplayMode currentMode : modes) {
if(currentMode.getWidth() == width &&
currentMode.getHeight() == height &&
currentMode.getBitsPerPixel() == depth) {
Display.setDisplayMode(currentMode);
break;
}
}
Display.setTitle("GameTest");
Display.setLocation(10, 10);
Display.create();
Display.sync(100);
GLU.gluPerspective(45,16/9,0,10);
}
catch(Exception e) {
Sys.alert("Erreur","Une erreur est survenue lors de la création de l'affichage : " + e);
System.exit(1);
}
float posX = 0;
float posY = 0;
float posZ = 0;
float yAngleRad = 0;
float yAngleDeg = 0;
int caseMax = 10;
// Boucle tant que la fenetre n'est pas fermee
while(!Display.isCloseRequested()){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
GLU.gluPerspective(45,16/9,0,100);
// Affichage d'un triangle (a gauche)
glBegin(GL_TRIANGLES);
glVertex3f(-0.39f, 0f, -1f);
glVertex3f(-0.41f, 0f, -1f);
glVertex3f(-0.41f, 0.1f, -1f);
glEnd();
yAngleRad = (float)Math.toRadians(yAngleDeg);
if(Keyboard.isKeyDown(Keyboard.KEY_UP)) {
posZ += 0.001f*Math.cos(yAngleRad);
posX -= 0.001f*Math.sin(yAngleRad);
}
if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
posZ -= 0.001f*Math.cos(yAngleRad);
posX += 0.001f*Math.sin(yAngleRad);
}
if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
yAngleDeg -= 1f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
yAngleDeg += 1f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
yAngleDeg += 1f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_ADD)) {
caseMax += 1;
}
if(Keyboard.isKeyDown(Keyboard.KEY_DIVIDE)) {
caseMax -= 1;
}
// Rotation puis translation suivant le deplacement
glRotatef(yAngleDeg,0,1,0);
glTranslatef(posX, posY, posZ);
// Affichage du damier
float size = 0.01f;
for(int i=-caseMax;i<caseMax;i++) {
for(int j=-caseMax;j<caseMax;j++) {
glBegin(GL_LINES);
glVertex3f(
0f+i*size,
-0.005f,
-0.01f+size*j);
glVertex3f(size+i*size,
-0.005f,
-0.01f+size*j);
glVertex3f(0f+i*size,
-0.005f,
-0.01f+size*j);
glVertex3f(0f+i*size,
-0.005f,
-0.01f+size+size*j);
glEnd();
}
}
Display.update();
// Affichage du nombre de case
Display.setTitle("GameSample - NbCases : "+(caseMax*caseMax));
}
}
} |
Partager