use of javax.vecmath.Matrix4f in project bdx by GoranM.
the class GameObject method updateLocalTransform.
private void updateLocalTransform() {
localTransform = parent.transform();
Matrix4f ms = new Matrix4f();
ms.setIdentity();
Vector3f ps = parent.scale();
ms.m00 = ps.x;
ms.m11 = ps.y;
ms.m22 = ps.z;
localTransform.mul(ms);
localTransform.invert();
localTransform.mul(transform());
}
use of javax.vecmath.Matrix4f in project MorePlanets by SteveKunG.
the class ItemRendererTieredRocket method getTransformForPerspective.
@Override
protected Matrix4f getTransformForPerspective(TransformType type) {
if (type == TransformType.GUI) {
Vector3f trans = new Vector3f(-0.08F, 0.0F, -0.08F);
Matrix4f ret = new Matrix4f();
ret.setIdentity();
Matrix4f mul = new Matrix4f();
mul.setIdentity();
mul.setScale(1.0F);
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(new Vector3f(0.225F, -0.1F, 0.0F));
ret.mul(mul);
mul.setIdentity();
mul.rotY((float) (Math.PI / 2.5F));
ret.mul(mul);
mul.setIdentity();
mul.rotX((float) (-Math.PI / 4.0F));
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(trans);
ret.mul(mul);
mul.setIdentity();
mul.rotY(ClientUtil.getMilliseconds() / 2000.0F);
ret.mul(mul);
mul.setIdentity();
trans.scale(-1.0F);
mul.setTranslation(trans);
ret.mul(mul);
mul.setIdentity();
mul.setScale(0.145F);
ret.mul(mul);
return ret;
}
if (type == TransformType.FIRST_PERSON_RIGHT_HAND) {
Vector3f trans = new Vector3f(0.5F, 3.2F, -3.6F);
Matrix4f ret = new Matrix4f();
ret.setIdentity();
Matrix4f mul = new Matrix4f();
mul.setIdentity();
Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(0, 45, 0));
mul.setRotation(rot);
ret.mul(mul);
mul.setIdentity();
mul.setScale(0.45F);
ret.mul(mul);
mul.setIdentity();
mul.rotX(Constants.halfPI);
ret.mul(mul);
mul.setIdentity();
mul.rotZ((float) (-0.65F + Math.PI));
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(trans);
ret.mul(mul);
mul.setIdentity();
mul.rotX((float) Math.PI);
ret.mul(mul);
return ret;
}
if (type == TransformType.FIRST_PERSON_LEFT_HAND) {
Vector3f trans = new Vector3f(0.4F, 3.2F, -3.2F);
Matrix4f ret = new Matrix4f();
ret.setIdentity();
Matrix4f mul = new Matrix4f();
mul.setIdentity();
Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(0, 35, 0));
mul.setRotation(rot);
ret.mul(mul);
mul.setIdentity();
mul.setScale(0.45F);
ret.mul(mul);
mul.setIdentity();
mul.rotX(Constants.halfPI);
ret.mul(mul);
mul.setIdentity();
mul.rotZ((float) (-0.65F + Math.PI));
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(trans);
ret.mul(mul);
mul.setIdentity();
mul.rotX((float) Math.PI);
ret.mul(mul);
return ret;
}
if (type == TransformType.THIRD_PERSON_RIGHT_HAND) {
Vector3f trans = new Vector3f(1.0F, -2.4F, 1.2F);
Matrix4f ret = new Matrix4f();
ret.setIdentity();
Matrix4f mul = new Matrix4f();
mul.setIdentity();
Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(75, 15, 0));
mul.setRotation(rot);
ret.mul(mul);
mul.setIdentity();
mul.setScale(0.6F);
ret.mul(mul);
mul.setIdentity();
mul.rotX((float) (Math.PI / 3.0F));
ret.mul(mul);
mul.setIdentity();
mul.rotZ((float) (-Math.PI / 2.0F));
ret.mul(mul);
mul.setIdentity();
mul.rotX(0.3F);
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(trans);
ret.mul(mul);
return ret;
}
if (type == TransformType.THIRD_PERSON_LEFT_HAND) {
Vector3f trans = new Vector3f(0.1F, -2.4F, 1.2F);
Matrix4f ret = new Matrix4f();
ret.setIdentity();
Matrix4f mul = new Matrix4f();
mul.setIdentity();
Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(75, 15, 0));
mul.setRotation(rot);
ret.mul(mul);
mul.setIdentity();
mul.setScale(0.6F);
ret.mul(mul);
mul.setIdentity();
mul.rotX((float) (Math.PI / 3.0F));
ret.mul(mul);
mul.setIdentity();
mul.rotZ((float) (-Math.PI / 2.0F));
ret.mul(mul);
mul.setIdentity();
mul.rotX(0.3F);
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(trans);
ret.mul(mul);
return ret;
}
if (type == TransformType.GROUND) {
Matrix4f ret = new Matrix4f();
ret.setIdentity();
Matrix4f mul = new Matrix4f();
mul.setIdentity();
mul.setScale(0.135F);
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(new Vector3f(0.5F, 1.5F, 0.5F));
ret.mul(mul);
return ret;
}
if (type == TransformType.FIXED) {
Matrix4f ret = new Matrix4f();
ret.setIdentity();
Matrix4f mul = new Matrix4f();
mul.setIdentity();
mul.setScale(0.135F);
ret.mul(mul);
mul.setIdentity();
mul.rotY(3.1F);
ret.mul(mul);
mul.setIdentity();
mul.setTranslation(new Vector3f(0.5F, -1.5F, 0.5F));
ret.mul(mul);
return ret;
}
return null;
}
use of javax.vecmath.Matrix4f in project bdx by GoranM.
the class GameObject method orientation.
public void orientation(Matrix3f ori) {
Matrix4f t = transform();
t.setRotation(ori);
transform(t);
}
use of javax.vecmath.Matrix4f in project bdx by GoranM.
the class GameObject method updateBody.
public void updateBody(Mesh mesh) {
GameObject compParent = parent != null && parent.body.getCollisionShape().isCompound() ? parent : null;
boolean isCompChild = compParent != null && !(currBodyType == BodyType.NO_COLLISION || currBodyType == BodyType.SENSOR);
if (isCompChild) {
parent(null);
}
Matrix4f transform = transform();
Vector3f scale = scale();
CollisionShape shape = body.getCollisionShape();
body.setCollisionShape(Bullet.makeShape(mesh.model.meshes.first(), currBoundsType, shape.getMargin(), shape.isCompound()));
Transform startTransform = new Transform();
body.getMotionState().getWorldTransform(startTransform);
Matrix4f originMatrix = new Matrix4f();
originMatrix.set(origin);
Transform centerOfMassTransform = new Transform();
centerOfMassTransform.set(originMatrix);
centerOfMassTransform.mul(startTransform);
body.setCenterOfMassTransform(centerOfMassTransform);
transform(transform);
scale(scale);
if (body.isInWorld()) {
scene.world.updateSingleAabb(body);
} else {
// update Aabb hack for when not in world
scene.world.addRigidBody(body);
scene.world.updateSingleAabb(body);
scene.world.removeRigidBody(body);
}
if (isCompChild) {
parent(compParent);
}
}
use of javax.vecmath.Matrix4f in project bdx by GoranM.
the class GameObject method join.
public void join(ArrayList<GameObject> objects, boolean endObjects) {
// collect scaled transforms per mesh
HashMap<Mesh, ArrayList<Matrix4f>> map = new HashMap<Mesh, ArrayList<Matrix4f>>();
Mesh m;
for (GameObject g : objects) {
m = g.mesh();
ArrayList<Matrix4f> l;
if (map.containsKey(m)) {
l = map.get(m);
} else {
l = new ArrayList<Matrix4f>();
map.put(m, l);
}
Matrix4f t = g.transform();
Vector3f s = g.scale();
t.setRow(3, s.x, s.y, s.z, 0);
l.add(t);
if (endObjects) {
g.end();
}
}
// join
join(map);
}
Aggregations