1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.shape;
\r
14 import java.util.ArrayList;
\r
15 import java.util.List;
\r
17 import javax.vecmath.AxisAngle4d;
\r
18 import javax.vecmath.Vector3d;
\r
20 import org.simantics.g3d.math.MathTools;
\r
24 public static Mesh create(double radius, int s) {
\r
25 if (s < 3 || radius < MathTools.NEAR_ZERO)
\r
26 throw new IllegalArgumentException();
\r
27 List<Vector3d> vertices = new ArrayList<Vector3d>(s+2);
\r
28 List<Vector3d> normals = new ArrayList<Vector3d>(vertices.size());
\r
29 List<Integer> indices = new ArrayList<Integer>();
\r
31 vertices.add(new Vector3d(0.0,0.0,0.0));
\r
32 normals.add(new Vector3d(0.0,-1.0,0.0));
\r
33 vertices.add(new Vector3d(0.0,radius*2.0,0.0));
\r
34 normals.add(new Vector3d(0.0,1.0,0.0));
\r
36 Vector3d v = new Vector3d(radius,0,0);
\r
37 for (int i = 0; i < s; i++) {
\r
38 AxisAngle4d aa = new AxisAngle4d(0,1,0,((double)i/(double)s)*Math.PI * 2);
\r
39 Vector3d t = new Vector3d();
\r
40 MathTools.rotate(MathTools.getQuat(aa), v, t);
\r
42 Vector3d n = new Vector3d(t);
\r
47 for (int i = 0; i < s; i++) {
\r
57 for (int i = 0; i < s; i++) {
\r
66 return new Mesh(vertices,normals,indices);
\r
70 public static void main(String arg[]) {
\r
71 Mesh s1 = create(1.0, 3);
\r
72 Mesh s2 = create(1.0, 4);
\r
73 System.out.println("debug " + s1 + "\n" + s2);
\r