?? indexedquadarraytest.java
字號:
import java.applet.Applet;
import java.awt.BorderLayout;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.geometry.Primitive;
public class IndexedQuadArrayTest extends Applet
{
public BranchGroup createBranchGroup()
{
BranchGroup branch=new BranchGroup();
BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
Background bg=new Background(new Color3f(1.0f,1.0f,0.0f));
bg.setApplicationBounds(bounds);
branch.addChild(bg);
DirectionalLight light=new DirectionalLight(new Color3f(1.0f,0.0f,0.0f),new Vector3f(0.0f,0.0f,-1.0f));
light.setInfluencingBounds(bounds);
branch.addChild(light);
TransformGroup trans=new TransformGroup();
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branch.addChild(trans);
MouseRotate rotate=new MouseRotate(trans);
rotate.setSchedulingBounds(bounds);
branch.addChild(rotate);
MouseZoom zoom=new MouseZoom(trans);
zoom.setSchedulingBounds(bounds);
branch.addChild(zoom);
MouseTranslate translate=new MouseTranslate(trans);
translate.setSchedulingBounds(bounds);
branch.addChild(translate);
trans.addChild(new IndexedQuadArrayShape());
branch.compile();
return branch;
}
public IndexedQuadArrayTest()
{
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.createBranchGroup());
}
public static void main(String[] args)
{
new MainFrame(new IndexedQuadArrayTest(),300,300);
}
}
class IndexedQuadArrayShape extends Shape3D
{
public IndexedQuadArrayShape()
{
int count=12;
int indexCount=8;
int[] index={0,1,5,6,7,9,10,11};
float[] ver={
-0.6f,0.6f,0.0f,-0.6f,-0.6f,0.0f,
-0.2f,-0.4f,0.0f,-0.2f,0.6f,0.0f,
0.0f,0.3f,0.0f,0.0f,-0.3f,0.0f,
0.2f,0.2f,0.0f,0.2f,0.7f,0.0f,
0.5f,0.6f,0.0f,0.6f,-0.2f,0.0f,
0.8f,-0.3f,0.0f,0.8f,0.6f,0.0f
};
float[] colors={
0.0f,0.5f,1.0f, 0.0f,0.5f,1.0f,
0.0f,0.8f,2.0f, 1.0f,0.0f,0.3f,
0.0f,1.0f,0.5f, 0.9f,1.0f,0.0f,
0.5f,0.0f,1.0f, 0.0f,0.5f,1.0f,
1.0f,0.5f,0.0f, 1.0f,0.0f,0.5f,
1.0f,0.8f,0.0f, 1.0f,0.5f,0.0f
};
IndexedQuadArray array=new IndexedQuadArray(count,IndexedQuadArray.COORDINATES|IndexedQuadArray.COLOR_3,indexCount);
array.setCoordinates(0,ver);
array.setColors(0,colors);
array.setCoordinateIndices(0,index);
array.setColorIndices(0,index);
PolygonAttributes attri=new PolygonAttributes();
attri.setCullFace(PolygonAttributes.CULL_NONE);
Appearance app=new Appearance();
app.setPolygonAttributes(attri);
this.setGeometry(array);
this.setAppearance(app);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -