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

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

Introduction

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

Prototype

public Vector3 prj(final Matrix4 matrix) 

Source Link

Document

Multiplies this vector by the given matrix dividing by w, assuming the fourth (w) component of the vector is 1.

Usage

From source file:com.bladecoder.engine.model.Sprite3DRenderer.java

License:Apache License

@Override
public void draw(SpriteBatch batch, float x, float y, float scale) {

    x = x - getWidth() / 2 * scale;//  ww w.  ja va2 s  . c  o m

    if (USE_FBO) {
        batch.draw(tex, x, y, 0, 0, width, height, scale, scale, 0);
    } else {
        float p0x, p0y, pfx, pfy;

        Vector3 tmp = new Vector3(); // TODO Make static for performance?
        updateViewport();

        // get screen coords for x and y
        tmp.set(x, y, 0);

        tmp.mul(batch.getTransformMatrix());
        tmp.prj(batch.getProjectionMatrix());
        p0x = VIEWPORT.width * (tmp.x + 1) / 2;
        p0y = VIEWPORT.height * (tmp.y + 1) / 2;

        tmp.set(x + width * scale, y + height * scale, 0);
        tmp.mul(batch.getTransformMatrix());
        tmp.prj(batch.getProjectionMatrix());
        pfx = VIEWPORT.width * (tmp.x + 1) / 2;
        pfy = VIEWPORT.height * (tmp.y + 1) / 2;

        batch.end();

        Gdx.gl20.glViewport((int) (p0x + VIEWPORT.x), (int) (p0y + VIEWPORT.y), (int) (pfx - p0x),
                (int) (pfy - p0y));

        Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT
                | (Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0));

        drawModel();

        Gdx.gl20.glViewport((int) VIEWPORT.x, (int) VIEWPORT.y, (int) VIEWPORT.width, (int) VIEWPORT.height);
        batch.begin();
    }
}

From source file:com.bladecoder.engineeditor.scneditor.ScnWidget.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();//from w  ww.  j a  va2  s .  com

    Color tmp = batch.getColor();
    batch.setColor(Color.WHITE);

    if (scn != null && !loading && !loadingError) {
        // BACKGROUND
        batch.disableBlending();
        tile.draw(batch, getX(), getY(), getWidth(), getHeight());
        batch.enableBlending();

        Vector3 v = new Vector3(getX(), getY(), 0);
        v = v.prj(batch.getTransformMatrix());

        batch.end();

        HdpiUtils.glViewport((int) v.x, (int) v.y, (int) getWidth(), (int) (getHeight()));

        getStage().calculateScissors(bounds, scissors);

        if (ScissorStack.pushScissors(scissors)) {
            // WORLD CAMERA
            sceneBatch.setProjectionMatrix(camera.combined);
            sceneBatch.begin();

            Array<AtlasRegion> scnBackground = scn.getBackground();

            if (scnBackground != null) {
                sceneBatch.disableBlending();

                float x = 0;

                for (AtlasRegion tile : scnBackground) {
                    sceneBatch.draw(tile, x, 0f);
                    x += tile.getRegionWidth();
                }

                sceneBatch.enableBlending();
            }

            // draw layers from bottom to top
            List<SceneLayer> layers = scn.getLayers();
            for (int i = layers.size() - 1; i >= 0; i--) {
                SceneLayer layer = layers.get(i);

                if (!layer.isVisible())
                    continue;

                List<InteractiveActor> actors = layer.getActors();

                for (InteractiveActor a : actors) {
                    if (a instanceof SpriteActor) {
                        boolean visibility = a.isVisible();
                        a.setVisible(true);
                        ((SpriteActor) a).draw(sceneBatch);
                        a.setVisible(visibility);
                    }
                }
            }

            sceneBatch.end();
            ScissorStack.popScissors();
        }

        drawer.drawBGBounds();

        if (showWalkZone && scn.getPolygonalNavGraph() != null) {
            drawer.drawBBoxWalkZone(scn, false);

            drawer.drawPolygonVertices(scn.getPolygonalNavGraph().getWalkZone(), Color.GREEN);
        }

        drawer.drawBBoxActors(scn);

        if (selectedActor != null) {
            drawer.drawSelectedActor(selectedActor);
        }

        getStage().getViewport().apply();

        // SCREEN CAMERA
        batch.begin();

        drawFakeDepthMarkers((SpriteBatch) batch);

        if (!inScene) {
            faRenderer.draw((SpriteBatch) batch);
        }

        // DRAW COORDS
        Vector2 coords = new Vector2(Gdx.input.getX(), Gdx.input.getY());
        screenToWorldCoords(coords);
        String str = MessageFormat.format("({0}, {1})", (int) coords.x, (int) coords.y);

        textLayout.setText(defaultFont, str);

        RectangleRenderer.draw((SpriteBatch) batch, 0f, getY() + getHeight() - textLayout.height - 15,
                textLayout.width + 10, textLayout.height + 10, BLACK_TRANSPARENT);
        defaultFont.draw(batch, textLayout, 5, getHeight() + getY() - 10);

        batch.setColor(tmp);

    } else {
        background.draw(batch, getX(), getY(), getWidth(), getHeight());

        String s;

        if (loading) {
            s = "LOADING...";

            try {
                if (!EngineAssetManager.getInstance().isLoading()) {
                    loading = false;

                    scn.retrieveAssets();

                    drawer.setCamera(camera);

                    invalidate();
                }
            } catch (Exception e) {
                Message.showMsg(getStage(), "Could not load assets for scene", 4);
                e.printStackTrace();
                loadingError = true;
                loading = false;
            }

        } else if (loadingError) {
            s = "ERROR IN SCENE DATA. CANNOT DISPLAY SCENE";
        } else if (Ctx.project.getProjectDir() == null) {
            s = "CREATE OR LOAD A PROJECT";
        } else {
            s = "THERE ARE NO SCENES IN THIS CHAPTER YET";
        }

        textLayout.setText(bigFont, s);

        bigFont.draw(batch, textLayout, (getWidth() - textLayout.width) / 2,
                getHeight() / 2 + bigFont.getLineHeight() * 3);

    }

}