/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq * Copyright (C) 2013 Marko Zivkovic * * Contact Information: marko88zivkovic at gmail dot com * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. This program is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. You should have received a copy of the * GNU General Public License along with this program; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * * This Java source code belongs to XLogo4Schools, written by Marko Zivkovic * during his Bachelor thesis at the computer science department of ETH Zürich, * in the year 2013 and/or during future work. * * It is a reengineered version of XLogo written by Loïc Le Coq, published * under the GPL License at http://xlogo.tuxfamily.org/ * * Contents of this file were initially written by Loïc Le Coq, * modifications, extensions, refactorings might have been applied by Marko Zivkovic */ package xlogo.kernel.perspective; import javax.media.j3d.Appearance; import javax.media.j3d.LineStripArray; import javax.media.j3d.Material; import javax.media.j3d.PolygonAttributes; import javax.media.j3d.Shape3D; import javax.media.j3d.LineAttributes; import javax.media.j3d.TransformGroup; import com.sun.j3d.utils.geometry.Sphere; import javax.media.j3d.Transform3D; import javax.vecmath.Color3f; import javax.vecmath.Point3d; import javax.vecmath.AxisAngle4d; import com.sun.j3d.utils.geometry.Cylinder; import javax.vecmath.Vector3d; import xlogo.kernel.LogoError; /** * * @author Marko Zivkovic - I decoupled this from Application * */ public class ElementLine extends Element3D { /** * This float stores the line Width for each 3D line * * @uml.property name="lineWidth" */ private float lineWidth; public ElementLine(Viewer3D v3d, float lineWidth) { super(v3d); this.lineWidth = lineWidth; //app.getKernel().getActiveTurtle().getPenWidth(); } public void addToScene() throws LogoError { int size = vertex.size(); if (size > 1) { if (lineWidth == 0.5) createSimpleLine(size); else createComplexLine(size); } } /** * This method draws a line with width 1 * * @param size */ private void createSimpleLine(int size) { int[] tab = { size }; LineStripArray line = new LineStripArray(size, LineStripArray.COORDINATES | LineStripArray.COLOR_3, tab); for (int i = 0; i < size; i++) { line.setCoordinate(i, vertex.get(i)); // System.out.println("sommet "+(2*i-1)+" "+vertex.get(i).x+" "+vertex.get(i).y+" "+vertex.get(i).z+" "); line.setColor(i, new Color3f(color.get(i))); } Shape3D s = new Shape3D(line); Appearance appear = new Appearance(); Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), new Color3f(0.0f, 0f, 0f), new Color3f(1f, 1.0f, 1.0f), new Color3f(1f, 1f, 1f), 64); appear.setMaterial(mat); appear.setLineAttributes(new LineAttributes(2 * lineWidth, LineAttributes.PATTERN_SOLID, false)); s.setAppearance(appear); // DrawPanel.listPoly.add(s); v3d.add3DObject(s); /* * for (int i=0;i