Search in sources :

Example 21 with Matrix4f

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());
}
Also used : Matrix4f(javax.vecmath.Matrix4f) Vector3f(javax.vecmath.Vector3f)

Example 22 with Matrix4f

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;
}
Also used : Matrix4f(javax.vecmath.Matrix4f) Vector3f(javax.vecmath.Vector3f) Quat4f(javax.vecmath.Quat4f)

Example 23 with Matrix4f

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);
}
Also used : Matrix4f(javax.vecmath.Matrix4f)

Example 24 with Matrix4f

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);
    }
}
Also used : Matrix4f(javax.vecmath.Matrix4f) CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform)

Example 25 with Matrix4f

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);
}
Also used : Matrix4f(javax.vecmath.Matrix4f) HashMap(java.util.HashMap) Vector3f(javax.vecmath.Vector3f) ArrayList(java.util.ArrayList) Mesh(com.nilunder.bdx.gl.Mesh)

Aggregations

Matrix4f (javax.vecmath.Matrix4f)29 Vector3f (javax.vecmath.Vector3f)10 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)4 Matrix3f (javax.vecmath.Matrix3f)3 Matrix4 (com.badlogic.gdx.math.Matrix4)2 Vector3 (com.badlogic.gdx.math.Vector3)2 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)2 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)2 Transform (com.bulletphysics.linearmath.Transform)2 Mesh (com.nilunder.bdx.gl.Mesh)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Vector4f (javax.vecmath.Vector4f)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)1 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)1 IMixinTextureAtlasSprite (com.almuradev.content.mixin.iface.IMixinTextureAtlasSprite)1 Face (com.almuradev.content.model.obj.geometry.Face)1 Group (com.almuradev.content.model.obj.geometry.Group)1 Vertex (com.almuradev.content.model.obj.geometry.Vertex)1