LWJGL: Is undefined?

florilu

Aktives Mitglied
Hi,

ich habe da ein kleines Problem mit dem ich mich gerade sehr rumschlage.

Undzwar versuche ich meinen Würfel zu generieren (Verschiedene Typen) und er kann das Programm nicht starten weil:
Code:
The constructor DefaultCube(Vector3f, Vector3f, Vector4f, Texture) is undefined

So und die beiden Codes:

CubeTerrain:
Java:
package src.Game;

import java.util.Random;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

import Methods.Cubes.DefaultCube;


public class CubeTerrain {
	
	// Size of the terrain measured in cubes
	public Vector3 arraySize;
	
	// Size of each cube
	public Vector3f cubeSize;
	
	// Optional translation
	private Vector3f translation;
	
	// The 3d array containing the cubes
	public DefaultCube[][][] terrain;
	
	// Textures
	private Texture stoneTexture;
	private Texture grassTexture;
	private Texture waterTexture;
	private Texture dirtTexture;
	
	// Display list
	private int displayList;
	
	private TextureStore textureStore;
	
	public CubeTerrain(Vector3 arraySize, Vector3f cubeSize, Vector3f translation, TextureStore textureStore) {
		this.arraySize = arraySize;
		this.cubeSize = cubeSize;
		this.translation = translation;
		this.textureStore = textureStore;
		
		// Create the cube array
		terrain = new DefaultCube[arraySize.x][arraySize.y][arraySize.z];
		
		for(int z = 0; z < arraySize.z; z++) {
			for(int y = 0; y < arraySize.y; y++) {
				for(int x = 0; x < arraySize.x; x++) {
					terrain[x][y][z] = null;
				}
			}
		}
		
		stoneTexture = textureStore.getTexture("res/stone.png");
		grassTexture = textureStore.getTexture("res/grass.png");
		waterTexture = textureStore.getTexture("res/water.png");
		dirtTexture = textureStore.getTexture("res/dirt.png");
	}
	
	public void generateTerrain(int maxHeight, int minHeight, int smoothLevel, int seed, float noiseSize, float persistence, int octaves, boolean textures) {
		// Stores the height of each x, z coordinate
		int heightData[][] = new int[arraySize.x][arraySize.z];
		
		// Make sure maxHeight and minHeight are within bounds of the cube array
		if(maxHeight > arraySize.y)
			maxHeight = arraySize.y;
		
		if(maxHeight < 0)
			maxHeight = 0;
		
		if(minHeight > arraySize.y)
			minHeight = arraySize.y;
		
		if(minHeight < 0)
			minHeight = 0;
		
		// Randomize the heights using Perlin noise
		for(int z = 0; z < arraySize.z; z++) {
			for(int x = 0; x < arraySize.x; x++) {
					heightData[x][z] = (int) (PerlinNoise2D.perlin2D(x, z, arraySize.x, arraySize.z, seed, 100.0f, 0.0001f, octaves) * (maxHeight - minHeight) + minHeight);
			}
		}
		
		// Smoothen the terrain
		while(smoothLevel > 0) {
			for(int z = 0; z < arraySize.z; z += 1) {
				for(int x = 0; x < arraySize.x; x += 1) {
					float totalHeight = 0.0f;
					float count = 0;
					
					if(z > 0) {
						totalHeight += heightData[x][z - 1];
						count++;
					}
					
					if(z < arraySize.z - 1) {
						totalHeight += heightData[x][z + 1];
						count++;
					}
					
					if(x > 0) {
						totalHeight += heightData[x - 1][z];
						count++;
					}
					
					if(x < arraySize.x - 1) {
						totalHeight += heightData[x + 1][z];
						count++;
					}
					
					heightData[x][z] = Math.round(totalHeight / count);
				}
			}
			
			smoothLevel--;
		}
		
		// Create the cubes
		for(int z = 0; z < arraySize.z; z++) {
			for(int x = 0; x < arraySize.x; x++) {
					for(int y = heightData[x][z]; y >= 0; y--) {
						terrain[x][y][z] = createCube(new Vector3(x, y, z), textures);
					}
			}
		}
		
		Random rand = new Random();
		
		// Calculate which sides each cube needs to render
		for(int z = 0; z < arraySize.z; z++) {
			for(int x = 0; x < arraySize.x; x++) {
				for(int y = heightData[x][z]; y >= 0; y--) {
					boolean renderTop = (y == heightData[x][z]) || (y == 0);
					boolean renderBottom = (y == 0) || (y == 3);
					boolean renderFront = (z == arraySize.z - 1) || (terrain[x][y][z + 1] == null);
					boolean renderBack = (z == 0) || (terrain[x][y][z - 1] == null);
					boolean renderRight = (x == arraySize.x - 1) || (terrain[x + 1][y][z] == null);
					boolean renderLeft = (x == 0) || (terrain[x - 1][y][z] == null);
					
					terrain[x][y][z].setVisibleSides(renderTop, renderBottom, renderFront, renderBack, renderRight, renderLeft);
				}
			}
		}
		
		// Create the display list
		displayList = GL11.glGenLists(1);
		GL11.glNewList(displayList, GL11.GL_COMPILE);
		
		for(int z = 0; z < arraySize.z; z++) {
			for(int x = 0; x < arraySize.x; x++) {
				for(int y = 0; y < arraySize.y; y++) {
					if(terrain[x][y][z] != null)
						terrain[x][y][z].render();
				}
			}
		}
		
		GL11.glEndList();
	}
	
	private DefaultCube createCube(Vector3 arrayPosition, boolean textures) {
		// Calculate the coordinates
		Vector3f pos1 = new Vector3f(arrayPosition.x * cubeSize.x, arrayPosition.y * cubeSize.y, arrayPosition.z * cubeSize.z);
		Vector3f pos2 = Vector3f.add(pos1, cubeSize);
		
		// Set texture depending on y
		Vector4f color = null;
		Texture texture = null;
		
		if(arrayPosition.y == 0) {
			// Dirt
			color = new Vector4f(0.35f, 0.15f, 0.0f, 1.0f);
			texture = dirtTexture;
		} else if(arrayPosition.y < 3) {
			// Water
			color = new Vector4f(0.0f, 0.2f, 0.7f, 0.6f);
			texture = waterTexture;
		} else if(arrayPosition.y < 6) {
			// Grass
			color = new Vector4f(0.2f, 0.4f, 0.1f, 1.0f);
			texture = grassTexture;
		} else {
			// Stone
			color = new Vector4f(0.3f, 0.3f, 0.3f, 1.0f);
			texture = stoneTexture;
		}
		
		if(!textures)
			texture = null;
		
		return new DefaultCube(pos1, pos2, color, texture);
	}
	
	public void render() {
		// Save the current matrix
		GL11.glPushMatrix();
		
		// Add the translation matrix
		GL11.glTranslatef(translation.x, translation.y, translation.z);
		
		// Call the display list
		GL11.glCallList(displayList);
		
		// Restore the matrix
		GL11.glPopMatrix();
	}
	
	/* Returns true if there is a solid cube at the given coordinates. */
	public boolean solidAt(Vector3f coordinates) {
		// Get the cube coordinates in the array
		Vector3 arrayCoordinates = new Vector3((int)((coordinates.x - translation.x) / cubeSize.x), (int)((coordinates.y - translation.y) / cubeSize.y), (int)((coordinates.z - translation.z) / cubeSize.z));
		
		// Is this within the array bounds?
		if(arrayCoordinates.x >= 0 && arrayCoordinates.x < arraySize.x &&
			arrayCoordinates.y >= 0 && arrayCoordinates.y < arraySize.y &&
			arrayCoordinates.z >= 0 && arrayCoordinates.z < arraySize.z) {
			// Is there a cube at this coordinate?
			if(terrain[arrayCoordinates.x][arrayCoordinates.y][arrayCoordinates.z] != null) {
				return true;
			}
		}
		
		return false;
	}
	
	public void release() {
		GL11.glDeleteLists(displayList, 1);
	}
}

Die Stelle die ich meine ist bei ca. Zeile 190

DefaultCube:
Java:
package Methods.Cubes;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;
import org.newdawn.slick.opengl.Texture;

public class DefaultCube {

	/* pos1 contains the lowest x, y, z. pos2 contains the heighest x, y, z */
	public Vector3f pos1, pos2;
	
	// Color to use if no texture is present
	public Vector4f color;
	
	// Texture class from Slick-Util library
	public Texture texture;
	
	// Determines which sides to draw
	protected boolean renderTop, renderBottom, renderFront, renderBack, renderRight, renderLeft;
	
	public DefaultCube(Vector3f pos1, Vector3f pos2, Vector4f color, Texture texture) {
		this.pos1 = pos1;
		this.pos2 = pos2;
		this.color = color;
		this.texture = texture;
		
		// Default is to draw all sides
		this.renderTop = true;
		this.renderBottom = true;
		this.renderFront = true;
		this.renderBack = true;
		this.renderRight = true;
		this.renderLeft = true;
	}
	
	/* Sets information about which sides to draw. */
	public void setVisibleSides(boolean drawTop, boolean drawBottom, boolean drawFront, boolean drawBack, boolean drawRight, boolean drawLeft) {
		this.renderTop = drawTop;
		this.renderBottom = drawBottom;
		this.renderFront = drawFront;
		this.renderBack = drawBack;
		this.renderRight = drawRight;
		this.renderLeft = drawLeft;
	}
	
	/* Renders the cube. */
	public void render() {
		if(texture != null) {
			// Set the texture
			GL11.glEnable(GL11.GL_TEXTURE_2D);
			GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
		} else {
			// Set the color
			GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
			GL11.glEnable(GL11.GL_COLOR_MATERIAL);
			GL11.glColor4f(color.x, color.y, color.z, color.w);
		}
		
		GL11.glBegin(GL11.GL_QUADS);
		
		// Top
		if(renderTop) {
			GL11.glNormal3f(1.0f, 1.0f, -1.0f);
			GL11.glTexCoord2f(1.0f, 0.0f);
			GL11.glVertex3f(pos2.x, pos2.y, pos1.z);
			GL11.glNormal3f(-1.0f, 1.0f, -1.0f);
			GL11.glTexCoord2f(0.0f, 0.0f);
			GL11.glVertex3f(pos1.x, pos2.y, pos1.z);
			GL11.glNormal3f(-1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0.0f, 1.0f);
			GL11.glVertex3f(pos1.x, pos2.y, pos2.z);
			GL11.glNormal3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1.0f, 1.0f);
			GL11.glVertex3f(pos2.x, pos2.y, pos2.z);
		}
		
		// Bottom
		if(renderBottom) {
			GL11.glNormal3f(1.0f, -1.0f, 1.0f);
			GL11.glTexCoord2f(1.0f, 0.0f);
			GL11.glVertex3f(pos2.x, pos1.y, pos2.z);
			GL11.glNormal3f(-1.0f, -1.0f, 1.0f);
			GL11.glTexCoord2f(0.0f, 0.0f);
			GL11.glVertex3f(pos1.x, pos1.y, pos2.z);
			GL11.glNormal3f(-1.0f, -1.0f, -1.0f);
			GL11.glTexCoord2f(0.0f, 1.0f);
			GL11.glVertex3f(pos1.x, pos1.y, pos1.z);
			GL11.glNormal3f(1.0f, -1.0f, -1.0f);
			GL11.glTexCoord2f(1.0f, 1.0f);
			GL11.glVertex3f(pos2.x, pos1.y, pos1.z);
		}
		
		// Front
		if(renderFront) {
			GL11.glNormal3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1.0f, 0.0f);
			GL11.glVertex3f(pos2.x, pos2.y, pos2.z);
			GL11.glNormal3f(-1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0.0f, 0.0f);
			GL11.glVertex3f(pos1.x, pos2.y, pos2.z);
			GL11.glNormal3f(-1.0f, -1.0f, 1.0f);
			GL11.glTexCoord2f(0.0f, 1.0f);
			GL11.glVertex3f(pos1.x, pos1.y, pos2.z);
			GL11.glNormal3f(1.0f, -1.0f, 1.0f);
			GL11.glTexCoord2f(1.0f, 1.0f);
			GL11.glVertex3f(pos2.x, pos1.y, pos2.z);
		}
		
		// Back
		if(renderBack) {
			GL11.glNormal3f(-1.0f, 1.0f, -1.0f);
			GL11.glTexCoord2f(1.0f, 0.0f);
			GL11.glVertex3f(pos1.x, pos2.y, pos1.z);
			GL11.glNormal3f(1.0f, 1.0f, -1.0f);
			GL11.glTexCoord2f(0.0f, 0.0f);
			GL11.glVertex3f(pos2.x, pos2.y, pos1.z);
			GL11.glNormal3f(1.0f, -1.0f, -1.0f);
			GL11.glTexCoord2f(0.0f, 1.0f);
			GL11.glVertex3f(pos2.x, pos1.y, pos1.z);
			GL11.glNormal3f(-1.0f, -1.0f, -1.0f);
			GL11.glTexCoord2f(1.0f, 1.0f);
			GL11.glVertex3f(pos1.x, pos1.y, pos1.z);
		}
		
		// Right
		if(renderRight) {
			GL11.glNormal3f(1.0f, 1.0f, -1.0f);
			GL11.glTexCoord2f(1.0f, 0.0f);
			GL11.glVertex3f(pos2.x, pos2.y, pos1.z);
			GL11.glNormal3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0.0f, 0.0f);
			GL11.glVertex3f(pos2.x, pos2.y, pos2.z);
			GL11.glNormal3f(1.0f, -1.0f, 1.0f);
			GL11.glTexCoord2f(0.0f, 1.0f);
			GL11.glVertex3f(pos2.x, pos1.y, pos2.z);
			GL11.glNormal3f(1.0f, -1.0f, -1.0f);
			GL11.glTexCoord2f(1.0f, 1.0f);
			GL11.glVertex3f(pos2.x, pos1.y, pos1.z);
		}
		
		// Left
		if(renderLeft) {
			GL11.glNormal3f(-1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1.0f, 0.0f);
			GL11.glVertex3f(pos1.x, pos2.y, pos2.z);
			GL11.glNormal3f(-1.0f, 1.0f, -1.0f);
			GL11.glTexCoord2f(0.0f, 0.0f);
			GL11.glVertex3f(pos1.x, pos2.y, pos1.z);
			GL11.glNormal3f(-1.0f, -1.0f, -1.0f);
			GL11.glTexCoord2f(0.0f, 1.0f);
			GL11.glVertex3f(pos1.x, pos1.y, pos1.z);
			GL11.glNormal3f(-1.0f, -1.0f, 1.0f);
			GL11.glTexCoord2f(1.0f, 1.0f);
			GL11.glVertex3f(pos1.x, pos1.y, pos2.z);
		}
		
		GL11.glEnd();
		
		// Reset color if color was used
		GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

		GL11.glDisable(GL11.GL_TEXTURE_2D);
		GL11.glDisable(GL11.GL_COLOR_MATERIAL);
	}
}

MfG:
Florilu
 
Ohne den Import sollte er sich schon früher beschweren. Klingt fast als würden im gleichen Package schon Klassen mit diesen Namen liegen ....?!
 
Habe mich durch andere Class Files usw. gestöbert und ich habe ja mal gesagt das ich was gefunden habe woraus ich lernen könnte, ist auch so gewesen, und derjenige macht sogesehen das Gleiche, hat die gleichen Klassen und verwendet die gleichen Methoden, und da klappts.

Der Inhalt dieser Klassen:
Vector2f:
Java:
package Methods.Cubes;

public class Vector2f {
	public float x, y;
	
	public Vector2f(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public void multiply(Vector2f a) {
		x *= a.x;
		y *= a.y;
	}
	
	public void add(Vector2f a) {
		x += a.x;
		y += a.y;
	}
	
	public static Vector2f multiply(Vector2f a, Vector2f b) {
		return new Vector2f(a.x * b.x, a.y * b.y);
	}
	
	public static Vector2f add(Vector2f a, Vector2f b) {
		return new Vector2f(a.x + b.x, a.y + b.y);
	}
}

Vector3:
Java:
package Methods.Cubes;


public class Vector3 {
	public int x, y, z;
	
	public Vector3(int x, int y, int z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public void multiply(Vector3 a) {
		x *= a.x;
		y *= a.y;
		z *= a.z;
	}
	
	public void add(Vector3 a) {
		x += a.x;
		y += a.y;
		z += a.z;
	}
	
	public static Vector3 multiply(Vector3 a, Vector3 b) {
		return new Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
	}
	
	public static Vector3 add(Vector3 a, Vector3 b) {
		return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
	}
}

Vector3f:
Java:
package Methods.Cubes;

public class Vector3f {

	public float x, y, z;
	
	public Vector3f(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public void multiply(Vector3f a) {
		x *= a.x;
		y *= a.y;
		z *= a.z;
	}
	
	public void add(Vector3f a) {
		x += a.x;
		y += a.y;
		z += a.z;
	}
	
	public static Vector3f multiply(Vector3f a, Vector3f b) {
		return new Vector3f(a.x * b.x, a.y * b.y, a.z * b.z);
	}
	
	public static Vector3f add(Vector3f a, Vector3f b) {
		return new Vector3f(a.x + b.x, a.y + b.y, a.z + b.z);
	}
}

Vector4f:
Java:
package Methods.Cubes;


public class Vector4f {

	public float x, y, z, a;
	
	public Vector4f(float x, float y, float z, float a) {
		this.x = x;
		this.y = y;
		this.z = z;
		this.a = a;
	}
	
	public void multiply(Vector4f b) {
		x *= b.x;
		y *= b.y;
		z *= b.z;
		a *= b.a;
	}
	
	public void add(Vector4f b) {
		x += b.x;
		y += b.y;
		z += b.z;
		a += b.a;
	}
	
	public static Vector4f multiply(Vector4f a, Vector4f b) {
		return new Vector4f(a.x * b.x, a.y * b.y, a.z * b.z, a.a * b.a);
	}
	
	public static Vector4f add(Vector4f a, Vector4f b) {
		return new Vector4f(a.x + b.x, a.y + b.y, a.z + b.z, a.a + b.a);
	}
}
 
Zuletzt bearbeitet:
Du darfst aber nicht mischen.

Wenn du in der einen Klasse einen org.lwjgl.util.vector.Vector3f und org.lwjgl.util.vector.Vector4f übergibst darf die andere keinen Methods.Cubes.Vector3f und Methods.Cubes.Vector4f erwarten.

BTW: Packages werden klein geschrieben...
 
Die groß und Kleinschreibung der Packages hat bisher nix ausgemacht ^^

Also ich verwende überall die gleichen Vector3f's usw.

Main.java:
Java:
import Methods.Cubes.DefaultCube;
import Methods.Cubes.Vector3;
import Methods.Cubes.Vector3f;
import Methods.Cubes.Vector4f;

FPSCamera.java:
Java:
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;

import Methods.Cubes.Vector3f;

Und wo DefaultCube ist, sind auch die ganzen Vector Files, deshalb brauch ich es hier nicht zu listen.

Aber wir weichen jetzt gerade vom eigentlichen Thema ab, ich würde gerne wissen wie ich es hinkriege damit er mir kein undefined mehr angibt und zu schreiben
Java:
return new DefaultCube(null, null, null, texture);
Währ ja sinnlos...hat da jemand von euch eine Lösung?


//edit
Klappt jetzt anscheinend, da ist nur eine kleine Spinnerei, meine Kamera zeigt die Blöcke nicht an, aber werde es schon iwie fixen können. Wenn nicht dann frag ich halt eben noch mal :lol:
 
Zuletzt bearbeitet:
Aber wir weichen jetzt gerade vom eigentlichen Thema ab, ich würde gerne wissen wie ich es hinkriege damit er mir kein undefined mehr angibt und zu schreiben

Tun wir eben NICHT.

In DefaultCube nutzt du nämlich:
Java:
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;
 

Neue Themen


Zurück
Oben