Search in sources :

Example 1 with PerspectiveCamera

use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.

the class EdgeDetectionTest method create.

public void create() {
    ShaderProgram.pedantic = false;
    /*
		 * shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal(
		 * "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest",
		 * "couldn't compile scene shader: " + shader.getLog()); }
		 */
    batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/convolution.frag").readString());
    if (!batchShader.isCompiled()) {
        Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());
    }
    ObjLoader objLoader = new ObjLoader();
    scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    sceneInstance = new ModelInstance(scene);
    modelBatch = new ModelBatch();
    fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0, 0, 10);
    cam.lookAt(0, 0, 0);
    cam.far = 30;
    batch = new SpriteBatch();
    batch.setShader(batchShader);
    fboRegion = new TextureRegion(fbo.getColorBufferTexture());
    fboRegion.flip(false, true);
    logger = new FPSLogger();
    calculateOffsets();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) ObjLoader(com.badlogic.gdx.graphics.g3d.loader.ObjLoader) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) FPSLogger(com.badlogic.gdx.graphics.FPSLogger)

Example 2 with PerspectiveCamera

use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.

the class BaseBulletTest method create.

@Override
public void create() {
    init();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    light = shadows ? new DirectionalShadowLight(1024, 1024, 20f, 20f, 1f, 300f) : new DirectionalLight();
    light.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(light);
    if (shadows)
        environment.shadowMap = (DirectionalShadowLight) light;
    shadowBatch = new ModelBatch(new DepthShaderProvider());
    modelBatch = new ModelBatch();
    world = createWorld();
    world.performanceCounter = performanceCounter;
    final float width = Gdx.graphics.getWidth();
    final float height = Gdx.graphics.getHeight();
    if (width > height)
        camera = new PerspectiveCamera(67f, 3f * width / height, 3f);
    else
        camera = new PerspectiveCamera(67f, 3f, 3f * height / width);
    camera.position.set(10f, 10f, 10f);
    camera.lookAt(0, 0, 0);
    camera.update();
    // Create some simple models
    final Model groundModel = modelBuilder.createRect(20f, 0f, -20f, -20f, 0f, -20f, -20f, 0f, 20f, 20f, 0f, 20f, 0, 1, 0, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal);
    disposables.add(groundModel);
    final Model boxModel = modelBuilder.createBox(1f, 1f, 1f, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), Usage.Position | Usage.Normal);
    disposables.add(boxModel);
    // Add the constructors
    // mass = 0: static body
    world.addConstructor("ground", new BulletConstructor(groundModel, 0f));
    // mass = 1kg: dynamic body
    world.addConstructor("box", new BulletConstructor(boxModel, 1f));
    // mass = 0: static body
    world.addConstructor("staticbox", new BulletConstructor(boxModel, 0f));
}
Also used : DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) DepthShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)

Example 3 with PerspectiveCamera

use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.

the class FrustumCullingTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to toggle view\nLong press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
    tempManifoldArr = new btPersistentManifoldArray();
    world.addConstructor("collisionBox", new BulletConstructor(world.getConstructor("box").model));
    // Create the entities
    final float dX = BOX_X_MAX - BOX_X_MIN;
    final float dY = BOX_Y_MAX - BOX_Y_MIN;
    final float dZ = BOX_Z_MAX - BOX_Z_MIN;
    for (int i = 0; i < BOXCOUNT; i++) world.add("collisionBox", BOX_X_MIN + dX * (float) Math.random(), BOX_Y_MIN + dY * (float) Math.random(), BOX_Z_MIN + dZ * (float) Math.random()).setColor(Color.GRAY);
    frustumCam = new PerspectiveCamera(camera.fieldOfView, camera.viewportWidth, camera.viewportHeight);
    frustumCam.far = Vector3.len(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    frustumCam.update();
    overviewCam = camera;
    overviewCam.position.set(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    overviewCam.lookAt(Vector3.Zero);
    overviewCam.far = 150f;
    overviewCam.update();
    final Model frustumModel = createFrustumModel(frustumCam.frustum.planePoints);
    disposables.add(frustumModel);
    frustumObject = createFrustumObject(frustumCam.frustum.planePoints);
    world.add(frustumEntity = new BulletEntity(frustumModel, frustumObject, 0, 0, 0));
    frustumEntity.setColor(Color.BLUE);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) com.badlogic.gdx.physics.bullet.collision.btPersistentManifoldArray(com.badlogic.gdx.physics.bullet.collision.btPersistentManifoldArray)

Example 4 with PerspectiveCamera

use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.

the class TextureRegion3DTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f);
    atlas = new TextureAtlas(Gdx.files.internal("data/testpack"));
    regions = atlas.getRegions();
    modelBatch = new ModelBatch(new DefaultShaderProvider());
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 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(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse));
    model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    instance = new ModelInstance(model);
    attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 5 with PerspectiveCamera

use of com.badlogic.gdx.graphics.PerspectiveCamera in project libgdx by libgdx.

the class PairCacheTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to toggle view\nLong press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
    world.addConstructor("collisionBox", new BulletConstructor(world.getConstructor("box").model));
    // Create the entities
    final float dX = BOX_X_MAX - BOX_X_MIN;
    final float dY = BOX_Y_MAX - BOX_Y_MIN;
    final float dZ = BOX_Z_MAX - BOX_Z_MIN;
    for (int i = 0; i < BOXCOUNT; i++) world.add("collisionBox", BOX_X_MIN + dX * (float) Math.random(), BOX_Y_MIN + dY * (float) Math.random(), BOX_Z_MIN + dZ * (float) Math.random()).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    manifoldArray = new btPersistentManifoldArray();
    disposables.add(manifoldArray);
    overviewCam = camera;
    overviewCam.position.set(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    overviewCam.lookAt(Vector3.Zero);
    overviewCam.far = 150f;
    overviewCam.update();
    frustumCam = new PerspectiveCamera(camera.fieldOfView, camera.viewportWidth, camera.viewportHeight);
    frustumCam.far = Vector3.len(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    frustumCam.update();
    final Model ghostModel = FrustumCullingTest.createFrustumModel(frustumCam.frustum.planePoints);
    disposables.add(ghostModel);
    // The ghost object does not need to be shaped as a camera frustum, it can have any collision shape.
    ghostObject = FrustumCullingTest.createFrustumObject(frustumCam.frustum.planePoints);
    disposables.add(ghostObject);
    world.add(ghostEntity = new BulletEntity(ghostModel, ghostObject, 0, 0, 0));
    disposables.add(ghostEntity);
    shapeRenderer = new ShapeRenderer();
    disposables.add(shapeRenderer);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Aggregations

PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)31 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)18 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)15 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)13 Material (com.badlogic.gdx.graphics.g3d.Material)12 Environment (com.badlogic.gdx.graphics.g3d.Environment)10 Texture (com.badlogic.gdx.graphics.Texture)9 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)9 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)9 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)9 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)8 Model (com.badlogic.gdx.graphics.g3d.Model)7 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)6 AssetManager (com.badlogic.gdx.assets.AssetManager)5 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)4 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)4 PerspectiveCamController (com.badlogic.gdx.tests.utils.PerspectiveCamController)4 Mesh (com.badlogic.gdx.graphics.Mesh)3