use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.
the class ShaderTest method create.
@Override
public void create() {
modelBatch = new ModelBatch(new DefaultShaderProvider() {
@Override
protected Shader createShader(Renderable renderable) {
if (renderable.material.has(TestAttribute.ID))
return new TestShader(renderable);
return super.createShader(renderable);
}
});
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0f, 0f, 20f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
Material testMaterial1 = new Material("TestMaterial1", new TestAttribute(1f));
Material redMaterial = new Material("RedMaterial", ColorAttribute.createDiffuse(Color.RED));
Material testMaterial2 = new Material("TestMaterial2", new TestAttribute(1f), ColorAttribute.createDiffuse(Color.BLUE));
ModelBuilder builder = new ModelBuilder();
Node node;
builder.begin();
node = builder.node();
node.id = "testCone1";
node.translation.set(-10, 0f, 0f);
builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial1).cone(5, 5, 5, 20);
node = builder.node();
node.id = "redSphere";
builder.part("redSphere", GL20.GL_TRIANGLES, Usage.Position, redMaterial).sphere(5, 5, 5, 20, 20);
node = builder.node();
node.id = "testCone1";
node.translation.set(10, 0f, 0f);
builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial2).cone(5, 5, 5, 20);
model = builder.end();
ModelInstance modelInstance;
modelInstance = new ModelInstance(model);
testAttribute1 = (TestAttribute) modelInstance.getMaterial("TestMaterial1").get(TestAttribute.ID);
testAttribute2 = (TestAttribute) modelInstance.getMaterial("TestMaterial2").get(TestAttribute.ID);
instances.add(modelInstance);
}
use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.
the class ShadowMappingTest method create.
@Override
public void create() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f));
environment.shadowMap = shadowLight;
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0f, 7f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 50f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(ColorAttribute.createDiffuse(Color.WHITE)));
mpb.setColor(1f, 1f, 1f, 1f);
mpb.box(0, -1.5f, 0, 10, 1, 10);
mpb.setColor(1f, 0f, 1f, 1f);
mpb.sphere(2f, 2f, 2f, 10, 10);
model = modelBuilder.end();
instance = new ModelInstance(model);
shadowBatch = new ModelBatch(new DepthShaderProvider());
Gdx.input.setInputProcessor(camController = new CameraInputController(cam));
}
use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.
the class TextureArrayTest method create.
@Override
public void create() {
GL30Profiler.enable();
ShaderProgram.prependVertexCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_EXT_texture_array : enable\n" : "#version 300 es\n";
ShaderProgram.prependFragmentCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_EXT_texture_array : enable\n" : "#version 300 es\n";
String[] texPaths = new String[] { "data/g3d/materials/Searing Gorge.jpg", "data/g3d/materials/Lava Cracks.jpg", "data/g3d/materials/Deep Fire.jpg" };
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(8, 10f, 20f);
camera.lookAt(10, 0, 10);
camera.up.set(0, 1, 0);
camera.update();
cameraController = new FirstPersonCameraController(camera);
Gdx.input.setInputProcessor(cameraController);
textureArray = new TextureArray(texPaths);
textureArray.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
shaderProgram = new ShaderProgram(Gdx.files.internal("data/shaders/texturearray.vert"), Gdx.files.internal("data/shaders/texturearray.frag"));
System.out.println(shaderProgram.getLog());
int vertexStride = 6;
int vertexCount = 100 * 100;
terrain = new Mesh(false, vertexCount * 6, 0, new VertexAttributes(VertexAttribute.Position(), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 3, ShaderProgram.TEXCOORD_ATTRIBUTE + 0)));
Pixmap data = new Pixmap(Gdx.files.internal("data/g3d/heightmap.png"));
float[] vertices = new float[vertexCount * vertexStride * 6];
int idx = 0;
for (int i = 0; i < 100 - 1; i++) {
for (int j = 0; j < 100 - 1; j++) {
idx = addVertex(i, j, vertices, data, idx);
idx = addVertex(i, j + 1, vertices, data, idx);
idx = addVertex(i + 1, j, vertices, data, idx);
idx = addVertex(i, j + 1, vertices, data, idx);
idx = addVertex(i + 1, j + 1, vertices, data, idx);
idx = addVertex(i + 1, j, vertices, data, idx);
}
}
terrain.setVertices(vertices);
data.dispose();
}
use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.
the class FogTest method create.
@Override
public void create() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(30f, 10f, 30f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 45f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
instance = new ModelInstance(model);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.
the class MaterialTest method create.
@Override
public void create() {
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
// Create material attributes. Each material can contain x-number of attributes.
textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture);
colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE);
blendingAttribute = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
ModelBuilder builder = new ModelBuilder();
model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
model.manageDisposable(texture);
modelInstance = new ModelInstance(model);
modelInstance.transform.rotate(Vector3.X, 45);
material = modelInstance.materials.get(0);
builder.begin();
MeshPartBuilder mpb = builder.part("back", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates, new Material(textureAttribute));
mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1);
backModel = builder.end();
background = new ModelInstance(backModel);
modelBatch = new ModelBatch();
camera = new PerspectiveCamera(45, 4, 4);
camera.position.set(0, 0, 3);
camera.direction.set(0, 0, -1);
camera.update();
Gdx.input.setInputProcessor(this);
}
Aggregations