Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (769) Games in Android Showcase (230) games submitted by our members Games in WIP (855) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 How to draw solid polygon (newbie)  (Read 4475 times) 0 Members and 1 Guest are viewing this topic.
rhhaney145

Senior Newbie

 « Posted 2007-06-20 13:56:38 »

I am very new at Java3D and trying to draw a solid polygon based on a set of Points (X, Y, and Z Coordinates). I was using JOGL but like the purely Object-oriented paradigm provided by Java3D. Anyway, I have a series of Points stored in a Vector and need to draw them as a Polygon that is solid. In JOGL I used the following code:
 1  2  3  4  5  6  7 `Vector pts = getPoints();gl.glBegin(GL.GL_POLYGON);for (int i = 0; i < pts.size(); i++)  {    PointData p = (PointData)pts.get(i);    gl.glVertex3f(p.x, p.y, p.z);}gl.glEnd();`

The problem is that when I have tried it with Java3D using the GeometryInfo Class I sometimes get strange triangulation renderings.  Can anyone out there help a newbie out?

Conzar

Junior Devvie

There is nothing common about common sense

 « Reply #1 - Posted 2007-06-20 16:07:26 »

You need to use a QuadArray.

So something like this
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16 `Point3f point0 = new Point3f(0,0,0);Point3f point1 = new Point3f(1,0,0);Point3f point2 = new Point3f(1,1,0);Point3f point3 = new Point3f(0,1,0);QuadArray quadArray = new QuadArray(4,QuadArray.COORDINATES | QuadArray.NORMALS);quadArray.setCoordinates(0,point0);quadArray.setCoordinates(1,point1);quadArray.setCoordinates(2,point2);quadArray.setCoordinates(3,point3);Vector3f norm = new Vector3f(0f,0f,1f);quadArray.setNormal(0,norm);quadArray.setNormal(1,norm);quadArray.setNormal(2,norm);quadArray.setNormal(3,norm);`

Ubuntu
rhhaney145

Senior Newbie

 « Reply #2 - Posted 2007-06-20 18:29:13 »

Thank you very much for the reply Conzar.

However, I probably should clarify the issue a little more.  The Model I am rendering is made up of a series of potentially complex (contain "holes") polygons that may or may not fall on a total vertex number that is a factor of 4.  Each polygon being rendered could have any number of vertices.  When this is the situation what is the best idea to do with Java3D ?

Once again, thank you for the response.
rhhaney145

Senior Newbie

 « Reply #3 - Posted 2007-06-21 15:07:00 »

All right,

I think I am begining to understand enough about Java3D to properly ask the question that I have regarding rendering Polygons.  I have a set of Polygons that I would like to render together to form a single Object.  I believe the problem is occurring when I try to append multiple Geometries, the following snippet of code shows what I am trying to do (this Class extends the Shape3D Class):
 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 `public void setGeometry() {        // The outers Vector contains a Collection of Polygon Objects (each of which is       // composed of a series of Point3d Objects)  ...        //        for (int i = 0; i < this.outers.size(); i++) {            this.gInf = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);            Polygon poly = (Polygon)this.outers.get(i);            Point3d[] outerPts = poly.outerToArray();            int[] stripCounts = {outerPts.length};            int[] contourCount = {1};            this.gInf.setCoordinates(outerPts);            this.gInf.setStripCounts(stripCounts);            Triangulator tr = new Triangulator();            tr.triangulate(this.gInf);            this.gInf.recomputeIndices();            NormalGenerator ng = new NormalGenerator();            ng.generateNormals(this.gInf);            this.gInf.recomputeIndices();            Stripifier st = new Stripifier();            st.stripify(this.gInf);            this.gInf.recomputeIndices();           //this.setGeometry(this.gInf.getGeometryArray());           this.addGeometry(this.gInf.getGeometryArray());        }// End of FOR-LOOP}// End of setGeometry()`

When I uncomment the setGeometry(this.gInf.getGeometryArray()) and comment-out the addGeometry(this.gInf.getGeometryArray()) methods I get a correct Polygon rendering (although only the LAST polygon in the series represented by the "outers" Vector is rendered.  I am hoping that this is a SIMPLE fix.  Can anyone out there PLEASE help a newbie out?

rhhaney145

Senior Newbie

 « Reply #4 - Posted 2007-06-28 12:57:27 »

Fixed the problem!!

It had nothing to do with the GeometryInfo Class. I had forgot to check the direction of the Point3d Objects to be rendered, thus the points sometimes yielded malformed triangle divisions.

Thanks everybody for all the help/hints.  It really helps a newbie like myself.
Conzar

Junior Devvie

There is nothing common about common sense

 « Reply #5 - Posted 2007-06-28 13:05:47 »

Glad you got it working man!

Ubuntu
Pages: [1]
 ignore  |  Print

 EgonOlsen (1597 views) 2018-06-10 19:43:48 EgonOlsen (1699 views) 2018-06-10 19:43:44 EgonOlsen (1153 views) 2018-06-10 19:43:20 DesertCoockie (1581 views) 2018-05-13 18:23:11 nelsongames (1181 views) 2018-04-24 18:15:36 nelsongames (1704 views) 2018-04-24 18:14:32 ivj94 (2471 views) 2018-03-24 14:47:39 ivj94 (1686 views) 2018-03-24 14:46:31 ivj94 (2770 views) 2018-03-24 14:43:53 Solater (909 views) 2018-03-17 05:04:08
 Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20Deployment and Packagingby philfrei2018-08-19 23:54:46
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org