Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  What should I use to draw a bunch of connected lines?  (Read 2011 times)
0 Members and 1 Guest are viewing this topic.
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Posted 2006-04-11 00:53:46 »

So in OpenGL I'd use: glBegin(GL_LINES) or glBegin(GL_POINTS) and throw in all my vertices I want for a long connection of lines.  What should I use in Java3D to achieve the same effect?  I can't seem to find a good resource to help me on this when I search.  I want to be able to modify the length, so add/remove vertices at any time, and I'd also like to be able to add separate points that would show up as dots.  So I want to be able to draw:
1  
 __ . _ ___ . _ . _____


Anyone know what I can use for that?

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2006-04-11 02:31:25 »

degenerate triangles?

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #2 - Posted 2006-04-11 05:18:06 »

I have no idea what that is...
I found the IndexedLineArray and LineArray classes but I'm not sure what to do with them.  I'm not sure if they can help me either.  The geometry package doesn't seem to have anything useful.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #3 - Posted 2006-04-11 16:12:29 »

Hi,

  Here are some snipets of code from a simulation I did.

  For a updateable geometry I used this(the numVerts is the maximum allowed for the applicaction):
1  
2  
3  
4  
5  
    tris = new TriangleArray(numVerts, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.BY_REFERENCE);
    tris.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
    tris.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
    tris.setCapability(GeometryArray.ALLOW_COUNT_READ);
    tris.setCapability(GeometryArray.ALLOW_COUNT_WRITE);


  For the appearance in lines this:
1  
      app.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0));


   Last, for the update, (using the GeometryUpdater interface):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
  public void updateData(Geometry geo){
    TriangleArray tris = (TriangleArray)geo;
    float[] coords = tris.getCoordRefFloat();
    float[] norms = tris.getNormalRefFloat();
    int validVerts = 0;
     //Upadte your vertex/normal/texcoord..
    //Now you can have a new number of  vertices..
    //set it to the geometry.
   tris.setValidVertexCount(validVerts);
  }


  This method is called from the behaviors that receives the input.

   SInce you want to show the lines and the vertices, you can have two Shape3D objects sharing the same geometry but using the line appearance y point appearance(look in the javadocs for the points, I also use CULL_NONE for them)

    Rafael .-


Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #4 - Posted 2006-04-11 17:42:48 »

OK I looked into the code you gave me and I feel like I have a better understanding of my options now.  However I'm having some trouble with the LineStripArray class.
1  
2  
3  
4  
5  
6  
7  
points[length] = new Point3d(x,y,z);
length++;
if (length < 2)
   return;
     
lines = new LineStripArray(points.length, GeometryArray.COORDINATES, stripLengths);
lines.setCoordinates(0, points);

gives me this:
1  
2  
3  
Exception in thread "main" java.lang.NullPointerException
at javax.media.j3d.GeometryArrayRetained.setCoordinates(GeometryArrayRetained.java:4033)
at javax.media.j3d.GeometryArray.setCoordinates(GeometryArray.java:1401)


stripLengths looks like this:
stripLengths = new int[] {100};
and points looks like this:
points = new Point3d[100];

so why am I getting a NullPointerException?  This only happens after the scene starts and I try to recreate "lines" as you see in the first block of code.  I've found 2 examples online of people creating new LineStripArray's during animation for this same effect and aparantly it works for them.  What am I missing?


EDIT:  Also, if I don't re-initialize lines, I can call the setCoordinate() method successfully before the application starts rendering, but if I call it afterward I get the NullPointerException.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #5 - Posted 2006-04-11 18:55:42 »

You can't update the geometry afer it goes live (the rendering begins).
The only way to change it is by setting the correct capabilities.(ALLOW_COORD_READ/WRITE look
for them in the docs).

From some discussions here I know hat the only safe place to update geometry is in
a GeomtryUpdater  called in a Behavior.

Rafael.-

Offline Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2006-04-12 02:22:41 »

To update at run time you need to do geometry by reference.  (And yes you need to set all the right properties.)

The updater actually isnt  ina behavior, its gets called back at avery specific time when its safe to make the chnage.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #7 - Posted 2006-04-20 02:20:03 »

OK here's what I have
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
stripLengths = new int[] {100};
      lines = new LineStripArray(100, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.BY_REFERENCE, stripLengths);
      lines.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
      lines.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
      lines.setCapability(GeometryArray.ALLOW_COUNT_READ);
      lines.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
      lines.setCapability(LineArray.ALLOW_COORDINATE_WRITE);
     
      setNode(new Shape3D(lines, getAppearance()));
       getAppearance().setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0));
       
       //addPoint(0, 0, 0);
     //addPoint(1, 1, 1);
      points[0] = new Point3d(0, 0, 0);
       points[1] = new Point3d(1, 1, 1);

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   public void addPoint(double x, double y, double z) {
      points[length] = new Point3d(x,y,z);
      length++;
     
      if (length < 2)
         return;
     
      lines.updateData(this);
   }
   
   public void updateData(Geometry geo){
      LineStripArray lsa = (LineStripArray)geo;
      lsa.setCoordinates(0, points);
   }


But I still get:
Exception in thread "main" java.lang.IllegalStateException: GeometryArray: cannot directly access data in BY_REFERENCE mode
when I call the addPoint() method once running.  What am I doing wrong?

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2006-04-20 06:52:58 »

Looks liek yo uare trying to call the updater directly from main.

You **cannot**.  You can only update the data on a callback in an updater.

RTFM

http://download.java.net/media/java3d/javadoc/1.3.2/javax/media/j3d/GeometryUpdater.html

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #9 - Posted 2006-04-20 19:57:54 »

Yeah I already read that.  I also found an example doing what I'm doing.

I am NOT calling the method that you just said I can't.  I'm calling the GeometryArray.updateData(GeometryUpdater) method.  Since that accesses something different I thought that's where it goes in the background to do it in a safe way.

In that code, lines = new LineStripArray, and this implements GeometryUpdater.

Edit:  Here's the full exception:
1  
2  
3  
4  
5  
6  
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: GeometryArray: cannot directly access data in BY_REFERENCE mode
   at javax.media.j3d.GeometryArray.setCoordinates(GeometryArray.java:1399)
   at org.opensourcephysics.display3d.java3d.ElementTrail.updateData(ElementTrail.java:127)
   at javax.media.j3d.GeometryArrayRetained.updateData(GeometryArrayRetained.java:6266)
   at javax.media.j3d.GeometryArray.updateData(GeometryArray.java:950)
   at org.opensourcephysics.display3d.java3d.ElementTrail.addPoint(ElementTrail.java:122)

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #10 - Posted 2006-04-21 01:36:09 »

Yeah I already read that.  I also found an example doing what I'm doing.

I am NOT calling the method that you just said I can't.  I'm calling the GeometryArray.updateData(GeometryUpdater) method. 

Sicne you didnt include that critical information in the code you posted, it seemed reasonable that you werent doing it.

Taking a closer look it loosk to me like you are trying to chnage the references (the ISA) not the data itself, which would be referred to BY the references.






Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #11 - Posted 2006-04-21 06:25:29 »

Just for clarification,
1  
lines = new LineStripArray...

was in the original code.  LineStripArray doesn't have the method you accused me of using, so there was no need for clarification.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Jeff

JGO Coder




Got any cats?


« Reply #12 - Posted 2006-04-21 06:52:25 »

im sorry, that line you qoted appears to be totally unrelated to any of the issues at hand.

You did not show us you were using GeometryArray.updateData() method ergo I assumed you were not.
Long distance mind reading is not a specilty of mine.

Now knwoing that you are, your problem looks stroingly to be that you are trying to change the geometry object rather then change the point data refernced through the geometry object.

TO quote the docs:
1  
2  
3  
4  
5  
By Reference: A new set of methods in Java 3D version 1.2 allows data to be accessed by reference, 
directly from the user's arrays. To use this feature, set the BY_REFERENCE bit in the vertexFormat field
of the constructor for this GeometryArray. In this mode, the various set methods for coordinates, normals,
colors, and texture coordinates are not used. Instead, new methods are used to set a reference to user-supplied
coordinate, color, normal, and texture coordinate arrays


RTFM: http://hermes.hud.ac.uk/info/manuals/java3d/javax/media/j3d/GeometryArray.html

You cannot chnage the geometry, you change the arrays the geometry refernces.



Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
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.

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

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

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

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
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!