/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2004, by :
* Corporate:
* EADS Corporate Research Center
* Individual:
* Nicolas Brodu
*
* $Id: CubeNodeJava3D.java,v 1.3 2005/09/02 11:57:30 ogor Exp $
*
* Changes
* -------
* 19-Mar-2004 : Creation date (NB);
*
*/
package syn3d.nodes.java3d;
import java.io.Serializable;
import javax.media.j3d.IndexedQuadArray;
import javax.media.j3d.Shape3D;
import syn3d.base.ActiveNode;
import syn3d.nodes.NodeResourcesManager;
/**
*
*/
public class CubeNodeJava3D extends ShapeNodeJava3D implements Serializable {
static final long serialVersionUID = 7563944186863056417L;
protected static int anonymousNodeNumber = 0;
// quad description of a cube
static float[] coords = new float[] {
1, -1, -1,
1, 1, -1,
-1, 1, -1,
-1, -1, -1,
1, -1, 1,
1, 1, 1,
-1, 1, 1,
-1, -1, 1,
};
// quad description of a cube
static int[] index = new int[] {
0, 1, 2, 3,
4, 5, 6, 7,
0, 1, 5, 4,
1, 2, 6, 5,
2, 3, 7, 6,
3, 0, 4, 7,
};
// quad description of a cube
static float NORM_INVERSE = (float)(1.0/Math.sqrt(3));
static float[] normals = new float[] {
NORM_INVERSE, -NORM_INVERSE, -NORM_INVERSE,
NORM_INVERSE, NORM_INVERSE, -NORM_INVERSE,
-NORM_INVERSE, NORM_INVERSE, -NORM_INVERSE,
-NORM_INVERSE, -NORM_INVERSE, -NORM_INVERSE,
NORM_INVERSE, -NORM_INVERSE, NORM_INVERSE,
NORM_INVERSE, NORM_INVERSE, NORM_INVERSE,
-NORM_INVERSE, NORM_INVERSE, NORM_INVERSE,
-NORM_INVERSE, -NORM_INVERSE, NORM_INVERSE,
};
public CubeNodeJava3D(ActiveNode parent) {
super(parent);
}
protected Shape3D createShape() {
IndexedQuadArray iqa = new IndexedQuadArray(coords.length / 3, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, index.length);
iqa.setCoordinates(0,coords);
iqa.setNormals(0,normals);
iqa.setCoordinateIndices(0,index);
iqa.setNormalIndices(0,index);
anonymousNodeNumber++;
name = NodeResourcesManager.getNodeName("Cube") + ((anonymousNodeNumber == 1) ? "" : String.valueOf(anonymousNodeNumber));
return new Shape3D(iqa);
}
}