Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  IndexedQuadArray in Xith3D  (Read 2168 times)
0 Members and 1 Guest are viewing this topic.
Offline zaknixon

Senior Newbie




</bored>


« Posted 2005-03-03 15:20:10 »

I am trying to refactor my J3D code to semi-match the Xith3D api.
I am trying to use the IndexedQuadArray node, but whenever I need to set my indicies ( setCoordinateIndices(0,indicies) in J3D), I have no equivalent in Xith3D...

Is there an alternate way of doing this?

Thanks

Zak Nixon

Huh

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline ewills

Junior Member




Java skeletal animation systems rock!


« Reply #1 - Posted 2005-03-03 16:17:17 »

Use setIndex(int[] i) to set all of the indices.
Offline zaknixon

Senior Newbie




</bored>


« Reply #2 - Posted 2005-03-04 10:54:48 »

Thanks for your reply, ewillis.
Is there also a way to set the color indicies as well?

So far, I can use a PointArray for my points and my geometry shows up (also QuadArray), but with the IndexedQuadArray, I am not seeing anything.

I have used the setIndex(int[] indicies) for the coordinates, and set my Shape3D's coloring attributes.

Anyone have examples of working with the IndexedQuadArray?

Thanks  :-/

Zak Nixon

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zaknixon

Senior Newbie




</bored>


« Reply #3 - Posted 2005-03-04 13:56:47 »

I have tried adding a quad using the IndexedQuadArray and a triangle using the IndexedTriangleArray. The quad does not display, but the triangle will. Below is my code.

The quad:
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  
      public Shape3D getGrid(){
            int numIndexes = 4;
            int[] indexes = new int[]{0,1,2,3};
            // Vector3f[] normals = new Vector3f[]{ new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f)};
           
            IndexedQuadArray a = new IndexedQuadArray(4,IndexedTriangleArray.COORDINATES,numIndexes);
           
            Point3f[] coords = new Point3f[]{ new Point3f(1.0f,1.0f,0.0f), new Point3f(-1.0f,1.0f,0.0f),new Point3f(-1.0f,-1.0f,0.0f),new Point3f(1.0f,-1.0f,0.0f)};
     
            a.setValidIndexCount(4);
            a.setCoordinates(0,coords);
            //a.setNormals(0,normals);
           a.setIndex(indexes);
           
            Appearance app = new Appearance();
          Material material = new Material();
          material.setAmbientColor(.6f,.6f,.6f);
          material.setLightingEnable(true);

            app.setColoringAttributes(new ColoringAttributes(new Color3f(1.0f,0.0f,0.0f),ColoringAttributes.FASTEST));
            app.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE,PolygonAttributes.CULL_NONE,0f));
            // app.setMaterial(material);
           
            Shape3D s = new Shape3D(a,app);
            return s;
      }




The triangle:
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  
      public Shape3D getTriangle(){
            int numIndexes = 3;
            int[] indexes = new int[]{0,1,2};
            // Vector3f[] normals = new Vector3f[]{ new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f)};
           
            IndexedTriangleArray a = new IndexedTriangleArray(3,IndexedTriangleArray.COORDINATES,numIndexes);
           
            Point3f[] coords = new Point3f[]{ new Point3f(1.0f,1.0f,0.0f), new Point3f(-1.0f,1.0f,0.0f),new Point3f(-1.0f,-1.0f,0.0f)};
     
            a.setValidIndexCount(3);
            a.setCoordinates(0,coords);
            //a.setNormals(0,normals);
           a.setIndex(indexes);
           
            Appearance app = new Appearance();
          Material material = new Material();
          material.setAmbientColor(.6f,.6f,.6f);
          material.setLightingEnable(true);

            app.setColoringAttributes(new ColoringAttributes(new Color3f(1.0f,0.0f,0.0f),ColoringAttributes.FASTEST));
            app.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE,PolygonAttributes.CULL_NONE,0f));
            // app.setMaterial(material);
           
            Shape3D s = new Shape3D(a,app);
            return s;
      }


Any thing I am doing wrong?

Thanks
Zak

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline ewills

Junior Member




Java skeletal animation systems rock!


« Reply #4 - Posted 2005-03-04 16:03:40 »

I suggest using com.xith3d.utility.geometry.XithGeometryInfo and com.xith3d.utility.geometry.GeometryCreator.  GeometryCreator lets you specify geometries in an OpenGL manner, XithGeometryInfo allows you to create various GeometryArraysS from a GeometryCreator.
Offline zaknixon

Senior Newbie




</bored>


« Reply #5 - Posted 2005-03-18 14:49:55 »

Well, unfourtunately, these classes do not support Quad geometry, just Triangle Strips.
There has to be a way to build simple quad geometry....

Any suggestions?

Zak

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline ewills

Junior Member




Java skeletal animation systems rock!


« Reply #6 - Posted 2005-03-18 17:15:54 »

You can always represent a quad as two triangles.  Is there a reason you really need to use a QuadArray?
Offline zaknixon

Senior Newbie




</bored>


« Reply #7 - Posted 2005-03-19 22:17:32 »

I am trying to draw a wireframe model of a sphere, like lat/lon lines. I already have the geometry defined as Indexed Quads. I could define them as individual lines, but that changes all of my algorithms and data structs.

Just trying to find a one-to-one correspondance between J3D and Xith.

Zak

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline mksingh1

Senior Newbie





« Reply #8 - Posted 2006-05-26 11:40:04 »

i guess there is no problem in ur code..the problem is with the one of the library class of Xith....go to the PACKAGE--com.xith3d.render.jogl......CLASS----ShapeAtomPeer....in this class go to the METHOD---private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray)....... in this method actually some code is missing..... i have made changes in this code....now the working code should be...



  private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray) {
       
        ProfileTimer.startProfile("drawGeometry");
        int numVertices = geoArray.getValidVertexCount();
//       
        if (numVertices == 0) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping because there are no valid vertices ");
            ProfileTimer.endProfile();
            return;
        }

       

        // get the format of verticies
        int format = geoArray.getVertexFormat();

        int stripCount = 0;
        int[] stripVertexCounts = null;

        // if a strip array then get the above two values
        if (geoArray instanceof GeometryStripArray) {
            stripCount = ((GeometryStripArray) geoArray).getNumStrips();
            stripVertexCounts = ((GeometryStripArray) geoArray).
                    getStripVertexCounts();
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a strip array " + stripCount + " strips");
        }

        // find out if color3f data was supplied and if it was use it


        int mode = 0;

        if ((geoArray instanceof IndexedGeometryArray)) {
            canvas.addTriangles( ((IndexedGeometryArray)geoArray).getValidIndexCount()/geoArray.getFaceSize());
           
        } else if (geoArray instanceof TriangleArray) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a triangle array with " + numVertices + " vertices");
            mode = GL.GL_TRIANGLES; // say that we want to draw trianlges
            canvas.addTriangles(numVertices/geoArray.getFaceSize());
        } else if (geoArray instanceof QuadArray) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a quad array with " + numVertices + " vertices");
            mode = GL.GL_QUADS; // say that we want to draw quads
            canvas.addTriangles(numVertices/geoArray.getFaceSize());
        } else if (geoArray instanceof PointArray) {
            mode = GL.GL_POINTS; // say that we want to draw points
            canvas.addTriangles(numVertices/geoArray.getFaceSize());
        } else if (geoArray instanceof LineArray) {
            mode = GL.GL_LINES; // say that we want to draw lines
        } else if (!(geoArray instanceof GeometryStripArray)) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping unknown geometry : " + geoArray.getClass().getName());
           
            ProfileTimer.endProfile();
            return; // don't know how to draw this
        }

        // do the actual drawing genericly

        setupBuffers(canvas, gl, geoArray);
        if (geoArray instanceof GeometryStripArray) {

            //setPointers(gl);

            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Starting drawing strips for GeometryStripArray");
            // loop through the strips

            if (geoArray instanceof LineStripArray) {
                mode = GL.GL_LINE_STRIP; // say that we want to draw a line strip
            } else if (geoArray instanceof TriangleStripArray) {
                mode = GL.GL_TRIANGLE_STRIP; // say that we want to draw a triangle strip
//                if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG,"Drawing a triangle strip "+strip+" of "+stripCount+" strips and "+stripVertexCounts[strip]+" vertices");
            } else if (geoArray instanceof TriangleFanArray) {
                mode = GL.GL_TRIANGLE_FAN; // say that we want to draw a triangle fan
            }

            int start = 0;
            for (int strip = 0; strip < stripCount; strip++) {

                gl.glDrawArrays(mode, start, stripVertexCounts[strip]);
                start += stripVertexCounts[strip];

            }
        } else if (geoArray instanceof IndexedGeometryArray) {
           if (geoArray instanceof IndexedLineArray) {
                mode = GL.GL_LINES; // say that we want to draw points
                IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
                gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
            }
           
           if (geoArray instanceof IndexedQuadArray) {
                 mode = GL.GL_QUADS; // say that we want to draw points
                 IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
                 gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
             }
            if (geoArray instanceof IndexedTriangleArray) {
                mode = GL.GL_TRIANGLES; // say that we want to draw points
                IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
                gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
            } else if ( geoArray instanceof IndexedGeometryStripArray ) {
                if ( geoArray instanceof IndexedTriangleStripArray ) {
               mode = GL.GL_TRIANGLE_STRIP;
                IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                int[] strips = igsa.getStripVertexCounts();
                int start = 0;
                for (int s = 0; s < strips.length; s++) {
                    gl.glDrawElements(mode,strips,GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                    start += strips;
                }
            }
                if ( geoArray instanceof IndexedLineStripArray ) {
                   mode = GL.GL_LINE_STRIP;
                    IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                    int[] strips = igsa.getStripVertexCounts();
                    int start = 0;
                    for (int s = 0; s < strips.length; s++) {
                        gl.glDrawElements(mode,strips,GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                        start += strips;
                    }
                }
                if ( geoArray instanceof IndexedTriangleFanArray ) {
                   mode = GL.GL_TRIANGLE_FAN;
                    IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                    int[] strips = igsa.getStripVertexCounts();
                    int start = 0;
                    for (int s = 0; s < strips.length; s++) {
                        gl.glDrawElements(mode,strips,GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                        start += strips;
                    }
                }
            }
           
        } else {
            gl.glDrawArrays(mode, geoArray.getInitialVertexIndex(), geoArray.getValidVertexCount());
        }
        ProfileTimer.endProfile();
    }



i guess replacing the previous code with this one,will solve ur problem......try this...All the best... n plzzz let me know if it works...
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.

CogWheelz (14 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!