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 libgdx by libgdx.
the class ModelInstance method invalidate.
/** Makes sure that each {@link NodePart} of the {@link Node} and its sub-nodes, doesn't reference a node outside this node
* tree and that all materials are listed in the {@link #materials} array. */
private void invalidate(Node node) {
for (int i = 0, n = node.parts.size; i < n; ++i) {
NodePart part = node.parts.get(i);
ArrayMap<Node, Matrix4> bindPose = part.invBoneBindTransforms;
if (bindPose != null) {
for (int j = 0; j < bindPose.size; ++j) {
bindPose.keys[j] = getNode(bindPose.keys[j].id);
}
}
if (!materials.contains(part.material, true)) {
final int midx = materials.indexOf(part.material, false);
if (midx < 0)
materials.add(part.material = part.material.copy());
else
part.material = materials.get(midx);
}
}
for (int i = 0, n = node.getChildCount(); i < n; ++i) {
invalidate(node.getChild(i));
}
}
use of com.badlogic.gdx.math.Matrix4 in project libgdx by libgdx.
the class SplitPane method draw.
@Override
public void draw(Batch batch, float parentAlpha) {
validate();
Color color = getColor();
Drawable handle = style.handle;
applyTransform(batch, computeTransform());
Matrix4 transform = batch.getTransformMatrix();
if (firstWidget != null) {
batch.flush();
getStage().calculateScissors(firstWidgetBounds, firstScissors);
if (ScissorStack.pushScissors(firstScissors)) {
if (firstWidget.isVisible())
firstWidget.draw(batch, parentAlpha * color.a);
batch.flush();
ScissorStack.popScissors();
}
}
if (secondWidget != null) {
batch.flush();
getStage().calculateScissors(secondWidgetBounds, secondScissors);
if (ScissorStack.pushScissors(secondScissors)) {
if (secondWidget.isVisible())
secondWidget.draw(batch, parentAlpha * color.a);
batch.flush();
ScissorStack.popScissors();
}
}
batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
resetTransform(batch);
}
use of com.badlogic.gdx.math.Matrix4 in project libgdx by libgdx.
the class MatrixJNITest method bench.
private void bench() {
Matrix4 mata = new Matrix4();
Matrix4 matb = new Matrix4();
long start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
mata.mul(matb);
}
Gdx.app.log("MatrixJNITest", "java matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
Matrix4.mul(mata.val, matb.val);
}
Gdx.app.log("MatrixJNITest", "jni matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
Vector3 vec = new Vector3();
start = TimeUtils.nanoTime();
for (int i = 0; i < 500000; i++) {
vec.mul(mata);
}
Gdx.app.log("MatrixJNITest", "java vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
float[] fvec = new float[3];
start = TimeUtils.nanoTime();
for (int i = 0; i < 500000; i++) {
Matrix4.mulVec(mata.val, fvec);
}
Gdx.app.log("MatrixJNITest", "jni vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
float[] fvecs = new float[3 * 500000];
start = TimeUtils.nanoTime();
Matrix4.mulVec(mata.val, fvecs, 0, 500000, 3);
Gdx.app.log("MatrixJNITest", "jni bulk vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
mata.inv();
}
Gdx.app.log("MatrixJNITest", "java inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
Matrix4.inv(mata.val);
}
Gdx.app.log("MatrixJNITest", "jni inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
}
Aggregations