com.badlogic.gdx.math.Matrix4 Java Examples
The following examples show how to use
com.badlogic.gdx.math.Matrix4.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RayHandler.java From uracer-kotd with Apache License 2.0 | 6 votes |
/** * Set combined camera matrix. Matrix will be copied and used for rendering * lights, culling. Matrix must be set to work in box2d coordinates. Matrix * has to be updated every frame(if camera is changed) * * * NOTE: Matrix4 is assumed to be orthogonal for culling and directional * lights. * * If any problems detected Use: [public void setCombinedMatrix(Matrix4 * combined, float x, float y, float viewPortWidth, float viewPortHeight)] * Instead * * * @param combined * matrix that include projection and translation matrices */ public void setCombinedMatrix( Matrix4 combined ) { System.arraycopy( combined.val, 0, this.combined.val, 0, 16 ); // updateCameraCorners float invWidth = combined.val[Matrix4.M00]; final float halfViewPortWidth = 1f / invWidth; final float x = -halfViewPortWidth * combined.val[Matrix4.M03]; x1 = x - halfViewPortWidth; x2 = x + halfViewPortWidth; float invHeight = combined.val[Matrix4.M11]; final float halfViewPortHeight = 1f / invHeight; final float y = -halfViewPortHeight * combined.val[Matrix4.M13]; y1 = y - halfViewPortHeight; y2 = y + halfViewPortHeight; }
Example #2
Source File: CCDrawManager.java From cocos2d-java with MIT License | 6 votes |
public static void MultMatrix( CCAffineTransform transform, float z) { //float[] transfrom4x4 = new float[16]; // Convert 3x3 into 4x4 matrix CCAffineTransform.CGAffineToGL(transform, transfrom4x4); //Matrix.Multiply(ref m_pTransform, ref m_Matrix, out m_Matrix); //Matrix4 tempMatrix4 = new Matrix4(m_Matrix.val); //Matrix4.mul(m_Matrix.val, transfrom4x4); Matrix4.mul(transfrom4x4, m_Matrix.val); m_Matrix.set(transfrom4x4); //Matrix4.mul(transfrom4x4, m_Matrix.val); SPRITE_BATCH.setTransformMatrix(m_Matrix); m_worldMatrixChanged = true; }
Example #3
Source File: InvisibleBody.java From GdxDemo3D with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: RayHandler.java From box2dlights with Apache License 2.0 | 6 votes |
/** * Sets combined camera matrix. * * <p>Matrix must be set to work in box2d coordinates, it will be copied * and used for culling and rendering. Remember to update it if camera * changes. This will work with rotated cameras. * * <p>NOTE: Matrix4 is assumed to be orthogonal for culling * and directional lights. * * @param combined * matrix that include projection and translation matrices * * @deprecated use {@link #setCombinedMatrix(OrthographicCamera)} or * {@link #setCombinedMatrix(Matrix4, float, float, float, float)} instead */ @Deprecated public void setCombinedMatrix(Matrix4 combined) { System.arraycopy(combined.val, 0, this.combined.val, 0, 16); // updateCameraCorners float invWidth = combined.val[Matrix4.M00]; final float halfViewPortWidth = 1f / invWidth; final float x = -halfViewPortWidth * combined.val[Matrix4.M03]; x1 = x - halfViewPortWidth; x2 = x + halfViewPortWidth; float invHeight = combined.val[Matrix4.M11]; final float halfViewPortHeight = 1f / invHeight; final float y = -halfViewPortHeight * combined.val[Matrix4.M13]; y1 = y - halfViewPortHeight; y2 = y + halfViewPortHeight; }
Example #5
Source File: ShaderTest.java From seventh with GNU General Public License v2.0 | 6 votes |
/** * */ public ShaderTest() { ShaderProgram.pedantic = false; vertBlur = loadShader("blurv.frag"); horBlur = loadShader("blurh.frag"); light = loadShader("light.frag"); shader = loadShader("inprint.frag"); this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // camera.setToOrtho(false); transform = new Matrix4(); camera.update(); batch = new SpriteBatch();//1024, shader); batch.setShader(null); batch.setProjectionMatrix(camera.combined); batch.setTransformMatrix(transform); this.buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); this.fboPing = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); this.fboPong = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); }
Example #6
Source File: SimpleRoom.java From gdx-vr with Apache License 2.0 | 6 votes |
@Override public void create() { assets = new AssetManager(); String model = "Bambo_House.g3db"; assets.load(model, Model.class); assets.finishLoading(); modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f)); DefaultShader.Config config = new Config(); config.defaultCullFace = GL20.GL_NONE; ShaderProvider shaderProvider = new DefaultShaderProvider(config); modelBatch = new ModelBatch(shaderProvider); ModelBuilder builder = new ModelBuilder(); float groundSize = 1000f; ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0, 1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0)); 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)); VirtualReality.renderer.listeners.add(this); // VirtualReality.head.setCyclops(true); }
Example #7
Source File: SpinEffectFactory.java From Klooni1010 with GNU General Public License v3.0 | 6 votes |
@Override public void draw(Batch batch) { age += Gdx.graphics.getDeltaTime(); final float progress = age * INV_LIFETIME; final float currentSize = Interpolation.pow2In.apply(size, 0, progress); final float currentRotation = Interpolation.sine.apply(0, TOTAL_ROTATION, progress); final Matrix4 original = batch.getTransformMatrix().cpy(); final Matrix4 rotated = batch.getTransformMatrix(); final float disp = +0.5f * (size - currentSize) // the smaller, the more we need to "push" to center + currentSize * 0.5f; // center the cell for rotation rotated.translate(pos.x + disp, pos.y + disp, 0); rotated.rotate(0, 0, 1, currentRotation); rotated.translate(currentSize * -0.5f, currentSize * -0.5f, 0); // revert centering for rotation batch.setTransformMatrix(rotated); Cell.draw(color, batch, 0, 0, currentSize); batch.setTransformMatrix(original); }
Example #8
Source File: HeadlessModel.java From gdx-proto with Apache License 2.0 | 5 votes |
private void loadNodes (Iterable<ModelNode> modelNodes) { nodePartBones.clear(); for (ModelNode node : modelNodes) { nodes.add(loadNode(null, node)); } for (ObjectMap.Entry<NodePart, ArrayMap<String, Matrix4>> e : nodePartBones.entries()) { if (e.key.invBoneBindTransforms == null) e.key.invBoneBindTransforms = new ArrayMap<Node, Matrix4>(Node.class, Matrix4.class); e.key.invBoneBindTransforms.clear(); for (ObjectMap.Entry<String, Matrix4> b : e.value.entries()) e.key.invBoneBindTransforms.put(getNode(b.key), new Matrix4(b.value).inv()); } }
Example #9
Source File: TreeGenerator.java From Skyland with MIT License | 5 votes |
public static void spawnDynamicTree(BulletWorld world, Matrix4 worldTransform) { BulletEntity dynamicTree = world.add("dynamicTree", 0, 0, 0); dynamicTree.radius = 1.5f; dynamicTree.body.userData = new BulletUserData("dynamicTree", dynamicTree); dynamicTree.body.setWorldTransform(worldTransform); ((btRigidBody) dynamicTree.body).applyImpulse(new Vector3(MathUtils.random(50, 60) * (MathUtils.random(0, 1) > 0 ? 1 : -1), 0, MathUtils.random(50, 60) * (MathUtils.random(0, 1) > 0 ? 1 : -1)), new Vector3(0, 1, 0)); }
Example #10
Source File: GdxCanvas.java From seventh with GNU General Public License v2.0 | 5 votes |
/** * */ public GdxCanvas() { this.batch = new SpriteBatch(); this.color = new Color(); this.tmpColor = new Color(); this.shaderStack = new Stack<>(); this.zoomStack = new Stack<>(); this.camera = new OrthographicCamera(getWidth(), getHeight()); this.camera.setToOrtho(true, getWidth(), getHeight()); this.camera.position.x = this.camera.viewportWidth/2; this.camera.position.y = this.camera.viewportHeight/2; this.camera.update(); this.viewport = new FitViewport(getWidth(), getHeight(), camera); this.viewport.apply(); this.generators = new HashMap<String, FreeTypeFontGenerator>(); this.fonts = new HashMap<String, BitmapFont>(); this.bounds = new GlyphLayout(); this.transform = new Matrix4(); //this.batch.setTransformMatrix(transform); //Matrix4 projection = new Matrix4(); //projection.setToOrtho( 0, getWidth(), getHeight(), 0, -1, 1); //this.batch.setProjectionMatrix(projection); // this.wHeight = getHeight(); this.batch.setProjectionMatrix(this.camera.combined); this.shapes = new ShapeRenderer(); //this.shapes.setTransformMatrix(transform); // this.shapes.setProjectionMatrix(projection); //this.shapes.setProjectionMatrix(camera.combined); this.fbo = new FrameBuffer(Format.RGBA8888, getWidth(), getHeight(), false); }
Example #11
Source File: VfxWidgetGroup.java From gdx-vfx with Apache License 2.0 | 5 votes |
@Override public void assignLocalMatrices(Matrix4 projection, Matrix4 transform) { preservedProjection.set(batch.getProjectionMatrix()); if (!matchWidgetSize) { projection = ownProjection; } batch.setProjectionMatrix(projection); }
Example #12
Source File: Builder.java From Skyland with MIT License | 5 votes |
public static void build(Matrix4 transform) { if (CURR_MODEL.equals(Models.MODEL_TREE_PROTOTYPE)) { TreeGenerator.spawnDynamicTree(Builder.WORLD, transform); } else if (CURR_MODEL.equals(Models.MODEL_LOG_PROTOTYPE)) { TreeGenerator.spawnLog(Builder.WORLD, transform); } else if (CURR_MODEL.equals(Models.MODEL_CAVE_PROTOTYPE)) { buildCave(transform); } }
Example #13
Source File: WorldDebugRenderer.java From killingspree with MIT License | 5 votes |
public void render(Matrix4 projectionMatrix) { renderer.begin(ShapeType.Line); renderer.setProjectionMatrix(projectionMatrix); renderer.setColor(Color.CYAN); for (int i = 0; i< world.bodies.size(); i++) { drawRectangle(world.bodies.get(i).rectangle); } renderer.end(); }
Example #14
Source File: SpineRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@Override public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) { SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource; if (cs != null && cs.skeleton != null) { Matrix4 tm = batch.getTransformMatrix(); tmp.set(tm); float originX = cs.skeleton.getRootBone().getX(); float originY = cs.skeleton.getRootBone().getY(); tm.translate(x, y, 0).rotate(0, 0, 1, rotation).scale(scaleX, scaleY, 1).translate(originX, originY, 0); // cs.skeleton.setX(x / scale); // cs.skeleton.setY(y / scale); batch.setTransformMatrix(tm); if (tint != null) cs.skeleton.setColor(tint); renderer.draw(batch, cs.skeleton); if (tint != null) batch.setColor(Color.WHITE); batch.setTransformMatrix(tmp); } else { float dx = getAlignDx(getWidth(), orgAlign); float dy = getAlignDy(getHeight(), orgAlign); RectangleRenderer.draw(batch, x + dx * scaleX, y + dy * scaleY, getWidth() * scaleX, getHeight() * scaleY, Color.RED); } }
Example #15
Source File: VfxFrameBuffer.java From gdx-vfx with Apache License 2.0 | 5 votes |
@Override public void assignLocalMatrices(Matrix4 projection, Matrix4 transform) { preservedProjection.set(getProjection()); preservedTransform.set(getTransform()); setProjection(projection); // setTransform(transform); }
Example #16
Source File: GameStage.java From GdxDemo3D with Apache License 2.0 | 5 votes |
@Override public void calculateScissors (Rectangle localRect, Rectangle scissorRect) { ScissorStack.calculateScissors(cameraUI, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight(), batch.getTransformMatrix(), localRect, scissorRect); Matrix4 transformMatrix; if (shapeRenderer != null && shapeRenderer.isDrawing()) transformMatrix = shapeRenderer.getTransformMatrix(); else transformMatrix = batch.getTransformMatrix(); ScissorStack.calculateScissors(cameraUI, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight(), transformMatrix, localRect, scissorRect); }
Example #17
Source File: Tree.java From Skyland with MIT License | 5 votes |
private void growTree(BulletWorld world) { Matrix4 transform = stump.transform.cpy(); transform.translate(0, 1.15f, 0); BulletEntity staticTree = world.add("staticTree", transform); staticTree.body.setCollisionFlags(staticTree.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); staticTree.body.setActivationState(com.badlogic.gdx.physics.bullet.collision.Collision.DISABLE_DEACTIVATION); staticTree.radius = 1.5f; staticTree.body.userData = new BulletUserData("staticTree", staticTree); this.tree = staticTree; }
Example #18
Source File: BGDrawer.java From libGDX-Path-Editor with Apache License 2.0 | 5 votes |
public void presentFakeBG(int scrW, int scrH, Matrix4 cameraCombined) { renderer.setProjectionMatrix(cameraCombined); renderer.begin(ShapeType.FilledRectangle); renderer.setColor(Color.BLACK); renderer.filledRect(0, 0, scrW, scrH); renderer.end(); renderer.begin(ShapeType.Rectangle); renderer.setColor(Color.YELLOW); renderer.rect(0, 0, scrW, scrH); renderer.end(); }
Example #19
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 5 votes |
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(); 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(); }
Example #20
Source File: LevelBuilder.java From gdx-proto with Apache License 2.0 | 5 votes |
/** bullet bodies are offset from model instances by a 90 degree rotation on X axis, boolean set to true handles this */ private static void setupStaticModel(Array<MeshPart> meshParts, Matrix4 matrix, boolean performVisualToPhysicalRotation) { //Log.debug("create static model at: " + matrix.getTranslation(tmp)); btCollisionObject obj = new btCollisionObject(); btCollisionShape shape = new btBvhTriangleMeshShape(meshParts); obj.setCollisionShape(shape); Physics.applyStaticGeometryCollisionFlags(obj); mtx.set(matrix); if (performVisualToPhysicalRotation) { mtx.rotate(Vector3.X, -90); } obj.setWorldTransform(mtx); Physics.inst.addStaticGeometryToWorld(obj); }
Example #21
Source File: TreeGenerator.java From Skyland with MIT License | 5 votes |
public static BulletEntity spawnLog(BulletWorld world, Matrix4 worldTransform) { BulletEntity log = world.add("log", 0, 0, 0); log.radius = 1; log.body.userData = new BulletUserData("log", log); log.body.setWorldTransform(worldTransform); ((btRigidBody) log.body).applyImpulse(new Vector3(MathUtils.random(50, 60) * (MathUtils.random(0, 1) > 0 ? 1 : -1), 0, MathUtils.random(50, 60) * (MathUtils.random(0, 1) > 0 ? 1 : -1)), new Vector3(0, 1, 0)); return log; }
Example #22
Source File: CanvasDrawer.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public void drawBGBounds() { // Gdx.gl20.glEnable(GL20.GL_BLEND); // Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); drawer.setProjectionMatrix(camera.combined); drawer.setTransformMatrix(new Matrix4()); drawer.begin(ShapeRenderer.ShapeType.Line); drawer.setColor(Color.MAGENTA); drawer.rect(0, 0, Ctx.project.getWorld().getWidth(), Ctx.project.getWorld().getHeight()); drawer.end(); }
Example #23
Source File: SplineRenderer.java From libGDX-Path-Editor with Apache License 2.0 | 5 votes |
public void present(Matrix4 cameraCombined, int curVertexIndex, int leftVertexIndex, int rightVertexIndex, renderMode mode) { renderer.setProjectionMatrix(cameraCombined); renderer.begin(ShapeType.FilledCircle); spline.present(renderer, curVertexIndex, leftVertexIndex, rightVertexIndex, mode, controlColor, segmentColor, selectColor); renderer.end(); }
Example #24
Source File: SimpleNode.java From Mundus with Apache License 2.0 | 5 votes |
@Override public Matrix4 getTransform() { if (parent == null) { return combined.set(localPosition, localRotation, localScale); } combined.set(localPosition, localRotation, localScale); return combined.mulLeft(parent.getTransform()); }
Example #25
Source File: SimpleNode.java From Mundus with Apache License 2.0 | 5 votes |
/** * Copy construction * * @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); }
Example #26
Source File: SimpleNode.java From Mundus with Apache License 2.0 | 5 votes |
public SimpleNode(int id) { super(id); localPosition = new Vector3(); localRotation = new Quaternion(); localScale = new Vector3(1, 1, 1); combined = new Matrix4(); }
Example #27
Source File: BulletSeekTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void create () { super.create(); BulletEntity ground = world.add("ground", 0f, 0f, 0f); ground.setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f); ground.body.userData = "ground"; BulletEntity characterBase = world.add("capsule", new Matrix4()); character = new SteeringBulletEntity(characterBase); character.setMaxLinearSpeed(50); character.setMaxLinearAcceleration(200); BulletEntity targetBase = world.add("staticbox", new Matrix4().setToTranslation(new Vector3(5f, 1.5f, 5f))); targetBase.body.setCollisionFlags(targetBase.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE); target = new SteeringBulletEntity(targetBase); setNewTargetInputProcessor(target, new Vector3(0, 1.5f, 0)); final Seek<Vector3> seekSB = new Seek<Vector3>(character, target); character.setSteeringBehavior(seekSB); Table detailTable = new Table(container.skin); detailTable.row(); addMaxLinearAccelerationController(detailTable, character, 0, 2000, 100); detailTable.row(); addSeparator(detailTable); detailTable.row(); addMaxLinearSpeedController(detailTable, character, 0, 200, 1); detailWindow = createDetailWindow(detailTable); }
Example #28
Source File: NetManager.java From gdx-proto with Apache License 2.0 | 5 votes |
public static void registerKryoClasses(Kryo k) { Class[] classes = new Class[]{ ServerUpdate.class, EntityUpdate.class, EntityUpdate[].class, Vector3.class, Vector3[].class, Matrix4.class, float[].class, ClientUpdate.class, CommandPackage.class, ClientRequest.class, ServerMessage.class, ServerMessage.AssignPlayerEntityId.class, ServerMessage.DestroyEntity.class, ServerMessage.ServerInfo.class, ServerMessage.LevelGeometry.class, ChatMessage.class, EntityInfoRequest.class, EntityInfoRequest.Response.class, BulletPackage.class, Entity.EntityGraphicsType.class, LevelStatic.class, LevelStatic[].class, }; for (Class clazz : classes) { k.register(clazz); } }
Example #29
Source File: CCParticleActor.java From cocos-ui-libgdx with Apache License 2.0 | 5 votes |
private void transformPoint(Vector3 v) { //transformVector(point->x, point->y, point->z, 1.0f, point) // MathUtil::transformVec4(m, x, y, z, w, (float*)dst); float w = 1; Matrix4 m4 = this.getStage().getCamera().combined; //m4.inv(); float[] m = m4.getValues(); v.x = v.x * m[0] + v.y * m[4] + v.z * m[8] + w * m[12]; v.y = v.x * m[1] + v.y * m[5] + v.z * m[9] + w * m[13]; v.z = v.x * m[2] + v.y * m[6] + v.z * m[10] + w * m[14]; }
Example #30
Source File: GameBatchRenderer.java From uracer-kotd with Apache License 2.0 | 5 votes |
public GameBatchRenderer (GL20 gl) { // setup a top-left origin // y-flip topLeftOrigin = new Matrix4(); topLeftOrigin.setToOrtho(0, ScaleUtils.PlayWidth, ScaleUtils.PlayHeight, 0, 0, 10); identity = new Matrix4(); // Issues may arise on Tegra2 (Asus Transformer) devices if the buffers' // count is higher than 10 // batch = new SpriteBatch(1000, 8); batch = new SpriteBatch(); begin = false; this.gl = gl; }