List of usage examples for com.badlogic.gdx.math Vector3 mul
public Vector3 mul(final Quaternion quat)
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;/*from ww w . j av a2s . co 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.digitale.connex.Actor.java
License:Open Source License
public void update(float delta) { this.shipRot.setEulerAngles(this.yawangle, this.pitchangle, 0); Vector3 heading = new Vector3(0, 0, -1); this.shipRot.transform(heading); this.heading = heading; // add heading vector to ship position this.position.add(heading.mul(this.velocity * 1.01f * delta)); this.healthBar = 0 + (hitpoints - 0) * (32 - 0) / (1000 - 0); /*/* w ww . j av a 2 s . co m*/ * A minimum of dataset B maximum of dataset a is from where you would * like normalised data set to start b is where you would like * normalised data set to end x is the value you are trying to normalise * a + (x-A)*(b-a)/(B-A) */ visible = false; if (distance < 5000) { if (Renderer.camera.frustum.pointInFrustum(position)) { if (status == 1) { if (hitpoints > 0) { visible = true; } else { visible = false; } } } } }
From source file:com.digitale.screens.GameLoop.java
License:Open Source License
@Override public void update(float delta) { simulation.update(delta);//from w w w. j a v a 2s .c o m droneOrbitAngle = droneOrbitAngle + 1; // detect and set black fade in // cameraHorizAngle= (int) (Ship.yawAngle/Math.PI); Input input = Gdx.app.getInput(); androidVersion = Gdx.app.getVersion(); float turnSpeed = .8f * simulation.gameSpeed; // System.out.println("accelx " + input.getAccelerometerX() + " accly " // + input.getAccelerometerY()); if (Ship.STATUS == 1 && Stardust3d.stationScreen == 0) { // only check accelerometer on android platforms if (androidVersion != 0) { accellerometer(input); } checkShipContols(input, turnSpeed, delta); // check rotations haven't gone too far rectifyShipAngles(); // set ship rotation (Quat) yaw and pitch from Euler Ship.shipRot.setEulerAngles(Ship.yawAngle, Ship.pitchAngle, 0); Vector3 heading = new Vector3(0, 0, -1); Ship.shipRot.transform(heading); Simulation.ship.heading = heading; // add heading vector to ship position Ship.position.add(heading.mul(Ship.SHIP_VELOCITY * delta)); rectifyTouchCoords(input); if (input.isTouched()) { menuSelected = false; if (Stardust3d.DEEPDEBUG) System.out.println("x=" + touch_x + " y=" + touch_y); // thumbcontrol(); rightmenu(); throttle(delta); leftmenu(); if (!menuSelected) { checkForSelection(); } } } if (Ship.STATUS == 0 && Stardust3d.stationScreen == 0) { rectifyTouchCoords(input); if (input.isTouched()) { if (Stardust3d.DEBUG) System.out.println("x=" + touch_x + " y=" + touch_y); thumbcontrol(); leftmenu(); dockedrightmenu(); } } }
From source file:com.digitale.sim.Simulation.java
License:Open Source License
public static void Collide(float frameDuration, Ship object1, Actor object2) { // Calculate the difference between the two objects. Vector3 difference = object1.position.sub(object2.position); float distanceAtFrameEnd = difference.len(); frameDuration = frameDuration * 100000; // Calculate the distance that a collision would occur at. float collisionDistance = (object1.SHIP_RADIUS / 2f) + (object2.INVADER_RADIUS / 2f); // Check of the objects are closer that the collision distance. if (distanceAtFrameEnd < collisionDistance) { // Move both objects back to the exact point of collision. float millisecondsAfterCollision = MoveBackToCollisionPoint(frameDuration, object1, object2, distanceAtFrameEnd, collisionDistance); if (Stardust3d.DEBUG) System.out.println(LOG_TAG + "milli after coll: " + millisecondsAfterCollision); // Calculate the normal of the collision plane. Vector3 normalPlane = difference; normalPlane.nor();/*from w ww . ja va 2s. c o m*/ // Calculate the collision plane. Vector3 collisionPlane = new Vector3(-normalPlane.x, normalPlane.y, normalPlane.z); // Calculate prior velocities relative the the collision plane and normal. float n_vel1 = (normalPlane.dot(object1.heading)); float c_vel1 = (collisionPlane.dot(object1.heading)); float n_vel2 = (normalPlane.dot(object2.heading)); float c_vel2 = (collisionPlane.dot(object2.heading)); // Calculate the scaler velocities of each object after the collision. float n_vel1_after = ((n_vel1 * (object1.mass - object2.mass)) + (2 * object2.mass * n_vel2)) / (object2.mass + object1.mass); float n_vel2_after = ((n_vel2 * (object2.mass - object1.mass)) + (2 * object1.mass * n_vel1)) / (object2.mass + object1.mass); //float velObject2Tangent_After = c_vel2; //float velObject1Tangent_After = c_vel1; // Convert the scalers to vectors by multiplying by the normalised plane vectors. Vector3 vec_n_vel2_after = normalPlane.mul(n_vel2_after); Vector3 vec_c_vel2 = collisionPlane.mul(c_vel2); Vector3 vec_n_vel1_after = normalPlane.mul(n_vel1_after); Vector3 vec_c_vel1 = collisionPlane.mul(c_vel1); // Combine the vectors back into a single vector in world space. Vector3 vel1_after = vec_n_vel1_after.add(vec_c_vel1); Vector3 vel2_after = vec_n_vel2_after.add(vec_c_vel2); // Reapply the move-back from before the collision (using the post collision velocity) Vector3 object1AdjustedPositionAfterCollision = object1.position .add(vel1_after.mul(millisecondsAfterCollision)); Vector3 object2AdjustedPositionAfterCollision = object2.position .add(vel2_after.mul(millisecondsAfterCollision)); // Set the objects new positions and velocities. object1.position = (object1AdjustedPositionAfterCollision); object1.heading = vel1_after; object2.position = object2AdjustedPositionAfterCollision; object2.heading = vel2_after; } }
From source file:com.lyeeedar.Roguelike3D.Game.GameObject.java
License:Open Source License
public void applyMovement(float delta, float vertical_acceleration) { if (velocity.len2() == 0) return;/* w w w .ja v a2 s .com*/ if (velocity.x < -MAX_SPEED) velocity.x = -MAX_SPEED; if (velocity.x > MAX_SPEED) velocity.x = MAX_SPEED; if (velocity.y < -MAX_SPEED) velocity.y = -MAX_SPEED; if (velocity.y > MAX_SPEED) velocity.y = MAX_SPEED; if (velocity.z < -MAX_SPEED) velocity.z = -MAX_SPEED; if (velocity.z > MAX_SPEED) velocity.z = MAX_SPEED; Level lvl = GameData.level; Vector3 tmp = Pools.obtain(Vector3.class); Vector3 v = Pools.obtain(Vector3.class).set(velocity.x, (velocity.y - 0.5f * vertical_acceleration * delta), velocity.z); v.mul(delta * 100); Tile below = lvl.getTile(position.x + v.x, position.z + v.z); if (below == null) { velocity.x = 0; velocity.z = 0; } // Check for collision if (lvl.collideSphereAll(position.x + v.x, position.y + v.y, position.z + v.z, radius, UID)) { // Collision! Now time to find which axis the collision was on. (Vertical or Horizontal) // ----- Check Vertical START ----- // if (lvl.collideSphereActorsAll(position.x, position.y + v.y, position.z, radius, UID) != null || lvl.collideSphereLevelObjectsAll(position.x, position.y + v.y, position.z, radius) != null) { velocity.y = 0; grounded = true; } // below else if (position.y + v.y - radius < below.floor) { velocity.y = 0; grounded = true; tmp.set(position.x, below.floor + radius, position.z); if (!lvl.collideSphereAll(tmp.x, tmp.y, tmp.z, radius, UID)) { this.positionAbsolutely(tmp.x, tmp.y, tmp.z); } } // above else if (lvl.hasRoof && position.y + v.y + radius > below.roof) { velocity.y = 0; grounded = false; tmp.set(position.x, below.roof - radius, position.z); if (!lvl.collideSphereAll(tmp.x, tmp.y, tmp.z, radius, UID)) { this.positionAbsolutely(tmp.x, tmp.y, tmp.z); } } // No y collision else { this.translate(0, v.y, 0); grounded = false; } // ----- Check Vertical END ----- // // ----- Check Horizontal START ----- // if (lvl.collideSphereAll(position.x + v.x, position.y, position.z + v.z, radius, UID)) { if (lvl.collideSphereAll(position.x + v.x, position.y, position.z, radius, UID)) { velocity.x = 0; v.x = 0; } if (lvl.collideSphereAll(position.x, position.y, position.z + v.z, radius, UID)) { velocity.z = 0; v.z = 0; } } this.translate(v.x, 0, v.z); // ----- Check Horizontal END ----- // } // No collision! So move normally else { this.translate(v.x, v.y, v.z); grounded = false; } if (grounded) { velocity.x = 0; velocity.z = 0; } Pools.free(v); Pools.free(tmp); }
From source file:com.lyeeedar.Roguelike3D.Graphics.Models.Shapes.java
License:Open Source License
public static Vector3 orthoNormalize(Vector3 vec1, Vector3 vec2) { vec1.nor();//from w ww . j a v a 2s .c om vec1.mul(vec2.dot(vec1)); vec2.sub(vec1); vec2.nor(); return vec2; }
From source file:com.ore.infinium.systems.TileRenderer.java
License:Open Source License
public void render(double elapsed) { if (m_world.m_mainPlayer == null) { return;//from ww w .j a v a2s . c om } if (!m_world.m_client.m_renderTiles) { return; } tilesInViewCountDebug = 0; m_batch.setProjectionMatrix(m_camera.combined); SpriteComponent sprite = spriteMapper.get(m_world.m_mainPlayer); Vector3 playerPosition = new Vector3(sprite.sprite.getX(), sprite.sprite.getY(), 0); //new Vector3(100, 200, 0);//positionComponent->position(); int tilesBeforeX = (int) (playerPosition.x / World.BLOCK_SIZE); int tilesBeforeY = (int) (playerPosition.y / World.BLOCK_SIZE); // determine what the size of the tiles are but convert that to our zoom level final Vector3 tileSize = new Vector3(World.BLOCK_SIZE, World.BLOCK_SIZE, 0); tileSize.mul(m_camera.combined); final int tilesInView = (int) (m_camera.viewportHeight / World.BLOCK_SIZE * m_camera.zoom);//m_camera.project(tileSize); final int startX = Math.max(tilesBeforeX - (tilesInView) - 2, 0); final int startY = Math.max(tilesBeforeY - (tilesInView) - 2, 0); final int endX = Math.min(tilesBeforeX + (tilesInView) + 2, World.WORLD_SIZE_X); final int endY = Math.min(tilesBeforeY + (tilesInView) + 2, World.WORLD_SIZE_Y); /* if (Math.abs(startX) != startX) { //qCDebug(ORE_TILE_RENDERER) << "FIXME, WENT INTO NEGATIVE COLUMN!!"; throw new IndexOutOfBoundsException("went into negative world column"); } else if (Math.abs(startY) != startY) { throw new IndexOutOfBoundsException("went into negative world row"); } */ //FIXME: this needs to be cached..it's supposedly very slow. m_batch.begin(); TextureAtlas.AtlasRegion region; int tilesInViewDebug = 0; String textureName = ""; for (int x = startX; x < endX; ++x) { for (int y = startY; y < endY; ++y) { ++tilesInViewDebug; Block block = m_world.blockAt(x, y); float tileX = World.BLOCK_SIZE * (float) x; float tileY = World.BLOCK_SIZE * (float) y; boolean drawWallTile = false; //String textureName = World.blockTypes.get(block.type).textureName; if (block.type == Block.BlockType.DirtBlockType) { if (block.hasFlag(Block.BlockFlags.GrassBlock)) { textureName = grassBlockMeshes.get(block.meshType); assert textureName != null : "block mesh lookup failure"; } else { textureName = dirtBlockMeshes.get(block.meshType); assert textureName != null : "block mesh lookup failure type: " + block.meshType; } } else if (block.type == Block.BlockType.StoneBlockType) { textureName = stoneBlockMeshes.get(block.meshType); assert textureName != null : "block mesh lookup failure type: " + block.meshType; } else if (block.type == Block.BlockType.NullBlockType) { if (block.wallType == Block.WallType.NullWallType) { //we can skip a draw call iff the wall, and block is null continue; } else { drawWallTile = true; } } else { assert false : "unhaneld block"; } if (drawWallTile) { m_batch.setColor(0.5f, 0.5f, 0.5f, 1); } //either we draw the wall tile, or the foreground tile. never both (yet? there might be *some* scenarios..) if (!drawWallTile) { region = m_tilesAtlas.findRegion(textureName); m_batch.draw(region, tileX, tileY, World.BLOCK_SIZE, World.BLOCK_SIZE); } else { //draw walls //hack of course, for wall drawing textureName = dirtBlockMeshes.get(0); assert textureName != null : "block mesh lookup failure type: " + block.meshType; region = m_tilesAtlas.findRegion(textureName); m_batch.draw(region, tileX, tileY, World.BLOCK_SIZE, World.BLOCK_SIZE); } if (drawWallTile) { m_batch.setColor(1, 1, 1, 1); } } } tilesInViewCountDebug = tilesInViewDebug; m_batch.end(); }