Java Code Examples for com.badlogic.gdx.graphics.VertexAttributes.Usage#Position

The following examples show how to use com.badlogic.gdx.graphics.VertexAttributes.Usage#Position . 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: PositionalLight.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
PositionalLight( RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree ) {
	super( rayHandler, rays, color, directionDegree, distance );
	start.x = x;
	start.y = y;
	sin = new float[ rays ];
	cos = new float[ rays ];
	endX = new float[ rays ];
	endY = new float[ rays ];

	lightMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute( Usage.Position, 2,
			"vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ), new VertexAttribute(
			Usage.Generic, 1, "s" ) );
	softShadowMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum * 2, 0, new VertexAttribute(
			Usage.Position, 2, "vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ),
			new VertexAttribute( Usage.Generic, 1, "s" ) );

	setMesh();
}
 
Example 2
Source File: FullscreenQuad.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private Mesh createFullscreenQuad () {
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, "a_position"),
		new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));

	tmpMesh.setVertices(verts);
	return tmpMesh;
}
 
Example 3
Source File: GameWorldRenderer.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private void createBackPlane () {
	plane = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
		new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));

	// @formatter:off
	float size = 10f;
	float verts[] = {-size / 2, 0, size / 2, size / 2, 0, size / 2, size / 2, 0, -size / 2, -size / 2, 0, -size / 2};
	// float verts[] = {size, 0, size, size, 0, 0, 0, 0, 0, 0, 0, size};

	float normals[] = {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
	// @formatter:on

	int vidx = 0, nidx = 0;
	int length = 6 * 4;
	float[] vertices = new float[length];
	for (int i = 0; i < length;) {
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
	}

	plane.setVertices(vertices);
	plane.setIndices(new short[] {0, 1, 2, 3});
}
 
Example 4
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private static VertexAttribute[] createVertexAttributes (boolean hasNormals, int uvs) {
	VertexAttribute[] attributes = new VertexAttribute[1 + (hasNormals ? 1 : 0) + uvs];
	int idx = 0;
	attributes[idx++] = new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE);
	if (hasNormals) attributes[idx++] = new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE);
	for (int i = 0; i < uvs; i++) {
		attributes[idx++] = new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i);
	}
	return attributes;
}
 
Example 5
Source File: DirectionalLight.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/**
 * Directional lights simulate light source that locations is at infinite
 * distance. Direction and intensity is same everywhere. -90 direction is
 * straight from up.
 * 
 * @param rayHandler
 * @param rays
 * @param color
 * @param directionDegree
 */
public DirectionalLight( RayHandler rayHandler, int rays, Color color, float directionDegree ) {

	super( rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY );

	vertexNum = (vertexNum - 1) * 2;

	start = new Vector2[ rayNum ];
	end = new Vector2[ rayNum ];
	for( int i = 0; i < rayNum; i++ ) {
		start[i] = new Vector2();
		end[i] = new Vector2();
	}
	setDirection( direction );

	// lightMesh = new Mesh(staticLight, vertexNum, 0, new VertexAttribute(
	// Usage.Position, 2, "vertex_positions"), new VertexAttribute(
	// Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(
	// Usage.Generic, 1, "s"));
	//
	// softShadowMesh = new Mesh(staticLight, vertexNum, 0,
	// new VertexAttribute(Usage.Position, 2, "vertex_positions"),
	// new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
	// new VertexAttribute(Usage.Generic, 1, "s"));

	lightMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute( Usage.Position, 2,
			"vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ), new VertexAttribute(
			Usage.Generic, 1, "s" ) );

	softShadowMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute( Usage.Position, 2,
			"vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ), new VertexAttribute(
			Usage.Generic, 1, "s" ) );

	update();
}
 
Example 6
Source File: LightMap.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private Mesh createLightMapMesh() {
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh( true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position" ), new VertexAttribute(
			Usage.TextureCoordinates, 2, "a_texCoord" ) );

	tmpMesh.setVertices( verts );
	return tmpMesh;

}
 
Example 7
Source File: ChainLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/**
 * Creates chain light from specified vertices
 * 
 * @param rayHandler
 *            not {@code null} instance of RayHandler
 * @param rays
 *            number of rays - more rays make light to look more realistic
 *            but will decrease performance, can't be less than MIN_RAYS
 * @param color
 *            color, set to {@code null} to use the default color
 * @param distance
 *            distance of light
 * @param rayDirection
 *            direction of rays
 *            <ul>
 *            <li>1 = left</li>
 *            <li>-1 = right</li>
 *            </ul>
 * @param chain
 *            float array of (x, y) vertices from which rays will be
 *            evenly distributed
 */
public ChainLight(RayHandler rayHandler, int rays, Color color,
		float distance, int rayDirection, float[] chain) {
	
	super(rayHandler, rays, color, distance, 0f);
	rayStartOffset = ChainLight.defaultRayStartOffset;
	this.rayDirection = rayDirection;
	vertexNum = (vertexNum - 1) * 2;
	endX = new float[rays];
	endY = new float[rays];
	startX = new float[rays];
	startY = new float[rays];
	this.chain = (chain != null) ?
				 new FloatArray(chain) : new FloatArray();
	
	lightMesh = new Mesh(
			VertexDataType.VertexArray, false, vertexNum, 0,
			new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	softShadowMesh = new Mesh(
			VertexDataType.VertexArray, false, vertexNum * 2,
			0, new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	setMesh();
}
 
Example 8
Source File: DirectionalLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/**
 * Creates directional light which source is at infinite distance,
 * direction and intensity is same everywhere
 * 
 * <p>-90 direction is straight from up
 * 
 * @param rayHandler
 *            not {@code null} instance of RayHandler
 * @param rays
 *            number of rays - more rays make light to look more realistic
 *            but will decrease performance, can't be less than MIN_RAYS
 * @param color
 *            color, set to {@code null} to use the default color
 * @param directionDegree
 *            direction in degrees
 */
public DirectionalLight(RayHandler rayHandler, int rays, Color color,
		float directionDegree) {
	
	super(rayHandler, rays, color, Float.POSITIVE_INFINITY, directionDegree);
	
	vertexNum = (vertexNum - 1) * 2;
	start = new Vector2[rayNum];
	end = new Vector2[rayNum];
	for (int i = 0; i < rayNum; i++) {
		start[i] = new Vector2();
		end[i] = new Vector2();
	}
	
	lightMesh = new Mesh(
			VertexDataType.VertexArray, staticLight, vertexNum, 0,
			new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	softShadowMesh = new Mesh(
			VertexDataType.VertexArray, staticLight, vertexNum, 0,
			new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	
	update();
}
 
Example 9
Source File: LightMap.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
private Mesh createLightMapMesh() {
	float[] verts = new float[VERT_SIZE];
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh(true, 4, 0, new VertexAttribute(
			Usage.Position, 2, "a_position"), new VertexAttribute(
			Usage.TextureCoordinates, 2, "a_texCoord"));

	tmpMesh.setVertices(verts);
	return tmpMesh;

}
 
Example 10
Source File: FullscreenQuad.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
private Mesh createFullscreenQuad() {
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh( VertexDataType.VertexArray, true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position" ),
			new VertexAttribute( Usage.TextureCoordinates, 2, "a_texCoord0" ) );

	tmpMesh.setVertices( verts );
	return tmpMesh;
}
 
Example 11
Source File: ViewportQuadMesh.java    From gdx-vfx with Apache License 2.0 4 votes vote down vote up
public ViewportQuadMesh() {
	this(new VertexAttribute(Usage.Position, 2, "a_position"),
			new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));
}
 
Example 12
Source File: PositionalLight.java    From box2dlights with Apache License 2.0 3 votes vote down vote up
/** 
 * Creates new positional light and automatically adds it to the specified
 * {@link RayHandler} instance.
 * 
 * @param rayHandler
 *            not null instance of RayHandler
 * @param rays
 *            number of rays - more rays make light to look more realistic
 *            but will decrease performance, can't be less than MIN_RAYS
 * @param color
 *            light color
 * @param distance
 *            light distance (if applicable)
 * @param x
 *            horizontal position in world coordinates
 * @param y
 *            vertical position in world coordinates
 * @param directionDegree
 *            direction in degrees (if applicable) 
 */
public PositionalLight(RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) {
	super(rayHandler, rays, color, distance, directionDegree);
	start.x = x;
	start.y = y;

	lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
		"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
		new VertexAttribute(Usage.Generic, 1, "s"));
	softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2,
		"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
		new VertexAttribute(Usage.Generic, 1, "s"));
	setMesh();
}