private static void transformMeshFactory(MeshFactory meshFactory, SimpleMatrix transformationMatrix) { MeshFactory mesh = meshFactory; SimpleMatrix normalMatrix = transformationMatrix.invert().transpose(); Set<Vector3d> procesed = new HashSet<Vector3d>(); List<Point3d> vertices = new ArrayList<Point3d>(); for (int i = 0; i < mesh.vertices.size(); i++) { Point3d p = mesh.vertices.get(i); vertices.add(TransformationMatrix3d.transform(p, transformationMatrix)); } mesh.vertices = vertices; List<Vector3d> normals = new ArrayList<Vector3d>(); for (int i = 0; i < mesh.normals.size(); i++) { Vector3d v = mesh.normals.get(i); // if (procesed.contains(v)) { // continue; // } procesed.add(v); v = TransformationMatrix3d.transform(v, normalMatrix); // XXX !!!; v.normalize(); normals.add(v); } mesh.normals = normals; }
private static RoofDebugOutput buildDebugInfo(RoofTypeOutput rto, List<RoofDormerTypeOutput> roofExtensionsList, Point2d startPoint, double height) { Point3d startPointMark = new Point3d(startPoint.x, height, -startPoint.y); List<Point3d> rectangleTransf = new ArrayList<Point3d>(); List<Point3d> rectangle = rto.getRectangle(); for (int i = 0; i < rectangle.size(); i++) { Point3d p = rectangle.get(i); rectangleTransf.add(TransformationMatrix3d.transform(p, rto.getTransformationMatrix())); } rto.setRectangle(rectangleTransf); RoofDebugOutput out = new RoofDebugOutput(); out.setBbox(rectangleTransf); out.setStartPoint(startPointMark); return out; }
private static int[][] buildSoftNormalsIndexs(MeshFactory meshFactory, int sectionCount, Point2d[] crossSection, int crossCount) { Vector2d[] crossSectionSoftNormals = calsSoftNormals(crossSection); int[][] softNormalsIntex = new int[sectionCount][]; for (int i = 0; i < sectionCount; i++) { double a = Math.toRadians(360) / sectionCount * i; SimpleMatrix rotY = TransformationMatrix3d.rotYA(a); softNormalsIntex[i] = new int[crossCount]; for (int j = 0; j < crossSection.length; j++) { // point Vector2d n2d = crossSectionSoftNormals[j]; Vector3d n = new Vector3d(n2d.x, n2d.y, 0); Vector3d transform = TransformationMatrix3d.transform(n, rotY); int in = meshFactory.addNormal(transform); softNormalsIntex[i][j] = in; } } return softNormalsIntex; }
private static Point3d[][] buildMesh(Point2d center, Point2d[] crossSection, int sectionCount) { int crossCount = crossSection.length; Point3d[][] mesh = new Point3d[sectionCount][]; for (int i = 0; i < sectionCount; i++) { double a = Math.toRadians(360) / sectionCount * i; SimpleMatrix tranA = TransformationMatrix3d.tranA(center.x, 0, -center.y); SimpleMatrix rotY = TransformationMatrix3d.rotYA(a); SimpleMatrix trans = tranA.mult(rotY); Point3d[] crossMesh = new Point3d[crossCount]; for (int j = 0; j < crossSection.length; j++) { // point Point2d cross = crossSection[j]; Point3d p = new Point3d(cross.x, cross.y, 0); crossMesh[j] = TransformationMatrix3d.transform(p, trans); } mesh[i] = crossMesh; } return mesh; }
protected void saveRenderConfiguration(LightConfiguration lightLocation) { lightLocation.getAmbientColor().getColorComponents(ambientLightColor); lightLocation.getDiffuseColor().getColorComponents(diffuseLightColor); Vector3d vector = new Vector3d(0, 0, -1); SimpleMatrix directionMatric = TransformationMatrix3d.rotYA(Math.toRadians(-lightLocation.getDirection())); SimpleMatrix angleMatric = TransformationMatrix3d.rotXA(Math.toRadians(lightLocation.getAngle())); SimpleMatrix matrix = directionMatric.mult(angleMatric); Vector3d position = TransformationMatrix3d.transform(vector, matrix); lightPosition[0] = (float) position.x; lightPosition[1] = (float) position.y; lightPosition[2] = (float) position.z; lightPosition[3] = 0f; }
public RectangleRoofHooksSpace(Point2d p1, Vector2d v1, double b, Plane3d pPlane) { super(); // this.p1 = p1; // this.v1 = v1; this.b = b; double angle = Math.atan2(v1.y, v1.x); // Math.toDegrees(angle); SimpleMatrix tr2d = TransformationMatrix2d.rotZA(-angle).mult(TransformationMatrix2d.tranA(-p1.x, -p1.y)); SimpleMatrix tr3d = TransformationMatrix3d.rotYA(-angle).mult(TransformationMatrix3d.tranA(-p1.x, 0, p1.y)); this.p1 = TransformationMatrix2d.transform(p1, tr2d); this.v1 = TransformationMatrix2d.transform(v1, tr2d); Point3d planePoint= TransformationMatrix3d.transform(pPlane.getPoint(), tr3d); Vector3d planeNormal = TransformationMatrix3d.transform(pPlane.getNormal(), tr3d); this.plane = new Plane3d(planePoint, planeNormal); SimpleMatrix trBack = TransformationMatrix3d.rotYA(angle).mult(TransformationMatrix3d.tranA(-p1.x, 0, p1.y)); this.transformationMatrix = trBack; }