Search in sources :

Example 1 with Vector4f

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

the class ItemLayerModel method putVertex.

private static void putVertex(UnpackedBakedQuad.Builder builder, VertexFormat format, Optional<TRSRTransformation> transform, EnumFacing side, float x, float y, float z, float u, float v) {
    Vector4f vec = new Vector4f();
    for (int e = 0; e < format.getElementCount(); e++) {
        switch(format.getElement(e).getUsage()) {
            case POSITION:
                if (transform.isPresent()) {
                    vec.x = x;
                    vec.y = y;
                    vec.z = z;
                    vec.w = 1;
                    transform.get().getMatrix().transform(vec);
                    builder.put(e, vec.x, vec.y, vec.z, vec.w);
                } else {
                    builder.put(e, x, y, z, 1);
                }
                break;
            case COLOR:
                builder.put(e, 1f, 1f, 1f, 1f);
                break;
            case UV:
                if (format.getElement(e).getIndex() == 0) {
                    builder.put(e, u, v, 0f, 1f);
                    break;
                }
            case NORMAL:
                builder.put(e, (float) side.getFrontOffsetX(), (float) side.getFrontOffsetY(), (float) side.getFrontOffsetZ(), 0f);
                break;
            default:
                builder.put(e);
                break;
        }
    }
}
Also used : Vector4f(javax.vecmath.Vector4f)

Example 2 with Vector4f

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

the class ItemTextureQuadConverter method putVertex.

private static void putVertex(UnpackedBakedQuad.Builder builder, VertexFormat format, TRSRTransformation transform, EnumFacing side, float x, float y, float z, float u, float v, int color) {
    Vector4f vec = new Vector4f();
    for (int e = 0; e < format.getElementCount(); e++) {
        switch(format.getElement(e).getUsage()) {
            case POSITION:
                if (transform == TRSRTransformation.identity()) {
                    builder.put(e, x, y, z, 1);
                } else // only apply the transform if it's not identity
                {
                    vec.x = x;
                    vec.y = y;
                    vec.z = z;
                    vec.w = 1;
                    transform.getMatrix().transform(vec);
                    builder.put(e, vec.x, vec.y, vec.z, vec.w);
                }
                break;
            case COLOR:
                // red
                float r = ((color >> 16) & 0xFF) / 255f;
                // green
                float g = ((color >> 8) & 0xFF) / 255f;
                // blue
                float b = ((color >> 0) & 0xFF) / 255f;
                // alpha
                float a = ((color >> 24) & 0xFF) / 255f;
                builder.put(e, r, g, b, a);
                break;
            case UV:
                if (format.getElement(e).getIndex() == 0) {
                    builder.put(e, u, v, 0f, 1f);
                    break;
                }
            case NORMAL:
                builder.put(e, (float) side.getFrontOffsetX(), (float) side.getFrontOffsetY(), (float) side.getFrontOffsetZ(), 0f);
                break;
            default:
                builder.put(e);
                break;
        }
    }
}
Also used : Vector4f(javax.vecmath.Vector4f)

Example 3 with Vector4f

use of javax.vecmath.Vector4f 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 4 with Vector4f

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

the class TRSRTransformation method rotate.

public static EnumFacing rotate(Matrix4f matrix, EnumFacing facing) {
    Vec3i dir = facing.getDirectionVec();
    Vector4f vec = new Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
    matrix.transform(vec);
    return EnumFacing.getFacingFromVector(vec.x, vec.y, vec.z);
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) Vector4f(javax.vecmath.Vector4f)

Example 5 with Vector4f

use of javax.vecmath.Vector4f in project bdx by GoranM.

the class PersistentManifold method sortCachedPoints.

/// sort cached points so most isolated points come first
private int sortCachedPoints(ManifoldPoint pt) {
    //calculate 4 possible cases areas, and take biggest area
    //also need to keep 'deepest'
    int maxPenetrationIndex = -1;
    //#define KEEP_DEEPEST_POINT 1
    //#ifdef KEEP_DEEPEST_POINT
    float maxPenetration = pt.getDistance();
    for (int i = 0; i < 4; i++) {
        if (pointCache[i].getDistance() < maxPenetration) {
            maxPenetrationIndex = i;
            maxPenetration = pointCache[i].getDistance();
        }
    }
    //#endif //KEEP_DEEPEST_POINT
    Stack stack = Stack.enter();
    float res0 = 0f, res1 = 0f, res2 = 0f, res3 = 0f;
    if (maxPenetrationIndex != 0) {
        Vector3f a0 = stack.alloc(pt.localPointA);
        a0.sub(pointCache[1].localPointA);
        Vector3f b0 = stack.alloc(pointCache[3].localPointA);
        b0.sub(pointCache[2].localPointA);
        Vector3f cross = stack.allocVector3f();
        cross.cross(a0, b0);
        res0 = cross.lengthSquared();
    }
    if (maxPenetrationIndex != 1) {
        Vector3f a1 = stack.alloc(pt.localPointA);
        a1.sub(pointCache[0].localPointA);
        Vector3f b1 = stack.alloc(pointCache[3].localPointA);
        b1.sub(pointCache[2].localPointA);
        Vector3f cross = stack.allocVector3f();
        cross.cross(a1, b1);
        res1 = cross.lengthSquared();
    }
    if (maxPenetrationIndex != 2) {
        Vector3f a2 = stack.alloc(pt.localPointA);
        a2.sub(pointCache[0].localPointA);
        Vector3f b2 = stack.alloc(pointCache[3].localPointA);
        b2.sub(pointCache[1].localPointA);
        Vector3f cross = stack.allocVector3f();
        cross.cross(a2, b2);
        res2 = cross.lengthSquared();
    }
    if (maxPenetrationIndex != 3) {
        Vector3f a3 = stack.alloc(pt.localPointA);
        a3.sub(pointCache[0].localPointA);
        Vector3f b3 = stack.alloc(pointCache[2].localPointA);
        b3.sub(pointCache[1].localPointA);
        Vector3f cross = stack.allocVector3f();
        cross.cross(a3, b3);
        res3 = cross.lengthSquared();
    }
    Vector4f maxvec = stack.allocVector4f();
    maxvec.set(res0, res1, res2, res3);
    int biggestarea = VectorUtil.closestAxis4(maxvec);
    stack.leave();
    return biggestarea;
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Aggregations

Vector4f (javax.vecmath.Vector4f)17 Stack (com.bulletphysics.util.Stack)8 Vector3f (javax.vecmath.Vector3f)8 StaticPlaneShape (com.bulletphysics.collision.shapes.StaticPlaneShape)1 AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)1 Transform (com.bulletphysics.linearmath.Transform)1 Matrix3f (javax.vecmath.Matrix3f)1 Matrix4f (javax.vecmath.Matrix4f)1 BlockFaceUV (net.minecraft.client.renderer.block.model.BlockFaceUV)1 Vec3i (net.minecraft.util.math.Vec3i)1 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)1