X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fshape%2FCone.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fshape%2FCone.java;h=5283eb444fac8785023648c3fe351e53a3cdd5a3;hb=58ebeb2baac48f9066c1395a9071f99745574ef9;hp=2f37840537cb1c7c051fe3d5ff7a43a14531c531;hpb=498c60eb6adbad0449879bdff55a2e203bfcbb01;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/shape/Cone.java b/org.simantics.g3d/src/org/simantics/g3d/shape/Cone.java index 2f378405..5283eb44 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/shape/Cone.java +++ b/org.simantics.g3d/src/org/simantics/g3d/shape/Cone.java @@ -1,75 +1,75 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g3d.shape; - -import java.util.ArrayList; -import java.util.List; - -import javax.vecmath.AxisAngle4d; -import javax.vecmath.Vector3d; - -import org.simantics.g3d.math.MathTools; - -public class Cone { - - public static Mesh create(double radius, int s) { - if (s < 3 || radius < MathTools.NEAR_ZERO) - throw new IllegalArgumentException(); - List vertices = new ArrayList(s+2); - List normals = new ArrayList(vertices.size()); - List indices = new ArrayList(); - - vertices.add(new Vector3d(0.0,0.0,0.0)); - normals.add(new Vector3d(0.0,-1.0,0.0)); - vertices.add(new Vector3d(0.0,radius*2.0,0.0)); - normals.add(new Vector3d(0.0,1.0,0.0)); - - Vector3d v = new Vector3d(radius,0,0); - for (int i = 0; i < s; i++) { - AxisAngle4d aa = new AxisAngle4d(0,1,0,((double)i/(double)s)*Math.PI * 2); - Vector3d t = new Vector3d(); - MathTools.rotate(MathTools.getQuat(aa), v, t); - vertices.add(t); - Vector3d n = new Vector3d(t); - n.normalize(); - normals.add(n); - } - - for (int i = 0; i < s; i++) { - indices.add(0); - - if (i < s - 1) - indices.add(i + 3); - else - indices.add(2); - indices.add(i + 2); - } - - for (int i = 0; i < s; i++) { - indices.add(1); - indices.add(i + 2); - if (i < s - 1) - indices.add(i + 3); - else - indices.add(2); - - } - return new Mesh(vertices,normals,indices); - - } - - public static void main(String arg[]) { - Mesh s1 = create(1.0, 3); - Mesh s2 = create(1.0, 4); - System.out.println("debug " + s1 + "\n" + s2); - } -} +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.shape; + +import java.util.ArrayList; +import java.util.List; + +import javax.vecmath.AxisAngle4d; +import javax.vecmath.Vector3d; + +import org.simantics.g3d.math.MathTools; + +public class Cone { + + public static Mesh create(double radius, int s) { + if (s < 3 || radius < MathTools.NEAR_ZERO) + throw new IllegalArgumentException(); + List vertices = new ArrayList(s+2); + List normals = new ArrayList(vertices.size()); + List indices = new ArrayList(); + + vertices.add(new Vector3d(0.0,0.0,0.0)); + normals.add(new Vector3d(0.0,-1.0,0.0)); + vertices.add(new Vector3d(0.0,radius*2.0,0.0)); + normals.add(new Vector3d(0.0,1.0,0.0)); + + Vector3d v = new Vector3d(radius,0,0); + for (int i = 0; i < s; i++) { + AxisAngle4d aa = new AxisAngle4d(0,1,0,((double)i/(double)s)*Math.PI * 2); + Vector3d t = new Vector3d(); + MathTools.rotate(MathTools.getQuat(aa), v, t); + vertices.add(t); + Vector3d n = new Vector3d(t); + n.normalize(); + normals.add(n); + } + + for (int i = 0; i < s; i++) { + indices.add(0); + + if (i < s - 1) + indices.add(i + 3); + else + indices.add(2); + indices.add(i + 2); + } + + for (int i = 0; i < s; i++) { + indices.add(1); + indices.add(i + 2); + if (i < s - 1) + indices.add(i + 3); + else + indices.add(2); + + } + return Mesh.create(vertices,normals,indices); + + } + + public static void main(String arg[]) { + Mesh s1 = create(1.0, 3); + Mesh s2 = create(1.0, 4); + System.out.println("debug " + s1 + "\n" + s2); + } +}