Search in sources :

Example 26 with Vector2d

use of javax.vecmath.Vector2d in project chordatlas by twak.

the class SkelFootprint method insert.

public static void insert(HalfMesh2 mesh, Line line, double softDist, boolean backwardsToo, boolean setLine) {
    Vector2d dir = line.dir(), nDir = new Vector2d(dir);
    nDir.negate();
    double remaining = line.length();
    for (HalfFace f : mesh.faces) {
        if (f.contains(line.start)) {
            HalfEdge n = f.fracture(line.start, nDir), p = f.fracture(line.start, dir);
            if (n == null || p == null) {
                System.err.println("geometry failure");
                return;
            }
            HalfEdge next = p.next.over, prev = n.next.over;
            HalfEdge dividing = f.split(mesh, n, p);
            dividing.split(line.start);
            ((SuperEdge) dividing.next).profLine = setLine ? (SuperLine) line : null;
            double l = dividing.next.length();
            if (remaining < l) {
                Point2d softStart = new Point2d(dir);
                softStart.scale(remaining / dir.length());
                softStart.add(line.start);
                dividing.next.split(softStart);
                ((SuperEdge) dividing.next.next).profLine = null;
                ((SuperEdge) dividing.next.next.over).profLine = null;
                double remSoftDist = softDist - dividing.next.next.line().length();
                if (remSoftDist > 0)
                    fracture(mesh, next, dir, 0, remSoftDist, null, setLine);
            } else if (next != null)
                fracture(mesh, next, dir, remaining - l, softDist, line, setLine);
            double softDistN = softDist - dividing.start.distance(line.start);
            if (backwardsToo && softDistN > 0 && prev != null) {
                fracture(mesh, prev, nDir, 0, softDistN, null, setLine);
            }
            return;
        }
    }
}
Also used : Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) SuperLine(org.twak.viewTrace.SuperLine) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace)

Example 27 with Vector2d

use of javax.vecmath.Vector2d in project chordatlas by twak.

the class SkelFootprint method fractureOnFeatures.

private void fractureOnFeatures(MultiMap<MegaFeatures, MFPoint> minis, List<Line> footprint, HalfMesh2 mesh) {
    for (MegaFeatures mf : minis.keySet()) pt: for (MFPoint pt : minis.get(mf)) {
        if (!Mathz.inRange(mf.megafacade.findPPram(pt), 0, 1))
            continue;
        Vector2d dir = pt.mega.megafacade.dir();
        dir.set(dir.y, -dir.x);
        Point2d probe = new Point2d(dir);
        probe.scale(2 / dir.length());
        probe.add(pt);
        for (// don't fracture near minifacade boundaries...we can't distinguish nice block bondaries
        Point2d avoid : // don't fracture near minifacade boundaries...we can't distinguish nice block bondaries
        pt.mega.megafacade.points()) if (avoid.distanceSquared(pt) < 4)
            continue pt;
        double bestDist = Double.MAX_VALUE;
        for (HalfFace f : mesh.faces) for (HalfEdge e : f) if (e.line().dir().angle(dir) < 0.4) {
            double dist = e.line().distance(probe);
            if (dist < bestDist)
                bestDist = dist;
        }
        if (bestDist > 0.3) {
            Vector2d end = new Vector2d(dir);
            end.scale(3 / end.length());
            end.add(probe);
            Vector2d start = new Vector2d(dir);
            start.scale(0.5 / start.length());
            start.add(pt);
            Line extra = new Line(new Point2d(start), new Point2d(end));
            SkelFootprint.insert(mesh, extra, 2, false, false);
        }
    }
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace)

Example 28 with Vector2d

use of javax.vecmath.Vector2d in project chordatlas by twak.

the class ImagePlaneGen method fudgeToDepth.

public void fudgeToDepth(float scale, Pano pano, List<Double> deltas) {
    Point3d worldPos = new Point3d();
    Vector3d worldNormal = new Vector3d(), planeNormal = new Vector3d(Jme3z.from(b));
    planeNormal.sub(Jme3z.from(a));
    planeNormal.normalize();
    planeNormal.set(planeNormal.z, 0, -planeNormal.x);
    int width = (int) (a.distance(b) * scale);
    for (int x = width / 3; x < 2 * width / 3; x++) {
        float[] planeWorld = uvToWorld(x / (float) width, 0.2f);
        Point3d requested = new Point3d(planeWorld[0], planeWorld[1], planeWorld[2]);
        pano.castTo(planeWorld, null, worldPos, worldNormal);
        if (!Double.isNaN(worldPos.x) && requested.distanceSquared(worldPos) < 30) {
            double delta = Mathz.signedAngle(new Vector2d(worldNormal.x, worldNormal.z), new Vector2d(planeNormal.x, planeNormal.z));
            if (Math.abs(delta) < 0.6)
                deltas.add(delta);
        }
    }
// PlaneGen out = this;
// 
// if ( deltas.size() > 20 ) {
// Collections.sort( deltas );
// 
// double delta = deltas.get( deltas.size() / 3 );
// 
// out = rotateByAngle( delta, 0 );
// 
// System.out.println(" delta is " + delta );
// }
// 
// calculateOnJmeThread();
// 
// return out;
}
Also used : Vector2d(javax.vecmath.Vector2d) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d)

Example 29 with Vector2d

use of javax.vecmath.Vector2d in project ct.js by ChatTriggers.

the class Shape method setCircle.

/**
 * Sets the shape as a circle.
 *
 * @param x      The x position
 * @param y      The y position
 * @param radius The radius
 * @param steps  The number of steps to take to complete the circle
 * @return The shape to allow for method chaining
 */
public Shape setCircle(float x, float y, float radius, int steps) {
    this.vertexes.clear();
    double theta = 2 * Math.PI / steps;
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xHolder;
    double circleX = 1;
    double circleY = 0;
    for (int i = 0; i < steps; i++) {
        this.vertexes.add(new Vector2d(x, y));
        this.vertexes.add(new Vector2d(circleX * radius + x, circleY * radius + y));
        xHolder = circleX;
        circleX = cos * circleX - sin * circleY;
        circleY = sin * xHolder + cos * circleY;
        this.vertexes.add(new Vector2d(circleX * radius + x, circleY * radius + y));
    }
    this.drawMode = 5;
    return this;
}
Also used : Vector2d(javax.vecmath.Vector2d)

Aggregations

Vector2d (javax.vecmath.Vector2d)29 Point2d (javax.vecmath.Point2d)15 Vector3d (javax.vecmath.Vector3d)12 ArrayList (java.util.ArrayList)9 Point3d (javax.vecmath.Point3d)8 List (java.util.List)7 Line (org.twak.utils.Line)7 SuperLine (org.twak.viewTrace.SuperLine)6 Line3d (org.twak.utils.geom.Line3d)5 LinearForm3D (org.twak.utils.geom.LinearForm3D)5 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Mesh (com.jme3.scene.Mesh)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 ColorRGBA (com.jme3.math.ColorRGBA)3 Node (com.jme3.scene.Node)3 VertexBuffer (com.jme3.scene.VertexBuffer)3 Graphics2D (java.awt.Graphics2D)3 Collection (java.util.Collection)3