Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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  
  Simple Geometry Utils  (Read 613 times)
0 Members and 1 Guest are viewing this topic.
Offline JoyrexJ9

Senior Newbie




Losing my mind...


« Posted 2004-06-30 15:30:49 »

Hi,

I require some simple geometry utility classes for generating planes, cylinders etc. (planes to beging with)
I've tried the TestUtils class but all it can generate is one big quad as the plane, this is messing with my lighting Sad so I need to tesselate the plane into sub-quads or triangles.

I'm tying to write a class, what is the best Geometry class to use for this sort of thing (QuadArray, TriangleArray or something else)?
Are there any docs on the format that QuadArray and Triangle array expect their data?  Huh

If something exists out there to already do this I'd gladly use that! I can't be the first person to have required this...

Cheers,
Ben

Ben
----------------------------------------------------
Dungeon Engine - http://cgi.bencoleman.plus.com/tiki/tiki-index.php?page=DungeonEngine
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #1 - Posted 2004-06-30 21:10:39 »

Hi,

Creatin these primitives in Xith3D is very simple. Take a look at createSphere(float R, int divisions) in TestUtils and you will easily get the idea of how to do indexed triangle array.

Additionally, you can use GeometryCreator and XithGeometryInfo in utility/geometry package to create geometry in OpenGL glBegin/glEnd way and get it out as GPU-cache-optimized Xith3D Shape.

Here is a short example on how to use it:

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  
30  
31  
32  
33  
34  
35  
36  
37  
            GeometryCreator gc = new GeometryCreator();
            for (int i = 0; i < indexedVertexes.length/3; i++)
            {
                  gc.addCoordinate(indexedVertexes[i*3],indexedVertexes[i*3+1],indexedVertexes[i*3+2]);
                  if (indexedNormals.length > 0)
                        gc.addNormal(indexedNormals[i*3],indexedNormals[i*3+1],indexedNormals[i*3+2]);
                  if (indexedTexCoords.length > 0)
                        gc.addTexCoord(indexedTexCoords[i*2],indexedTexCoords[i*2+1]);
            }
            for (int i = 0; i < indexes.length/3; i++)
            {
//                  System.out.println("Face " + indexes[i*3] + " " + indexes[i*3+1] + " " + indexes[i*3+2]);
                 gc.addCoordIndex(indexes[i*3]);
                  gc.addCoordIndex(indexes[i*3+1]);
                  gc.addCoordIndex(indexes[i*3+2]);
                  if (indexedNormals.length > 0)
                  {
                        gc.addNormalIndex(indexes[i*3]);
                        gc.addNormalIndex(indexes[i*3+1]);
                        gc.addNormalIndex(indexes[i*3+2]);
                  }
                  if (indexedTexCoords.length > 0)
                  {
                        gc.addTexIndex(indexes[i*3]);
                        gc.addTexIndex(indexes[i*3+1]);
                        gc.addTexIndex(indexes[i*3+2]);
                  }
                  gc.nextFace();
            }
            XithGeometryInfo xgi = new XithGeometryInfo();
            gc.fillGeometryInfo(xgi);
            xgi.weldVertices();
            xgi.optimizeTrianglesForCache();

            IndexedTriangleArray shapeGeom = xgi.createIndexedTriangleArray(geomFlags);

            shape.setGeometry(shapeGeom);


As of docs, you can take a look at Java3D docs - it uses similar format for data in GeometryArrays.

Yuri

Yuri Vl. Gushchin
JProof Group
Offline JoyrexJ9

Senior Newbie




Losing my mind...


« Reply #2 - Posted 2004-07-01 13:07:49 »

Thanks, for the reply I've managed to write something now, that suits my needs. I just used QuadArray.

I had a look at GeometryCreator and I didn't understand it, but I think I've got it now.

Here's a link to my class, it creates planes in one of the three orientations and the planes can be subdivided into smaller quads.
http://cgi.bencoleman.plus.com/files/PlaneGenerator.java

Ben

Ben
----------------------------------------------------
Dungeon Engine - http://cgi.bencoleman.plus.com/tiki/tiki-index.php?page=DungeonEngine
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.

xsi3rr4x (22 views)
2014-04-15 18:08:23

BurntPizza (17 views)
2014-04-15 03:46:01

UprightPath (31 views)
2014-04-14 17:39:50

UprightPath (15 views)
2014-04-14 17:35:47

Porlus (31 views)
2014-04-14 15:48:38

tom_mai78101 (57 views)
2014-04-10 04:04:31

BurntPizza (115 views)
2014-04-08 23:06:04

tom_mai78101 (214 views)
2014-04-05 13:34:39

trollwarrior1 (182 views)
2014-04-04 12:06:45

CJLetsGame (189 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!