Examples of Triangle


Examples of com.jme3.math.Triangle

     * @param bb
     *            the bounding box for projecting
     * @return UV coordinates after the projection
     */
    public static float[] cubeProjection(float[] positions, BoundingBox bb) {
        Triangle triangle = new Triangle();
        Vector3f x = new Vector3f(1, 0, 0);
        Vector3f y = new Vector3f(0, 1, 0);
        Vector3f z = new Vector3f(0, 0, 1);
        Vector3f min = bb.getMin(null);
        float[] ext = new float[] { bb.getXExtent() * 2.0f, bb.getYExtent() * 2.0f, bb.getZExtent() * 2.0f };

        float[] uvCoordinates = new float[positions.length / 3 * 2];
        float borderAngle = (float) Math.sqrt(2.0f) / 2.0f;
        for (int i = 0, pointIndex = 0; i < positions.length; i += 9) {
            triangle.set(0, positions[i], positions[i + 1], positions[i + 2]);
            triangle.set(1, positions[i + 3], positions[i + 4], positions[i + 5]);
            triangle.set(2, positions[i + 6], positions[i + 7], positions[i + 8]);
            Vector3f n = triangle.getNormal();
            float dotNX = Math.abs(n.dot(x));
            float dorNY = Math.abs(n.dot(y));
            float dotNZ = Math.abs(n.dot(z));
            if (dotNX > borderAngle) {
                if (dotNZ < borderAngle) {// discard X-coordinate
                    uvCoordinates[pointIndex++] = (triangle.get1().y - min.y) / ext[1];
                    uvCoordinates[pointIndex++] = (triangle.get1().z - min.z) / ext[2];
                    uvCoordinates[pointIndex++] = (triangle.get2().y - min.y) / ext[1];
                    uvCoordinates[pointIndex++] = (triangle.get2().z - min.z) / ext[2];
                    uvCoordinates[pointIndex++] = (triangle.get3().y - min.y) / ext[1];
                    uvCoordinates[pointIndex++] = (triangle.get3().z - min.z) / ext[2];
                } else {// discard Z-coordinate
                    uvCoordinates[pointIndex++] = (triangle.get1().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get1().y - min.y) / ext[1];
                    uvCoordinates[pointIndex++] = (triangle.get2().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get2().y - min.y) / ext[1];
                    uvCoordinates[pointIndex++] = (triangle.get3().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get3().y - min.y) / ext[1];
                }
            } else {
                if (dorNY > borderAngle) {// discard Y-coordinate
                    uvCoordinates[pointIndex++] = (triangle.get1().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get1().z - min.z) / ext[2];
                    uvCoordinates[pointIndex++] = (triangle.get2().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get2().z - min.z) / ext[2];
                    uvCoordinates[pointIndex++] = (triangle.get3().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get3().z - min.z) / ext[2];
                } else {// discard Z-coordinate
                    uvCoordinates[pointIndex++] = (triangle.get1().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get1().y - min.y) / ext[1];
                    uvCoordinates[pointIndex++] = (triangle.get2().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get2().y - min.y) / ext[1];
                    uvCoordinates[pointIndex++] = (triangle.get3().x - min.x) / ext[0];
                    uvCoordinates[pointIndex++] = (triangle.get3().y - min.y) / ext[1];
                }
            }
            triangle.setNormal(null);// clear the previous normal vector
        }
        return uvCoordinates;
    }
View Full Code Here

Examples of com.jme3.math.Triangle

            float y = positions[i + 1];
            uvCoordinates[j + 1] = (y - vBase) / bt.getHeight();
        }

        // looking for splitted triangles
        Triangle triangle = new Triangle();
        for (int i = 0; i < positions.length; i += 9) {
            triangle.set(0, positions[i], positions[i + 1], positions[i + 2]);
            triangle.set(1, positions[i + 3], positions[i + 4], positions[i + 5]);
            triangle.set(2, positions[i + 6], positions[i + 7], positions[i + 8]);
            float sgn1 = Math.signum(triangle.get1().x - cx);
            float sgn2 = Math.signum(triangle.get2().x - cx);
            float sgn3 = Math.signum(triangle.get3().x - cx);
            float xSideFactor = sgn1 + sgn2 + sgn3;
            float ySideFactor = Math.signum(triangle.get1().z - cz) + Math.signum(triangle.get2().z - cz) + Math.signum(triangle.get3().z - cz);
            if ((xSideFactor > -3 || xSideFactor < 3) && ySideFactor < 0) {// the triangle is on the splitting plane
                if (sgn1 == 1.0f) {
                    uvCoordinates[i / 3 * 2] += 1.0f;
                }
                if (sgn2 == 1.0f) {
View Full Code Here

Examples of com.jme3.math.Triangle

            angle = v.angleBetween(vBase);// result between [0; PI]
            uvCoordinates[j + 1] = angle / FastMath.PI;
        }

        // looking for splitted triangles
        Triangle triangle = new Triangle();
        for (int i = 0; i < positions.length; i += 9) {
            triangle.set(0, positions[i], positions[i + 1], positions[i + 2]);
            triangle.set(1, positions[i + 3], positions[i + 4], positions[i + 5]);
            triangle.set(2, positions[i + 6], positions[i + 7], positions[i + 8]);
            float sgn1 = Math.signum(triangle.get1().x - cx);
            float sgn2 = Math.signum(triangle.get2().x - cx);
            float sgn3 = Math.signum(triangle.get3().x - cx);
            float xSideFactor = sgn1 + sgn2 + sgn3;
            float ySideFactor = Math.signum(triangle.get1().y - cy) + Math.signum(triangle.get2().y - cy) + Math.signum(triangle.get3().y - cy);
            if ((xSideFactor > -3 || xSideFactor < 3) && ySideFactor < 0) {// the triangle is on the splitting plane
                if (sgn1 == 1.0f) {
                    uvCoordinates[i / 3 * 2] += 1.0f;
                }
                if (sgn2 == 1.0f) {
View Full Code Here

Examples of com.jme3.math.Triangle

            final Vector3f intersection = new Vector3f();
            final Vector2f loc = tracer.getGridLocation();

            if (tracer.isRayPerpendicularToGrid()) {
                Triangle hit = new Triangle();
                checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit);
                float distance = worldPickRay.origin.distance(intersection);
                CollisionResult cr = new CollisionResult(intersection, distance);
                cr.setGeometry(patch);
                cr.setContactNormal(hit.getNormal());
                results.addCollision(cr);
                return intersection;
            }
           
           

            while (loc.x >= -1 && loc.x <= patch.getSize() &&
                   loc.y >= -1 && loc.y <= patch.getSize()) {

                //System.out.print(loc.x+","+loc.y+" : ");
                // check the triangles of main square for intersection.
                Triangle hit = new Triangle();
                if (checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit)) {
                    // we found an intersection, so return that!
                    float distance = worldPickRay.origin.distance(intersection);
                    CollisionResult cr = new CollisionResult(intersection, distance);
                    cr.setGeometry(patch);
                    results.addCollision(cr);
                    cr.setContactNormal(hit.getNormal());
                    return intersection;
                }

                // because of how we get our height coords, we will
                // sometimes be off by a grid spot, so we check the next
                // grid space up.
                int dx = 0, dz = 0;
                Direction d = tracer.getLastStepDirection();
                switch (d) {
                case PositiveX:
                case NegativeX:
                    dx = 0;
                    dz = 1;
                    break;
                case PositiveZ:
                case NegativeZ:
                    dx = 1;
                    dz = 0;
                    break;
                }

                if (checkTriangles(loc.x + dx, loc.y + dz, workRay, intersection, patch, hit)) {
                    // we found an intersection, so return that!
                    float distance = worldPickRay.origin.distance(intersection);
                    CollisionResult cr = new CollisionResult(intersection, distance);
                    results.addCollision(cr);
                    cr.setGeometry(patch);
                    cr.setContactNormal(hit.getNormal());
                    return intersection;
                }

                tracer.next();
            }
View Full Code Here

Examples of com.jme3.math.Triangle

     * @param x local x coordinate
     * @param z local z coordinate
     * @return a triangle in world space not local space
     */
    protected Triangle getTriangleAtPoint(float x, float z, Vector3f scale, Vector3f translation) {
        Triangle tri = getTriangleAtPoint(x, z);
        if (tri != null) {
            tri.get1().multLocal(scale).addLocal(translation);
            tri.get2().multLocal(scale).addLocal(translation);
            tri.get3().multLocal(scale).addLocal(translation);
        }
        return tri;
    }
View Full Code Here

Examples of com.jme3.math.Triangle

        int index = findClosestHeightIndex(gridX, gridY);
        if (index < 0) {
            return null;
        }

        Triangle t = new Triangle(new Vector3f(), new Vector3f(), new Vector3f());
        Triangle t2 = new Triangle(new Vector3f(), new Vector3f(), new Vector3f());

        float h1 = hdata[index];                // top left
        float h2 = hdata[index + 1];            // top right
        float h3 = hdata[index + width];        // bottom left
        float h4 = hdata[index + width + 1];    // bottom right


        if ((gridX == 0 && gridY == 0) || (gridX == width - 2 && gridY == width - 2)) {
            // top left or bottom right grid point
            t.get(0).x = (gridX);
            t.get(0).y = (h1);
            t.get(0).z = (gridY);

            t.get(1).x = (gridX);
            t.get(1).y = (h3);
            t.get(1).z = (gridY + 1);

            t.get(2).x = (gridX + 1);
            t.get(2).y = (h4);
            t.get(2).z = (gridY + 1);

            t2.get(0).x = (gridX);
            t2.get(0).y = (h1);
            t2.get(0).z = (gridY);

            t2.get(1).x = (gridX + 1);
            t2.get(1).y = (h4);
            t2.get(1).z = (gridY + 1);

            t2.get(2).x = (gridX + 1);
            t2.get(2).y = (h2);
            t2.get(2).z = (gridY);
        } else {
            // all other grid points
            t.get(0).x = (gridX);
            t.get(0).y = (h1);
            t.get(0).z = (gridY);

            t.get(1).x = (gridX);
            t.get(1).y = (h3);
            t.get(1).z = (gridY + 1);

            t.get(2).x = (gridX + 1);
            t.get(2).y = (h2);
            t.get(2).z = (gridY);

            t2.get(0).x = (gridX + 1);
            t2.get(0).y = (h2);
            t2.get(0).z = (gridY);

            t2.get(1).x = (gridX);
            t2.get(1).y = (h3);
            t2.get(1).z = (gridY + 1);

            t2.get(2).x = (gridX + 1);
            t2.get(2).y = (h4);
            t2.get(2).z = (gridY + 1);
        }

        return new Triangle[]{t, t2};
    }
View Full Code Here

Examples of com.kjoshi.shareit.responsible.Triangle

*/
public class ChainOfResponsibility {
  public static void main(String[] args) {
    // I am keeping Circle in the last in the chain so starting from Circle
    Area circle = new Circle();
    Area triangle = new Triangle(circle);
    Area rectangle = new Rectangle(triangle);
    Area square = new Square(rectangle);
    for (String shape : listOfShapes()) {
      square.findArea(shape);
    }
View Full Code Here

Examples of com.sk89q.worldedit.regions.polyhedron.Triangle

        case 3:
            // Generate minimal mesh to start from
            final Vector[] v = vertices.toArray(new Vector[vertices.size()]);

            triangles.add((new Triangle(v[0], v[1], v[2])));
            triangles.add((new Triangle(v[0], v[2], v[1])));
            return true;
        }

        // Look for triangles that face the vertex and remove them
        final Set<Edge> borderEdges = new LinkedHashSet<Edge>();
        for (Iterator<Triangle> it = triangles.iterator(); it.hasNext(); ) {
            final Triangle triangle = it.next();

            // If the triangle can't be seen, it's not relevant
            if (!triangle.above(vertex)) {
                continue;
            }

            // Remove the triangle from the mesh
            it.remove();

            // ...and remember its edges
            for (int i = 0; i < 3; ++i) {
                final Edge edge = triangle.getEdge(i);
                if (borderEdges.remove(edge)) {
                    continue;
                }

                borderEdges.add(edge);
View Full Code Here

Examples of com.sk89q.worldedit.regions.polyhedron.Triangle

    public void shift(Vector change) throws RegionOperationException {
        shiftCollection(vertices, change);
        shiftCollection(vertexBacklog, change);

        for (int i = 0; i < triangles.size(); ++i) {
            final Triangle triangle = triangles.get(i);

            final Vector v0 = change.add(triangle.getVertex(0));
            final Vector v1 = change.add(triangle.getVertex(1));
            final Vector v2 = change.add(triangle.getVertex(2));

            triangles.set(i, new Triangle(v0, v1, v2));
        }

        minimumPoint = change.add(minimumPoint);
        maximumPoint = change.add(maximumPoint);
        centerAccum = change.multiply(vertices.size()).add(centerAccum);
View Full Code Here

Examples of cranks.geom.Triangle

                  step = new ConstructionStep(this,
                              new Object[]{objectToBeAdded}, LINE);
                break;

                case MOUSE_MODE_TRIANGLE:
                  objectToBeAdded = new Triangle(mouseClicks[0], mouseClicks[1],
                                                 mouseClicks[2]);
                  step = new ConstructionStep(this,
                              new Object[]{objectToBeAdded}, TRIANGLE);
                break;
                default :
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.