-2
실린더를 만들어야하는 클래스를 작성하려고했습니다. 그러나 내 ArrayList
을 그리려고 할 때 같은 값을 가진 180 개의 객체가 있습니다. 내 ArrayList
에 쿼드를 추가하려고 할 때 거기에 무엇이 잘못되었는지 이해하지 못합니다.ArrayList에 요소 추가
public class Planet {
public static ArrayList<Quad> createRing(int x, int y, int z, int radius) {
ArrayList<Quad> quads = new ArrayList<Quad>();
for (int i = 0; i < 360; i++) {
float x1 = (float) (Math.sin(Math.toRadians(i)) * radius);
float y1 = (float) (Math.cos(Math.toRadians(i)) * radius);
i++;
float x2 = (float) (Math.sin(Math.toRadians(i)) * radius);
float y2 = (float) (Math.cos(Math.toRadians(i)) * radius);
quads.add(new Quad(new Vector3f(x1, y1, 4), new Vector3f(x2, y2, 4), new Vector3f(x2, y2, 0),
new Vector3f(x1, y1, 0)));
}
return quads;
}
}
----QUAD.java
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
public class Quad {
//have to be non-static
static Vector3f Cord1;
static Vector3f Cord2;
static Vector3f Cord3;
static Vector3f Cord4;
//have to be non-static
public Quad(Vector3f cord1,Vector3f cord2,Vector3f cord3,Vector3f cord4) {
Cord1 = cord1;
Cord2 = cord2;
Cord3 = cord3;
Cord4 = cord4;
}
public void draw() {
//GL11.glBegin(GL11.GL_QUADS);
GL11.glColor3f(1, 0, 0);
GL11.glVertex3f(Cord1.x, Cord1.y, Cord1.z);
GL11.glVertex3f(Cord2.x, Cord2.y, Cord2.z);
GL11.glVertex3f(Cord3.x, Cord3.y, Cord3.z);
GL11.glVertex3f(Cord4.x, Cord4.y, Cord4.z);
}
public void out() {
System.out.println(Cord1.x+" "+ Cord1.y+" "+ Cord1.z);
System.out.println(Cord2.x+" "+ Cord2.y+" "+ Cord2.z);
System.out.println(Cord3.x+" "+ Cord3.y+" "+ Cord3.z);
System.out.println(Cord4.x+" "+ Cord4.y+" "+ Cord4.z);
}
}
당신은'System.out.println (eins);을 시도 했습니까? System.out.println (zwei); 등등과 같은지 확인하십시오. 매번 다른 값을 할당 하시겠습니까? –
나는 for 루프의 값을 변경하여 테스트했고 매번 다른 실린더가있는 부분을 얻었습니다. 하지만 나는 한 번에 전체 실린더를 그릴 수 없습니다. –
'Quad'는 당신이 정의한 클래스인가요? 그 구성원은 정적입니까? 해당 클래스의 코드를 추가하십시오. 정적 인 경우 비 정적으로 만듭니다. –