Search in sources :

Example 1 with Matrix4f

use of javax.vecmath.Matrix4f in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method getMatrix.

@SuppressWarnings("deprecation")
public static Matrix4f getMatrix(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform) {
    javax.vecmath.Matrix4f m = new javax.vecmath.Matrix4f(), t = new javax.vecmath.Matrix4f();
    m.setIdentity();
    m.setTranslation(TRSRTransformation.toVecmath(transform.translation));
    t.setIdentity();
    t.rotY(transform.rotation.y);
    m.mul(t);
    t.setIdentity();
    t.rotX(transform.rotation.x);
    m.mul(t);
    t.setIdentity();
    t.rotZ(transform.rotation.z);
    m.mul(t);
    t.setIdentity();
    t.m00 = transform.scale.x;
    t.m11 = transform.scale.y;
    t.m22 = transform.scale.z;
    m.mul(t);
    return m;
}
Also used : Matrix4f(javax.vecmath.Matrix4f) Matrix4f(javax.vecmath.Matrix4f)

Example 2 with Matrix4f

use of javax.vecmath.Matrix4f in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method applyUVLock.

public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, EnumFacing originalSide, ITransformation rotation) {
    TRSRTransformation global = new TRSRTransformation(rotation.getMatrix());
    Matrix4f uv = global.getUVLockTransform(originalSide).getMatrix();
    Vector4f vec = new Vector4f(0, 0, 0, 1);
    vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(0)) / 16;
    vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(0)) / 16;
    uv.transform(vec);
    // / vec.w;
    float uMin = 16 * vec.x;
    // / vec.w;
    float vMin = 16 * vec.y;
    vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(2)) / 16;
    vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(2)) / 16;
    vec.z = 0;
    vec.w = 1;
    uv.transform(vec);
    // / vec.w;
    float uMax = 16 * vec.x;
    // / vec.w;
    float vMax = 16 * vec.y;
    if (uMin > uMax) {
        float t = uMin;
        uMin = uMax;
        uMax = t;
    }
    if (vMin > vMax) {
        float t = vMin;
        vMin = vMax;
        vMax = t;
    }
    float a = (float) Math.toRadians(blockFaceUV.rotation);
    Vector3f rv = new Vector3f(MathHelper.cos(a), MathHelper.sin(a), 0);
    Matrix3f rot = new Matrix3f();
    uv.getRotationScale(rot);
    rot.transform(rv);
    int angle = MathHelper.normalizeAngle(-(int) Math.round(Math.toDegrees(Math.atan2(rv.y, rv.x)) / 90) * 90, 360);
    return new BlockFaceUV(new float[] { uMin, vMin, uMax, vMax }, angle);
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4f(javax.vecmath.Matrix4f) Vector4f(javax.vecmath.Vector4f) Matrix3f(javax.vecmath.Matrix3f) Vector3f(javax.vecmath.Vector3f) BlockFaceUV(net.minecraft.client.renderer.block.model.BlockFaceUV)

Example 3 with Matrix4f

use of javax.vecmath.Matrix4f in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method getMatrix.

public static Matrix4f getMatrix(ModelRotation modelRotation) {
    Matrix4f ret = new Matrix4f(TRSRTransformation.toVecmath(modelRotation.getMatrix4d())), tmp = new Matrix4f();
    tmp.setIdentity();
    tmp.m03 = tmp.m13 = tmp.m23 = .5f;
    ret.mul(tmp, ret);
    tmp.invert();
    //tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
    ret.mul(tmp);
    return ret;
}
Also used : Matrix4f(javax.vecmath.Matrix4f)

Example 4 with Matrix4f

use of javax.vecmath.Matrix4f in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method handleCameraTransforms.

@SuppressWarnings("deprecation")
public static IBakedModel handleCameraTransforms(IBakedModel model, ItemCameraTransforms.TransformType cameraTransformType, boolean leftHandHackery) {
    if (model instanceof IPerspectiveAwareModel) {
        Pair<? extends IBakedModel, Matrix4f> pair = ((IPerspectiveAwareModel) model).handlePerspective(cameraTransformType);
        if (pair.getRight() != null) {
            Matrix4f matrix = new Matrix4f(pair.getRight());
            if (leftHandHackery) {
                matrix.mul(flipX, matrix);
                matrix.mul(matrix, flipX);
            }
            multiplyCurrentGlMatrix(matrix);
        }
        return pair.getLeft();
    } else {
        //if(leftHandHackery) GlStateManager.scale(-1, 1, 1);
        ItemCameraTransforms.applyTransformSide(model.getItemCameraTransforms().getTransform(cameraTransformType), leftHandHackery);
    //if(leftHandHackery) GlStateManager.scale(-1, 1, 1);
    }
    return model;
}
Also used : Matrix4f(javax.vecmath.Matrix4f) IPerspectiveAwareModel(net.minecraftforge.client.model.IPerspectiveAwareModel)

Example 5 with Matrix4f

use of javax.vecmath.Matrix4f in project MinecraftForge by MinecraftForge.

the class ModelBlockAnimation method getPartTransform.

@Nullable
public TRSRTransformation getPartTransform(IModelState state, BlockPart part, int i) {
    ImmutableCollection<MBJointWeight> infos = getJoint(i);
    if (!infos.isEmpty()) {
        Matrix4f m = new Matrix4f(), tmp;
        float weight = 0;
        for (MBJointWeight info : infos) {
            if (info.getWeights().containsKey(i)) {
                ModelBlockAnimation.MBJoint joint = new ModelBlockAnimation.MBJoint(info.getName(), part);
                Optional<TRSRTransformation> trOp = state.apply(Optional.of(joint));
                if (trOp.isPresent() && trOp.get() != TRSRTransformation.identity()) {
                    float w = info.getWeights().get(i)[0];
                    tmp = trOp.get().getMatrix();
                    tmp.mul(w);
                    m.add(tmp);
                    weight += w;
                }
            }
        }
        if (weight > 1e-5) {
            m.mul(1f / weight);
            return new TRSRTransformation(m);
        }
    }
    return null;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4f(javax.vecmath.Matrix4f) Nullable(javax.annotation.Nullable)

Aggregations

Matrix4f (javax.vecmath.Matrix4f)27 Vector3f (javax.vecmath.Vector3f)9 Matrix3f (javax.vecmath.Matrix3f)3 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)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 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)1 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)1 Node (com.badlogic.gdx.graphics.g3d.model.Node)1 NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)1 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1