[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model ParameterBlock.java, 1.12, 1.13 Comm
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-10-22 15:21:16
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21334/src/net/sourceforge/bprocessor/model Modified Files: ParameterBlock.java Command.java Log Message: added cylinder command Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Command.java 22 Oct 2007 12:47:32 -0000 1.10 --- Command.java 22 Oct 2007 15:21:18 -0000 1.11 *************** *** 10,15 **** --- 10,17 ---- import java.util.ArrayList; import java.util.Collection; + import java.util.HashSet; import java.util.LinkedList; import java.util.List; + import java.util.Set; *************** *** 155,159 **** public void evaluate() { Edge edge = (Edge) parameters.get("edge"); ! int n = (int) (parameters.getDouble("n")); Vertex from = edge.from; Vertex to = edge.to; --- 157,161 ---- public void evaluate() { Edge edge = (Edge) parameters.get("edge"); ! int n = parameters.getDouble("n").intValue(); Vertex from = edge.from; Vertex to = edge.to; *************** *** 173,176 **** --- 175,251 ---- /** + * A command to create a cylinder + */ + public static class Cylinder extends Command { + /** + * + */ + public Cylinder() { + parameters.add(new Attribute("radius", 1.0)); + parameters.add(new Attribute("height", 3.0)); + parameters.add(new Attribute("slices", 10.0)); + } + + /** {@inheritDoc}} */ + @Override + public String getGeneralName() { + return "Create cylinder"; + } + + /** {@inheritDoc}} */ + @Override + public void evaluate() { + double r = parameters.getDouble("radius"); + double h = parameters.getDouble("height"); + int s = parameters.getDouble("slices").intValue(); + + List<Edge> edges = new LinkedList<Edge>(); + Vertex first = null, prev = null; + for (int i = 0; i < s; i++) { + double val = i * Math.PI * 2 / s; + double sin = Math.sin(val); + double cos = Math.cos(val); + Vertex cur = new Vertex(cos, sin, 0); + if (first == null) { + first = cur; + } + if (prev != null) { + edges.add(new Edge(prev, cur)); + } + prev = cur; + } + edges.add(new Edge(prev, first)); + Surface bottom = new Surface(edges); + Space inside = Project.getInstance().world().createConstructionSpace("Cylinder"); + Space world = Project.getInstance().world(); + bottom.setFrontDomain(inside); + Set<Surface> sides = new HashSet<Surface>(); + Surface top = bottom.extrusion(h, sides); + world.add(inside); + world.insert(bottom); + for (Surface surface : sides) { + List<Vertex> normals = new LinkedList<Vertex>(); + for (Vertex v : surface.getVertices()) { + Vertex normal = v.copy(); + normal.setZ(0); + normal.scale(-1); + normal.normalize(); + normals.add(normal); + } + surface.setNormals(normals); + world.insert(surface); + } + Collection<Edge> visibleEdges = Surface.edges(sides); + visibleEdges.removeAll(top.getEdges()); + visibleEdges.removeAll(bottom.getEdges()); + Project.getInstance().getCurrentCamera().getHiddenGeometrics().addAll(visibleEdges); + sides.add(top); + sides.add(bottom); + world.insert(top); + Project.getInstance().changed(world); + } + } + + /** * * *************** *** 232,238 **** /** ! * ! * @param vertices collecting ! * @param system system */ public Scale(Collection<Vertex> vertices, CoordinateSystem system) { --- 307,313 ---- /** ! * Scale a collection of vertices ! * @param vertices The list of verts ! * @param system The system to translate into */ public Scale(Collection<Vertex> vertices, CoordinateSystem system) { Index: ParameterBlock.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ParameterBlock.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ParameterBlock.java 22 Oct 2007 06:55:09 -0000 1.12 --- ParameterBlock.java 22 Oct 2007 15:21:18 -0000 1.13 *************** *** 80,84 **** * @return double value */ ! public double getDouble(String key) { for (Attribute current : parameters) { if (current.getName().equals(key)) { --- 80,84 ---- * @return double value */ ! public Double getDouble(String key) { for (Attribute current : parameters) { if (current.getName().equals(key)) { |