Example usage for com.badlogic.gdx.math Matrix4 Matrix4

List of usage examples for com.badlogic.gdx.math Matrix4 Matrix4

Introduction

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

Prototype

public Matrix4(Quaternion quaternion) 

Source Link

Document

Constructs a rotation matrix from the given Quaternion .

Usage

From source file:airfoil.etc.Controller.java

License:Open Source License

public Controller(Viewport viewport) {
    super();/*from   w  w w  . ja  va  2  s.  c  o m*/
    this.width = (int) viewport.width;
    this.height = (int) viewport.height;
    this.orientation = new Matrix4(new Quaternion(XA, 180));
}

From source file:airfoil.etc.Controller.java

License:Open Source License

@Override
public boolean touchDragged(int x, int y, int pointer) {

    final Vector3 delta;

    if (this.button) {

        delta = new Vector3(x, y, 0).sub(this.last).mul(0.5f);

        this.last.set(x, y, 0);
    } else {//  w  ww  .j  ava 2 s  .  co m

        delta = new Vector3(0, x, y).sub(this.last).mul(0.5f);

        this.last.set(0, x, y);
    }

    final Quaternion rotation;

    if (this.button) {

        rotation = new Quaternion(YA, -delta.x).mul(new Quaternion(YA, delta.y));
    } else {

        rotation = new Quaternion(ZA, delta.z).mul(new Quaternion(ZA, -delta.y));
    }

    this.rotation.mul(new Matrix4(rotation));

    this.reinit();

    return true;
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.gameManager.GameLoop.java

License:Open Source License

/**
 * Launch the creation of the batch thanks to the camera. if debug == true,
 * set up the debugger matrix// www  .ja  v  a  2s  . c  o  m
 * 
 * @param cam    : the OrthographicCamera of the game
 * @param debug : load the debugging matrix
 * 
 * GameLoop(OrthographicCamera cam, boolean debug)
 */
public GameLoop(final OrthographicCamera cam, final boolean debug) {

    // creation of the batch and matrix (physical edges of the bodies)
    // debugger
    batch = new SpriteBatch();
    batch.setProjectionMatrix(cam.combined);

    if (debug) {
        debugMatrix = new Matrix4(cam.combined);
        debugMatrix.scale(GraphicManager.getGameToWorld(), GraphicManager.getGameToWorld(), 1f);

        debugRenderer = new Box2DDebugRenderer();
    }

    // Create only once the graphicManager
    graphicManager = new GraphicManager();

    // Load the font
    fontOswald = new BitmapFont(Gdx.files.internal("fonts/Oswald/Oswald.fnt"),
            Gdx.files.internal("fonts/Oswald/Oswald.png"), false);
    fontOsaka = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"),
            Gdx.files.internal("fonts/Osaka/Osaka.png"), false);

    fontOsakaRed = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"),
            Gdx.files.internal("fonts/Osaka/Osaka.png"), false);
    fontOsakaRed.setColor(.95f, .05f, .05f, 1f);

    // Pause
    if (GlobalSettings.GAME.isGdxMenus()) {
        fontPause = new BitmapFont(Gdx.files.internal("fonts/OsakaBig/OsakaBig.fnt"),
                Gdx.files.internal("fonts/OsakaBig/OsakaBig.png"), false);
        fontPause.setColor(.95f, .05f, .05f, 1f);
        texturePause = new Texture("buttons/home_button.png");
        pixmapFade = new Pixmap(1, 1, Format.RGB888);
        spriteFade = new Sprite(new Texture(pixmapFade));
        spriteFade.setColor(0, 0, 0, 0);
        spriteFade.setSize(GlobalSettings.APPWIDTH * 2, GlobalSettings.APPHEIGHT * 2); // bigger size to cover all the zone
        spriteFade.setPosition(-GlobalSettings.APPWIDTH / 2, -GlobalSettings.APPHEIGHT / 2);
    }

    // load the counter
    countDown = new CountDown(2, 2, 1f, "anim/countdown.png", true); // 3 sec

    // new randomGenerator
    random = new Random();
}

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

License:Apache License

public void onDrawEye(Eye paramEye) {

    Gdx.gl.glClearColor(BACKGROUND_COLOR.r, BACKGROUND_COLOR.g, BACKGROUND_COLOR.b, BACKGROUND_COLOR.a);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    camera.setEyeViewAdjustMatrix(new Matrix4(paramEye.getEyeView()));
    float[] perspective = paramEye.getPerspective(Z_NEAR, Z_FAR);
    camera.setEyeProjection(new Matrix4(perspective));
    camera.update();//from   w  ww  .  ja v  a2s .  c om

    game.modelBatch.begin(camera);
    game.modelBatch.render(instances, environment);
    game.modelBatch.end();

    game.spriteBatch.begin();
    if (showTarget)
        game.spriteBatch.draw(target, (Gdx.graphics.getWidth() - target.getWidth()) / 2,
                (Gdx.graphics.getHeight() - target.getHeight()) / 2);
    if (visibleUI) {
        score.draw(game.spriteBatch, HudUtils.formattedScore(scoreValue),
                (Gdx.graphics.getWidth()
                        - (score.getSpaceWidth() * HudUtils.formattedScore(scoreValue).length())) / 2,
                Gdx.graphics.getHeight() - MARGIN_SCREEN);
        if (life.size() > 0) {
            int size = (life.size() * life.get(0).getWidth()) + ((life.size() - 1) * MARGIN_HEART);
            float center = (Gdx.graphics.getWidth() - size) / 2;
            for (int i = 0; i < life.size(); i++) {
                Texture item = life.get(i);
                game.spriteBatch.draw(item, center + ((item.getWidth() + MARGIN_HEART) * i), MARGIN_SCREEN);
            }
        }
    }
    renderSprite(Gdx.graphics.getDeltaTime());
    game.spriteBatch.end();
    if (endFade.isPlaying)
        endFade.shows(Gdx.graphics.getDeltaTime());
    if (laser.isPlaying)
        laser.shows(Gdx.graphics.getDeltaTime());
}

From source file:CB_UI_Base.graphics.GL_Matrix.java

License:Open Source License

public GL_Matrix(ext_Matrix matrix) {
    if (matrix == null) {
        matrix4 = new Matrix4(DEFAULT);
    } else {//  w ww . j  av  a  2  s  . com
        if (((GL_Matrix) matrix).matrix4 == null) {
            matrix4 = new Matrix4(DEFAULT);
        } else {
            matrix4 = new Matrix4(((GL_Matrix) matrix).matrix4);
        }
    }
}

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

License:Apache License

public Maze2Drenderer(TiledMap tm, Physics2D physics) {
    font = new BitmapFont();
    this.physics = physics;
    renderer = new Box2DDebugRenderer();
    ballLoc = new Vector2();
    map = tm;//  w w w .j a  va 2  s . co  m

    camera = new OrthographicCamera(Assets.VIRTUAL_SCREEN_WIDTH, Assets.VIRTUAL_SCREEN_HEIGHT);
    camera.position.set(Assets.VIRTUAL_SCREEN_WIDTH / 2f, Assets.VIRTUAL_SCREEN_HEIGHT / 2f, 0);
    camera.update();

    //Load Marble Sprite
    marbleSprite = new Sprite(Assets.marble);
    marbleSprite.setBounds(0, 0, 16, 16);

    tilerender = new OrthogonalTiledMapRenderer(map);

    //createFixtures(Assets.mazemap);

    debugProj = new Matrix4(camera.combined);
    debugProj.scale(Assets.PIXELS_PER_METER, Assets.PIXELS_PER_METER, 1);
    batcher = new SpriteBatch();

    batcher.setProjectionMatrix(camera.combined);
    batcher.enableBlending();

    tilerender.setView(camera);

}

From source file:com.cyphercove.lwptools.core.GaussianBlur.java

License:Apache License

/**
 * Set the normalized depth that the texture is rendered at if depthTestingToScene it true.
 *//*from   w ww  .j ava  2s .co  m*/
public void setTextureToSceneDepth(float depth) {
    OrthographicCamera tempCam = new OrthographicCamera(2, 2);
    tempCam.position.set(0, 0, depth);
    tempCam.near = 0;
    tempCam.far = 1;
    tempCam.update();
    fboToSceneProjectionMatrix = new Matrix4(tempCam.combined);
    tempCam.up.set(1, 0, 0);
    tempCam.update();
    fboToSceneProjectionMatrixRight = new Matrix4(tempCam.combined);
    tempCam.up.set(-1, 0, 0);
    tempCam.update();
    fboToSceneProjectionMatrixLeft = new Matrix4(tempCam.combined);

}

From source file:com.mbrlabs.mundus.commons.scene3d.SimpleNode.java

License:Apache License

/**
 * Copy construction/* w w  w.  j av  a  2s  .  c o  m*/
 * 
 * @param simpleNode
 * @param id
 */
public SimpleNode(SimpleNode simpleNode, int id) {
    super(id);
    this.localPosition = new Vector3(simpleNode.localPosition);
    this.localRotation = new Quaternion(simpleNode.localRotation);
    this.localScale = new Vector3(simpleNode.localScale);
    this.combined = new Matrix4(simpleNode.combined);
}

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

License:Apache License

private void setRigidBody(BlenderEmpty blenderEmpty, Model model, Vector3 scale) {
    this.shapeType = blenderEmpty.custom_properties.get(blenderCollisionShapeField);
    this.mass = Float.parseFloat(blenderEmpty.custom_properties.get(blenderMassField));

    tmpScale.set(blenderEmpty.scale.x * scale.x, blenderEmpty.scale.y * scale.y,
            blenderEmpty.scale.z * scale.z);

    if (shapeType.equals("capsule")) {
        float radius = Math.max(tmpScale.x, tmpScale.z);
        shape = new btCapsuleShape(radius, scale.y);

    } else if (shapeType.equals("sphere")) {
        float radius = Math.max(Math.max(tmpScale.x, tmpScale.y), tmpScale.z);
        shape = new btSphereShape(radius);

    } else if (shapeType.equals("box")) {
        shape = new btBoxShape(tmpScale);

    } else if (shapeType.equals("convex_hull")) {
        // We need a model instance with the correct scale
        ModelInstance modelInstance = new ModelInstance(model);
        GameModel.applyTransform(position, rotation, scale, modelInstance);
        // Copy the vertices to a work buffer, where we apply the model global transform to them
        Matrix4 transform = new Matrix4(modelInstance.nodes.get(0).globalTransform);
        Mesh mesh = modelInstance.model.meshes.get(0);
        FloatBuffer workBuffer = BufferUtils.newFloatBuffer(mesh.getVerticesBuffer().capacity());
        BufferUtils.copy(mesh.getVerticesBuffer(), workBuffer,
                mesh.getNumVertices() * mesh.getVertexSize() / 4);
        BufferUtils.transform(workBuffer, 3, mesh.getVertexSize(), mesh.getNumVertices(), transform);

        // First create a shape using all the vertices, then use the built in tool to reduce
        // the number of vertices to a manageable amount.
        btConvexShape convexShape = new btConvexHullShape(workBuffer, mesh.getNumVertices(),
                mesh.getVertexSize());/*from  w w w  . ja  v  a 2  s . co m*/
        btShapeHull hull = new btShapeHull(convexShape);
        hull.buildHull(convexShape.getMargin());
        shape = new btConvexHullShape(hull);
        convexShape.dispose();
        hull.dispose();

    } else if (shapeType.equals("none")) {
        shape = null;

    } else {
        throw new GdxRuntimeException("Cannot load collision shape data for " + blenderEmpty.name + " from '"
                + blenderEmpty.name + "'");
    }
    setCollisionFlags(this.mass);
}

From source file:com.qualcomm.vuforia.samples.Vuforia.VuforiaCamera.java

License:Apache License

@Override
public void update(boolean updateFrustum) {
    float aspect = viewportWidth / viewportHeight;

    float[] ViewMatrix = DataHolder.getInstance().getData();
    float[] ProjMatrix = DataHolder.getInstance().getData2();

    if (ViewMatrix != null && ProjMatrix != null) {

        Matrix4 temp = new Matrix4(ViewMatrix.clone());
        Matrix4 temp2 = new Matrix4(ProjMatrix.clone());

        temp.rotate(1, 0, 0, 90);//from  ww w.  j a v  a 2 s .c o  m

        projection.set(temp2);
        view.set(temp);

        //            projection.setToProjection(Math.abs(near), Math.abs(far), fieldOfView, aspect);
        //            view.setToLookAt(position, tmp.set(position).add(direction), up);

        combined.set(projection);
        Matrix4.mul(combined.val, view.val);

        if (updateFrustum) {
            invProjectionView.set(combined);
            Matrix4.inv(invProjectionView.val);
            frustum.update(invProjectionView);
        }

    }

}