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

 BurntPizza (27 views) 2015-04-23 03:42:11 theagentd (31 views) 2015-04-22 16:23:07 Riven (45 views) 2015-04-16 10:48:47 Duke0200 (52 views) 2015-04-16 01:59:01 Fairy Tailz (38 views) 2015-04-14 20:13:12 Riven (41 views) 2015-04-12 21:36:37 bus hotdog (58 views) 2015-04-10 02:39:32 CopyableCougar4 (61 views) 2015-04-10 00:51:04 BurntPizza (62 views) 2015-04-06 22:06:58 ags1 (62 views) 2015-04-02 10:58:48
 theagentd 23x BurntPizza 16x wessles 15x alwex 11x 65K 11x kingroka123 11x kevglass 8x phu004 8x Rayvolution 8x Olo 7x ra4king 7x Ecumene 7x KevinWorkman 7x Roquen 7x chrislo27 7x Hanksha 7x
 How 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:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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