Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to draw solid polygon (newbie)  (Read 1998 times)
0 Members and 1 Guest are viewing this topic.
Offline rhhaney145

Senior Newbie





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

Please Help,

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?

Thanks in advance.
Offline Conzar

Junior Duke




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);


Now just add the QuadArray to the scene graph and your all set.

Ubuntu
Offline 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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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?

Thanks in advance.
Offline rhhaney145

Senior Newbie





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

Fixed the problem!! Grin

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.
Offline Conzar

Junior Duke




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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (53 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (43 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!