Hi Fredrik,
The index order is not correct in the test program,
try this:
/*
* Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
public Geometry getIndexedQuadArray()
{
IndexedQuadArray indexedQuadArray = new IndexedQuadArray(8,
GeometryArray.COORDINATES | GeometryArray.COLOR_3,
24);
indexedQuadArray.setCoordinate(0, new Point3f(-0.5f, 0.5f, 0.5f ));
indexedQuadArray.setCoordinate(1, new Point3f(-0.5f, 0.5f, -0.5f ));
indexedQuadArray.setCoordinate(2, new Point3f( 0.5f, 0.5f, -0.5f ));
indexedQuadArray.setCoordinate(3, new Point3f( 0.5f, 0.5f, 0.5f ));
indexedQuadArray.setCoordinate(4, new Point3f(-0.5f, -0.5f, 0.5f ));
indexedQuadArray.setCoordinate(5, new Point3f(-0.5f, -0.5f, -0.5f ));
indexedQuadArray.setCoordinate(6, new Point3f( 0.5f, -0.5f, -0.5f ));
indexedQuadArray.setCoordinate(7, new Point3f( 0.5f, -0.5f, 0.5f ));
indexedQuadArray.setCoordinateIndex( 0, 0);
indexedQuadArray.setCoordinateIndex( 1, 3);
indexedQuadArray.setCoordinateIndex( 2, 2);
indexedQuadArray.setCoordinateIndex( 3, 1);
indexedQuadArray.setCoordinateIndex( 4, 4);
indexedQuadArray.setCoordinateIndex( 5, 5);
indexedQuadArray.setCoordinateIndex( 6, 6);
indexedQuadArray.setCoordinateIndex( 7, 7);
indexedQuadArray.setCoordinateIndex( 8, 7);
indexedQuadArray.setCoordinateIndex( 9, 6);
indexedQuadArray.setCoordinateIndex( 10, 2);
indexedQuadArray.setCoordinateIndex( 11, 3);
indexedQuadArray.setCoordinateIndex( 12, 0);
indexedQuadArray.setCoordinateIndex( 13, 1);
indexedQuadArray.setCoordinateIndex( 14, 5);
indexedQuadArray.setCoordinateIndex( 15, 4);
indexedQuadArray.setCoordinateIndex( 16, 4);
indexedQuadArray.setCoordinateIndex( 17, 7);
indexedQuadArray.setCoordinateIndex( 18, 3);
indexedQuadArray.setCoordinateIndex( 19, 0);
indexedQuadArray.setCoordinateIndex( 20, 5);
indexedQuadArray.setCoordinateIndex( 21, 1);
indexedQuadArray.setCoordinateIndex( 22, 2);
indexedQuadArray.setCoordinateIndex( 23, 6);
indexedQuadArray.setColor(0, new Color3f(0, 1, 0));
indexedQuadArray.setColor(1, new Color3f(0, 1, 0));
indexedQuadArray.setColor(2, new Color3f(0, 1, 0));
indexedQuadArray.setColor(3, new Color3f(0, 1, 0));
indexedQuadArray.setColor(4, new Color3f(1, 0, 0));
indexedQuadArray.setColor(5, new Color3f(1, 0, 0));
indexedQuadArray.setColor(6, new Color3f(1, 0, 0));
indexedQuadArray.setColor(7, new Color3f(1, 0, 0));
return indexedQuadArray;
}
There is another another problem in Test3dBrick,
the two GeometryArray get in
addGeometry(getContour());
addGeometry(getBody());
is not in the same equivalence class (see Shape3D) so it
will throws IllegalArgumentException Exception in v1.2.1
(make sure you are using the latest version)
I've attach another program for you to test CULL_NONE
which should work.
- Kelvin
------------------
Java 3D Team
Sun Microsystems Inc.
>X-Unix-From: [EMAIL PROTECTED] Wed Aug 15 06:32:21 2001
>Delivered-To: [EMAIL PROTECTED]
>MIME-Version: 1.0
>Content-Transfer-Encoding: 7bit
>X-Priority: 3 (Normal)
>X-MSMail-Priority: Normal
>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
>Importance: Normal
>Date: Wed, 15 Aug 2001 15:22:17 +0200
>From: Fredrik Andersson <[EMAIL PROTECTED]>
>Subject: [JAVA3D] Problems with PolygonAttributes.CULL_NONE
>To: [EMAIL PROTECTED]
>
>Hello!
>
>I'm trying to get the "PolygonAttributes.CULL_NONE" to work in an 3D applet.
>But I can't get it right
>
>
>I ad here a full class wich extends Shape3D, wich in my opinion use
>"PolygonAttributes.CULL_NONE", wich also in my opinion shuld be solid.
>
>I also add the html-file to run it and an applet.
>When you have started the applet, start navigate with ARROW_DOWN-key. Then
>You will see the Shape3d
>
> The shape3d-class
>
>import java.applet.*;
>import java.awt.*;
>import java.awt.Frame;
>import java.awt.event.*;
>import com.sun.j3d.utils.applet.MainFrame;
>import com.sun.j3d.utils.universe.*;
>import com.sun.j3d.utils.geometry.*;
>import javax.media.j3d.*;
>import javax.vecmath.*;
>import java.awt.event.*;
>import java.util.Enumeration;
>
>
>
>public class Test3dBrick extends Shape3D
>{
>
> public Test3dBrick()
> {
> createAppearance();
> addGeometry(getContour());
> addGeometry(getBody());
> }
>
> public void createAppearance()
> {
> Appearance appearance = new Appearance();
> PolygonAttributes polygonAttributes = new PolygonAttributes();
> polygonAttributes.setCullFace(PolygonAttributes.CULL_NONE);
> polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
> polygonAttributes.setBackFaceNormalFlip(true);
> appearance.setPolygonAttributes(polygonAttributes);
> setAppearance(appearance);
> }
>
>
> public Geometry getContour()
> {
> Color3f darkgray = new Color3f(0.2f, 0.2f, 0.2f);
>
> IndexedLineArray indexedLineArray = new IndexedLineArray(8,
>GeometryArray.COORDINATES | GeometryArray.COLOR_3 , 24);
>
> indexedLineArray.setCoordinate(0, new
>Point3f( -0.201f, -0.001f, -0.201f ));
> indexedLineArray.setCoordinate(1, new Point3f( -0.201f, -0.001f,
>0.201f ));
> indexedLineArray.setCoordinate(2, new Point3f( 0.201f, -0.001f,
> 0.201f ));
> indexedLineArray.setCoordinate(3, new
>Point3f( 0.201f, -0.001f, -0.201f ));
>
> indexedLineArray.setCoordinate(4, new Point3f( -0.201f,
>0.201f, -0.201f ));
> indexedLineArray.setCoordinate(5, new Point3f( -0.201f, 0.201f,
>0.201f ));
> indexedLineArray.setCoordinate(6, new Point3f( 0.201f, 0.201f,
>0.201f ));
> indexedLineArray.setCoordinate(7, new Point3f( 0.201f,
>0.201f, -0.201f ));
>
> indexedLineArray.setCoordinateIndex( 0, 0);
> indexedLineArray.setCoordinateIndex( 1, 1);
>
> indexedLineArray.setCoordinateIndex( 2, 1);
> indexedLineArray.setCoordinateIndex( 3, 2);
>
> indexedLineArray.setCoordinateIndex( 4, 2);
> indexedLineArray.setCoordinateIndex( 5, 3);
>
> indexedLineArray.setCoordinateIndex( 6, 3);
> indexedLineArray.setCoordinateIndex( 7, 0);
>
> indexedLineArray.setCoordinateIndex( 10, 4);
> indexedLineArray.setCoordinateIndex( 11, 5);
>
> indexedLineArray.setCoordinateIndex( 12, 5);
> indexedLineArray.setCoordinateIndex( 13, 6);
>
> indexedLineArray.setCoordinateIndex( 14, 6);
> indexedLineArray.setCoordinateIndex( 15, 7);
>
> indexedLineArray.setCoordinateIndex( 16, 7);
> indexedLineArray.setCoordinateIndex( 17, 4);
>
> indexedLineArray.setCoordinateIndex( 8, 0);
> indexedLineArray.setCoordinateIndex( 9, 4);
>
> indexedLineArray.setCoordinateIndex( 18, 1);
> indexedLineArray.setCoordinateIndex( 19, 5);
>
> indexedLineArray.setCoordinateIndex( 20, 2);
> indexedLineArray.setCoordinateIndex( 21, 6);
>
> indexedLineArray.setCoordinateIndex( 22, 3);
> indexedLineArray.setCoordinateIndex( 23, 7);
>
> indexedLineArray.setColor(0, darkgray);
>
> return indexedLineArray;
> }
>
> public Geometry getBody()
> {
> Color3f lightgray = new Color3f(0.8f, 0.8f, 0.8f);
>
> IndexedQuadArray indexedQuadArray = new IndexedQuadArray(8,
>GeometryArray.COORDINATES | GeometryArray.COLOR_3 , 24);
>
> indexedQuadArray.setCoordinate(0, new Point3f( -0.2f, 0.0f, -0.2f
>));
> indexedQuadArray.setCoordinate(1, new Point3f( -0.2f, 0.0f, 0.2f ));
> indexedQuadArray.setCoordinate(2, new Point3f( 0.2f, 0.0f, 0.2f ));
> indexedQuadArray.setCoordinate(3, new Point3f( 0.2f, 0.0f, -0.2f ));
>
> indexedQuadArray.setCoordinate(4, new Point3f( -0.2f, 0.2f, -0.2f
>));
> indexedQuadArray.setCoordinate(5, new Point3f( -0.2f, 0.2f, 0.2f ));
> indexedQuadArray.setCoordinate(6, new Point3f( 0.2f, 0.2f, 0.2f ));
> indexedQuadArray.setCoordinate(7, new Point3f( 0.2f, 0.2f, -0.2f ));
>
> indexedQuadArray.setCoordinateIndex( 0, 0);
> indexedQuadArray.setCoordinateIndex( 1, 1);
> indexedQuadArray.setCoordinateIndex( 2, 2);
> indexedQuadArray.setCoordinateIndex( 3, 3);
>
> indexedQuadArray.setCoordinateIndex( 4, 4);
> indexedQuadArray.setCoordinateIndex( 5, 5);
> indexedQuadArray.setCoordinateIndex( 6, 6);
> indexedQuadArray.setCoordinateIndex( 7, 7);
>
> indexedQuadArray.setCoordinateIndex( 8, 0);
> indexedQuadArray.setCoordinateIndex( 9, 4);
> indexedQuadArray.setCoordinateIndex( 10, 5);
> indexedQuadArray.setCoordinateIndex( 11, 1);
>
> indexedQuadArray.setCoordinateIndex( 12, 1);
> indexedQuadArray.setCoordinateIndex( 13, 5);
> indexedQuadArray.setCoordinateIndex( 14, 6);
> indexedQuadArray.setCoordinateIndex( 15, 7);
>
> indexedQuadArray.setCoordinateIndex( 16, 2);
> indexedQuadArray.setCoordinateIndex( 17, 6);
> indexedQuadArray.setCoordinateIndex( 18, 7);
> indexedQuadArray.setCoordinateIndex( 19, 3);
>
> indexedQuadArray.setCoordinateIndex( 20, 0);
> indexedQuadArray.setCoordinateIndex( 21, 4);
> indexedQuadArray.setCoordinateIndex( 22, 7);
> indexedQuadArray.setCoordinateIndex( 23, 3);
>
> indexedQuadArray.setColor(0, lightgray);
>
> return indexedQuadArray;
>
> }
>
>
>
>}
>
>The html-file:
>
><html>
> <head></head>
> <body bgcolor=Yellow>
> <!--"CONVERTED_APPLET"-->
><!-- CONVERTER VERSION 1.3 -->
><OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
>WIDTH = "600" HEIGHT = "400"
>codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Vers
>ion=1,3,0,0">
><PARAM NAME = CODE VALUE = "Shape3DTesterApplet.class" >
><PARAM NAME = CODEBASE VALUE = "." >
>
><PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
><PARAM NAME="scriptable" VALUE="false">
><PARAM NAME = "archive" VALUE ="java.zip">
><COMMENT>
><EMBED type="application/x-java-applet;version=1.3" CODE =
>"Shape3DTesterApplet.class" CODEBASE = "." WIDTH = "600" HEIGHT = "400"
>archive = "java.zip" scriptable=false
>pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><N
>OEMBED></COMMENT>
>
></NOEMBED></EMBED>
></OBJECT>
>
>
><!--"END_CONVERTED_APPLET"-->
>
> </body>
></html>
>
>
>The applet
>
>import java.applet.*;
>import java.awt.*;
>import java.awt.Frame;
>import java.awt.event.*;
>import com.sun.j3d.utils.applet.MainFrame;
>import com.sun.j3d.utils.universe.*;
>import com.sun.j3d.utils.geometry.*;
>import javax.media.j3d.*;
>import javax.vecmath.*;
>import com.sun.j3d.utils.behaviors.keyboard.*;
>
>
>public class Shape3DTesterApplet extends Applet
>{
> public void init()
> {
>
> setLayout(new BorderLayout());
> GraphicsConfiguration config =
>SimpleUniverse.getPreferredConfiguration();
>
> Canvas3D canvas3D = new Canvas3D(config);
> add("Center", canvas3D);
>
> SimpleUniverse simpleUniverse = new SimpleUniverse(canvas3D);
>
> BranchGroup branchGroup = new BranchGroup();
>
> branchGroup.addChild(addShape3D());
>
>
> TransformGroup transformGroup1 =
>simpleUniverse.getViewingPlatform().getViewPlatformTransform();
> KeyNavigatorBehavior keyNavigatorBehavior = new
>KeyNavigatorBehavior(transformGroup1);
> keyNavigatorBehavior.setSchedulingBounds(new BoundingSphere(new
>Point3d(-3.0f, -3.0f, -3.0f),10000.0));
>
> branchGroup.addChild(keyNavigatorBehavior);
>
>
> simpleUniverse.addBranchGraph(branchGroup);
>
> }
>
> public Shape3D addShape3D()
> {
> Test3dBrick test3dBrick = new Test3dBrick();
> return test3dBrick;
> }
>
>}
>
>Best regards <br>
>Fredrik
>
>===========================================================================
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff JAVA3D-INTEREST". For general help, send email to
>[EMAIL PROTECTED] and include in the body of the message "help".
/*
* "@(#)PolygonAttributesTest.java 1.2 00/06/12"
*
* Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import com.sun.j3d.utils.behaviors.mouse.*;
public class PolygonAttributesTest extends JApplet
implements ActionListener {
PolygonAttributes pa;
JComboBox pMode;
JComboBox pCullFace;
JCheckBox pNormalFlip;
JTextField pOffset;
JTextField pOffsetFactor;
BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
Appearance app = new Appearance();
pa = new PolygonAttributes();
pa.setCapability(PolygonAttributes.ALLOW_CULL_FACE_READ);
pa.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE);
pa.setCapability(PolygonAttributes.ALLOW_NORMAL_FLIP_READ);
pa.setCapability(PolygonAttributes.ALLOW_NORMAL_FLIP_WRITE);
pa.setCapability(PolygonAttributes.ALLOW_MODE_READ);
pa.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
pa.setCapability(PolygonAttributes.ALLOW_OFFSET_READ);
pa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);
pa.setPolygonOffset(-0.2f);
pa.setPolygonOffsetFactor(-0.3f);
app.setPolygonAttributes(pa);
TriangleArray tri1 = new TriColorTranslate(1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f);
TriangleArray tri2 = new TriColorTranslate(0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f);
Shape3D shape1 = new Shape3D(tri1, app);
Shape3D shape2 = new Shape3D(tri2, null);
Transform3D t = new Transform3D();
// move the object upwards
t.set(new Vector3f(0.0f, 0.3f, 0.0f));
// Shrink the object
t.setScale(0.6);
TransformGroup trans = new TransformGroup(t);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
trans.addChild(shape1);
// offset the second shape a little bit
t.setIdentity(); // we can reuse Transform3D
// t.set(new Vector3f(0.0f, 0.3f, 0.0f));
TransformGroup trans2 = new TransformGroup(t);
trans2.addChild(shape2);
trans.addChild(trans2);
objRoot.addChild(trans);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
// Create the drag behavior node
MouseRotate behavior = new MouseRotate();
behavior.setTransformGroup(trans);
trans.addChild(behavior);
behavior.setSchedulingBounds(bounds);
// Create the zoom behavior node
MouseZoom behavior2 = new MouseZoom();
behavior2.setTransformGroup(trans);
trans.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
// Create the zoom behavior node
MouseTranslate behavior3 = new MouseTranslate();
behavior3.setTransformGroup(trans);
trans.addChild(behavior3);
behavior3.setSchedulingBounds(bounds);
// Let Java 3D perform optimizations on this scene graph.
objRoot.compile();
return objRoot;
}
public PolygonAttributesTest() {
Container contentPane = getContentPane();
Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
BranchGroup scene = createSceneGraph();
// SimpleUniverse is a Convenience Utility class
SimpleUniverse u = new SimpleUniverse(c);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
// Create GUI
JPanel panel = new JPanel();
BoxLayout boxlayout = new BoxLayout(panel,
BoxLayout.Y_AXIS);
panel.setLayout(boxlayout);
panel.add(createAttributesPanel());
panel.add(createOffsetPanel());
contentPane.add("South", panel);
// create menu bar
JMenuBar mb = new JMenuBar();
// since Canvas3D is heavy weight,
// the menu will hidden behind it if not set this
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
JMenu fileMenu = new JMenu("File");
JMenuItem exitItem = new JMenuItem("Exit");
fileMenu.add(exitItem);
mb.add(fileMenu);
getRootPane().setJMenuBar(mb);
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
contentPane.add("Center", c);
}
JPanel createAttributesPanel() {
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder("Polygon Attributes"));
String mode[] = {"POLYGON_POINT", "POLYGON_LINE", "POLYGON_FILL"};
pMode = new JComboBox(mode);
pMode.addActionListener(this);
pMode.setSelectedIndex(pa.getPolygonMode());
String cullFace[] = {"CULL_NONE", "CULL_BACK", "CULL_FRONT"};
pCullFace = new JComboBox(cullFace);
pCullFace.addActionListener(this);
pCullFace.setSelectedIndex(pa.getCullFace());
panel.add(new JLabel("Mode"));
panel.add(pMode);
panel.add(new JLabel("Cull Face"));
panel.add(pCullFace);
pNormalFlip = new JCheckBox("BackFaceNormalFlip",
pa.getBackFaceNormalFlip());
pNormalFlip.addActionListener(this);
panel.add(pNormalFlip);
return panel;
}
JPanel createOffsetPanel() {
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder("Polygon Offset"));
pOffset = new JTextField(pa.getPolygonOffset()+"", 3);
pOffset.addActionListener(this);
panel.add(new JLabel("Offset"));
panel.add(pOffset);
pOffsetFactor = new JTextField(pa.getPolygonOffsetFactor()+"",
3);
pOffsetFactor.addActionListener(this);
panel.add(new JLabel("Offset Factor"));
panel.add(pOffsetFactor);
return panel;
}
public void actionPerformed(ActionEvent e) {
Object target = e.getSource();
if (target == pMode) {
pa.setPolygonMode(pMode.getSelectedIndex());
}
else if (target == pCullFace) {
pa.setCullFace(pCullFace.getSelectedIndex());
}
else if (target == pNormalFlip) {
pa.setBackFaceNormalFlip(pNormalFlip.isSelected());
}
else if (target == pOffset) {
try {
pa.setPolygonOffset(Float.parseFloat(pOffset.getText()));
} catch (NumberFormatException ex) {
pOffset.setText(pa.getPolygonOffset()+"");
}
}
else if (target == pOffsetFactor) {
try {
pa.setPolygonOffsetFactor(
Float.parseFloat(pOffsetFactor.getText()));
} catch (NumberFormatException ex) {
pOffsetFactor.setText(pa.getPolygonOffsetFactor()+"");
}
}
}
public static void main(String[] args) {
Frame frame = new MainFrame(new PolygonAttributesTest(), 500, 500);
}
}
/*
* "@(#)TriColorTranslate.java 1.1 99/10/01"
*
* Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
import javax.media.j3d.*;
public class TriColorTranslate extends TriangleArray {
private static final float[] verts = {
// front face (red)
1.0f, -1.0f, -1.0f,
0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 1.0f,
};
private float red;
private float green;
private float blue;
private float translateX = 0.0f;
private float translateY = 0.0f;
private float translateZ = 0.0f;
public TriColorTranslate(float r, float g, float b,
float x, float y, float z) {
super(3, TriangleArray.COORDINATES | TriangleArray.COLOR_3);
red = r;
green = g;
blue = b;
translateX = x;
translateY = y;
translateZ = z;
setTri();
}
public TriColorTranslate(float r, float g, float b) {
super(3, TriangleArray.COORDINATES | TriangleArray.COLOR_3);
red = r;
green = g;
blue = b;
setTri();
}
private void setTri() {
int i;
float[] val = new float[3];
for (i=0; i<3; i++) {
val[0] = verts[i*3 + 0] + translateX;
val[1] = verts[i*3 + 1] + translateY;
val[2] = verts[i*3 + 2] + translateZ;
setCoordinate(i, val);
val[0] = red;
val[1] = green;
val[2] = blue;
setColor(i, val);
}
}
}