/** Method to transform the texture coordinates (UV) in the float array. This is a potentially slow operation, use with care. * @param matrix the transformation matrix * @param vertices the float array * @param vertexSize the number of floats in each vertex * @param offset the offset within a vertex to the texture location * @param start the vertex to start with * @param count the amount of vertices to transform */ public static void transformUV (final Matrix3 matrix, final float[] vertices, int vertexSize, int offset, int start, int count) { if (start < 0 || count < 1 || ((start + count) * vertexSize) > vertices.length) throw new IndexOutOfBoundsException("start = " + start + ", count = " + count + ", vertexSize = " + vertexSize + ", length = " + vertices.length); final Vector2 tmp = new Vector2(); int idx = offset + (start * vertexSize); for (int i = 0; i < count; i++) { tmp.set(vertices[idx], vertices[idx + 1]).mul(matrix); vertices[idx] = tmp.x; vertices[idx + 1] = tmp.y; idx += vertexSize; } }
/** Method to transform the texture coordinates (UV) in the float array. This is a potentially slow operation, use with care. * @param matrix the transformation matrix * @param vertices the float array * @param vertexSize the number of floats in each vertex * @param offset the offset within a vertex to the texture location * @param start the vertex to start with * @param count the amount of vertices to transform */ public static void transformUV (final Matrix3 matrix, final float[] vertices, int vertexSize, int offset, int start, int count) { if (start < 0 || count < 1 || ((start + count) * vertexSize) > vertices.length) throw new IndexOutOfBoundsException("start = " + start + ", count = " + count + ", vertexSize = " + vertexSize + ", length = " + vertices.length); final Vector2 tmp = new Vector2(); int idx = offset + (start * vertexSize); for (int i = 0; i < count; i++) { tmp.set(vertices[idx], vertices[idx + 1]).mul(matrix); vertices[idx] = tmp.x; vertices[idx + 1] = tmp.y; idx += vertexSize; } }
Matrix3 mat3 = new Matrix3(); //do your transformations Vector2 vec2 = new Vector2(object.getX(), object.getY()); vec2.mul(mat3); object.setPosition(vec2.x, vec2.y);
/** * Applies attached body initial transform to all lights rays */ void applyAttachment() { if (body == null || staticLight) return; restorePosition.setToTranslation(bodyPosition); rotateAroundZero.setToRotationRad(bodyAngle + bodyAngleOffset); for (int i = 0; i < rayNum; i++) { tmpVec.set(startX[i], startY[i]).mul(rotateAroundZero).mul(restorePosition); startX[i] = tmpVec.x; startY[i] = tmpVec.y; tmpVec.set(endX[i], endY[i]).mul(rotateAroundZero).mul(restorePosition); endX[i] = tmpVec.x; endY[i] = tmpVec.y; } }
/** * Applies attached body initial transform to all lights rays */ void applyAttachment() { if (body == null || staticLight) return; restorePosition.setToTranslation(bodyPosition); rotateAroundZero.setToRotationRad(bodyAngle + bodyAngleOffset); for (int i = 0; i < rayNum; i++) { tmpVec.set(startX[i], startY[i]).mul(rotateAroundZero).mul(restorePosition); startX[i] = tmpVec.x; startY[i] = tmpVec.y; tmpVec.set(endX[i], endY[i]).mul(rotateAroundZero).mul(restorePosition); endX[i] = tmpVec.x; endY[i] = tmpVec.y; } }
((Vector2)relativeLocPosition).mul(orientationMatrix); else if (relativeLocPosition instanceof Vector3) ((Vector3)relativeLocPosition).mul(orientationMatrix);
/** Method to transform the texture coordinates (UV) in the float array. This is a potentially slow operation, use with care. * @param matrix the transformation matrix * @param vertices the float array * @param vertexSize the number of floats in each vertex * @param offset the offset within a vertex to the texture location * @param start the vertex to start with * @param count the amount of vertices to transform */ public static void transformUV (final Matrix3 matrix, final float[] vertices, int vertexSize, int offset, int start, int count) { if (start < 0 || count < 1 || ((start + count) * vertexSize) > vertices.length) throw new IndexOutOfBoundsException("start = " + start + ", count = " + count + ", vertexSize = " + vertexSize + ", length = " + vertices.length); final Vector2 tmp = new Vector2(); int idx = offset + (start * vertexSize); for (int i = 0; i < count; i++) { tmp.set(vertices[idx], vertices[idx + 1]).mul(matrix); vertices[idx] = tmp.x; vertices[idx + 1] = tmp.y; idx += vertexSize; } }
void updateBody() { if (body == null || staticLight) return; final Vector2 vec = body.getPosition(); tmpVec.set(0, 0).sub(bodyPosition); bodyPosition.set(vec); zeroPosition.setToTranslation(tmpVec); restorePosition.setToTranslation(bodyPosition); rotateAroundZero.setToRotationRad(bodyAngle).inv().rotateRad(body.getAngle()); bodyAngle = body.getAngle(); for (int i = 0; i < rayNum; i++) { tmpVec.set(startX[i], startY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); startX[i] = tmpVec.x; startY[i] = tmpVec.y; tmpVec.set(endX[i], endY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); endX[i] = tmpVec.x; endY[i] = tmpVec.y; } }
void updateBody() { if (body == null || staticLight) return; final Vector2 vec = body.getPosition(); tmpVec.set(0, 0).sub(bodyPosition); bodyPosition.set(vec); zeroPosition.setToTranslation(tmpVec); restorePosition.setToTranslation(bodyPosition); rotateAroundZero.setToRotationRad(bodyAngle).inv().rotateRad(body.getAngle()); bodyAngle = body.getAngle(); for (int i = 0; i < rayNum; i++) { tmpVec.set(startX[i], startY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); startX[i] = tmpVec.x; startY[i] = tmpVec.y; tmpVec.set(endX[i], endY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); endX[i] = tmpVec.x; endY[i] = tmpVec.y; } }
public void updateGameLoop(float deltaTime) { Vector2 current = body.getPosition(); Vector2 target = new Vector2(100, 100); if (!current.equals(target)) { float speed = 20f; Vector2 direction = target.sub(current); float distanceToTarget = direction.len(); float travelDistance = speed * deltaTime; // the target is very close, so we set the position to the target directly if (distanceToTarget <= travelDistance) { body.setTransform(target, body.getAngle()); } else { direction.nor(); // move a bit in the target direction body.setTransform(current.add(direction.mul(travelDistance)), body.getAngle()); } } }
center.mul(1.0f / area); data.center.set(center.cpy().add(s));
((Vector2)relativeLocPosition).mul(orientationMatrix); else if (relativeLocPosition instanceof Vector3) ((Vector3)relativeLocPosition).mul(orientationMatrix);