stephenallred
YaBB Newbies
Offline
Posts: 6
England
Creating objects for 3D shapes in Eclipse?
Jan 21st , 2009, 1:20pm
Hi, I'm trying to create a Cube object using the following code: import processing.core.*; import processing.opengl.*; import javax.media.opengl.*; class Cube { PVector[] vertices = new PVector[24]; float w, h, d; Cube(){ } Cube(float w, float h, float d){ this.w = w; this.h = h; this.d = d; // Cube composed of 6 quads // Front vertices[0] = new PVector(-w/2, -h/2, d/2); vertices[1] = new PVector(w/2, -h/2, d/2); vertices[2] = new PVector(w/2, h/2, d/2); vertices[3] = new PVector(-w/2, h/2, d/2); // Left vertices[4] = new PVector(-w/2, -h/2, d/2); vertices[5] = new PVector(-w/2, -h/2, -d/2); vertices[6] = new PVector(-w/2, h/2, -d/2); vertices[7] = new PVector(-w/2, h/2, d/2); // Right vertices[8] = new PVector(w/2, -h/2, d/2); vertices[9] = new PVector(w/2, -h/2, -d/2); vertices[10] = new PVector(w/2, h/2, -d/2); vertices[11] = new PVector(w/2, h/2, d/2); // Back vertices[12] = new PVector(-w/2, -h/2, -d/2); vertices[13] = new PVector(w/2, -h/2, -d/2); vertices[14] = new PVector(w/2, h/2, -d/2); vertices[15] = new PVector(-w/2, h/2, -d/2); // Top vertices[16] = new PVector(-w/2, -h/2, d/2); vertices[17] = new PVector(-w/2, -h/2, -d/2); vertices[18] = new PVector(w/2, -h/2, -d/2); vertices[19] = new PVector(w/2, -h/2, d/2); // Bottom vertices[20] = new PVector(-w/2, h/2, d/2); vertices[21] = new PVector(-w/2, h/2, -d/2); vertices[22] = new PVector(w/2, h/2, -d/2); vertices[23] = new PVector(w/2, h/2, d/2); } void create(){ for (int i=0; i<6; i++){ beginShape(QUADS); for (int j = 0; j < 4; j++){ vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z); } endShape(); } } } However, Eclipse is saying the QUADS constant doesn't exist, the vertex() method doesn't exist, and the endShape() method doesn't exist. When compiled and called I get the following runtime error: Exception in thread "Animation Thread" java.lang.Error: Unresolved compilation problems: QUADS cannot be resolved The method vertex(float, float, float) is undefined for the type Cube The method endShape() is undefined for the type Cube at Cube.create(Cube.java:57) at Test3.draw(Test3.java:54) at processing.core.PApplet.handleDraw(PApplet.java:1395) at processing.core.PApplet.run(PApplet.java:1300) at java.lang.Thread.run(Thread.java:637) If I make Cube extend PGraphics3D these warnings are removed, but are replaced by a runtime error of: Exception in thread "Animation Thread" java.lang.NullPointerException at processing.core.PGraphics3D.endShapeModelToCamera(PGraphics3D.java:650) at processing.core.PGraphics3D.endShape(PGraphics3D.java:605) at processing.core.PGraphics.endShape(PGraphics.java:1133) at Cube.create(Cube.java:61) at Test3.draw(Test3.java:54) at processing.core.PApplet.handleDraw(PApplet.java:1395) at processing.core.PApplet.run(PApplet.java:1300) at java.lang.Thread.run(Thread.java:637) Cube extending PGraphicsOpenGl gives the same runtime error. Any ideas how to get the methods and constant visible without runtime errors? Cheers Calling context for cube: import processing.core.*; import processing.opengl.*; import javax.media.opengl.*; public class Test3 extends PApplet { private boolean debugMode = true; float bricksPerLayer = 16; float brickLayers = 18; Cube brick; float brickWidth = 60, brickHeight = 25, brickDepth = 25; float radius = 175; float angle = 0; public void setup() { size(800, 600, OPENGL); frameRate(60); brick = new Cube(brickWidth, brickHeight, brickDepth); } public void draw() { //lights(); background(230,230,230); lights(); float cameraY = (float)(height/2.0); float fov = (float)(PI/3); float cameraZ = cameraY / tan((float)(fov / 2.0)); float aspect = (float)(width)/((float)(height)); perspective(fov, aspect, (float)(cameraZ/2.0), (float)(cameraZ*10.0)); float tempX = 0, tempY = 0, tempZ = 0; for (int i = 0; i < brickLayers; i++){ // Increment rows tempY -= brickHeight; // Alternate brick seams angle = 360/bricksPerLayer*i/2; for (int j = 0; j < bricksPerLayer; j++){ tempZ = cos(radians(angle))*radius; tempX = sin(radians(angle))*radius; pushMatrix(); translate(tempX, tempY, tempZ); rotateY(radians(angle)); // Add crenelation if (i==brickLayers-1){ if (j%2 == 0){ brick.create(); } } // Create main tower else { brick.create(); } popMatrix(); angle += 360.0/bricksPerLayer; } } if(debugMode){ println("Frame Rate: " + frameRate); println("Mouse X: " + mouseX); println("Mouse Y: " + mouseY); } } public static void main(String args[]) { PApplet.main(new String[] {"Test3"}); } }