org.lwjgl.util.vector.Vector2f Java Examples

The following examples show how to use org.lwjgl.util.vector.Vector2f. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldToScreen.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
public static Vector2f worldToScreen(Vector3f pointInWorld, Matrix4f view, Matrix4f projection, int screenWidth, int screenHeight) {
        Vector4f clipSpacePos = multiply(multiply(new Vector4f(pointInWorld.x, pointInWorld.y, pointInWorld.z, 1.0f), view), projection);

        Vector3f ndcSpacePos = new Vector3f(clipSpacePos.x / clipSpacePos.w, clipSpacePos.y / clipSpacePos.w, clipSpacePos.z / clipSpacePos.w);

//        System.out.println(pointInNdc);

        float screenX = ((ndcSpacePos.x + 1.0f) / 2.0f) * screenWidth;
        float screenY = ((1.0f - ndcSpacePos.y) / 2.0f) * screenHeight;

        // nPlane = -1, fPlane = 1
        if (ndcSpacePos.z < -1.0 || ndcSpacePos.z > 1.0) {
            return null;
        }

        return new Vector2f(screenX, screenY);
    }
 
Example #2
Source File: GuiStats.java    From GokiStats with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void initGui() {
    for (int stat = 0; stat < StatBase.totalStats; stat++) {
        Vector2f pos = getButton(stat);
        this.buttonList.add(new GuiStatButton(stat, (int) pos.x, (int) pos.y, 24, 24, StatBase.stats.get(stat), this.player));
        this.currentColumn += 1;
        if (this.currentColumn >= COLUMNS[this.currentRow]) {
            this.currentRow += 1;
            this.currentColumn = 0;
        }
        if (this.currentRow >= COLUMNS.length) {
            this.currentRow = (COLUMNS.length - 1);
        }
    }
}
 
Example #3
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void pushTo(SubMesh destMesh, final float xOffset, final float yOffset, final float zOffset, Rotation horizRotation, final float horizAngleDeg, Rotation vertRotation, final float vertAngleDeg)
{
	Matrix4f transform = createTransform(horizRotation, horizAngleDeg, vertRotation, vertAngleDeg);
	
	for (int i=0; i<positions.size(); i++)
	{
		Vector3f pos = new Vector3f( positions.get(i) );
		
		if (transform != null)
		{
			Vector4f dest = new Vector4f();
			Matrix4f.transform(transform, new Vector4f(pos.x, pos.y, pos.z, 1.0f), dest);
			
			pos.x = dest.x / dest.w;
			pos.y = dest.y / dest.w;
			pos.z = dest.z / dest.w;
		}
		
		destMesh.positions.add( new Vector3f(positions.get(i) ));
		destMesh.colours.add( new Vector4f(colours.get(i) ));
		destMesh.texCoords.add( new Vector2f(texCoords.get(i) ));
	}
}
 
Example #4
Source File: MeshUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addDoubleSidedQuad(Mesh mesh, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector4f colour, Vector2f uv0, Vector2f uv1, Vector2f uv2, Vector2f uv3)
{
	// Clockwise
	mesh.addVertex(p0, colour, uv0.x, uv0.y);
	mesh.addVertex(p1, colour, uv1.x, uv1.y);
	mesh.addVertex(p2, colour, uv2.x, uv2.y);
	mesh.addVertex(p3, colour, uv3.x, uv3.y);
	
	// Anticlockwise
	mesh.addVertex(p0, colour, uv0.x, uv0.y);
	mesh.addVertex(p3, colour, uv3.x, uv3.y);
	mesh.addVertex(p2, colour, uv2.x, uv2.y);
	mesh.addVertex(p1, colour, uv1.x, uv1.y);
}
 
Example #5
Source File: JpctMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public JpctMesh(World world, JpctTexture texture)
{
	this.world = world;
	
	verts = new ArrayList<Vector3f>();
	colours = new ArrayList<Vector4f>();
	texCoords = new ArrayList<Vector2f>();
	
	object3D = new Object3D(1024);

//	obj.setBaseTexture("box");
	object3D.setCulling(false);
}
 
Example #6
Source File: MeshUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addQuad(Mesh mesh, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector4f colour, Vector2f uv0, Vector2f uv1, Vector2f uv2, Vector2f uv3)
{
	mesh.addVertex(p0, colour, uv0.x, uv0.y);
	mesh.addVertex(p1, colour, uv1.x, uv1.y);
	mesh.addVertex(p2, colour, uv2.x, uv2.y);
	mesh.addVertex(p3, colour, uv3.x, uv3.y);
}
 
Example #7
Source File: GuiStats.java    From GokiStats with MIT License 5 votes vote down vote up
private Vector2f getButton(int n) {
    Vector2f vec = new Vector2f();
    int columns = COLUMNS[this.currentRow];
    int x = n % columns;
    int y = this.currentRow;
    int rows = COLUMNS.length;
    float width = columns * 32 * SCALE;
    float height = rows * 36 * SCALE;
    vec.x = (width / columns * x + (this.width - width + 8.0F) / 2.0F);
    vec.y = (height / rows * y + (this.height - height + 12.0F) / 2.0F);
    return vec;
}
 
Example #8
Source File: GeometryLoader.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
private float convertDataToArrays() {
	float furthestPoint = 0;
	for (int i = 0; i < vertices.size(); i++) {
		Vertex currentVertex = vertices.get(i);
		if (currentVertex.getLength() > furthestPoint) {
			furthestPoint = currentVertex.getLength();
		}
		Vector3f position = currentVertex.getPosition();
		Vector2f textureCoord = textures.get(currentVertex.getTextureIndex());
		Vector3f normalVector = normals.get(currentVertex.getNormalIndex());
		verticesArray[i * 3] = position.x;
		verticesArray[i * 3 + 1] = position.y;
		verticesArray[i * 3 + 2] = position.z;
		texturesArray[i * 2] = textureCoord.x;
		texturesArray[i * 2 + 1] = 1 - textureCoord.y;
		normalsArray[i * 3] = normalVector.x;
		normalsArray[i * 3 + 1] = normalVector.y;
		normalsArray[i * 3 + 2] = normalVector.z;
		VertexSkinData weights = currentVertex.getWeightsData();
		jointIdsArray[i * 3] = weights.jointIds.get(0);
		jointIdsArray[i * 3 + 1] = weights.jointIds.get(1);
		jointIdsArray[i * 3 + 2] = weights.jointIds.get(2);
		weightsArray[i * 3] = weights.weights.get(0);
		weightsArray[i * 3 + 1] = weights.weights.get(1);
		weightsArray[i * 3 + 2] = weights.weights.get(2);

	}
	return furthestPoint;
}
 
Example #9
Source File: GeometryLoader.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
private void readTextureCoords() {
	String texCoordsId = meshData.getChild("polylist").getChildWithAttribute("input", "semantic", "TEXCOORD")
			.getAttribute("source").substring(1);
	XmlNode texCoordsData = meshData.getChildWithAttribute("source", "id", texCoordsId).getChild("float_array");
	int count = Integer.parseInt(texCoordsData.getAttribute("count"));
	String[] texData = texCoordsData.getData().split(" ");
	for (int i = 0; i < count/2; i++) {
		float s = Float.parseFloat(texData[i * 2]);
		float t = Float.parseFloat(texData[i * 2 + 1]);
		textures.add(new Vector2f(s, t));
	}
}
 
Example #10
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addQuad(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector4f colour, Vector2f uv0, Vector2f uv1, Vector2f uv2, Vector2f uv3)
{
	addVertex(p0, colour, uv0.x, uv0.y);
	addVertex(p1, colour, uv1.x, uv1.y);
	addVertex(p2, colour, uv2.x, uv2.y);
	addVertex(p3, colour, uv3.x, uv3.y);
}
 
Example #11
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void pushTo(Mesh mesh, final float xOffset, final float yOffset, final float zOffset, Rotation horizRotation, final float horizAngleDeg, Rotation vertRotation, final float vertAngleDeg)
{
	Matrix4f transform = createTransform(horizRotation, horizAngleDeg, vertRotation, vertAngleDeg);
	
	for (int i=0; i<positions.size(); i++)
	{
		Vector3f pos = new Vector3f( positions.get(i) );
		Vector2f tex = texCoords.get(i);
		Vector4f col = colours.get(i);
		
		if (transform != null)
		{
			Vector4f dest = new Vector4f();
			Matrix4f.transform(transform, new Vector4f(pos.x, pos.y, pos.z, 1.0f), dest);
			
			pos.x = dest.x / dest.w;
			pos.y = dest.y / dest.w;
			pos.z = dest.z / dest.w;
		}
		
		pos.x += xOffset;
		pos.y += yOffset;
		pos.z += zOffset;
		
		mesh.addVertex(pos, col, tex.x, tex.y);
	}
}
 
Example #12
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void pushTo(SubMesh dest, final float xOffset, final float yOffset, final float zOffset)
{
	for (int i=0; i<positions.size(); i++)
	{
		dest.positions.add( new Vector3f(positions.get(i) ));
		dest.colours.add( new Vector4f(colours.get(i) ));
		dest.texCoords.add( new Vector2f(texCoords.get(i) ));
	}
}
 
Example #13
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void addBlock(SubMesh subMesh, final float x, final float y, final float z,
							final float width, final float height, final float depth,
							Vector4f colour, SubTexture sideTex, SubTexture topTex, SubTexture bottomTex)
{
	final float uRange = sideTex.u1 - sideTex.u0;
	final float vRange = sideTex.v1 - sideTex.v0;
	
	
	// West
	subMesh.addQuad( new Vector3f(x, y+height, z), new Vector3f(x, y+height, z+depth),
					new Vector3f(x, y, z+depth),  new Vector3f(x, y, z), 
					colour, new Vector2f(sideTex.u0 + uRange * z,			sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u0 + uRange * (z + depth),		sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u0 + uRange * (z + depth),		sideTex.v1 - vRange * y),
 					new Vector2f(sideTex.u0 + uRange * z,			sideTex.v1 - vRange * y));
	
	// North
	subMesh.addQuad( new Vector3f(x+width, y+height, z), new Vector3f(x, y+height, z),
					new Vector3f(x, y, z),  new Vector3f(x+width, y, z), 
					colour, new Vector2f(sideTex.u1 - uRange * (x + width),		sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u1 - uRange * x,			sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u1 - uRange * x,			sideTex.v1 - vRange * y),
 					new Vector2f(sideTex.u1 - uRange * (x + width),		sideTex.v1 - vRange * y));
	
	// South
	subMesh.addQuad( new Vector3f(x, y+height, z+depth), new Vector3f(x+width, y+height, z+depth),
					new Vector3f(x+width, y, z+depth),  new Vector3f(x, y, z+depth), 
					colour, new Vector2f(sideTex.u1 - uRange * (x + width),		sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u1 - uRange * x,			sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u1 - uRange * x,			sideTex.v1 - vRange * y),
 					new Vector2f(sideTex.u1 - uRange * (x + width),		sideTex.v1 - vRange * y));
	
	// East
	subMesh.addQuad(new Vector3f(x+width, y+height, z+depth), new Vector3f(x+width, y+height, z),
					new Vector3f(x+width, y, z), new Vector3f(x+width, y, z+depth), 
					colour, new Vector2f(sideTex.u0 + uRange * z,	sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u0 + uRange * (z + depth),		sideTex.v1 - vRange * (y + height)),
 					new Vector2f(sideTex.u0 + uRange * (z + depth),		sideTex.v1 - vRange * y),
 					new Vector2f(sideTex.u0 + uRange * z,			sideTex.v1 - vRange * y));
	
	if(topTex != null)
	{
		// Top
		subMesh.addQuad(new Vector3f(x, y+height, z), new Vector3f(x+width, y+height, z),
						new Vector3f(x+width, y+height, z+depth), new Vector3f(x, y+height, z+depth), 
						colour, new Vector2f(topTex.u0 + uRange * x,		topTex.v0 + vRange * z),
						new Vector2f(topTex.u0 + uRange * (x + width),	topTex.v0 + vRange * z),
						new Vector2f(topTex.u0 + uRange * (x + width),	topTex.v0 + vRange * (z + depth)),
						new Vector2f(topTex.u0 + uRange * x,		topTex.v0 + vRange * (z + depth)));
	}
	
	// Bottom
	subMesh.addQuad(new Vector3f(x, y, z), new Vector3f(x, y, z+depth),
					new Vector3f(x+width, y, z+depth), new Vector3f(x+width, y, z), 
					colour, new Vector2f(bottomTex.u0 + uRange * x,		bottomTex.v0 + vRange * z),
					new Vector2f(bottomTex.u0 + uRange * (x + width),	bottomTex.v0 + vRange * z),
					new Vector2f(bottomTex.u0 + uRange * (x + width),	bottomTex.v0 + vRange * (z + depth)),
					new Vector2f(bottomTex.u0 + uRange * x,		bottomTex.v0 + vRange * (z + depth)));
}
 
Example #14
Source File: Cake.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void addEdgeGeometry(int x, int y, int z, BlockContext world, BlockTypeRegistry registry, RawChunk chunk, Geometry geometry)
{
	final int data = chunk.getBlockData(x, y, z);
	
	Mesh topMesh = geometry.getMesh(top.texture, Geometry.MeshType.AlphaTest);
	Mesh sideMesh = geometry.getMesh(side.texture, Geometry.MeshType.AlphaTest);
	Mesh interiorMesh = geometry.getMesh(interior.texture, Geometry.MeshType.AlphaTest);
	
	final float lightness = Chunk.getLight(world.getLightStyle(), LightFace.Top, chunk, x, y, z);
	
	Vector4f white = new Vector4f(lightness, lightness, lightness, 1);
	
	final float texel = 1.0f / 16.0f;
	final float offset = texel * 2 * data;
	
	final float actualY = y + 0.5f;
	
	final float uRange = top.u1 - top.u0;
	final float uEdge = uRange / 16.0f;
	final float uSeg = (uRange / 8.0f);
	float uInc = uEdge + uSeg * data;
	
	// Top
	MeshUtil.addQuad(topMesh,	new Vector3f(x + texel + offset,	actualY, z),
								new Vector3f(x+1-texel,				actualY, z),
								new Vector3f(x+1-texel,				actualY, z+1),
								new Vector3f(x + texel + offset,	actualY, z+1),
								white,
								new Vector2f(top.u0+uInc, top.v0),
								new Vector2f(top.u1-uSeg, top.v0),
								new Vector2f(top.u1-uSeg, top.v1),
								new Vector2f(top.u0+uInc, top.v1)
				);
	
	// South
	MeshUtil.addQuad(sideMesh,	new Vector3f(x + texel + offset,	actualY,	z+1-texel),
								new Vector3f(x+1-texel,				actualY,	z+1-texel),
								new Vector3f(x+1-texel,				y,			z+1-texel),
								new Vector3f(x + texel + offset,	y,			z+1-texel),
								white,
								new Vector2f(side.u0+uInc, side.v0),
								new Vector2f(side.u1-uSeg, side.v0),
								new Vector2f(side.u1-uSeg, side.v1),
								new Vector2f(side.u0+uInc, side.v1)
				);

	// North
	MeshUtil.addQuad(sideMesh,	new Vector3f(x+1-texel,	actualY,	z+texel),
								new Vector3f(x+texel+offset,	actualY,	z+texel),
								new Vector3f(x+texel+offset,	y,			z+texel),
								new Vector3f(x+1-texel,	y,			z+texel),
								white,
								new Vector2f(side.u0+uInc, side.v0),
								new Vector2f(side.u1-uSeg, side.v0),
								new Vector2f(side.u1-uSeg, side.v1),
								new Vector2f(side.u0+uInc, side.v1)
				);
	
	// West
	SubTexture westTex = data == 0 ? side : interior;
	Mesh westMesh = data == 0 ? sideMesh : interiorMesh;
	MeshUtil.addQuad(westMesh,	new Vector3f(x+texel+offset,	actualY,	z+texel),
								new Vector3f(x+texel+offset,	actualY,	z+1-texel),
								new Vector3f(x+texel+offset,	y,			z+1-texel),
								new Vector3f(x+texel+offset,	y,			z+texel),
								white,
								new Vector2f(westTex.u0+uSeg, westTex.v0),
								new Vector2f(westTex.u1-uSeg, westTex.v0),
								new Vector2f(westTex.u1-uSeg, westTex.v1),
								new Vector2f(westTex.u0+uSeg, westTex.v1)
				);
	
	// East (always the same)
	MeshUtil.addQuad(sideMesh,	new Vector3f(x+1-texel, actualY,	z+1),
								new Vector3f(x+1-texel, actualY,	z),
								new Vector3f(x+1-texel, y,			z),
								new Vector3f(x+1-texel, y,			z+1),
								white,
								side);
}
 
Example #15
Source File: Tripwire.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void addEdgeGeometry(int x, int y, int z, BlockContext world, BlockTypeRegistry registry, RawChunk rawChunk, Geometry geometry)
{
	Mesh mesh = geometry.getMesh(texture.texture, Geometry.MeshType.Transparent);
	
	final boolean hasNorth = world.getBlockType(rawChunk.getChunkCoord(), x, y, z-1) instanceof Tripwire || 
								world.getBlockType(rawChunk.getChunkCoord(), x, y, z-1) instanceof TripwireHook;
	final boolean hasSouth = world.getBlockType(rawChunk.getChunkCoord(), x, y, z+1) instanceof Tripwire ||
								world.getBlockType(rawChunk.getChunkCoord(), x, y, z+1) instanceof TripwireHook;
	final boolean hasEast = world.getBlockType(rawChunk.getChunkCoord(), x+1, y, z) instanceof Tripwire ||
								world.getBlockType(rawChunk.getChunkCoord(), x+1, y, z) instanceof TripwireHook;
	final boolean hasWest = world.getBlockType(rawChunk.getChunkCoord(), x-1, y, z) instanceof Tripwire ||
								world.getBlockType(rawChunk.getChunkCoord(), x-1, y, z) instanceof TripwireHook;

	
	final float lightness = Chunk.getLight(world.getLightStyle(), LightFace.Top, rawChunk, x, y, z);
	Vector4f light = new Vector4f(colour.r * lightness, colour.g * lightness, colour.b * lightness, colour.a);
	
	final float nudge = 1.0f/16.0f;
	final float actualY = y + nudge;

	//North/South tripwire
	if ((!hasNorth && !hasSouth && !hasEast && !hasWest) || hasNorth)
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x+0.48f,	actualY, z),
								new Vector3f(x+0.52f,	actualY, z),
								new Vector3f(x+0.52f,	actualY, z+0.25f),
								new Vector3f(x+0.48f,	actualY, z+0.25f), 
								light, new Vector2f(topTexture.u0, topTexture.v1), new Vector2f(topTexture.u0, topTexture.v0),new Vector2f(topTexture.u1, topTexture.v0), new Vector2f(topTexture.u1, topTexture.v1));
	}
	
	if ((!hasNorth && !hasSouth && !hasEast && !hasWest) || hasNorth || (hasSouth && !hasEast && !hasWest))
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x+0.48f,	actualY, z+0.25f),
								new Vector3f(x+0.52f,	actualY, z+0.25f),
								new Vector3f(x+0.52f,	actualY, z+0.50f),
								new Vector3f(x+0.48f,	actualY, z+0.50f), 
								light, new Vector2f(topTexture.u0, topTexture.v1), new Vector2f(topTexture.u0, topTexture.v0),new Vector2f(topTexture.u1, topTexture.v0), new Vector2f(topTexture.u1, topTexture.v1));
	}
	
	if ((!hasNorth && !hasSouth && !hasEast && !hasWest) || (hasNorth && !hasEast && !hasWest) || hasSouth)
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x+0.48f,	actualY, z+0.50f),
								new Vector3f(x+0.52f,	actualY, z+0.50f),
								new Vector3f(x+0.52f,	actualY, z+0.75f),
								new Vector3f(x+0.48f,	actualY, z+0.75f), 
								light, new Vector2f(topTexture.u0, topTexture.v1), new Vector2f(topTexture.u0, topTexture.v0),new Vector2f(topTexture.u1, topTexture.v0), new Vector2f(topTexture.u1, topTexture.v1));
	}
	
	if ((!hasNorth && !hasSouth && !hasEast && !hasWest) || hasSouth)
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x+0.48f,	actualY, z+0.75f),
								new Vector3f(x+0.52f,	actualY, z+0.75f),
								new Vector3f(x+0.52f,	actualY, z+1),
								new Vector3f(x+0.48f,	actualY, z+1), 
								light, new Vector2f(topTexture.u0, topTexture.v1), new Vector2f(topTexture.u0, topTexture.v0),new Vector2f(topTexture.u1, topTexture.v0), new Vector2f(topTexture.u1, topTexture.v1));
	}
	
	
	//East/West tripwire	
	if (hasWest)
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x,			actualY, z+0.48f),
								new Vector3f(x+0.25f,	actualY, z+0.48f),
								new Vector3f(x+0.25f,	actualY, z+0.52f),
								new Vector3f(x,			actualY, z+0.52f),
								light, topTexture);
	}
	
	if (hasWest || (hasEast && !hasNorth && !hasSouth))
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x+0.25f,	actualY, z+0.48f),
								new Vector3f(x+0.50f,	actualY, z+0.48f),
								new Vector3f(x+0.50f,	actualY, z+0.52f),
								new Vector3f(x+0.25f,	actualY, z+0.52f),
								light, topTexture);
	}
	
	if ((hasWest && !hasNorth && !hasSouth) || hasEast)
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x+0.50f,	actualY, z+0.48f),
								new Vector3f(x+0.75f,	actualY, z+0.48f),
								new Vector3f(x+0.75f,	actualY, z+0.52f),
								new Vector3f(x+0.50f,	actualY, z+0.52f),
								light, topTexture);
	}
	
	if (hasEast)
	{
		MeshUtil.addQuad(mesh,	new Vector3f(x+0.75f,	actualY, z+0.48f),
								new Vector3f(x+1,		actualY, z+0.48f),
								new Vector3f(x+1,		actualY, z+0.52f),
								new Vector3f(x+0.75f,	actualY, z+0.52f),
								light, topTexture);
	}
}
 
Example #16
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void addVertex(Vector3f position, Vector4f colour, final float u, final float v)
{
	positions.add(new Vector3f(position));
	texCoords.add(new Vector2f(u, v));
	colours.add(new Vector4f(colour));
}
 
Example #17
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SubMesh()
{
	positions = new ArrayList<Vector3f>();
	texCoords = new ArrayList<Vector2f>();
	colours = new ArrayList<Vector4f>();
}
 
Example #18
Source File: BedNew.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void addEdgeGeometry(final int x, final int y, final int z, BlockContext world, BlockTypeRegistry registry, RawChunk rawChunk, Geometry geometry)
{
	final int data = rawChunk.getBlockData(x, y, z);
	final boolean isHead = (data & 0x8) > 0;
	
	final float texel = 1.0f / 64.0f;
	
	String xyz = "x" +String.valueOf(x) + "y" + String.valueOf(y) + "z" + String.valueOf(z);
	BedEntity be = rawChunk.getBeds().get(xyz);
	String color = "red";
	if (be != null)
		color = Colors.byId(be.getColor()).getName();

	SubTexture texture = world.getTexturePack().findTexture(null, "bed_"+color);
	SubTexture headTop = new SubTexture(texture.texture, texture.u0+texel*6, texture.v0+texel*6, texture.u0+texel*22, texture.v0+texel*21.8f);
	SubTexture footTop = new SubTexture(texture.texture, texture.u0+texel*6, texture.v0+texel*28.2f, texture.u0+texel*22, texture.v0+texel*43.9f);
	SubTexture headSide = new SubTexture(texture.texture, texture.u0, texture.v0+texel*6.1f, texture.u0+texel*6, texture.v0+texel*21.9f);
	SubTexture footSide = new SubTexture(texture.texture, texture.u0, texture.v0+texel*28.1f, texture.u0+texel*6, texture.v0+texel*43.9f);
	SubTexture headEdge = new SubTexture(texture.texture, texture.u0+texel*6.1f, texture.v0, texture.u0+texel*21.9f, texture.v0+texel*6);
	SubTexture footEdge = new SubTexture(texture.texture, texture.u0+texel*22.1f, texture.v0+texel*22, texture.u0+texel*37.9f, texture.v0+texel*27.9f);
	SubTexture leg = new SubTexture(texture.texture, texture.u0+texel*50, texture.v0+texel*3.1f, texture.u0+texel*53, texture.v0+texel*6);
	
	final float lightness = Chunk.getLight(world.getLightStyle(), LightFace.Top, rawChunk, x, y, z);
	Vector4f white = new Vector4f(lightness, lightness, lightness, 1);
	
	final float height = 1.0f / 16.0f * 9.0f;
	final float legHeight = 1.0f / 16.0f * 3.0f;
	
	SubMesh bedMesh = new SubMesh();
	
	SubTexture topTex = isHead ? headTop : footTop;
	bedMesh.addQuad(new Vector3f(0, height, 0), new Vector3f(1, height, 0), new Vector3f(1, height, 1), new Vector3f(0, height, 1), white, topTex);
	
	// Head or feet sides
	if (isHead)
	{
		//Top edge
		bedMesh.addQuad(new Vector3f(0, legHeight, 0), new Vector3f(1, legHeight, 0), new Vector3f(1, height, 0), new Vector3f(0, height, 0), white, headEdge);
		
		//Head sides
		bedMesh.addQuad(new Vector3f(1, height, 0), new Vector3f(1, legHeight, 0), new Vector3f(1, legHeight, 1), new Vector3f(1, height, 1), white, 
				new Vector2f(headSide.u1, headSide.v0), new Vector2f(headSide.u0, headSide.v0),new Vector2f(headSide.u0, headSide.v1), new Vector2f(headSide.u1, headSide.v1));
		bedMesh.addQuad(new Vector3f(0, legHeight, 0), new Vector3f(0, height, 0), new Vector3f(0, height, 1), new Vector3f(0, legHeight, 1), white, headSide);
		
		//Legs
		SubMesh.addBlockSimple(bedMesh, 0, 0, 0, legHeight, legHeight, legHeight, white, leg, leg, leg);
		SubMesh.addBlockSimple(bedMesh, 1-legHeight, 0, 0, legHeight, legHeight, legHeight, white, leg, leg, leg);
	}
	else
	{
		//Bottom edge
		bedMesh.addQuad(new Vector3f(1, legHeight, 1), new Vector3f(0, legHeight, 1), new Vector3f(0, height, 1), new Vector3f(1, height, 1), white, footEdge);
		
		//Feet sides
		bedMesh.addQuad(new Vector3f(1, height, 0), new Vector3f(1, legHeight, 0), new Vector3f(1, legHeight, 1), new Vector3f(1, height, 1), white, 
				new Vector2f(footSide.u1, footSide.v0), new Vector2f(footSide.u0, footSide.v0),new Vector2f(footSide.u0, footSide.v1), new Vector2f(footSide.u1, footSide.v1));
		bedMesh.addQuad(new Vector3f(0, legHeight, 0), new Vector3f(0, height, 0), new Vector3f(0, height, 1), new Vector3f(0, legHeight, 1), white, footSide);
		
		//Legs
		SubMesh.addBlockSimple(bedMesh, 0, 0, 1-legHeight, legHeight, legHeight, legHeight, white, leg, leg, leg);
		SubMesh.addBlockSimple(bedMesh, 1-legHeight, 0, 1-legHeight, legHeight, legHeight, legHeight, white, leg, leg, leg);
	}

	
	SubMesh.Rotation rotation = Rotation.None;
	float angle = 0;
	
	final int dir = (data & 0x3);
	if (dir == 0)
	{
		// Head is pointing south
		rotation = Rotation.AntiClockwise;
		angle = 180;
	}
	else if (dir == 1)
	{
		// Head is pointing west
		rotation = Rotation.Clockwise;
		angle = 90;
	}
	else if (dir == 2)
	{
		// Head is pointing north
	}
	else if (dir == 3)
	{
		// Head is pointing east
		rotation = Rotation.AntiClockwise;
		angle = 90;
	}
	else
	{
		System.err.println("Warning: Unknown block data for bed");
	}
	
	// Apply rotation
	bedMesh.pushTo(geometry.getMesh(texture.texture, Geometry.MeshType.AlphaTest), x, y, z, rotation, angle);
}
 
Example #19
Source File: WorldToScreen.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
public static Vector2f worldToScreen(Vector3f pointInWorld, int screenWidth, int screenHeight) {
    return worldToScreen(pointInWorld, getMatrix(GL11.GL_MODELVIEW_MATRIX), getMatrix(GL11.GL_PROJECTION_MATRIX), screenWidth, screenHeight);
}
 
Example #20
Source File: Bed.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void addEdgeGeometry(final int x, final int y, final int z, BlockContext world, BlockTypeRegistry registry, RawChunk rawChunk, Geometry geometry)
{
	final int data = rawChunk.getBlockData(x, y, z);
	final boolean isHead = (data & 0x8) > 0;
	
	final float lightness = Chunk.getLight(world.getLightStyle(), LightFace.Top, rawChunk, x, y, z);
	Vector4f white = new Vector4f(lightness, lightness, lightness, 1);
	
	final float height = 1.0f / 16.0f * 9.0f;
	
	SubMesh headSideMesh = new SubMesh();
	SubMesh headTopMesh = new SubMesh();
	SubMesh footSideMesh = new SubMesh();
	SubMesh rightMesh = new SubMesh();
	SubMesh leftMesh = new SubMesh();
	
	// Create the geometry in the unit cube
	
	SubTexture topTex = isHead ? headTop : footTop;
	headTopMesh.addQuad(new Vector3f(0, height, 0), new Vector3f(1, height, 0), new Vector3f(1, height, 1), new Vector3f(0, height, 1), white, topTex);
	
	// Head or feet sides
	if (isHead)
	{
		headSideMesh.addQuad(new Vector3f(1, height, 1), new Vector3f(1, height, 0), new Vector3f(1, 0, 0), new Vector3f(1, 0, 1), white, headSide);
	}
	else
	{
		footSideMesh.addQuad(new Vector3f(0, height, 0), new Vector3f(0, height, 1), new Vector3f(0, 0, 1), new Vector3f(0, 0, 0), white, footSide);
	}
	
	// Left side (if lying down in bed facing up)
	SubTexture leftSide = isHead ? headEdge : footEdge;
	leftMesh.addQuad(new Vector3f(0, height, 1), new Vector3f(1, height, 1), new Vector3f(1, 0, 1), new Vector3f(0, 0, 1), white, leftSide);
	
	// Right side
	
	SubTexture rightSide = isHead ? headEdge : footEdge;
	rightMesh.addQuad(new Vector3f(1, height, 0), new Vector3f(0, height, 0), new Vector3f(0, 0, 0), new Vector3f(1, 0, 0), white,
					new Vector2f(rightSide.u1, rightSide.v0), new Vector2f(rightSide.u0, rightSide.v0),new Vector2f(rightSide.u0, rightSide.v1), new Vector2f(rightSide.u1, rightSide.v1) );
	
	SubMesh.Rotation rotation = Rotation.None;
	float angle = 0;
	
	final int dir = (data & 0x3);
	if (dir == 0)
	{
		// Head is pointing west
		rotation = Rotation.AntiClockwise;
		angle = 90;
	}
	else if (dir == 1)
	{
		// Head is pointing north
		rotation = Rotation.Clockwise;
		angle = 180;
	}
	else if (dir == 2)
	{
		// Head is pointing east
		rotation = Rotation.Clockwise;
		angle = 90;
	}
	else if (dir == 3)
	{
		// Head is pointing south
	}
	else
	{
		System.err.println("Warning: Unknown block data for bed");
	}
	
	// Apply rotation
	rightMesh.pushTo(geometry.getMesh(rightSide.texture, Geometry.MeshType.AlphaTest), x, y, z, rotation, angle);
	leftMesh.pushTo(geometry.getMesh(leftSide.texture, Geometry.MeshType.AlphaTest), x, y, z, rotation, angle);
	headSideMesh.pushTo(geometry.getMesh(headSide.texture, Geometry.MeshType.AlphaTest), x, y, z, rotation, angle);
	headTopMesh.pushTo(geometry.getMesh(topTex.texture, Geometry.MeshType.AlphaTest), x, y, z, rotation, angle);
	footSideMesh.pushTo(geometry.getMesh(footSide.texture, Geometry.MeshType.AlphaTest), x, y, z, rotation, angle);
}
 
Example #21
Source File: JpctMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void addVertex(Vector3f position, Vector4f colour, float u, float v)
{
	verts.add(position);
	colours.add(colour);
	texCoords.add(new Vector2f(u, v));
	
	if (verts.size() == 4)
	{
		final int textureId = 0; // TODO!
		
		Vector3f v0 = verts.get(0);
		Vector3f v1 = verts.get(1);
		Vector3f v2 = verts.get(2);
		Vector3f v3 = verts.get(3);
		
	//	Vector4f c0 = colours.get(0);
	//	Vector4f c1 = colours.get(1);
	//	Vector4f c2 = colours.get(2);
	//	Vector4f c3 = colours.get(3);
		
		Vector2f uv0 = texCoords.get(0);
		Vector2f uv1 = texCoords.get(1);
		Vector2f uv2 = texCoords.get(2);
		Vector2f uv3 = texCoords.get(3);
		
		// TODO: Figure out how to add vertex colours
		
		object3D.addTriangle(	new SimpleVector(v0.x, v0.y, v0.z), uv0.x, uv0.y,
								new SimpleVector(v1.x, v1.y, v1.z), uv1.x, uv1.y,
								new SimpleVector(v2.x, v2.y, v2.z), uv2.x, uv2.y,
								textureId);
		
		object3D.addTriangle(	new SimpleVector(v2.x, v2.y, v2.z), uv2.x, uv2.y,
								new SimpleVector(v3.x, v3.y, v3.z), uv3.x, uv3.y,
								new SimpleVector(v0.x, v0.y, v0.z), uv0.x, uv0.y,
								textureId);
		
		verts.clear();
		colours.clear();
		texCoords.clear();
	}
}
 
Example #22
Source File: CompositePrimitive.java    From ldparteditor with MIT License 4 votes vote down vote up
public Vector2f getMousePosition() {
    return mouse_position;
}
 
Example #23
Source File: Composite3D.java    From ldparteditor with MIT License 4 votes vote down vote up
public Vector2f getOldMousePosition() {
    return oldMousePosition;
}
 
Example #24
Source File: Composite3D.java    From ldparteditor with MIT License 4 votes vote down vote up
public Vector2f getMousePosition() {
    return mousePosition;
}
 
Example #25
Source File: UniformVec2.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
public void loadVec2(Vector2f vector) {
	loadVec2(vector.x, vector.y);
}
 
Example #26
Source File: UniformVec2.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
public void loadVec2(Vector2f vector) {
	loadVec2(vector.x, vector.y);
}
 
Example #27
Source File: Light.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
public Light(Vector3f direction, Colour colour, Vector2f lightBias) {
	this.direction = direction;
	this.direction.normalise();
	this.colour = colour;
	this.lightBias = lightBias;
}
 
Example #28
Source File: WaterGenerator.java    From LowPolyWater with The Unlicense 3 votes vote down vote up
/**
 * Gets the 4 indicator values for a certain vertex. This is done by
 * calculating the vector from the current vertex to each of the other two
 * vertices in the current triangle.
 * 
 * The 3 vertex positions are taken from the "vertexPositions" array, and
 * then the offset vectors are calculated by subtracting the current vertex
 * position from the other vertex position.
 * 
 * The offsets are then stored in an array as bytes (not converted to bytes,
 * but simply cast to bytes) and returned. The size of each grid square must
 * be an integer value for this to work, otherwise the offsets wouldn't be
 * able to be represented correctly as bytes.
 * 
 * @param currentVertex
 *            - The index of the current vertex in the current grid square
 *            (A number between 0 and 3).
 * @param vertexPositions
 *            - The 4 corner positions of the current grid square, stored in
 *            the following order: 0 = top left, 1 = bottom left, 2 = top
 *            right, 3 = bottom right
 * @param vertex1
 *            - The index of one of the other vertices in the triangle
 *            (number between 0 and 3).
 * @param vertex2
 *            - The index of the other vertex in the triangle (number
 *            between 0 and 3).
 * @return
 */
private static byte[] getIndicators(int currentVertex, Vector2f[] vertexPositions, int vertex1, int vertex2) {
	Vector2f currentVertexPos = vertexPositions[currentVertex];
	Vector2f vertex1Pos = vertexPositions[vertex1];
	Vector2f vertex2Pos = vertexPositions[vertex2];
	Vector2f offset1 = Vector2f.sub(vertex1Pos, currentVertexPos, null);
	Vector2f offset2 = Vector2f.sub(vertex2Pos, currentVertexPos, null);
	return new byte[] { (byte) offset1.x, (byte) offset1.y, (byte) offset2.x, (byte) offset2.y };
}
 
Example #29
Source File: WaterGenerator.java    From LowPolyWater with The Unlicense 3 votes vote down vote up
/**
 * Calculates the x,z positions of the 4 corners of a grid square.
 * 
 * @param col
 *            - The column number of the grid square.
 * @param row
 *            - The row number of the grid square.
 * @return An array contain 4 positions. Each 2D position is the x,z
 *         position of one of the corners. The corners are stored in the
 *         following order: 0 = top left, 1 = bottom left, 2 = top right, 3
 *         = bottom right
 */
private static Vector2f[] calculateCornerPositions(int col, int row) {
	Vector2f[] vertices = new Vector2f[4];
	vertices[0] = new Vector2f(col, row);
	vertices[1] = new Vector2f(col, row + 1);
	vertices[2] = new Vector2f(col + 1, row);
	vertices[3] = new Vector2f(col + 1, row + 1);
	return vertices;
}
 
Example #30
Source File: WaterGenerator.java    From LowPolyWater with The Unlicense 3 votes vote down vote up
/**
 * Stores the vertex data for a given triangle of the mesh into the
 * ByteBuffer. First it is determined which 3 of the vertices of the current
 * grid square make up the triangle. The indexes for a grid square are as
 * follows:
 * 
 * 0 = top left, 1 = bottom left, 2 = top right, 3 = bottom right.
 * 
 * This is the order that the corner positions are stored in the "cornerPos"
 * array.
 * 
 * Once it has been determined which 3 vertices make up the triangle, the
 * vertex data for those 3 vertices is stored in the ByteBuffer. For each
 * vertex the x,z position is stored, along with the 4 indicator values.
 * 
 * @param cornerPos
 *            - The 4 corner positions for the current grid square, stored
 *            in the order specified above.
 * @param buffer
 *            - The buffer containing all the vertex data for the mesh.
 * @param left
 *            - Indicates whether the triangle being stored is the triangle
 *            on the left or the right of the current grid square.
 */
private static void storeTriangle(Vector2f[] cornerPos, ByteBuffer buffer, boolean left) {
	int index0 = left ? 0 : 2;
	int index1 = 1;
	int index2 = left ? 2 : 3;
	DataStoring.packVertexData(cornerPos[index0], getIndicators(index0, cornerPos, index1, index2), buffer);
	DataStoring.packVertexData(cornerPos[index1], getIndicators(index1, cornerPos, index2, index0), buffer);
	DataStoring.packVertexData(cornerPos[index2], getIndicators(index2, cornerPos, index0, index1), buffer);
}