포인트 (별 모양)를 그리는 코드를 만들었지 만 움직일 수있게 만들었지 만이 애니메이션을 반복하고 몇 초 후에 멈추지 않게하려면 어떻게해야합니까? 이 애니메이션에서 리소스를 낭비하고 싶지 않기 때문에 (화면을 잃어버린 점을 지우지 않으면) 이것을 수행하는 가장 좋은 방법은 무엇입니까?이 애니메이션이 반복되도록 루프 만들기
package game;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import java.util.Random;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.*;
import org.lwjgl.*;
public class Main {
public Main() {
try {
Display.setDisplayMode(Display.getDesktopDisplayMode());
Display.setFullscreen(true);
Display.create();
} catch(LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
int width = Display.getWidth();
int height = Display.getHeight();
System.out.println("" + width);
System.out.println("" + height);
gluPerspective((float) 30, 1280f/800f, 0.001f, 100);
glMatrixMode(GL_MODELVIEW);
Point[] points = new Point[10000];
Random random = new Random();
for(int i=0;i<points.length;i++) {
points[i] = new Point((random.nextFloat() - 0.5f) * 100f, (random.nextFloat() - 0.5f) * 100f, random.nextInt(200) - 200);
}
float speed = 0.25f;
while(!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0, 0, speed);
glBegin(GL_POINTS);
for(Point p : points) {
glVertex3f(p.x, p.y, p.z);
}
glEnd();
System.out.println("" + speed);
Display.update();
Display.sync(60);
}
}
public static class Point {
float x, y, z;
public Point(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
}
}
UPDATE
는 지금은이 코드를 가지고 있지만 루프는 사람이 내가이 문제를 해결할 수있는 방법을 알고 않는, 매우 obvios입니까?
package game;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import java.util.Random;
import org.lwjgl.opengl.*;
import org.lwjgl.*;
public class Main {
public Main() {
try {
Display.setDisplayMode(Display.getDesktopDisplayMode());
Display.setFullscreen(true);
Display.create();
} catch(LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
int width = Display.getWidth();
int height = Display.getHeight();
System.out.println("" + width);
System.out.println("" + height);
gluPerspective((float) 30, 1280f/800f, 0.001f, 100);
glMatrixMode(GL_MODELVIEW);
Point[] points = new Point[10000];
Random random = new Random();
for(int i=0;i<points.length;i++) {
points[i] = new Point((random.nextFloat() - 0.5f) * 100f, (random.nextFloat() - 0.5f) * 100f, random.nextInt(200) - 200);
}
float speed = 0.25f;
int count = 0;
while(!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
count++;
if(count < 100)
glTranslatef(0, 0, speed);
else
{
glTranslatef(0, 0, -100 * speed);
count = 0;
}
glBegin(GL_POINTS);
for(Point p : points) {
glVertex3f(p.x, p.y, p.z);
}
glTranslatef(0, 0, width);
glBegin(GL_POINTS);
for(Point p : points) {
glVertex3f(p.x, p.y, p.z);
}
glEnd();
Display.update();
Display.sync(60);
}
}
public static class Point {
float x, y, z;
public Point(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
}
}
아이디어가 있으십니까? 어쩌면 나는 그것이 사라졌을 때 그것을 다시 설정할 수 있습니다. 하지만 그 중 하나를 수행하는 방법을 모르겠다 – core16
게시물을 업데이 트되었습니다 ... – core16