use of com.badlogic.gdx.math.Matrix4 in project commons-gdx by gemserk.
the class ImmediateModeRendererUtils method getProjectionMatrix.
public static Matrix4 getProjectionMatrix() {
if (projectionMatrix == null) {
projectionMatrix = new Matrix4();
// don't like the Gdx.graphics here
projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
return projectionMatrix;
}
use of com.badlogic.gdx.math.Matrix4 in project nhglib by VoidZombie.
the class TiledForwardShader method cullSpotLight.
private void cullSpotLight(NhgLight light) {
Matrix4 a = MatrixPool.getMatrix4();
a.setToTranslation(light.position);
Matrix4 b = MatrixPool.getMatrix4();
b.set(a).translate(new Vector3(light.direction).scl(light.radius));
Vector3 p1 = VectorPool.getVector3();
Vector3 p2 = VectorPool.getVector3();
Vector3 m = VectorPool.getVector3();
a.getTranslation(p1);
b.getTranslation(p2);
m.set(p1).add(p2).scl(0.5f);
float radius = p1.dst(p2) * 0.5f;
if (camera.frustum.sphereInFrustum(m, radius)) {
lightsToRender.add(light);
}
VectorPool.freeVector3(p1, p2, m);
MatrixPool.freeMatrix4(a, b);
}
use of com.badlogic.gdx.math.Matrix4 in project nhglib by VoidZombie.
the class PhysicsSystem method process.
@Override
protected void process(int entityId) {
NodeComponent nodeComponent = nodeMapper.get(entityId);
RigidBodyComponent bodyComponent = rigidBodyMapper.get(entityId);
if (!bodyComponent.isAdded()) {
Matrix4 initialTransform = new Matrix4();
Vector3 trn = nodeComponent.getTranslation();
Vector3 scl = new Vector3(1, 1, 1);
Quaternion rtn = nodeComponent.getRotationQuaternion();
initialTransform.set(trn, rtn, scl);
bodyComponent.addToWorld(dynamicsWorld, initialTransform);
} else {
nodeComponent.setTranslation(bodyComponent.getTranslation());
nodeComponent.setRotation(bodyComponent.getRotation());
nodeComponent.applyTransforms();
}
}
use of com.badlogic.gdx.math.Matrix4 in project bdx by GoranM.
the class GameObject method scale.
public void scale(float x, float y, float z, boolean updateLocal) {
activate();
// Set unit scale
Matrix4 t = modelInstance.transform;
Matrix4 mat_scale = new Matrix4();
Vector3 s = new Vector3();
t.getScale(s);
mat_scale.scl(1 / s.x, 1 / s.y, 1 / s.z);
t.mul(mat_scale);
scale.set(x, y, z);
// Set target scale
mat_scale.idt();
mat_scale.scl(x, y, z);
t.mul(mat_scale);
// Relevant bullet body update
CollisionShape cs = body.getCollisionShape();
cs.setLocalScaling(new Vector3f(x, y, z));
if (body.isInWorld() && body.isStaticOrKinematicObject())
scene.world.updateSingleAabb(body);
// Child propagation
Vector3f ps = scale();
Matrix4f pt = transform();
Matrix4f ct = new Matrix4f();
Matrix4f ms = new Matrix4f();
ms.setIdentity();
ms.m00 = ps.x;
ms.m11 = ps.y;
ms.m22 = ps.z;
pt.mul(ms);
for (GameObject c : children) {
c.scale(scale().mul(c.localScale), false);
ct.mul(pt, c.localTransform);
c.transform(ct, false);
}
if (parent != null && updateLocal) {
updateLocalScale();
}
}
use of com.badlogic.gdx.math.Matrix4 in project libgdx by libgdx.
the class ArrowShapeBuilder method build.
/** Build an arrow
* @param x1 source x
* @param y1 source y
* @param z1 source z
* @param x2 destination x
* @param y2 destination y
* @param z2 destination z
* @param capLength is the height of the cap in percentage, must be in (0,1)
* @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1]
* @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */
public static void build(MeshPartBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float capLength, float stemThickness, int divisions) {
Vector3 begin = obtainV3().set(x1, y1, z1), end = obtainV3().set(x2, y2, z2);
float length = begin.dst(end);
float coneHeight = length * capLength;
float coneDiameter = 2 * (float) (coneHeight * Math.sqrt(1f / 3));
float stemLength = length - coneHeight;
float stemDiameter = coneDiameter * stemThickness;
Vector3 up = obtainV3().set(end).sub(begin).nor();
Vector3 forward = obtainV3().set(up).crs(Vector3.Z);
if (forward.isZero())
forward.set(Vector3.X);
forward.crs(up).nor();
Vector3 left = obtainV3().set(up).crs(forward).nor();
Vector3 direction = obtainV3().set(end).sub(begin).nor();
// Matrices
Matrix4 userTransform = builder.getVertexTransform(obtainM4());
Matrix4 transform = obtainM4();
float[] val = transform.val;
val[Matrix4.M00] = left.x;
val[Matrix4.M01] = up.x;
val[Matrix4.M02] = forward.x;
val[Matrix4.M10] = left.y;
val[Matrix4.M11] = up.y;
val[Matrix4.M12] = forward.y;
val[Matrix4.M20] = left.z;
val[Matrix4.M21] = up.z;
val[Matrix4.M22] = forward.z;
Matrix4 temp = obtainM4();
// Stem
transform.setTranslation(obtainV3().set(direction).scl(stemLength / 2).add(x1, y1, z1));
builder.setVertexTransform(temp.set(transform).mul(userTransform));
CylinderShapeBuilder.build(builder, stemDiameter, stemLength, stemDiameter, divisions);
// Cap
transform.setTranslation(obtainV3().set(direction).scl(stemLength).add(x1, y1, z1));
builder.setVertexTransform(temp.set(transform).mul(userTransform));
ConeShapeBuilder.build(builder, coneDiameter, coneHeight, coneDiameter, divisions);
builder.setVertexTransform(userTransform);
freeAll();
}
Aggregations