Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  trianglestriparray, and modelling wire frames  (Read 3263 times)
0 Members and 1 Guest are viewing this topic.
Offline cmd_ikari

Senior Newbie




Java games rock!


« Posted 2005-04-12 16:24:33 »

Hello,

I am currently working on a 3d landscape representation project, and have come accross a problem, in that i am not so sure how to read in the stored height values into a triangle strip array.

I have realised that in the timeframe i have left (until next thurs 21st april) i wont be able to complete the scope of my project.

However, it has been brought to my attention that creating a wire mesh for display, will be sufficient for the project.

Unfortunately, as i said, i'm having trouble creating the triangle strip array, so that i can place this into my Canvas3D as a wireframe object.

I was wondering if anyone has any example code showing how this maybe done, or even any recommended tutorials which can explain the essentials of the process. Any resources would help alot.

Any help would be much appreciated, as i am quickly running out of time.

Thanks
Andrew
Offline Mike Jacobs

Junior Devvie





« Reply #1 - Posted 2005-04-12 17:59:31 »

Check out the HelloWorld3 example here: http://sys-con.com/story/?storyid=46231&DE=1

Mike

Special Effects for Java 3D games: http://www.indietechnologies.com
Offline Breakfast

Senior Devvie




for great justice!


« Reply #2 - Posted 2005-04-12 21:07:35 »

getHeightField() is a call to a method of the local class.

Otherwise it would be ObjectName.getHeightField()

These are basic first-principles. I find it very hard to believe that you have got this far through a CS degree course without knowing the most fundamental elements of object oriented programming. Either your tutors and lecturers have let you down by not teaching the principles and checking your work properly or you have let yourself down by copying other people's code without understanding it. Either way, the last thing you need right now is to be learning the language at the same time that you are writing your dissertation and with only a week to spare-one of those "made your own bed, now lie on it" moments I guess.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #3 - Posted 2005-04-13 14:49:54 »

Fair Enough comments Breakfast. And thanks for the example code posted in my other forum post.

Thanks for the honesty! Cant really argue with what you said. My knowledge of java is failry limited and i seem outta my depth. but there is nothing for it, except for me to persevere.

If i can be so bold as to ask one final question.

Basically, my equivalent of the heightfield() method is a 3D array storing the x,y,z values. In a response to one of my earlier posts, it was bought to my attention that i probably didnt need an 3D array to store the height values, and that "there is no point in recording the x and z co-ordinates because they will always be the same as your position in the array and the only irregular quantity will be the height."

Now my question is, will it still work with a 3D array, or would it be wiser to just scrap it and try a simpler 2 dimensianal array?

p.s. from now i'll try be more careful and precise with my questioning.
Offline Breakfast

Senior Devvie




for great justice!


« Reply #4 - Posted 2005-04-13 15:19:30 »

You will need the 3D data eventually, so there is no harm in having it, but it is technically extraneous. I would go with the normal 2D array because it is simpler to implement and you will find it a lot easier to work with.

If you know that your steps in x and z both have an interval of 1 metre then to find the height at position (3, 4) you know that you can just look in your heightarray at [3][4] and there it is.

To create an Arraylist of point3d objects from your arrays you can just do this kind of thing
1  
2  
3  
for (int i=0;i<heightMap.length;i++)
     for (int j=0;j<heightMap[i].length;j++)
            MyHeights.add(new Point3d(i, heightMap[i][j], j);
Offline Breakfast

Senior Devvie




for great justice!


« Reply #5 - Posted 2005-04-13 15:22:43 »

The trouble with learning Java3D is that it is a complete bastard and not like other programming anyway- I appreciate that (partly because I did much of my learning on a commercial project, before jgo began, and mostly from the javadocs) and given that you are putting the effort in to learning it I will answer questions when I can.

It helps me too because often other people will point out that my code is rubbish and how it should be written. There is always room for improvement.
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #6 - Posted 2005-04-13 15:45:47 »

Sweet. Thanks again.

Will give it a crack, and attempt to sort it out. I'll post my progress, incase anyone else needs to know how it works out.

cheers
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #7 - Posted 2005-04-18 10:54:25 »

Hi.

So far I've managed to get the basic classes i need for the model: specifying the height values, reading them into the array, the universe class, the canvas 3D and the GUI.

Now i want to represent the points as a wire mesh. I see that u need to add the Shape to the draw function in java 3D.

Can anyone tell me whether i need to specify that it should draw the model as a wire frame, or does it automatically render it as a wire frame. I havent had much luck finding any resources on wire frames.

Any help would be much appreciated

Thanks
Andrew
Offline Breakfast

Senior Devvie




for great justice!


« Reply #8 - Posted 2005-04-18 13:23:24 »

The way the model fits together is that you create an object that extends Shape3D to contain your geometry data ( the code I gave you on the other thread should cover most of that ) that tells the system about the geometry. To control how it looks you will need to look at the Appearance, which is used to control things like colour, shininess and so on. I haven't really used wireframe display- I tend to use texturemapped polygons - but I think you would do this through the Appearance, specifically the PolygonAttributes. Take a look at those in the javadoc and you should be able to work it out from there.

Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #9 - Posted 2005-04-18 15:28:28 »

Ahh, i see. I'll probably just end up trying to figure out the texturemapped polygons. Thanks Breakfast.

By the way, i've managed to find your games programming tutorial that was posted on the earlier forum pages.

I'm finding it very useful indeed, and just want to give u some feed back, and let you know that its done in a really clear easy way to understand.

Thank you

p.s for anyone new to java 3d, having dificulty creating object models, or just wanting a clearer explanation of how to create apps i suggest checkin out the tutorial http://www.newview.co.uk/javatutorial/

(hope u dont mind me posting the address breakfast? if u'd like me to get rid of it, just let me know, and i'll modify this response)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Breakfast

Senior Devvie




for great justice!


« Reply #10 - Posted 2005-04-18 18:04:38 »

Of course not. We moved our site to a new server and I only realised that the tutorial hadn't moved over a couple of weeks back- I only actually got it sorted on Friday.

I'm glad to hear it's still useful to people...
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #11 - Posted 2005-04-19 16:18:41 »

Hi,

Does anyone one have any ideas (related resources even) how i'd get my "camera" to move slowly across my landscape, preferably staying say a metre or so off the ground. There doesnt have to be a set route (although that would help), even just moving in a straight line while in the scope of the landscape would be acceptable

Cheers
Offline Breakfast

Senior Devvie




for great justice!


« Reply #12 - Posted 2005-04-19 19:31:40 »

You need to create a viewplatformbehaviour to do this. If you look at the stuff from my Purple Dude tutorial the last section has the camera moving when you move your character. It should be possible to take out the direction checks so that you just move the camera every frame regardless of user interaction there. I never got around to rotating the camera but again it shouldn't be too hard to do based on that code, especially if you're not having to rotate around a character and can just base the movement off the user interaction.
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #13 - Posted 2005-04-21 08:44:42 »

Hi,

this might seem like a silly question, but i havent been able to figure it out yet.

Whenever i've tried using code like
   add("Center", c);
or
   myLocale.addBranchGraph( myBranch );

i get error messages such as:

1)invalid method declaration; return type required, illegal start of type, <identifier> expected.

or

2)cannot find symbol:
method addBranchGraph()

Now, i'm not so sure about errors in java, but from as far as i can figure out in 2) it seems to be asking me to create the method addBranchGroup()...

If this is the case, what wud u put in a method addBranchGroup(), as all i want to do is add the branchgroup myBranch, to my Locale.

I'm showing my lack of knowledge and grasp of java and java3d here, but i just dont understand, and it doesnt seem clear. Even when i look at the api documentation for things such as Branchgroup, it inherits methods for addchild, but these dont seem to work, without being asked to make the method addchild??? i would have thought that these inherited methods shud already have methods in the api telling them what to do, no?

I have also checked that i have the right import statements for the related classes!!??!!

any help wud be much appreciated

Andrew
Offline Breakfast

Senior Devvie




for great justice!


« Reply #14 - Posted 2005-04-21 09:33:40 »

In the first instance you're looking at a call that has fallen outside it's method - I usually get that problem when I am near the end of a class and I've just had some nested loops going on and just got an extra set of closing brackets by mistake.

In the second case I'm not entirely sure what is going on - Locale has an addBranchGraph method and so assuming your locale and your branchgroup are both created correctly that call should just work. If you posted the relevant method I may be able to take a look at it and make some suggestions.
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #15 - Posted 2005-04-21 21:07:46 »

Hi.

O.k. as my proj demonstration is tommorow, this is one of the last few couple questions i'm gonna get time to ask.

first off, after u've actually specified the triangle strip array, how do u then make that TSA into an object/Shape3D. I've tried to convert the coords into Point3d, so that i can place them in the TSA.

After that, i'm unsure what to do next.

and finally, Breakfast do u mind if i put u in my acknowledgement section of my dissertation, as you really have been a great help. The most help any one has given me actually!
Offline Jeff

JGO Coder




Got any cats?


« Reply #16 - Posted 2005-04-22 02:17:46 »

Here's hunk of code from my NWN loader...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
private Node getTrimeshShape3D(TrimeshNode tnode) {
            Appearance app = getAppearance(tnode);
            IndexedTriangleArray trigeometry = cookGeometry(tnode, app);
            Shape3D shape = new Shape3D(trigeometry);
            PolygonAttributes polyattr = new PolygonAttributes();
            if (WIREFRAME) {
                  polyattr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
            }
            app.setPolygonAttributes(polyattr);
            shape.setAppearance(app);
            return shape;
      }


TrimeshNode is am NWN structure, dont worry about it.
getAppearance() creates an Appearance object based on whats in TrimeshNode. I can post that for you if you want to see an example.

cookGeometry returns what in my case is an IndexedTriangleArray but any geometry can be passed in the Shape3D constuctor.

Hope that helps.

JK

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 Breakfast

Senior Devvie




for great justice!


« Reply #17 - Posted 2005-04-22 14:10:14 »

The method I gave you in the other thread is designed to be part of a class that extends Shape3D  but the critical part is probably the myShape3D.setGeometry( Geometry g) bit - you can just create a Shape3D and call that on it.

You don't have to ask my permission to thank me, but I would be honoured to get a mention Smiley
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #18 - Posted 2005-04-27 11:17:30 »

Hey,

Got my demonstration outta the way, a bit unsuccesfully, but scraped through. Am still gonna try get this app working tho, as now its just annoying me - cant let J3D beat me Smiley

Thanks for all the help so far guys.

Breakfast - i've tried setting the geometry to Myshape3D as u sugested! Still have an error ")" expected...

Now by looking at it, it MS3D.setGeometry(Geometry gi);
It looks like there isnt Geometry specified, even though i thought GeometryInfo would inherit Geometry's properties. Have tried to call GeometryInfo in the brackets instead, but still the same error....

In my class i've also called a new instance of TriangleStripArray in the fields called tris. And then in the SetStripA() method, i've called a new instance of GeometryInfo gi. Is the new instance tris extrenous to my needs?

Well what i tried to do instead was this...
   MS3D.setGeometry(tris);
not sure if thats doing what i need it to do tho??

any ideas, or would the source code help?

thanks 4 the help
Andrew
Offline Jeff

JGO Coder




Got any cats?


« Reply #19 - Posted 2005-04-27 18:37:38 »

Quote

Breakfast - i've tried setting the geometry to Myshape3D as u sugested! Still have an error ")" expected...


That sounds like a Java syntax error, show us the line the compielr is complainign about.

Quote

Now by looking at it, it MS3D.setGeometry(Geometry gi);
It looks like there isnt Geometry specified, even though i thought GeometryInfo would inherit Geometry's properties. Have tried to call GeometryInfo in the brackets instead, but still the same error....


Um, GeometryInfo is soemthign totally differen from Geometry.  Its a meta-information hodler for things like the automatic normal generator.

The Shape3D wouldnt care about a GemeotryInfo it just wants a Geometry.

You've got me rathr confused as to what youa re trying to do...


In my class i've also called a new instance of TriangleStripArray in the fields called tris. And then in the SetStripA() method, i've called a new instance of GeometryInfo gi. Is the new instance tris extrenous to my needs?

Well what i tried to do instead was this...
   MS3D.setGeometry(tris);
not sure if thats doing what i need it to do tho??

any ideas, or would the source code help?

thanks 4 the help
Andrew[/quote]

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 cmd_ikari

Senior Newbie




Java games rock!


« Reply #20 - Posted 2005-04-27 21:18:53 »

Hi,

I see that i didnt make it that clear what i was asking about.

firstly, the line

MS3D.setGeometry(Geometry gi);

is the one that is giving the error. But as u've explained, the gi is from GeometryInfo, and that isnt related to Geomtry

Well, u see, this is the part of my prog that i cant figure out, hence the poor explanation.

So basically i am asking, how do i need to specify Shape3D before i call the setGeometry method?

Or by extending Shape in my SetStripA() method will i be able to call setGeometry without a problem? Extending is not so clear in the java text books or notes i have, even though, its fairly fundamental java i suppose.

I could keep asking questions, but i feel i could have the total wrong end of the stick, and the questions just seem to be way off target from what i shud really be asking!

Thanks for being so patient dude...

Well i've also put the code from the class i attempted to write below. Maybe that might be clearer than my questions

public class SetStripA extends Geometry{
   
   private static Color3f matColor = new Color3f(.9f,.7f,.2f);

   
   //******************FIELDS*****************************//
   /** The integer array to hold the height of the terrain at each point on the grid*/
   int[][] m_nTerrainHeightArray;
   /** Terrain grid width (x)*/
   int m_nTerrainGridX = 0;
   /** Terrain grid height/length (y)*/
   int m_nTerrainGridY = 0;

   int[] stripCounts;
   
   // The number of vertices (or coordinates) is based on the
   // number of horizontal strips (height - 1)(50) times the
   // number of vertices per strip (width * 2)(102).
   Point3d[] coords = new Point3d[5100];
   
       
   TriangleStripArray tris = new TriangleStripArray(
               coords.length,
               GeometryArray.COORDINATES,
               stripCounts );

   //*********Constructors*****************
       
   /** Creates a new instance of TriangleStripArrayClass */
public SetStripA(int vertexCount,
               int[] stripVertexCounts,
               int[] mystripCounts) {
   
   //New instance of shape3d
   Shape3D MS3D = new Shape3D();
   
   vertexCount = 2601;
   // The strip counts handling    
   this.stripCounts = new int[51];
   for (int strip = 0; strip < 51; strip++) {
       stripCounts[strip] = 10;
   }

   
   int[][] hf = GetTerrainValues();
   // The height field
   BranchGroup objRoot = new BranchGroup();

   GeometryInfo gi =
   new GeometryInfo(GeometryInfo.TRIANGLE_STRIP_ARRAY);
   
   //
   // Create a stripCount array showing the number of vertices in each
   // strip
   //
   int[] stripCounts = new int[m_nTerrainGridX-1];
       for(int strip = 0; strip < m_nTerrainGridX-1; strip++)
       stripCounts[strip] = (m_nTerrainGridY)*2;


   int ci = 0; // coordinate index

 
   for (int m_nTerrainGridX = 0; m_nTerrainGridX < m_nTerrainHeightArray.length; m_nTerrainGridX++){
       for (int m_nTerrainGridY = 0; m_nTerrainGridY < m_nTerrainHeightArray.length; m_nTerrainGridY++) {
           // use compass bearings to id the corners
           int sw = hf[m_nTerrainGridX][m_nTerrainGridY];
           int nw = hf[m_nTerrainGridX + 1][m_nTerrainGridY];

           coords[ci] = new Point3d(m_nTerrainGridY, nw, - (m_nTerrainGridX + 1));
           coords[ci + 1] = new Point3d(m_nTerrainGridY, sw, -m_nTerrainGridX);
           ci = ci + 2;
       }
   }
   gi.setStripCounts(stripCounts);
   gi.setCoordinates(coords);  
   
   NormalGenerator ng= new NormalGenerator();
   ng.setCreaseAngle((float) Math.toRadians(30));
   ng.generateNormals(gi);
   //MS3D.setGeometry(Geometry gi); ********> This is where i get the ")" expected error*****
   MS3D.setGeometry(tris);
   }
}

There's a couple of extra methods in my class, but this gives the basic gist, i'd say. I've taken a bit off the code u left in the other thread, but to be honest, i left out a fair bit that was unclear, and then tried to write it as best i cud figure out.

Cheers again
Offline Jeff

JGO Coder




Got any cats?


« Reply #21 - Posted 2005-04-27 22:35:35 »

Quote
Hi,

I see that i didnt make it that clear what i was asking about.

firstly, the line

MS3D.setGeometry(Geometry gi);


Well if thats your code ofcourse its a syntax error.

Method definitiosn take type names, method invocations just take the parameters SO

1  
2  
3  
public void method setGeometry(Geometry gi){

...


Would be legal, as would

1  
settGeometry(gl);


But what you typed is defintiely not legal Java code.


1  
    //MS3D.setGeometry(Geometry gi); ********> This is where i get the ")" expected error*****


Yup. See how this syntax is differnt from other method calls in your code?

1  
    MS3D.setGeometry(tris);


This would be correct, IF you were invoking a static method on a class named MS3D.

It is not what I woudl expect to see. Rather I woudl expect to see something like this...

1  
myShape3D = new Shape3D(tris);


Where my shape3D was declared either statically or locally like thuis:

1  
Shape3D myShape3D;


I hope that helps.


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 cmd_ikari

Senior Newbie




Java games rock!


« Reply #22 - Posted 2005-04-28 21:53:47 »

Hi,

Thanks for the help Jk. I'm attempting to use what u've said to clean up my implementation process.

I'll let u know how it goes.

Andrew
Offline cmd_ikari

Senior Newbie




Java games rock!


« Reply #23 - Posted 2005-04-29 18:40:44 »

Hi,

Think i might have sorted out the problem, but not entirely sure. Still working on it really.

Have another question tho. Every time i use the statement (even when trying to run other people's examples)
locale.addBranchGraph(viewBranch); (althought mostly with anything in the (...), ie contentBranch etc. i always get an error cannot find symbol addBranchGraph...

Now when i try and create the addBranchGraph() method, it always tells me a return type is required...

basically, i cant seem to find out what return type it wants anywhere online...

Anyone know?
ta
Offline Breakfast

Senior Devvie




for great justice!


« Reply #24 - Posted 2005-04-29 18:57:18 »

Are you using a SimpleUniverse or creating your own subclass of VirtualUniverse?


Offline Jeff

JGO Coder




Got any cats?


« Reply #25 - Posted 2005-04-29 19:53:52 »

Quote
Hi,

Think i might have sorted out the problem, but not entirely sure. Still working on it really.

Have another question tho. Every time i use the statement (even when trying to run other people's examples)
locale.addBranchGraph(viewBranch); (althought mostly with anything in the (...), ie contentBranch etc. i always get an error cannot find symbol addBranchGraph...

Now when i try and create the addBranchGraph() method, it always tells me a return type is required...



Ima bit confused again. What class is locale an instance of?  A J3D class or one of your own?

All the classes in the J3D API and their fields and methods are decoumenetd in the J3D AP Javadoc:

https://j3d-core.dev.java.net/files/documents/1674/12424/java3d-1_3_2-doc.tar.gz

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 cmd_ikari

Senior Newbie




Java games rock!


« Reply #26 - Posted 2005-04-30 11:24:02 »

Hi,

I'm using a simple universe for now. Seems the more documented of the two universes.

The locale class is in the J3d API. but i've just seen it takes the value of virtual universe.

I suppose i need to use virtual universe then if i'm using locale.

Cheers for that
Offline Breakfast

Senior Devvie




for great justice!


« Reply #27 - Posted 2005-04-30 17:45:44 »

If you're using a SimpleUniverse do you need to be making direct calls to a Locale at all?

Can you not just get by with adding your root BranchGroup directly to the SimpleUniverse?
Offline Jeff

JGO Coder




Got any cats?


« Reply #28 - Posted 2005-05-01 03:58:59 »

If your using simepl unvierse, dont emss with locale, add the scenegraph direictly to your univese with

mySimpleUniverse.addBranchGraph ( myBranchGroup);

You may alsoi need to et your clipping plane in order to see anything. I set it to out  of the way with this call in MDLViewer....

simpleU.getViewer().getView().setBackClipDistance(10000.0);



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.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (53 views)
2014-12-09 22:41:13

BurntPizza (86 views)
2014-12-08 04:46:31

JscottyBieshaar (48 views)
2014-12-05 12:39:02

SHC (63 views)
2014-12-03 16:27:13

CopyableCougar4 (65 views)
2014-11-29 21:32:03

toopeicgaming1999 (126 views)
2014-11-26 15:22:04

toopeicgaming1999 (117 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!