1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
| import javax.vecmath.*;
import com.xith3d.scenegraph.*; import com.xith3d.test.*; import com.xith3d.loaders.texture.*;
import com.xith3d.render.*; import com.xith3d.render.jogl.*;
public class indexTest { public Shape3D shape; IndexedTriangleArray geo; private Point3f[] coordinates; private Vector3f[] normals; private Color3f[] colors; private int[] indices; private TexCoord2f[] texCoords; private int MAX_INDICES; private int MAX_COORDINATES; public PolygonAttributes pa; private Texture2D texture; private ColoringAttributes ca; private Material mat; private Appearance app; public static void main(String[] args) { new indexTest(); } public Shape3D createShape(){ int size = 5; MAX_COORDINATES = size * size; MAX_INDICES = (size-1)*(size-1) * 6; this.generateCoordinates(size); this.generateIndices(size); this.generateTextureCoordinates(size); this.generateGeometry();
shape = new Shape3D(geo); TextureLoader.tf.registerPath("."); TextureLoader.tf.registerPath(".."); texture = (Texture2D) TextureLoader.tf.getMinMapTexture("stone.jpg"); pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE,PolygonAttributes.CULL_NONE,0); app = new Appearance(); app.setTexture(texture); app.setPolygonAttributes(pa); shape.setAppearance(app); shape.setBoundsAutoCompute(false); shape.setBounds(new BoundingSphere(new Point3f(0,0,0),100000)); return shape; } private void generateIndices(int size){ indices = new int[MAX_INDICES]; int index=0; for(int z = 0; z < size-1; z++){ for(int x = 0; x < size-1; x++){ indices[index++] = x + ( z * size ); indices[index++] = x + 1 + ( z * size); indices[index++] = x + 1 + ((z + 1) * (size)); indices[index++] = x + (z * size); indices[index++] = x + 1 + ((z + 1) * (size)); indices[index++] = x + ((z + 1) * (size)); } } } private void generateTextureCoordinates(int size){ texCoords = new TexCoord2f[MAX_COORDINATES]; int index=0; for(int z = 0; z < size; z++) for(int x = 0; x < size; x++) texCoords[index++] = new TexCoord2f((float)x / (float)(size-1), (float)z / (float)(size-1)); } private void generateCoordinates(int size){ coordinates = new Point3f[MAX_COORDINATES]; int index=0; for(int z=0; z<size; z++) for(int x=0; x<size; x++) coordinates[index++] = new Point3f((float)x, 0.0f, (float)z); } private void generateGeometry() { geo = new IndexedTriangleArray(MAX_COORDINATES, TriangleArray.COORDINATES | TriangleArray.TEXTURE_COORDINATE_2, MAX_INDICES); geo.setValidVertexCount(MAX_COORDINATES); geo.setCoordinates(0, coordinates); geo.setValidIndexCount(MAX_INDICES); geo.setIndex(indices); geo.setTexCoordRef2f(0,texCoords); }
public void start(View view) { while (true){ Transform3D viewT = new Transform3D(); viewT.lookAt(new Point3f(5,5,-5),new Point3f(5,0,0),new Point3f(0,1,0)); view.setTransform(viewT); view.renderOnce(); try { Thread.sleep(10L); } catch (Exception e) { } } }
public indexTest() { VirtualUniverse universe = new VirtualUniverse();
View view = new View(); universe.addView(view);
Locale locale = new Locale(); universe.addLocale(locale);
BranchGroup scene = new BranchGroup(); locale.addBranchGraph(scene); Shape3D plane = createShape(); Geometry geo = Cube.createCubeViaTriangles(0, 0, 0, 1, true); Shape3D sh = new Shape3D(geo, new Appearance()); scene.addChild(sh); scene.addChild(plane);
RenderPeer rp = new RenderPeerImpl(); CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false); Canvas3D canvas = new Canvas3D(); canvas.set3DPeer(cp);
view.addCanvas3D(canvas); start(view); } } |