Monday 18 November 2013

Simple Polygon Creation


Since you can't use ColorCube's for all of your polygons, 
the next step is to learn how to create your own shapes. 

First create an Appearance 
    Appearance polygon1Appearance = new Appearance();

Lets make a simple Rectangle:
in this example, the rectangle will have height of 3m and width of 2m, 
with coordinates (0,0,0), (2,0,0), (2,3,0) and (0,3,0) 
(notice the veritices are in counter-clockwise order) 

 QuadArray polygon1 = new QuadArray (4, QuadArray.COORDINATES);
     polygon1.setCoordinate (0, new Point3f (0f, 0f, 0f));
     polygon1.setCoordinate (1, new Point3f (2f, 0f, 0f));
     polygon1.setCoordinate (2, new Point3f (2f, 3f, 0f));
     polygon1.setCoordinate (3, new Point3f (0f, 3f, 0f));

Then add the Polygon to the Scene Graph using that Appearance (assuming objRoot is your SceneGraph name) 
     objRoot.addChild(new Shape3D(polygon1,polygon1Appearance));

 

Note: If you do not put your verticies in counter-clockwise order, they will not be seen. 

No comments: