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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations