Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Xith3D Forums / Re: new Text2D implementation on: 2005-09-18 20:32:38
Thanks Florian, I plan on using this but am having a few problems.  I'm new at this so it could very well be user error. 

First of all when you call the constructor "public Text ( String newText )" it doesn't initialize user data so you get null pointer exceptions.  Second, when I use the other constructor to initialize everything I set font to "Arial" but all I get out is rectangle polygons where the text should be.  Do I need to set up the fonts somehow?

Last I was wondering if you could add a feature to have the text always facing the screen even when you rotate view.  That's how the old static Text2D worked.  I might be able to figure this out myself, not too sure yet though, like I said I'm new at this.  Thanks!
2  Java Game APIs & Engines / Xith3D Forums / Re: new Text2D implementation on: 2005-07-16 01:55:03
Would using this dynamic text2d be better for displaying FPS than the swing tutorial counter?  People have been complaining about the swing right?
3  Java Game APIs & Engines / Xith3D Forums / Re: Loading animations? on: 2005-06-25 23:32:20
Thanks kev, this loader rocks!  Although I do have a question.  I'm using Milkshape 3d, I just started learning it.  There doesn't appear to be a way to save multiple animations in one .md2 file.  It appears in your example with the alien you call both the run and stand animations from the same file, how is this possible?  Am I missing something or do I need to find a better modeling program?
4  Java Game APIs & Engines / Xith3D Forums / Re: Loading animations? on: 2005-06-25 01:16:26
I finally got a chance to check out the newdawn MD2 loader... looks pretty easy to use although there are some compilation errors:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
java.lang.Error: Unresolved compilation problems: 
   BranchGroup.ALLOW_CHILDREN_READ cannot be resolved
   BranchGroup.ALLOW_CHILDREN_EXTEND cannot be resolved
   BranchGroup.ALLOW_CHILDREN_WRITE cannot be resolved

   at org.newdawn.xith3d.loaders.md2.MD2ModelInstance.<init>(MD2ModelInstance.java:72)
   at org.newdawn.xith3d.loaders.md2.MD2Model.getInstance(MD2Model.java:101)
   at MD2Test.loadModel(MD2Test.java:200)
   at MD2Test.<init>(MD2Test.java:117)
   at MD2Test.main(MD2Test.java:275)
Exception in thread "main"

I don't seem to have a definition for those BranchGroup constants?  Can anyone give me information on how to resolve?  Thanks!
5  Java Game APIs & Engines / Xith3D Forums / Re: Loading animations? on: 2005-05-11 14:31:27
Great, very helpful thanks.  Any suggestions on which modeling programs I can use?  Hopefully there are some good free ones out there.
6  Java Game APIs & Engines / Xith3D Forums / Loading animations? on: 2005-05-09 16:02:02
I'm looking for information on how to load a model and animations for my game.  I need a soldier with animations such as run, grenade, shoot, etc.  Obviously I'll start off with something simpler, but that's my ultimate goal.

I'm new to this so I'm wondering what format models I should use and if there are any free modeling programs I can use to make models that will load easily.  Basically any information to help me get started with adding animated models to my game.  Thanks!
7  Java Game APIs & Engines / Xith3D Forums / Re: Text labels on: 2005-03-08 16:10:23
Quote

I am needing to place text labels as a part of naming things in my 3D universe, that would move along with the object as it is being updated.

I need to implement this is my game as well.  I haven't attempted it yet but I was planning on using the Text2D class in the toolkit.  Take a look at that and let me know if it works for you:
https://xith-tk.dev.java.net/servlets/ProjectDocumentList
8  Java Game APIs & Engines / Xith3D Forums / Re: Picking on: 2005-03-08 03:25:10
I found another post mentioning Canvas3D.createPickRay().  I had to download the method from CVS but it was worth it, helped me a ton I think I got it figured out now.  Thanks guys!

createPickRay() from CVS
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  
    public void createPickRay(int x, int y, Point3f o, Vector3f d) {
        float w = (float) canvas.getWidth();
        float h = (float) canvas.getHeight();
        float a = h / w;
        if (view.getProjectionPolicy() == View.PERSPECTIVE_PROJECTION) {
            // normalize the pixel location to between -1.0 and 1.0 and modify the x
           // coordinate to take aspect ratio into account.
           float rx = (2.0f * (float) x / w - 1.0f) / a;
            float ry = 2.0f - 2.0f * (float) y / h - 1.0f;

            // calculate the distance between viewer and view plane.
           float vpd = 1.0f / (float) Math.tan(view.getFieldOfView());

            // originate the ray at the local origin of the viewer and direct it
           // toward the local position of the click in the view plane.
           o.set(0.0f, 0.0f, 0.0f);
            d.set(rx, ry, -vpd);
            d.normalize();
        } else {
            // normalize the pixel location to between -1.0 and 1.0 and modify the y
           // coordinate to take aspect ratio into account.
           float rx = 2.0f * (float) x / w - 1.0f;
            float ry = a * (2.0f - 2.0f * (float) y / h - 1.0f);

            // originate the ray at local position of the click in the view plane
           // and direct it along the -Z axis.
           float s = view.getScreenScale();
            o.set(s * rx, s * ry, 0.0f);
            d.set(0.0f, 0.0f, -1.0f);
        }

        // transform the ray into world space.
       view.getTransform().transform(o);
        view.getTransform().transform(d);
    }
9  Java Game APIs & Engines / Xith3D Forums / Re: Picking on: 2005-03-05 14:53:25
I have got a flat shape... a quad.  So I should try DonCrudelis' code or is that just for terrain object?  Here is what I'm doing now, I changed Global.terrain.getY to 0, and I pass in Z for Y and Y for Z since I have Y as up.  

1  
2  
3  
4  
5  
6  
7  
8  
9  
      public void mouseClicked(MouseEvent e) {
            Vector3f vect = new Vector3f();
            vect = getTerrainIntersection(e.getPoint(), new Point3f(camX, camZ,
                        camY), new Point3f(viewX, 0, viewY));
            System.out.println(vect.x); // x coord
           System.out.println(vect.z); // y coord
           
            isViewChangeScheduled = true;
      }


What I get out of this are values very close to my viewX and viewY I put into it.  My viewX=5 and viewY=5 i get output like:
X = 5.0227056
Y = 4.992122
X = 5.004961
Y = 5.0184546
X = 4.9696717
Y = 5.014441

clicking in various places - this is obviously not what I want =/

oh yeah, and this is with the camera overhead looking straight down, if I change the angle of it then it gives me different numbers, but still nothing close to what I want
10  Java Game APIs & Engines / Xith3D Forums / Re: Picking on: 2005-03-05 12:03:14
I am getting so frustrated with this, I can't get this to work.  Most of this stuff I am not following.  I either need a detailed tutorial to follow or some code I can plug in and run with.

I have my eye at (camX, camY, camZ) and I have it looking at (viewX, viewY, 0)  I'm just trying to get the X,Y coords where the user clicked Z will always be 0 its a flat terrain... I've spent so much time on this and still have nothing Sad

please help!
11  Java Game APIs & Engines / Xith3D Forums / Re: Picking on: 2005-03-04 23:55:12
Thanks Macca, I've had some more time to look at this and realized Globals.terrain.getY is also undefined.  Any ideas about that one?

Globals.terrain.getY(pointerPos.x, pointerPos.z)
12  Java Game APIs & Engines / Xith3D Forums / Re: Picking on: 2005-03-03 00:49:28
can someone tell me what "rayDir" is and how do I get it?
13  Java Game APIs & Engines / Xith3D Forums / Re: Picking terrain on: 2005-03-03 00:49:04
Thanks Macca!  I do have a question about it though, please refer to the posted thread.
14  Java Game APIs & Engines / Xith3D Forums / Re: Picking terrain on: 2005-02-27 16:35:22
I guess I'm not really looking to "pick"  I just need the coordinates on my XY plane.
15  Java Game APIs & Engines / Xith3D Forums / Re: Picking terrain on: 2005-02-27 13:16:36
I am having major problems with this.  I cannot seem to find any clear examples anywhere and all the explanations I find just go over my head.  I have an XY plane where Z is 0 and I need the XY coords of where they click on that plane.  Can anyone help?
16  Java Game APIs & Engines / Xith3D Forums / Re: understanding branchgroup and transformgroup on: 2005-02-06 20:47:37
A couple more questions:

1) On that Java3D site they talk about Text2D... is there a similar feature for Xith3D?

2) Is there a geometry feature to draw a cylinder?

thanks!
17  Java Game APIs & Engines / Xith3D Forums / Re: understanding branchgroup and transformgroup on: 2005-02-05 14:11:41
Wow, very helpful.  thanks!
18  Java Game APIs & Engines / Xith3D Forums / understanding branchgroup and transformgroup on: 2005-02-05 03:37:36
I've been playing with Xith3D off and on for several months now and I'm trying to get my mind around how the BranchGroup and TransformGroup are best used.  

So as I understand it you make a universe and add a locale and a scene (branchgroup), one of each right?  Now if I have several Shape3d's to add at different translations and rotations, do I need to create two new TransformGroup's (one for translation one for rotation) for every shape?  Or am I supposed to just keep using the original objTranslate and objRotate and "reset" them after drawing each shape?

Hopefully I am making some sense here, its possible I'm just entirely confused and no one will understand me.
19  Java Game APIs & Engines / Xith3D Forums / box feature? on: 2004-11-15 03:40:29
The create cube function used in the tutorials is very simple I like it, there wouldn't happen to be a similar function for drawing a 3d box with different length, height, and width would there?  It would be much easier than plotting coords for 6 different quads to get a box.
20  Java Game APIs & Engines / Xith3D Forums / Re: rotation question on: 2004-11-12 07:39:02
Quote
To rotate around a particular axis, this is one way.
1  
hero.getTransform().setRotation(new AxisAngle4f(new Vector3f(0, 0, 1), 3.14f))


It sounds to me like you have two transform3d nodes (one for rotation and one for translation) and that you have their positions in the scenegraph mixed up.

To convert mouse coords to world coords, you might need to consider that the (0,0) is at the top left of the canvas for the mouse and (0,0,0) is at the center. You can always do a hack conversion like this "(e.getX() - canvas.getWidth()/2)/3;" till you can figure out the trig to get the correct values of depth

Thank you for the reply, however I still can't seem to get it working the way I want.  What is the "hero" in that line of code?  

Your saying the best way to get the X,Y coords in world is to convert from mouse coords using math?  I'll play with that idea some more and see if I can figure something out.  

Here is my code so you get a better idea of what I'm trying to do, I want to rotate around viewX and viewY and it will only rotate around 0,0.  If you notice any other problems, please comment.  Thanks!

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  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
import javax.vecmath.*;
import java.awt.*;
import java.awt.event.*;

// Xith3D
import com.xith3d.scenegraph.*;
import com.xith3d.test.*;

// use Jogl
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
import com.xith3d.loaders.texture.*; // new

public class Xith implements KeyListener
{
      //Data to be determined later
     private int SCREEN_WIDTH = 1024;
      private int SCREEN_HEIGHT = 768;
      private int MAP_WIDTH = 10;
      private int MAP_HEIGHT = 10;
      private int STARTING_TILE_X = 5;
      private int STARTING_TILE_Y = 5;
     
      //Universe
     private VirtualUniverse universe;
      private View view;
      private BranchGroup scene;

      //VIEW
     private boolean isViewChangeScheduled = true;
      //Rotation
     private TransformGroup objRotate;
      private Transform3D rotate;
      private boolean isRotationScheduled = true;
      private float rotX = 0;
      private float rotY = 0;
      private float rotZ = 0;
      //Zoom/Translation
     private TransformGroup objTranslate;
      private Transform3D translate;
     
      private float camX = 0;
      private float camY = 0;
      private float camZ = 10f;
     
      private float viewX = STARTING_TILE_X;
      private float viewY = STARTING_TILE_Y;
     
      private static final float PI = 3.141592654f;
     
    /**
     * Our own EventListener.
     */

    class EventListener implements AWTEventListener
    {
        public void eventDispatched(AWTEvent event)
        {
            if(event instanceof MouseEvent)
            {
                MouseEvent e = (MouseEvent) event;
                switch(e.getID())
                {
                    case MouseEvent.MOUSE_PRESSED: mousePressed(e); break;
                    case MouseEvent.MOUSE_RELEASED: mouseReleased(e); break;
                    case MouseEvent.MOUSE_DRAGGED: mouseDragged(e); break;
                }
            }
            else if(event instanceof KeyEvent)
            {
                KeyEvent e = (KeyEvent) event;
                switch(e.getID())
                {
                    case KeyEvent.KEY_TYPED: keyTyped(e); break;
                }
            }
        }
    }

      /**
       * Starts the application.
       */

      public static void main(String[] args)
      {
            new Xith();
      }

      public Xith()
      {
            // Texture and TextureLoader
           Texture2D textureGrass = null;
            TextureLoader tl = new TextureLoader();

            // specifying the paths for textures
           // there can be more than one path
           tl.registerPath("./");

            // load the texture, if the texture isn't there the
           // program immediatley exits and prints an error
           textureGrass = (Texture2D) tl.getMinMapTexture("textures/grass.png");

            // create the virtual universe and view
           createUniverse();

            // let objects along this path translate
           translate = new Transform3D();
            objTranslate = new TransformGroup(translate);
            scene.addChild(objTranslate);

            // let objects along this path rotate
           rotate = new Transform3D();
            objRotate = new TransformGroup(rotate);
            objTranslate.addChild(objRotate);
                       
            // create Cube
           Geometry terrain = createMap();
            Geometry wall = createWall();
            Appearance a = new Appearance();
            a.setTexture(textureGrass);
            Shape3D sh = new Shape3D(terrain, a);
            objRotate.addChild(sh);
            Shape3D sh2 = new Shape3D(wall, a);
            objRotate.addChild(sh2);

            // turn the scene into a render friendly format
           scene.compile();

            // create a canvas for our graphics
           RenderPeer rp = new RenderPeerImpl();
            CanvasPeer cp = rp.makeCanvas(null, SCREEN_WIDTH, SCREEN_HEIGHT, 32, false);
            Canvas3D canvas = new Canvas3D();
            canvas.set3DPeer(cp);

        Toolkit.getDefaultToolkit().addAWTEventListener(
                new EventListener(),   AWTEvent.KEY_EVENT_MASK
                                     | AWTEvent.MOUSE_EVENT_MASK
                                     | AWTEvent.MOUSE_MOTION_EVENT_MASK);

            //Add keylistener
           cp.getComponent().addKeyListener(this);

            // modify our view so we can see the cube
           view.addCanvas3D(canvas);
            view.startView();

            // main rendering loop
           while (true)
            {
                  view.renderOnce();

                  if (isViewChangeScheduled )
                        handleView();
                  if (isRotationScheduled )
                        handleRotation();
            }
      }

      private void createUniverse()
      {
            universe = new VirtualUniverse();

            // add a view to the universe
           view = new View();
            universe.addView(view);

            // add a locale
           Locale locale = new Locale();
            universe.addLocale(locale);

            // create a BranchGroup
           scene = new BranchGroup();
            locale.addBranchGraph(scene);
      }

      private void handleView()
      {            
            float distance = camZ;
            camY = viewY;
            //float z = camZ - (camZ * (float)(Math.sin(rotX)));
           camX = viewX;
           
            view.getTransform().lookAt(
                        new Vector3f(camX, camY, camZ),            // location of eye
                       new Vector3f(viewX, viewY, 0),             // center of view
                       new Vector3f(0, 1, 0));                        // vector pointing up
           //translate.setTranslation(new Vector3f(transX, transY, transZ));
           isViewChangeScheduled = false;
            //objTranslate.setTransform(translate);
     }

      private void handleRotation()
      {      
            rotate.rotXYZ(rotX, rotY, rotZ);
            isRotationScheduled = false;
            objRotate.setTransform( rotate );      
      }
     
      public Geometry createMap()
      {
            Point3f[] coords = new Point3f[] {
                        new Point3f(0, 0, 0),
                        new Point3f(MAP_WIDTH, 0, 0),
                        new Point3f(MAP_WIDTH, MAP_HEIGHT, 0),
                        new Point3f(0, MAP_HEIGHT, 0)};
            TexCoord2f[] texCoords = new TexCoord2f[] {
                        new TexCoord2f(0f, 0f),
                        new TexCoord2f(MAP_WIDTH, 0f),
                        new TexCoord2f(MAP_WIDTH, MAP_HEIGHT),
                        new TexCoord2f(0f, MAP_HEIGHT) };
           
            QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
            g.setCoordinates(0, coords);
            g.setTextureCoordinates( 0, 0, texCoords );

            return g;
      }

      public Geometry createWall()
      {
            Point3f[] coords = new Point3f[] {
                        new Point3f(5, 5, 0),
                        new Point3f(6, 5, 0),
                        new Point3f(6, 5, 3),
                        new Point3f(5, 5, 3)};
            TexCoord2f[] texCoords = new TexCoord2f[] {
                        new TexCoord2f(0f, 0f),
                        new TexCoord2f(1f, 0f),
                        new TexCoord2f(1f, 1f),
                        new TexCoord2f(0f, 1f) };
           
            QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
            g.setCoordinates(0, coords);
            g.setTextureCoordinates( 0, 0, texCoords );

            return g;
      }
     
      public void keyPressed(KeyEvent e)
      {
            switch (e.getKeyCode())
            {
                  case KeyEvent.VK_INSERT :
                        changeTilt(-0.1f);
                        break;
                  case KeyEvent.VK_HOME :
                        changeTilt(0.1f);
                        break;
                  case KeyEvent.VK_END :
                        changeRotation(+0.2f);
                        break;
                  case KeyEvent.VK_DELETE :
                        changeRotation(-0.2f);
                        break;
                  case KeyEvent.VK_UP :
                        changeViewY(+0.1f);
                        break;
                  case KeyEvent.VK_DOWN :
                        changeViewY(-0.1f);
                        break;
                  case KeyEvent.VK_RIGHT :
                        changeViewX(0.1f);
                        break;
                  case KeyEvent.VK_LEFT :
                        changeViewX(-0.1f);
                        break;
                  case KeyEvent.VK_PAGE_UP :
                        changeZoom(-0.1f);
                        break;
                  case KeyEvent.VK_PAGE_DOWN :
                        changeZoom(0.1f);
                        break;
            }
      }

    public void mouseDragged(MouseEvent e)
    {}

    private void mousePressed(MouseEvent e)
    {
          //viewX=-1*(e.getX() - canvas.getWidth()/2)/3;
         //viewY=-1*(e.getY() - canvas.getHeight()/2)/3;

        isViewChangeScheduled=true;
    }

    private void mouseReleased(MouseEvent e)
    {}
     
      private void changeViewX( float change )
      {
            changeView( change, 0 );
      }
     
      private void changeViewY( float change )
      {
            changeView( 0, change );
      }

      private void changeView( float xChange, float yChange )
      {
            viewX += xChange;
            viewY += yChange;            
            isViewChangeScheduled = true;
      }

      private void changeZoom( float change )
      {
            camZ += change;
            isViewChangeScheduled = true;
      }
     
      private void changeTilt( float change )
      {
            rotX += change;
            isRotationScheduled = true;
      }
     
      private void changeRotation( float change )
      {
            rotZ += change;
            isRotationScheduled = true;
      }

      public void keyTyped(KeyEvent e)
      {}

      public void keyReleased(KeyEvent e)
      {}
}
21  Java Game APIs & Engines / Xith3D Forums / rotation question on: 2004-11-11 08:01:54
Hi, I have what is probably a simple question and I'm learning Xith3D to use to create a game so expect many more!

I'm wondering how I can use the rotate function to rotate around the Z axis at specified X and Y coords.  Instead of always rotating around (0,0).  Sorry if this is in the docs somewhere I must have missed it, thanks!

Ok, I have another question already, its along the same lines so I'll post it here as well:

I have my event listener set up already, and I'm wondering how I can get the X and Y coords of where the user clicks.  I got the mouse coords using e.getX() and e.getY() however that doesn't help me I need the X,Y coords on my game map.  Thanks again.
22  Java Game APIs & Engines / Xith3D Forums / Re: need texture help on: 2004-08-07 17:53:53
Thanks hawk,  I was trying to use the code from the simple texture tutorial, I guess it doesn't work with the quad.  Here is my working code snippet if anyone else was having this problem:

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  
            // create a BranchGroup
           BranchGroup scene = new BranchGroup();
            locale.addBranchGraph(scene);
           
            // Define Texture coords for a square shape
         TexCoord2f[] texCoords = new TexCoord2f[] {
                      new TexCoord2f(0f, 0f),
                        new TexCoord2f(1f, 0f),
                        new TexCoord2f(1f, 1f),
                        new TexCoord2f(0f, 1f) };
           
            // draw Terrain
         Point3f[] coords = new Point3f[] {
                      new Point3f(0, 0, 0),
                        new Point3f(MAP_WIDTH, 0, 0),
                        new Point3f(MAP_WIDTH, 0, MAP_HEIGHT),
                        new Point3f(0, 0, MAP_HEIGHT),
          };

          QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES |
                                                                            GeometryArray.TEXTURE_COORDINATE_2);
          g.setCoordinates(0,coords);
          g.setTextureCoordinates(0,0,texCoords);
           
            Appearance a = new Appearance();
            a.setTexture(textureTerrain);
23  Java Game APIs & Engines / Xith3D Forums / need texture help on: 2004-08-07 04:52:30
Hi all, I'm new to Xith and still fairly new to 3D programming.  Using the tutorials I came up with this simple program.  I'm trying to display texture on a quad instead of the cube used in the tutorial, it changes the quad's color, but the texture doesn't show.  I'm using the glass.png texture from the tutorial:

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  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
package xith;

import javax.vecmath.*;

// Xith3D
import com.xith3d.scenegraph.*;
import com.xith3d.test.*;

// use Jogl
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
import com.xith3d.loaders.texture.*;

public class Xith
{
      private int SCREEN_WIDTH = 1024;
      private int SCREEN_HEIGHT = 768;
      private int MAP_WIDTH = 40;
      private int MAP_HEIGHT = 40;
      private int STARTING_VIEW_X = 10;
      private int STARTING_VIEW_Z = 10;
     
      public static void main (String[] args)
      {
            new Xith();
      }
     
      public Xith()
      {
            // Texture and TextureLoader
           Texture2D textureTerrain = null;
            TextureLoader tl = new TextureLoader();
           
            // Specify paths for textures, there can be more than one path
           tl.registerPath("./textures");
           
            //load the texture, program will crash if texture doesn't exist
           textureTerrain = (Texture2D)tl.getMinMapTexture("glass.png");
           
            //create virtual univers
           VirtualUniverse universe = new VirtualUniverse();
           
            // add a view to universe
           View view = new View();
            universe.addView(view);
           
            // add a locale
           Locale locale = new Locale();
            universe.addLocale(locale);
           
            // create a BranchGroup
           BranchGroup scene = new BranchGroup();
            locale.addBranchGraph(scene);
           
            // draw Terrain
         Point3f[] coords = new Point3f[] {
                      new Point3f(0, 0, 0),
                        new Point3f(MAP_WIDTH, 0, 0),
                        new Point3f(MAP_WIDTH, 0, MAP_HEIGHT),
                        new Point3f(0, 0, MAP_HEIGHT),
          };

          QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES);
          g.setCoordinates(0,coords);
           
            Appearance a = new Appearance();
            a.setTexture(textureTerrain);
           
          Shape3D Terrain = new Shape3D(g, a);
            scene.addChild(Terrain);
           
            // turn the scene into a render friendly format
           scene.compile();
           
            //create a canvas for our graphics
           RenderPeer rp = new RenderPeerImpl();
            CanvasPeer cp = rp.makeCanvas(null,SCREEN_WIDTH,SCREEN_HEIGHT,16,false);
            Canvas3D canvas = new Canvas3D();
            canvas.set3DPeer(cp);
           
            //modify our view
           view.addCanvas3D(canvas);
            view.getTransform().lookAt(
                        new Vector3f( STARTING_VIEW_X, 15, STARTING_VIEW_Z),            // location of eye
                       new Vector3f( STARTING_VIEW_X, 0, STARTING_VIEW_Z+3),            // center of view
                       new Vector3f( 0, 1, 0));      // vector pointing up
           view.startView();
           
      }
}
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (74 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (28 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!