Package com.ardor3d.intersection

Examples of com.ardor3d.intersection.PrimitiveKey


                for (int t = 0; t < storeB.length; t++) {
                    transformB.applyForward(storeB[t]);
                }
                if (Intersection.intersection(storeA, storeB)) {
                    test = true;
                    aList.add(new PrimitiveKey(_primitiveIndices[i], _section));
                    bList.add(new PrimitiveKey(collisionTree._primitiveIndices[j], collisionTree._section));
                }
            }
        }

        return test;
View Full Code Here


                points = data.getPrimitiveVertices(_primitiveIndices[i], _section, points);
                for (int t = 0; t < points.length; t++) {
                    transform.applyForward(points[t]);
                }
                if (ray.intersects(points, null)) {
                    result.add(new PrimitiveKey(_primitiveIndices[i], _section));
                }
            }
        }
        return result;
    }
View Full Code Here

        }

        Vector3[] vertices = null;
        final double[] distances = new double[primitives.size()];
        for (int i = 0; i < primitives.size(); i++) {
            final PrimitiveKey key = primitives.get(i);
            vertices = getMeshData().getPrimitiveVertices(key.getPrimitiveIndex(), key.getSection(), vertices);
            // convert to world coord space
            final int max = getMeshData().getIndexMode(key.getSection()).getVertexCount();
            for (int j = 0; j < max; j++) {
                if (vertices[j] != null) {
                    getWorldTransform().applyForward(vertices[j]);
                }
            }
            final double triDistanceSq = ray.getDistanceToPrimitive(vertices);
            distances[i] = triDistanceSq;
        }

        // FIXME: optimize! ugly bubble sort for now
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int sort = 0; sort < distances.length - 1; sort++) {
                if (distances[sort] > distances[sort + 1]) {
                    // swap
                    sorted = false;
                    final double temp = distances[sort + 1];
                    distances[sort + 1] = distances[sort];
                    distances[sort] = temp;

                    // swap primitives too
                    final PrimitiveKey temp2 = primitives.get(sort + 1);
                    primitives.set(sort + 1, primitives.get(sort));
                    primitives.set(sort, temp2);
                }
            }
        }
View Full Code Here

        // act on drag
        final PickData pickData = _results.getPickData(0);
        final Spatial picked = (Spatial) pickData.getTarget();
        if (picked instanceof Mesh && pickData.getIntersectionRecord().getNumberOfIntersections() > 0) {
            final PrimitiveKey key = pickData.getIntersectionRecord().getIntersectionPrimitive(0);
            ((Mesh) picked).getMeshData().getPrimitiveVertices(key.getPrimitiveIndex(), key.getSection(),
                    new Vector3[] { _calcVec3A, _calcVec3B, _calcVec3C });
            picked.localToWorld(_calcVec3A, _calcVec3A);
            picked.localToWorld(_calcVec3B, _calcVec3B);
            picked.localToWorld(_calcVec3C, _calcVec3C);
            final Vector3 loc = getNewOffset(oldMouse, current, camera, manager);
View Full Code Here

        final FloatBuffer color1 = sphere.getMeshData().getColorBuffer();
        final FloatBuffer color2 = torus.getMeshData().getColorBuffer();

        if (oldData != null) {
            for (int j = 0; j < oldData.getSourcePrimitives().size(); j++) {
                final PrimitiveKey key = oldData.getSourcePrimitives().get(j);
                sphereMD.getPrimitiveIndices(key.getPrimitiveIndex(), key.getSection(), indexBuffer);
                BufferUtils.setInBuffer(colorSpread[indexBuffer[0] % 3], color1, indexBuffer[0]);
                BufferUtils.setInBuffer(colorSpread[indexBuffer[1] % 3], color1, indexBuffer[1]);
                BufferUtils.setInBuffer(colorSpread[indexBuffer[2] % 3], color1, indexBuffer[2]);
            }

            for (int j = 0; j < oldData.getTargetPrimitives().size(); j++) {
                final PrimitiveKey key = oldData.getTargetPrimitives().get(j);
                torusMD.getPrimitiveIndices(key.getPrimitiveIndex(), key.getSection(), indexBuffer);
                BufferUtils.setInBuffer(colorSpread[indexBuffer[0] % 3], color2, indexBuffer[0]);
                BufferUtils.setInBuffer(colorSpread[indexBuffer[1] % 3], color2, indexBuffer[1]);
                BufferUtils.setInBuffer(colorSpread[indexBuffer[2] % 3], color2, indexBuffer[2]);
            }
        }

        results.clear();
        PickingUtil.findCollisions(torusNode, sphereNode, results);

        if (results.getNumber() > 0) {
            oldData = results.getCollisionData(0);
            for (int i = 0; i < oldData.getSourcePrimitives().size(); i++) {
                final PrimitiveKey key = oldData.getSourcePrimitives().get(i);
                sphereMD.getPrimitiveIndices(key.getPrimitiveIndex(), key.getSection(), indexBuffer);
                BufferUtils.setInBuffer(ColorRGBA.RED, color1, indexBuffer[0]);
                BufferUtils.setInBuffer(ColorRGBA.RED, color1, indexBuffer[1]);
                BufferUtils.setInBuffer(ColorRGBA.RED, color1, indexBuffer[2]);
            }

            for (int i = 0; i < oldData.getTargetPrimitives().size(); i++) {
                final PrimitiveKey key = oldData.getTargetPrimitives().get(i);
                torusMD.getPrimitiveIndices(key.getPrimitiveIndex(), key.getSection(), indexBuffer);
                BufferUtils.setInBuffer(ColorRGBA.BLUE, color2, indexBuffer[0]);
                BufferUtils.setInBuffer(ColorRGBA.BLUE, color2, indexBuffer[1]);
                BufferUtils.setInBuffer(ColorRGBA.BLUE, color2, indexBuffer[2]);
            }
        }
View Full Code Here

TOP

Related Classes of com.ardor3d.intersection.PrimitiveKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.