use of javax.vecmath.Vector2d in project chordatlas by twak.
the class Tube method tube.
public static void tube(MeshBuilder out, Collection<LinearForm3D> before, Collection<LinearForm3D> after, Line3d line, LinearForm3D left, LinearForm3D right, CrossGen gen) {
if (angle(before, line) < 0.1 || angle(after, line) < 0.1)
// too pointy to touch
return;
Point3d middle = line.fromPPram(0.5);
Vector3d along = line.dir();
along.normalize();
Vector3d nAlong = new Vector3d(along);
nAlong.negate();
Vector3d o1 = left.normal(), u1 = new Vector3d();
u1.cross(along, o1);
Frame frame = Mathz.buildFrame(o1, u1, along, middle);
Vector3d u2 = right.normal();
u2.cross(u2, along);
// u2.add( middle );
Vector2d leftDir = Mathz.toXY(frame, u1);
Vector2d rightDir = Mathz.toXY(frame, u2);
List<Point3d> profilePts = gen.gen(leftDir, rightDir).stream().map(p -> Mathz.fromXY(frame, p)).collect(Collectors.toList());
List<LinearForm3D> dummy = new ArrayList<>();
for (Pair<Point3d, Point3d> pair : new ConsecutivePairs<Point3d>(profilePts, true)) {
Point3d f1 = clip(pair.first(), along, after, dummy), f2 = clip(pair.second(), along, after, dummy), b1 = clip(pair.first(), nAlong, before, dummy), b2 = clip(pair.second(), nAlong, before, dummy);
out.add(f2, f1, b1, b2);
}
// cap( out, after , along, profilePts, true );
// cap( out, before, nAlong, profilePts, false );
}
use of javax.vecmath.Vector2d in project chordatlas by twak.
the class GreebleEdge method roofGreeble.
public static boolean roofGreeble(Face f, MeshBuilder roof) {
boolean isWall = isWall(f);
for (Loop<SharedEdge> sl : f.edges) {
for (Loopable<SharedEdge> sel : sl.loopableIterator()) {
SharedEdge se = sel.get();
boolean otherIsWall = isWall(se.getOther(f));
if (!isWall && !otherIsWall) {
Face oF = se.getOther(f);
if (oF == null || order(f, oF) || f.edge.getPlaneNormal().angle(oF.edge.getPlaneNormal()) < 0.4)
continue;
List<LinearForm3D> start = new ArrayList(), end = new ArrayList<>();
{
SharedEdge fPrev = se.getAdjEdge(f, false), fNext = se.getAdjEdge(f, true), ofPrev = se.getAdjEdge(oF, false), ofNext = se.getAdjEdge(oF, true);
if (fNext == null || fPrev == null || ofNext == null || ofPrev == null)
continue;
double overHang = -0.03;
if (isWall(fNext.getOther(f)))
end.add(toLF(fNext.getOther(f), overHang));
else
end.add(roofTween(fNext, se, f));
if (isWall(ofPrev.getOther(oF)))
end.add(toLF(ofPrev.getOther(oF), overHang));
else
end.add(roofTween(se, ofPrev, oF));
if (isWall(fPrev.getOther(f)))
start.add(toLF(fPrev.getOther(f), overHang));
else
start.add(roofTween(se, fPrev, f));
if (isWall(ofNext.getOther(oF)))
start.add(toLF(ofNext.getOther(oF), overHang));
else
start.add(roofTween(ofNext, se, oF));
}
Point3d s = se.getStart(f), e = se.getEnd(f);
if (end.contains(null) || start.contains(null))
continue;
Tube.tube(roof, end, start, new Line3d(new Point3d(s.x, s.z, s.y), new Point3d(e.x, e.z, e.y)), toLF(f, 0), toLF(oF, 0), new CrossGen() {
@Override
public List<Point2d> gen(Vector2d left, Vector2d right) {
Vector2d l = new Vector2d(left);
l.normalize();
Vector2d lP = new Vector2d(l.y, -l.x);
Vector2d r = new Vector2d(right);
r.normalize();
Vector2d rP = new Vector2d(-r.y, r.x);
List<Point2d> out = new ArrayList();
double width = 0.15, height = 0.03;
Vector2d rn = new Vector2d(r);
rn.negate();
// height / Math.sin ( ( Math.PI - l.angle( rn ) ) /2 );
double cenOffset = 0.02;
Vector2d cen = new Vector2d(lP);
cen.add(rP);
cen.normalize();
for (double[] coords : new double[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, -width }, { 0, 0, 0, height, -width }, { 0, 0, cenOffset, 0, 0 }, { -width, height, 0, 0, 0 }, { -width, 0, 0, 0, 0 } }) {
Point2d tmp = new Point2d(l), tmp2;
tmp.scale(coords[0]);
tmp2 = new Point2d(lP);
tmp2.scale(coords[1]);
tmp.add(tmp2);
tmp2 = new Point2d(cen);
tmp2.scale(coords[2]);
tmp.add(tmp2);
tmp2 = new Point2d(rP);
tmp2.scale(coords[3]);
tmp.add(tmp2);
tmp2 = new Point2d(r);
tmp2.scale(coords[4]);
tmp.add(tmp2);
out.add(tmp);
}
return out;
}
});
}
}
}
return true;
}
use of javax.vecmath.Vector2d in project chordatlas by twak.
the class ImagePlaneGen method rotateByAngle.
public ImagePlaneGen rotateByAngle(double deltaAngle, double distance) {
Line nLine = new Line(new Point2d(a.x, a.z), new Point2d(b.x, b.z));
Point2d cen = nLine.fromPPram(0.5);
double angle = nLine.aTan2() + deltaAngle;
double len = nLine.length() / 2;
Vector2d dir = new Vector2d(-Math.cos(angle) * len, -Math.sin(angle) * len);
Point2d start = new Point2d(cen), end = new Point2d(cen);
start.add(dir);
end.sub(dir);
ImagePlaneGen out = new ImagePlaneGen(this);
out.a.set((float) start.x, a.y, (float) start.y);
out.b.set((float) end.x, b.y, (float) end.y);
out.calcUV();
return out;
}
use of javax.vecmath.Vector2d in project chordatlas by twak.
the class Concarnie method project.
public static Point2d project(Line l, Point2d pt) {
Vector2d v1 = new Vector2d(l.end);
v1.sub(l.start);
Vector2d v2 = new Vector2d(pt);
v2.sub(l.start);
double param = v2.dot(v1) / v1.length();
if (param < 0 || param > v1.length())
return null;
v1.normalize();
v1.scale(param);
v1.add(l.start);
return new Point2d(v1);
}
use of javax.vecmath.Vector2d in project chordatlas by twak.
the class WindowGen method calculate.
@Override
public void calculate() {
for (Spatial s : gNode.getChildren()) s.removeFromParent();
FeatureCache fg = tweed.features;
int i = 0;
if (fg != null) {
for (MegaFeatures mf : fg.getBlock(block.center).features) {
Vector3f along, up, in;
{
Vector2d mfl = mf.megafacade.dir();
mfl.normalize();
along = new Vector3f((float) mfl.x, 0, (float) mfl.y);
up = new Vector3f(0, 1, 0);
in = along.cross(up);
}
Vector3f mfStart = Jme3z.to(Pointz.to3(mf.megafacade.start));
for (ImageFeatures im : mf.features) {
MeshBuilder mb = new MeshBuilder();
float offset = (float) Math.random() * 5;
for (MiniFacade mini : im.miniFacades) {
for (DRectangle r : mini.rects.get(Feature.WINDOW)) {
Vector3f loc = new Vector3f(mfStart);
loc.addLocal(along.mult((float) r.x));
loc.addLocal(up.mult((float) r.y));
createWindow(mb, mb, new Window(loc.add(in.mult(offset + 0.4f)), along, up, r.width, r.height, 0.3, 0.4, 0.6));
}
if (!mini.rects.get(Feature.WINDOW).isEmpty()) {
Vector3f loc = new Vector3f(mfStart);
loc.addLocal(along.mult((float) mini.left)).addLocal(in.mult(offset));
mb.addCube(loc, up, along, in, (float) mini.height, (float) mini.width, 0.1f);
}
}
Geometry g = new Geometry(this.getClass().getSimpleName());
g.setMesh(mb.getMesh());
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", Jme3z.toJme(Rainbow.getColour(i)));
mat.setColor("Ambient", Jme3z.toJme(Rainbow.getColour(i)));
mat.setBoolean("UseMaterialColors", true);
g.setMaterial(mat);
i++;
gNode.attachChild(g);
}
}
}
super.calculate();
}
Aggregations