[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model TransformStack.java, NONE, 1.1 AxisR
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv966/src/net/sourceforge/bprocessor/model Modified Files: Translate.java Space.java Scale.java Added Files: TransformStack.java AxisRotate.java Removed Files: FullRotate.java Log Message: Translations and Rotations in scripting --- FullRotate.java DELETED --- Index: Translate.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Translate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Translate.java 19 Sep 2006 10:00:09 -0000 1.1 --- Translate.java 27 Sep 2006 08:36:25 -0000 1.2 *************** *** 35,38 **** --- 35,52 ---- tz = 0; } + + /** + * Constructor + * @param x x + * @param y y + * @param z z + */ + public Translate(double x, double y, double z) { + super(); + tx = x; + ty = y; + tz = z; + } + /** *************** *** 114,118 **** */ public Vertex transform(Vertex vertex) { ! return vertex; } --- 128,135 ---- */ public Vertex transform(Vertex vertex) { ! double x = vertex.getX() + tx; ! double y = vertex.getY() + ty; ! double z = vertex.getZ() + tz; ! return new Vertex(x, y, z); } --- NEW FILE: TransformStack.java --- //--------------------------------------------------------------------------------- // $Id: TransformStack.java,v 1.1 2006/09/27 08:36:25 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.List; import java.util.Stack; /** * Transformation stack */ public class TransformStack extends Transform { /** stack */ private Stack stack; /** * Contructor * */ public TransformStack() { super(); stack = new Stack(); } /** * * @return stack */ public Stack stack() { return stack; } /** * Push a transform * @param transform Transfrom */ public void push(Transform transform) { stack.push(transform); } /** * Pop a transform * */ public void pop() { stack.pop(); } /** * Insert a transform * @param transform Transform */ public void insert(Transform transform) { stack.add(0, transform); } /** * @param vertex Vertex * @return vertex */ public Vertex transform(Vertex vertex) { for (int i = stack.size(); i > 0; i--) { Transform current = (Transform) stack.get(i - 1); vertex = current.transform(vertex); } return vertex; } /** * @param attributes List of attributes */ public void setAttributes(List attributes) { } /** * @return List of Attributes */ public List getAttributes() { return null; } /** * @return Name */ public String getGeneralName() { return "Transformation Stack"; } } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** Space.java 26 Sep 2006 09:52:24 -0000 1.66 --- Space.java 27 Sep 2006 08:36:25 -0000 1.67 *************** *** 126,130 **** /** The transformation */ ! private List transformations; --- 126,130 ---- /** The transformation */ ! private TransformStack transform; *************** *** 187,191 **** description = new Description(""); envelope = new HashSet(); ! transformations = new LinkedList(); if (container) { vertices = new HashMap(); --- 187,191 ---- description = new Description(""); envelope = new HashSet(); ! transform = new TransformStack(); if (container) { vertices = new HashMap(); *************** *** 270,275 **** * @return transformations */ ! public List getTransformations() { ! return transformations; } --- 270,275 ---- * @return transformations */ ! public TransformStack getTransformations() { ! return transform; } *************** *** 279,283 **** */ public void addTransform(Transform transform) { ! transformations.add(transform); } --- 279,283 ---- */ public void addTransform(Transform transform) { ! this.transform.insert(transform); } *************** *** 1257,1261 **** } } ! Iterator iter = getTransformations().iterator(); while (iter.hasNext()) { Transform current = (Transform) iter.next(); --- 1257,1261 ---- } } ! Iterator iter = getTransformations().stack().iterator(); while (iter.hasNext()) { Transform current = (Transform) iter.next(); --- NEW FILE: AxisRotate.java --- //--------------------------------------------------------------------------------- // $Id: AxisRotate.java,v 1.1 2006/09/27 08:36:25 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Rotate */ public class AxisRotate extends Transform { /** rotate x */ private double rx; /** rotate y */ private double ry; /** rotate z */ private double rz; /** angle */ private double angle; /** * Constructor */ public AxisRotate() { super(); rx = 0; ry = 0; rz = 1; angle = 0; } /** * * @param a a * @param x x * @param y y * @param z z */ public AxisRotate(double a, double x, double y, double z) { super(); rx = x; ry = y; rz = z; angle = a; } /** * @param value new value */ public void rx(double value) { rx = value; } /** * * @return rx */ public double rx() { return rx; } /** * @param value new value */ public void ry(double value) { ry = value; } /** * * @return ry */ public double ry() { return ry; } /** * @param value new value */ public void rz(double value) { rz = value; } /** * * @return rz */ public double rz() { return rz; } /** * * @param value new value */ public void angle(double value) { angle = value; } /** * * @return angle */ public double angle() { return angle; } /** * Set attributes * @param attributes List */ public void setAttributes(List attributes) { Iterator iter = attributes.iterator(); while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); if (a.getName().equals("Rotate X")) { rx(((Double)a.getValue()).doubleValue()); } else if (a.getName().equals("Rotate Y")) { ry(((Double)a.getValue()).doubleValue()); } else if (a.getName().equals("Rotate Z")) { rz(((Double)a.getValue()).doubleValue()); } else if (a.getName().equals("Angle")) { angle(((Double)a.getValue()).doubleValue()); } } Project.getInstance().changed(Project.getInstance()); } /** * Get attributes * @return List */ public List getAttributes() { ArrayList res = new ArrayList(); res.add(new Attribute("Rotate X", new Double(rx()))); res.add(new Attribute("Rotate Y", new Double(ry()))); res.add(new Attribute("Rotate Z", new Double(rz()))); res.add(new Attribute("Angle", new Double(angle()))); return res; } /** * @param vertex Vertex * @return Vertex */ public Vertex transform(Vertex vertex) { Matrix matrix = Matrix.rotation(angle, rx, ry, rz); double values[] = new double[4]; values[0] = vertex.getX(); values[1] = vertex.getY(); values[2] = vertex.getZ(); values[3] = 1; values = matrix.multiply(values); return new Vertex(values[0], values[1], values[2]); } /** * Get display name * @return name */ public String getGeneralName() { return "Rotate"; } } Index: Scale.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Scale.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Scale.java 19 Sep 2006 10:00:09 -0000 1.1 --- Scale.java 27 Sep 2006 08:36:25 -0000 1.2 *************** *** 114,118 **** */ public Vertex transform(Vertex vertex) { ! return vertex; } --- 114,121 ---- */ public Vertex transform(Vertex vertex) { ! double x = vertex.getX() * sx; ! double y = vertex.getY() * sy; ! double z = vertex.getZ() * sz; ! return new Vertex(x, y, z); } |