Example usage for com.badlogic.gdx.graphics.g3d.environment DirectionalLight DirectionalLight

List of usage examples for com.badlogic.gdx.graphics.g3d.environment DirectionalLight DirectionalLight

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d.environment DirectionalLight DirectionalLight.

Prototype

DirectionalLight

Source Link

Usage

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.ScreenBase.java

License:Apache License

private void setupEnviroment() {
    camera = new CardboardCamera();
    camera.position.set(0f, CAMERA_Y, 0f);
    camera.lookAt(0f, CAMERA_Y, -1f);//from  w  w  w.j  a  v a 2  s .  com
    camera.near = Z_NEAR;
    camera.far = Z_FAR;

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 0.5f));
    environment.set(new ColorAttribute(ColorAttribute.Fog, BACKGROUND_COLOR.r, BACKGROUND_COLOR.g,
            BACKGROUND_COLOR.b, BACKGROUND_COLOR.a));
    environment.add(new DirectionalLight().set(0.6f, 0.6f, 0.4f, -0.5f, -0.6f, -0.5f));
    environment.add(new DirectionalLight().set(0.6f, 0.6f, 0.4f, 0.5f, -0.6f, 0.5f));
}

From source file:com.andgate.ikou.view.GameScreen.java

License:Open Source License

private void createEnvironment() {
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.set(new ColorAttribute(ColorAttribute.Fog, 1f, 1f, 1f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    shadowLight = new DirectionalShadowLight(1024, 1024, 60f, 60f, .1f, 50f);
    shadowLight.set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f);
    //environment.shadowMap = shadowLight;

    shadowBatch = new ModelBatch(new DepthShaderProvider());
}

From source file:com.badlogic.gdx.tests.ViewportTest3.java

License:Apache License

public void create() {
    modelBatch = new ModelBatch();
    modelBuilder = new ModelBuilder();

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    shadowLight = new DirectionalLight();
    shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(shadowLight);//  w w w . j  av  a  2  s .  c  o m

    modelBatch = new ModelBatch();

    camera = new PerspectiveCamera();
    camera.fieldOfView = 67;
    camera.near = 0.1f;
    camera.far = 300f;
    camera.position.set(0, 0, 100);
    camera.lookAt(0, 0, 0);

    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();

    names = ViewportTest1.getViewportNames();
    name = names.first();

    ModelBuilder modelBuilder = new ModelBuilder();
    Model boxModel = modelBuilder.createBox(50f, 50f, 50f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    boxInstance = new ModelInstance(boxModel);
    boxInstance.transform.rotate(1, 0, 0, 30);
    boxInstance.transform.rotate(0, 1, 0, 30);

    Gdx.input.setInputProcessor(new InputAdapter() {
        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}

From source file:com.badlogic.invaders.Renderer.java

License:Apache License

public Renderer() {
    try {//from ww  w.j  a  v a2  s  .  c o  m
        lights = new Environment();
        lights.add(new DirectionalLight().set(Color.WHITE, new Vector3(-1, -0.5f, 0).nor()));

        spriteBatch = new SpriteBatch();
        modelBatch = new ModelBatch();

        backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true);
        backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

        font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"),
                false);

        camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.barconr.games.marblegame.Maze3Drenderer.java

License:Apache License

public Maze3Drenderer() {
    modelBatch = new ModelBatch();
    instances = new ArrayList<ModelInstance>();
    modelBuilder = new ModelBuilder();

    createModels(Assets.mazemap);/*from  w w w . ja va2 s.c o  m*/

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    float mapPixelWidth = layerWidth * CUBE_SIZE;
    float mapPixelHeight = layerHeight * CUBE_SIZE;

    cam.position.set((float) Gdx.graphics.getWidth() / 2, (float) Gdx.graphics.getHeight() / 2, 100f);
    cam.lookAt((float) Gdx.graphics.getWidth() / 2, (float) Gdx.graphics.getHeight() / 2, 0);

    cam.near = 0.1f;
    cam.far = 150f;

    cam.update();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

}

From source file:com.mygdx.game.scene.GameScene.java

License:Apache License

private void spawnLight(BlenderLight bLight) {
    Vector3 direction = new Vector3(V3_DOWN);
    direction.rotate(Vector3.X, bLight.rotation.x);
    direction.rotate(Vector3.Z, bLight.rotation.z);
    direction.rotate(Vector3.Y, bLight.rotation.y);

    // TODO: Don't know how to map lamp intensity in blender to libgdx correctly
    float intensity = bLight.lamp_energy;
    float cutoffAngle = bLight.lamp_falloff;
    float exponent = 1;

    if (bLight.type.equals("PointLamp")) {
        BaseLight<?> light = new PointLight().set(bLight.lamp_color.r, bLight.lamp_color.g, bLight.lamp_color.b,
                bLight.position, bLight.lamp_energy);
        lights.add(light);/*  w  w w . ja  va2 s.c o m*/

    } else if (bLight.type.equals("SpotLamp")) {
        BaseLight<?> light = new SpotLight().set(bLight.lamp_color, bLight.position, direction, intensity,
                cutoffAngle, exponent);
        lights.add(light);

    } else if (bLight.type.equals("SunLamp")) {
        BaseLight<?> light = new DirectionalLight().set(bLight.lamp_color.r, bLight.lamp_color.g,
                bLight.lamp_color.b, direction.x, direction.y, direction.z);
        lights.add(light);
        shadowCameraDirection.set(direction);
    }
}

From source file:com.nsoft.boxuniverse.world.BaseWorld.java

License:Open Source License

public BaseWorld(WorldDefinition def, boolean needGeneration) {

    this.def = def;
    layers = new Layer[def.NumLayers];

    batch = new SpriteBatch();
    background = new Texture(def.BackGroundPath);

    b = new ModelBatch();
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0, 0, 10);//from  ww w  .j a v a2s  .c o  m
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    e = new Environment();
    e.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    e.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    for (int i = 0; i < layers.length; i++) {

        layers[i] = new Layer(i, needGeneration);
    }

    // debug();
}

From source file:com.qualcomm.vuforia.samples.libGDX.screens.ChooseBallScreen.java

License:Apache License

@Override
public void create() {
    if (app.createServerScreen.create != null) {
        app.createServerScreen.create.resetUserChoiceState();
        app.createServerScreen.create.startBallsDistribute();
    } else if (app.joinServerScreen.join != null) {
        PropertiesSingleton.getInstance()
                .initRandomCoinPosition(PropertiesSingleton.getInstance().getChosenIsland());
        //PropertiesSingleton.getInstance().initRandomPowerupPosition(PropertiesSingleton.getInstance().getChosenIsland());
    }/*from  ww w  .j a  v a2 s.  c o  m*/

    modelBatch = new ModelBatch();

    fps = new FPSLogger();
    Gdx.app.log("height: " + Gdx.graphics.getHeight() + "", "width: " + Gdx.graphics.getWidth() + "");

    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));
    environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f,
            0.8f, -1f, -.8f, -.2f));
    environment.shadowMap = shadowLight;

    shadowBatch = new ModelBatch(new DepthShaderProvider());

    cam = new VuforiaCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    instances = new Array<ModelInstance>();
    //       instances.add(new ModelInstance(model, "floor"));
    //        instances.add(ball = new Ball(model, "ball"));
    //        ball.setPosition(1f, 1f, 1f);

    this.stage = new Stage(new StretchViewport(Gdx.graphics.getHeight(), Gdx.graphics.getHeight()));

    initFonts();
    //        BitmapFont font = new BitmapFont();
    Label.LabelStyle labelStyle = new Label.LabelStyle(app.font60, Color.WHITE);
    Label.LabelStyle labelStyle2 = new Label.LabelStyle(app.font60, Color.WHITE);
    Label labelTitle = new Label("CHOOSE BALL ", labelStyle);
    LabelScore = new Label("apple", labelStyle2);
    //        labelTitle.setScale(Gdx.graphics.getWidth() / 10, Gdx.graphics.getHeight() / 10);
    Gdx.app.log("width: " + Gdx.graphics.getWidth(), "height: " + Gdx.graphics.getHeight());
    labelTitle.setPosition(Gdx.graphics.getHeight() / 2 - labelTitle.getWidth() / 2,
            Gdx.graphics.getHeight() - labelTitle.getHeight() * 2);

    LabelScore.setPosition(Gdx.graphics.getHeight() - (LabelScore.getWidth() + Gdx.graphics.getHeight() / 50),
            LabelScore.getHeight() / 2);

    swipe = new Image(new Sprite(new Texture(Gdx.files.internal("swipe2.png"))));
    swipe.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1)));
    //        swipe.setSize((stage.getWidth()) / 6, stage.getHeight() / 6);
    swipe.setPosition(Gdx.graphics.getHeight() / 2 - swipe.getWidth() / 2,
            Gdx.graphics.getHeight() / 2 - swipe.getHeight() / 2);
    stage.addActor(swipe);

    accept = new Image(new Sprite(new Texture(Gdx.files.internal("accept.png"))));
    //        accept.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1)));
    accept.setSize((stage.getWidth()) / 10, stage.getWidth() / 10);
    accept.setPosition(Gdx.graphics.getHeight() / 2 - accept.getWidth() / 2, accept.getHeight());
    //        stage.addActor(accept);

    stage.addActor(LabelScore);
    stage.addActor(labelTitle);

    TextureAtlas atlasVote = new TextureAtlas("Buttons.pack");

    Skin voteSkin = new Skin(atlasVote);

    ImageButton.ImageButtonStyle voteButtonStyle = new ImageButton.ImageButtonStyle(); //Instaciate
    voteButtonStyle.up = voteSkin.getDrawable("ready"); //Set image for not pressed button
    voteButtonStyle.checked = voteSkin.getDrawable("notready"); //Set image for not pressed button

    readyButton = new ImageButton(voteButtonStyle);

    readyButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (app.joinServerScreen.join != null) {
                app.joinServerScreen.join.sendBallChoice(ballNames.get(currentBall));
            } else if (app.createServerScreen.create != null) {
                app.createServerScreen.create.serverUser.setBallChoice(ballNames.get(currentBall));
                app.createServerScreen.create.serverUser.setChosen(true);
                app.createServerScreen.create.notifyBalls();
            }
        }
    });

    readyButton.setSize((stage.getWidth()) / 5, stage.getWidth() / 10);

    readyButton.setPosition(Gdx.graphics.getHeight() / 2 - readyButton.getWidth() / 2, 0);
    stage.addActor(readyButton);

    for (int i = 0; i < ballNames.size; i++) {
        Model tmpModel = assets.get("3d/balls/" + ballNames.get(i) + ".g3db", Model.class);

        for (int k = 0; k < tmpModel.meshes.size; k++)
            tmpModel.meshes.get(k).scale(5, 5, 5);
        //            String id = tmpModel.nodes.get(0).id;
        //            Node node = tmpModel.getNode(id);
        //            node.scale.set(30f, 30f, 30f);
        //            node.translation.set(0, 15f, 0);
        //            tmpModel.calculateTransforms();
        instances.add(new ModelInstance(tmpModel));
    }

    InputMultiplexer inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(stage);
    inputMultiplexer.addProcessor(new GestureDetector(0.0f, 0.0f, 0.0f, 5f, this));
    Gdx.input.setInputProcessor(inputMultiplexer);
}

From source file:com.shirleydean.panicflower.PFGame.java

License:Apache License

@Override
public void create() {
    //       setUpperText("To my deanest Shirley");
    //       setUpperText("To whom it may concern!");
    //       setLowerText("Happy Valentines Day!");

    batch = new SpriteBatch();
    font = new BitmapFont();
    font.setColor(Color.RED);//from w  ww  . j ava 2  s . co m

    modelBatch = new ModelBatch();
    environment = new Environment();

    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 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(0.0001f, 2f, 0.0001f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    assets = new AssetManager();
    assets.load(modelName, Model.class);
    loading = true;
}

From source file:graphics.CargoSpace3D.java

License:Apache License

@Override
public void create() {
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    modelBatch = new ModelBatch();

    cam = new PerspectiveCamera(100, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);//  w w  w .  j a v a2  s  . c  o m
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    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);

    ModelBuilder modelBuilder = new ModelBuilder();
    MeshPartBuilder builder;

    List<Model> models = new ArrayList<Model>();
    instances = new ArrayList<ModelInstance>();

    for (float x = GRID_MIN; x <= GRID_MAX_Y; x += 1) {
        for (float y = GRID_MIN; y <= GRID_MAX_X; y += 1) {
            for (float z = GRID_MIN; z <= GRID_MAX_Z; z += 1) {

                if (cargoSpace.getCargoSpace()[(int) x][(int) y][(int) z] != 0) {
                    if (cargoSpace.getCargoSpace()[(int) x][(int) y][(int) z] == 1) {
                        drawCargoCube(modelBuilder, models, x, y, z, new Color(0.6f, .7f, .7f, 0));
                    }
                    if (cargoSpace.getCargoSpace()[(int) x][(int) y][(int) z] == 2) {
                        drawCargoCube(modelBuilder, models, x, y, z, new Color(0.3f, .7f, .9f, 0));
                    }
                    if (cargoSpace.getCargoSpace()[(int) x][(int) y][(int) z] == 3) {
                        drawCargoCube(modelBuilder, models, x, y, z, new Color(0.9f, .4f, .2f, 0));
                    }

                }
            }
        }
    }
    System.out.println("Done");

}