Example usage for com.badlogic.gdx.math Vector3 X

List of usage examples for com.badlogic.gdx.math Vector3 X

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector3 X.

Prototype

Vector3 X

To view the source code for com.badlogic.gdx.math Vector3 X.

Click Source Link

Usage

From source file:br.com.abby.linear.OrientedBoundingBox.java

License:Apache License

public void rotateX(float angle) {
    transform.rotate(Vector3.X.mul(transform), angle);
}

From source file:com.badlogic.gdx.tests.dragome.examples.GearsDemo.java

@Override
public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);//from  w  ww. ja  va  2  s .c  om
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    cam.update();

    if (modelBatch != null) {
        angle += 1.0f;

        gear1.transform.setToTranslation(-3.0f, -2.0f, 0.0f);
        gear2.transform.setToTranslation(3.1f, -2.0f, 0.0f);
        gear3.transform.setToTranslation(-3.1f, 4.2f, 0.0f);
        gear1.transform.rotate(Vector3.Z, angle);
        gear2.transform.rotate(Vector3.Z, -2.0f * angle - 9.0f);
        gear3.transform.rotate(Vector3.Z, -2.0f * angle - 25.0f);

        final float delta = Gdx.graphics.getDeltaTime();

        sl.position.sub(transformedCenter);
        sl.position.rotate(Vector3.X, delta * 50f);
        sl.position.rotate(Vector3.Y, delta * 13f);
        sl.position.rotate(Vector3.Z, delta * 3f);
        sl.position.add(transformedCenter.set(center).mul(transform));

        modelBatch.begin(cam);
        modelBatch.render(gear1, environment);
        modelBatch.render(gear2, environment);
        modelBatch.render(gear3, environment);
        pLight.worldTransform.setTranslation(sl.position);
        modelBatch.render(pLight);
        modelBatch.end();

        float timeSec = TimeUtils.millis() - time;

        if (timeSec > 1000) {
            time = TimeUtils.millis();
            fps = Gdx.graphics.getFramesPerSecond();
        }
        batch.begin();
        font.draw(batch, "FPS: " + fps, 15, Gdx.graphics.getHeight() - 15);
        batch.end();
    }
}

From source file:com.cyphercove.doublehelix.MainRenderer.java

License:Apache License

@Override
public void draw(float deltaTime, float xOffsetFake, float xOffsetLooping, float xOffsetSmooth, float yOffset) {
    deltaTime = Math.min(deltaTime, MAX_FRAME_TIME);
    if (screenshotPause)
        deltaTime = 0;/*ww w .  j  a v  a 2  s.c o  m*/

    float _xOffset = isPreview ? 0.5f
            : (Settings.pseudoScrolling ? xOffsetFake
                    : (Settings.smoothScrolling ? xOffsetSmooth : xOffsetLooping));

    GL20 gl = Gdx.gl;

    if (!firstFrameDrawn) {
        gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        gl.glClearColor(0, 0, 0, 1);
        gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
        firstFrameDrawn = true;
        return;
    }

    if (needFinishCreate) {
        finishCreate();
        //film grain wasn't created til now so need to initialize its size
        filmGrain.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        filmGrainForBloom.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    }

    if (settingsAdapter != null)
        settingsAdapter.updateInLoop(deltaTime);

    //UPDATES
    Texture.TextureFilter particleMinFilter = Settings.trilinearParticles
            ? Texture.TextureFilter.MipMapLinearLinear
            : Texture.TextureFilter.MipMapLinearNearest;
    particleATexture.setFilter(particleMinFilter, Texture.TextureFilter.Linear);
    particlePointTexture.setFilter(particleMinFilter, Texture.TextureFilter.Linear);

    mainHelixTransformManager.localEulers.z += deltaTime * MAIN_HELIX_ROTATION_DPS * Settings.speed;
    mainHelixTransformManager.apply();
    rearHelixTransformManager.localEulers.z += deltaTime * 0.5f * MAIN_HELIX_ROTATION_DPS * Settings.speed;
    rearHelixTransformManager.apply();

    cam.up.set(0, 1, 0);
    cam.direction.set(0, 0, -1);
    cam.rotate(-41.998f, 1, 0, 0);
    cam.rotate(146.964f, 0, 1, 0);
    cam.rotate(18.503f, 0, 0, 1);

    camPosition.set(0.45617f, 4.11359f, 0.14467f); //set it here and reapply when needed.
    if (cam.viewportWidth > cam.viewportHeight) {//landscape
        camPosition.rotate(Vector3.Z, -(_xOffset - 0.5f) * 47.5f - 15.0f);
    } else {//portrait
        camPosition.rotate(Vector3.Z, -(_xOffset - 0.5f) * 65f);
    }
    cam.position.set(camPosition); //temporarily apply it to get correct direction with lookAt
    cam.lookAt(-.4703f, 0f, 3.5032f);

    sssShader.lightDirection.set(1, 0, 0).rotate(Vector3.Y, lightH).rotate(Vector3.X, lightV);

    particles.update(deltaTime, sssShader.lightDirection); //MUST BE DONE WHILE CAM IS IN POSITION

    backgroundShader.color.set(Settings.backgroundColor);

    //BLOOM SURFACE DRAWING
    if (Settings.bloom) {
        bloom.begin();
        cam.position.set(0, 0, 0);
        cam.update();
        modelBatch.begin(cam);
        modelBatch.render(backgroundBloomModelInstance, unlitShader);
        modelBatch.end();

        cam.position.set(camPosition);
        cam.update();
        modelBatch.begin(cam);
        modelBatch.render(mainHelixModelInstance, blackShader);
        modelBatch.render(rearHelixModelInstance, blackShader);
        modelBatch.end();

        bloom.end();
    }

    //BLUR SURFACE DRAWING
    if (Settings.dof) {
        rearDOFBlur.setClearColor(tmpColor.set(Settings.backgroundColor).mul(AMBIENT_BRIGHTNESS));
        rearDOFBlur.begin();
        modelBatch.begin(cam);
        modelBatch.render(backgroundModelInstance, backgroundShader);
        modelBatch.end();

        cam.position.set(camPosition);
        cam.update();

        sssShader.setShouldFadeEnds(true);
        modelBatch.begin(cam);
        modelBatch.render(rearHelixModelInstance, sssShader);
        modelBatch.end();
        rearDOFBlur.end();
    }

    //MAIN DRAWING
    Gdx.gl.glClearColor(Settings.backgroundColor.r, Settings.backgroundColor.g, Settings.backgroundColor.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    if (Settings.dof) {
        rearDOFBlur.render();
    } else {
        modelBatch.begin(cam);
        modelBatch.render(backgroundModelInstance, backgroundShader);
        modelBatch.end();
    }

    cam.position.set(camPosition);
    cam.update();

    sssShader.setShouldFadeEnds(false);
    modelBatch.begin(cam);
    modelBatch.render(mainHelixModelInstance, sssShader);
    modelBatch.end();

    if (!Settings.dof) {
        sssShader.setShouldFadeEnds(true);
        modelBatch.begin(cam);
        modelBatch.render(rearHelixModelInstance, sssShader);
        modelBatch.end();
    }

    boolean doFilmGrain = Settings.filmGrain || Settings.scanLines || Settings.vignette;

    if (Settings.bloom) {
        if (doFilmGrain) {
            bloom.setCustomShaderPreparer(filmGrainForBloom);
            bloom.render(filmGrainForBloom.filmGrainShaderProgram);
        } else {
            bloom.setCustomShaderPreparer(null);
            bloom.render(bloomShaderProgram);
        }
    } else if (doFilmGrain) {
        filmGrain.render();
    }

    particles.draw(decalBatch, billboardDecalBatch);

    fader.render(deltaTime);
}

From source file:com.cyphercove.doublehelix.TransformManager.java

License:Apache License

public void apply() {
    modelInstance.transform.idt().translate(position).rotate(Vector3.X, eulers.x).rotate(Vector3.Y, eulers.y)
            .rotate(Vector3.Z, eulers.z);
    tmp.idt().rotate(Vector3.X, localEulers.x).rotate(Vector3.Y, localEulers.y).rotate(Vector3.Z,
            localEulers.z);// w  ww. ja  va  2 s .c  om
    modelInstance.transform.mul(tmp);
}

From source file:com.mygdx.game.objects.GameModel.java

License:Apache License

public static void applyTransform(Vector3 location, Vector3 rotation, Vector3 scale,
        ModelInstance modelInstance) {//from   w  w w .j  av  a  2s . c o m
    for (Node node : modelInstance.nodes) {
        node.scale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
    }
    modelInstance.transform.rotate(Vector3.X, rotation.x);
    modelInstance.transform.rotate(Vector3.Z, rotation.z);
    modelInstance.transform.rotate(Vector3.Y, rotation.y);
    modelInstance.transform.setTranslation(location);

    modelInstance.calculateTransforms();
}

From source file:com.mygdx.game.objects.InvisibleBody.java

License:Apache License

public InvisibleBody(String id, btCollisionShape shape, float mass, Vector3 location, Vector3 rotation,
        short belongsToFlag, short collidesWithFlag, boolean callback, boolean noDeactivate) {
    this(id, shape, mass,
            new Matrix4().rotate(Vector3.X, rotation.x).rotate(Vector3.Z, rotation.z)
                    .rotate(Vector3.Y, rotation.y).setTranslation(location),
            belongsToFlag, collidesWithFlag, callback, noDeactivate);
}

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

License:Apache License

private GameObject spawnFromBlueprint(GameObjectBlueprint bp) {
    if (bp.pfx != null) {
        ParticleEffect originalEffect = assets.getAsset(bp.pfx, ParticleEffect.class);
        // we cannot use the originalEffect, we must make a copy each time we create new particle effect
        ParticleEffect effect = originalEffect.copy();
        particleEffects.add(effect);/*from   w w w.j  a v  a 2s.  c o m*/
        effect.translate(bp.position);
        effect.rotate(Vector3.X, 180);
        effect.init();
        effect.start();
        ParticleSystem particleSystem = ParticleSystem.get();
        particleSystem.add(effect);
        return null;
    }
    if (bp.model != null && bp.shape != null) {

        return spawnGameModelBody(bp, bp.position);

    } else if (bp.model == null && bp.shape != null) {
        InvisibleBody obj = new InvisibleBody(bp.name, bp.shape, bp.mass, bp.position, bp.rotation,
                bp.belongsToFlag, bp.collidesWithFlag, bp.callback, bp.noDeactivate);
        addGameObject(obj);
        return obj;

    } else if (bp.model != null) {
        GameModel obj = new GameModel(bp.model, bp.name, bp.position, bp.rotation, bp.scale);
        obj.visibleOnLayers.clear();
        obj.visibleOnLayers.or(bp.visibleOnLayers);
        addGameObject(obj);
        return obj;
    } else {
        throw new GdxRuntimeException("Could not read blueprint " + bp);
    }
}

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);//ww w  .  j a 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.mygdx.game.scene.GameScene.java

License:Apache License

public void setToSceneCamera(GhostCamera camera) {
    Vector3 direction = new Vector3(V3_DOWN);
    direction.rotate(Vector3.X, sceneCamera.rotation.x);
    direction.rotate(Vector3.Z, sceneCamera.rotation.z);
    direction.rotate(Vector3.Y, sceneCamera.rotation.y);
    direction.nor();//from w  w  w.  jav  a  2 s .c  o  m

    camera.fieldOfView = sceneCamera.fov;
    camera.targetPosition.set(sceneCamera.position);
    camera.targetDirection.set(direction);
    camera.targetUp.set(Vector3.Y);
    camera.snapToTarget();
    camera.update();
}

From source file:com.mygdx.game.utilities.ModelFactory.java

License:Apache License

public static Model buildCompassModel() {
    float compassScale = 5;
    ModelBuilder modelBuilder = new ModelBuilder();
    Model arrow = modelBuilder.createArrow(Vector3.Zero, Vector3.Y.cpy().scl(compassScale), null,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    modelBuilder.begin();//  w w w  .  j  a  v a 2  s .c o m

    Mesh zArrow = arrow.meshes.first().copy(false);
    zArrow.transform(new Matrix4().rotate(Vector3.X, 90));
    modelBuilder.part("part1", zArrow, GL20.GL_TRIANGLES,
            new Material(ColorAttribute.createDiffuse(Color.BLUE)));

    modelBuilder.node();
    Mesh yArrow = arrow.meshes.first().copy(false);
    modelBuilder.part("part2", yArrow, GL20.GL_TRIANGLES,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)));

    modelBuilder.node();
    Mesh xArrow = arrow.meshes.first().copy(false);
    xArrow.transform(new Matrix4().rotate(Vector3.Z, -90));
    modelBuilder.part("part3", xArrow, GL20.GL_TRIANGLES,
            new Material(ColorAttribute.createDiffuse(Color.RED)));

    arrow.dispose();
    return modelBuilder.end();
}