Search in sources :

Example 1 with Vector3f

use of javax.vecmath.Vector3f 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 2 with Vector3f

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

the class VertexLighterFlat method processQuad.

@Override
protected void processQuad() {
    float[][] position = quadData[posIndex];
    float[][] normal = null;
    float[][] lightmap = quadData[lightmapIndex];
    float[][] color = quadData[colorIndex];
    if (normalIndex != -1 && (quadData[normalIndex][0][0] != -1 || quadData[normalIndex][0][1] != -1 || quadData[normalIndex][0][2] != -1)) {
        normal = quadData[normalIndex];
    } else {
        normal = new float[4][4];
        Vector3f v1 = new Vector3f(position[3]);
        Vector3f t = new Vector3f(position[1]);
        Vector3f v2 = new Vector3f(position[2]);
        v1.sub(t);
        t.set(position[0]);
        v2.sub(t);
        v1.cross(v2, v1);
        v1.normalize();
        for (int v = 0; v < 4; v++) {
            normal[v][0] = v1.x;
            normal[v][1] = v1.y;
            normal[v][2] = v1.z;
            normal[v][3] = 0;
        }
    }
    int multiplier = -1;
    if (tint != -1) {
        multiplier = blockInfo.getColorMultiplier(tint);
    }
    VertexFormat format = parent.getVertexFormat();
    int count = format.getElementCount();
    for (int v = 0; v < 4; v++) {
        position[v][0] += blockInfo.getShx();
        position[v][1] += blockInfo.getShy();
        position[v][2] += blockInfo.getShz();
        float x = position[v][0] - .5f;
        float y = position[v][1] - .5f;
        float z = position[v][2] - .5f;
        //if(blockInfo.getBlock().isFullCube())
        {
            x += normal[v][0] * .5f;
            y += normal[v][1] * .5f;
            z += normal[v][2] * .5f;
        }
        float blockLight = lightmap[v][0], skyLight = lightmap[v][1];
        updateLightmap(normal[v], lightmap[v], x, y, z);
        if (dataLength[lightmapIndex] > 1) {
            if (blockLight > lightmap[v][0])
                lightmap[v][0] = blockLight;
            if (skyLight > lightmap[v][1])
                lightmap[v][1] = skyLight;
        }
        updateColor(normal[v], color[v], x, y, z, tint, multiplier);
        if (diffuse) {
            float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
            for (int i = 0; i < 3; i++) {
                color[v][i] *= d;
            }
        }
        if (EntityRenderer.anaglyphEnable) {
            applyAnaglyph(color[v]);
        }
        // no need for remapping cause all we could've done is add 1 element to the end
        for (int e = 0; e < count; e++) {
            VertexFormatElement element = format.getElement(e);
            switch(element.getUsage()) {
                case POSITION:
                    // position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float
                    /*float[] pos = new float[4];
                        System.arraycopy(position[v], 0, pos, 0, position[v].length);
                        pos[0] += blockInfo.getBlockPos().getX();
                        pos[1] += blockInfo.getBlockPos().getY();
                        pos[2] += blockInfo.getBlockPos().getZ();*/
                    parent.put(e, position[v]);
                    break;
                case NORMAL:
                    if (normalIndex != -1) {
                        parent.put(e, normal[v]);
                        break;
                    }
                case COLOR:
                    parent.put(e, color[v]);
                    break;
                case UV:
                    if (element.getIndex() == 1) {
                        parent.put(e, lightmap[v]);
                        break;
                    }
                default:
                    parent.put(e, quadData[e][v]);
            }
        }
    }
    tint = -1;
}
Also used : Vector3f(javax.vecmath.Vector3f) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 3 with Vector3f

use of javax.vecmath.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class BufferedTriangleCallback method processTriangle.

@Override
public void processTriangle(Vector3f[] triangle, int partId, int triangleIndex) {
    // Three sets of individual lines
    // The new Vector is needed as the given triangle reference is from a pool
    vertices.add(new Vector3f(triangle[0]));
    vertices.add(new Vector3f(triangle[1]));
    vertices.add(new Vector3f(triangle[2]));
}
Also used : Vector3f(javax.vecmath.Vector3f)

Example 4 with Vector3f

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

the class Dbvt method update.

public boolean update(Node leaf, DbvtAabbMm volume, float margin) {
    if (leaf.volume.Contain(volume)) {
        return false;
    }
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    tmp.set(margin, margin, margin);
    volume.Expand(tmp);
    update(leaf, volume);
    stack.leave();
    return true;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 5 with Vector3f

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

the class Dbvt method topdown.

private static Node topdown(Dbvt pdbvt, ObjectArrayList<Node> leaves, int bu_treshold) {
    if (leaves.size() > 1) {
        if (leaves.size() > bu_treshold) {
            Stack stack = Stack.enter();
            DbvtAabbMm vol = bounds(leaves);
            Vector3f org = vol.Center(stack.allocVector3f());
            ObjectArrayList[] sets = new ObjectArrayList[2];
            for (int i = 0; i < sets.length; i++) {
                sets[i] = new ObjectArrayList();
            }
            int bestaxis = -1;
            int bestmidp = leaves.size();
            int[][] splitcount = new int[][] { { 0, 0 }, { 0, 0 }, { 0, 0 } };
            Vector3f x = stack.allocVector3f();
            for (int i = 0; i < leaves.size(); i++) {
                leaves.getQuick(i).volume.Center(x);
                x.sub(org);
                for (int j = 0; j < 3; j++) {
                    splitcount[j][x.dot(axis[j]) > 0f ? 1 : 0]++;
                }
            }
            for (int i = 0; i < 3; i++) {
                if ((splitcount[i][0] > 0) && (splitcount[i][1] > 0)) {
                    int midp = Math.abs(splitcount[i][0] - splitcount[i][1]);
                    if (midp < bestmidp) {
                        bestaxis = i;
                        bestmidp = midp;
                    }
                }
            }
            if (bestaxis >= 0) {
                //sets[0].reserve(splitcount[bestaxis][0]);
                //sets[1].reserve(splitcount[bestaxis][1]);
                split(leaves, sets[0], sets[1], org, axis[bestaxis]);
            } else {
                //sets[1].reserve(leaves.size()/2);
                for (int i = 0, ni = leaves.size(); i < ni; i++) {
                    sets[i & 1].add(leaves.getQuick(i));
                }
            }
            Node node = createnode(pdbvt, null, vol, null);
            node.childs[0] = topdown(pdbvt, sets[0], bu_treshold);
            node.childs[1] = topdown(pdbvt, sets[1], bu_treshold);
            node.childs[0].parent = node;
            node.childs[1].parent = node;
            stack.leave();
            return node;
        } else {
            bottomup(pdbvt, leaves);
            return leaves.getQuick(0);
        }
    }
    return leaves.getQuick(0);
}
Also used : ObjectArrayList(com.bulletphysics.util.ObjectArrayList) Vector3f(javax.vecmath.Vector3f) Node(com.bulletphysics.collision.broadphase.Dbvt.Node) Stack(com.bulletphysics.util.Stack)

Aggregations

Vector3f (javax.vecmath.Vector3f)265 Stack (com.bulletphysics.util.Stack)197 Transform (com.bulletphysics.linearmath.Transform)53 Matrix3f (javax.vecmath.Matrix3f)25 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)14 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 Matrix4f (javax.vecmath.Matrix4f)9 Vector4f (javax.vecmath.Vector4f)8 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)7 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)6 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 SphereShape (com.bulletphysics.collision.shapes.SphereShape)4 RigidBody (com.bulletphysics.dynamics.RigidBody)4 HashMap (java.util.HashMap)4 Quat4f (javax.vecmath.Quat4f)4 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)3 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)3