]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java
White space clean-up
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / shape / ArcCylinder.java
index 348fd8520cc5f27850b163454f7987eee8b60d53..6f82e33cab924b4de7c082550970f02597ca7ee2 100644 (file)
@@ -97,6 +97,56 @@ public class ArcCylinder {
                return new Mesh(vertices, normals, indices);
        }
        
+       public Mesh create(Point3d c, Vector3d axis, Vector3d an, double R, double r, double a, int res, double res2) {
+               
+       
+               
+               int steps = 0;
+               double sa = 0.0;
+               
+               Vector3d rn = new Vector3d(axis);
+               rn.normalize();
+               Vector3d r1 = new Vector3d(an);
+               r1.normalize();
+               r1.scale(R);
+
+               
+               if ((a +0.0001) > Math.PI) {
+                       steps = 1;
+               } else {
+                       steps = (int)(Math.ceil(a/res2));
+                       if (steps == 0)
+                               steps = 1;
+                       sa = a/steps;
+               }
+
+               List<Tuple3d> vertices = new ArrayList<Tuple3d>(res * (steps+1));
+               List<Tuple3d> normals = new ArrayList<Tuple3d>(res * (steps+1));
+               List<Integer> indices = new ArrayList<Integer>();
+               
+               for (int i = 0; i <= steps; i++) {
+                       Vector3d p;
+                       Vector3d t;
+                       p = new Vector3d();
+                       double ca = sa * i;
+                       Quat4d q = MathTools.getQuat(new AxisAngle4d(rn, ca));
+                       MathTools.rotate(q, r1, p);
+                       t = new Vector3d();
+                       t.cross(rn,p);
+                       t.normalize();
+                       p.add(c);
+                               
+                       
+                       createCircle(vertices, normals, p, t, rn, res, r);
+               }
+               int count = steps*res*6;
+               for (int i = 0; i < count; i++) {
+                       indices.add(-1);
+               }       
+               createIndices(steps, res, indices);
+               return new Mesh(vertices, normals, indices);
+       }
+       
        private static void createCircle(List<Tuple3d> points, List<Tuple3d> normals, Tuple3d p, Vector3d t, Vector3d n, int res, double radius) {
                n = new Vector3d(n);
                n.scale(radius);
@@ -128,9 +178,9 @@ public class ArcCylinder {
                                int iv = c*resolution + s;
                                
                                /*
-                            iv+1 ---- iv + resolution + 1
-                                     | /|
-                                     |/ |
+                                iv+1 ---- iv + resolution + 1
+                                         | /|
+                                         |/ |
                                   iv ---- iv + resolution 
                                */
                                if (s < resolution - 1) {