?? linestriparray.java
字號:
import java.applet.Applet;
import java.awt.BorderLayout;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
//import javax.media.j3d.LineStripArray;
import javax.vecmath.*;
public class LineStripArray extends Applet
{
public BranchGroup createBranchGroupSceneGraph()
{
BranchGroup branchGroupRoot=new BranchGroup();
BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
Color3f bgColor=new Color3f(1.0f,1.0f,1.0f);
Background bg=new Background(bgColor);
bg.setApplicationBounds(bounds);
branchGroupRoot.addChild(bg);
Color3f directionalColor=new Color3f(1.0f,0.0f,0.0f);
Vector3f vec=new Vector3f(0.0f,0.0f,-1.0f);
DirectionalLight directionalLight=new DirectionalLight(directionalColor,vec);
directionalLight.setInfluencingBounds(bounds);
branchGroupRoot.addChild(directionalLight);
Appearance app=new Appearance();
Material material=new Material();
material.setDiffuseColor(new Color3f(1.0f,1.0f,0.0f));
app.setMaterial(material);
TransformGroup transformGroup=new TransformGroup();
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branchGroupRoot.addChild(transformGroup);
MouseRotate mouseRotate=new MouseRotate();
mouseRotate.setTransformGroup(transformGroup);
branchGroupRoot.addChild(mouseRotate);
mouseRotate.setSchedulingBounds(bounds);
MouseZoom mouseZoom=new MouseZoom();
mouseZoom.setTransformGroup(transformGroup);
branchGroupRoot.addChild(mouseZoom);
mouseZoom.setSchedulingBounds(bounds);
MouseTranslate mouseTranslate=new MouseTranslate();
mouseTranslate.setTransformGroup(transformGroup);
branchGroupRoot.addChild(mouseTranslate);
mouseTranslate.setSchedulingBounds(bounds);
transformGroup.addChild(this.shapeLines());
branchGroupRoot.compile();
return branchGroupRoot;
}
public Shape3D shapeLines()
{
Shape3D shapeLines0=new Shape3D();
float vertexes[]={
-0.8f,0.8f,0.0f,0.8f,0.8f,0.0f,
-0.8f,0.2f,0.0f,0.8f,0.2f,0.0f,
-0.8f,-0.2f,0.0f,0.8f,-0.2f,0.0f,
-0.8f,-0.8f,0.0f,0.8f,-0.8f,0.0f
};
float colors[]={
1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,
0.0f,0.0f,1.0f,1.0f,1.0f,0.0f,
0.0f,1.0f,1.0f,1.0f,0.0f,1.0f,
0.0f,0.0f,0.0f,0.3f,0.0f,0.0f
};
int[] substrips=new int[2];
substrips[0]=4;
substrips[1]=4;
javax.media.j3d.LineStripArray lines=new javax.media.j3d.LineStripArray(8,LineArray.COORDINATES|LineArray.COLOR_3,substrips);
lines.setCoordinates(0,vertexes);
lines.setColor(0,colors);
LineAttributes lineAttributes=new LineAttributes();
lineAttributes.setLineWidth(9.0f);
lineAttributes.setLineAntialiasingEnable(true);
lineAttributes.setLinePattern(0);
Appearance app=new Appearance();
app.setLineAttributes(lineAttributes);
shapeLines0.setGeometry(lines);
shapeLines0.setAppearance(app);
return shapeLines0;
}
public LineStripArray()
{
this.setLayout(new BorderLayout());
Canvas3D c=new Canvas3D(SimpleUniverse.getPreferredConfiguration());
this.add(c,"Center");
SimpleUniverse u=new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(this.createBranchGroupSceneGraph());
}
public static void main(String[] args)
{
new MainFrame(new LineStripArray(),300,300);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -