Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (602) Games in Android Showcase (171) games submitted by our members Games in WIP (650) 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 2342 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

You cannot reply to this message, because it is very, very old.

 Jesse (16 views) 2015-07-29 04:35:27 Riven (37 views) 2015-07-27 16:38:00 Riven (18 views) 2015-07-27 15:35:20 Riven (21 views) 2015-07-27 12:26:13 Riven (12 views) 2015-07-27 12:23:39 BurntPizza (30 views) 2015-07-25 00:14:37 BurntPizza (42 views) 2015-07-24 22:06:39 BurntPizza (24 views) 2015-07-24 06:06:53 NoxInc (31 views) 2015-07-22 22:16:53 NoxInc (18 views) 2015-07-22 22:13:39
 theagentd 51x wessles 45x basil_ 35x orangepascal 28x KaiHH 26x Riven 19x ags1 17x mooman219 17x bornander 14x KudoDEV 13x princec 12x Jesse 11x CelestialCreator 11x klaus 11x Zaneris 9x philfrei 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 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