com.badlogic.gdx.graphics.Mesh.VertexDataType Java Examples

The following examples show how to use com.badlogic.gdx.graphics.Mesh.VertexDataType. 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: 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 #4
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 #5
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 #6
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 #7
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();
}