我有一个矩形,这将是我移动对象的基础。
我试图仅在按下 A 按钮时旋转对象,释放时对象应停止旋转。
package Tanc;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.LWJGLException;
public class Tanc{
public Tanc(){
try{
Display.setDisplayMode(new DisplayMode(640,480));
Display.setTitle("Tanc");
Display.create();
}catch(LWJGLException e){
e.printStackTrace();
}
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glOrtho(1, 1, 1, 1, 1, -1);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glMatrixMode(GL11.GL_PROJECTION);
float y_angle = 0;
boolean aFlag = false;
while(!Display.isCloseRequested()){
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
// GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glRectd(0, 0, 0.2f, 0.3f);
GL11.glTranslatef(0, 0, 0);
while(Keyboard.next()){
if(Keyboard.getEventKey() == Keyboard.KEY_A){
aFlag = true;
}
}
if(aFlag){
y_angle = 0.1f;
GL11.glRotatef(y_angle, 0, 0, 1);
}
else{
y_angle = 0;
GL11.glRotatef(0, 0, 0, 1);
}
// GL11.glPopMatrix();
Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
public static void main(String[] args){
new Tanc();
}
}