Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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: Lighting problems on: 2004-06-08 15:54:46
*bump*

Surely someone must have experienced similar problems?

Or is the problem in my code, not in xith?

Terje
2  Java Game APIs & Engines / Xith3D Forums / Lighting problems on: 2004-06-03 09:18:50
Okay, so now I'm starting to get comfortable with Xith3D, and I want to explore some of the more advanced functionality. Therefore, I decided to start playing around with lighting and shadows, and it turns out things don't work as I suspected them to.

First of all, the point lights are broken. With that, I mean that they seem to use the local coordinates of the light to calculate the lighting... This has already been mentioned in another thread, http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1082736276;start=2#2 , but I thought I could overcome it by manually transforming the light's position doing something like:
1  
2  
3  
Point3f location = new Point3f(0.0f,0.0f,0.0f);
myWorldTransform.get(location);
plight.setLocation(location);


However, it seems the local coordinates of the geometry is used as well. That means if you, like me, like to have your objects centered around 0,0,0 and then move them with transformgroups, you will get strange results when using a point light. This may of course be wrong, but at least it seemed to me like it was working this way.

Any plans of fixing this?

Second, I can't seem to figure out how to get the shadows working properly. I have made sure all my geometry is sealed (at least as far as I can tell), and then I choose a node and call setIsOccluder(true). This does create some sort of shadows effect, but not anything like I had in mind. Am I missing a step here?

Third, the directional light seems a bit strange as well. I have several cylinder shapes that I have rotated, translated and non-uniformly scaled. Their material has no specular or ambient component, only a diffuse one (red). When applying a directional light to the scene, the cylinders that are tallest have a darker color on the face closest to the observer. If my understanding of lighting is correct, the diffuse color should only depend on the incoming angle of the light, and since this is a directional light, that angle should be the same regardless of the size of the cylinders. See the attached screenshot:


Could there be a bug in the directional light code as well?

Any help to clear these things up would be highly appreciated.

Best regards,
Terje
3  Java Game APIs & Engines / Xith3D Forums / Re: How to create a transparency texture on plane on: 2004-05-30 01:41:35
I'm assuming you want just parts of the texture to be transparent, not the whole thing.

First, you need a picture with an alpha (transparency channel) in it. That means gif or png (and maybe others), but afaik no jpeg.

Then, you need to load the image using one of the functions that let you specify the format, and specify "RGBA" to support the Alpha channel in the image.

If you plan to run your code from a jar file (applet, web start etc) the below code can be quite useful:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
  BufferedImage skinImg = null;
            try {
                  skinImg = ImageIO.read(cl.getResource("filename.png"));
            } catch (IOException e1) {
                  e1.printStackTrace();
            }
            Texture2D skin = (Texture2D)tl.constructTexture(skinImg,
                        "RGBA",
                        false,
                        Texture.BASE_LEVEL,        // Mag-Filter
                       Texture.BASE_LEVEL_LINEAR, // Min-Filter
                       Texture.WRAP,                        // Boundry-Mode
                       false,
                        0);            


Then, apply the transparancy attributes as you already do, note that you can set the transparancy value to 0.0f and still have the trasparent parts of the texture be transparent.

If it still doesn't work, take a look at the Text2D code I have posted at https://xith-tk.dev.java.net

Good luck

Terje
4  Java Game APIs & Engines / Xith3D Forums / Re: Text2D for xith on: 2004-05-29 15:30:17
Okay, the file is added to the xith-tk page.

However, I couldn't create a page in the wiki. I tried going to http://xith.org/tiki-index.php?page=Text2D and the option "create" is not there.

Is my tiki user (orz) lacking some rights?

Terje
5  Java Game APIs & Engines / Xith3D Forums / Re: UIWindowManager HELP on: 2004-05-27 22:54:39
I had the same problem with the deformation of the text when not running fullscreen. However, a quick and dirty fix is putting the canvas inside a JPanel in a JFrame, eg:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
Dimension d = new Dimension(800, 600);
JFrame mainWindow = new JFrame("Xith3D");
JPanel panel = new JPanel();
panel.setPreferredSize(d);
panel.setMaximumSize(d);
panel.setMinimumSize(d);
mainWindow.getContentPane().add(panel);
mainWindow.pack();
mainWindow.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainWindow.setLocation(100,100);
RenderPeer renderPeer = new RenderPeerImpl();
CanvasPeer canvasPeer = renderPeer.makeCanvas(
                              panel,
                              d.width,
                              d.height,
                              16,
                              false);


The canvas will not resize with the window, but at least you get a window that can be moved and closed.

Terje
6  Java Game APIs & Engines / Xith3D Forums / Re: Text2D for xith on: 2004-05-25 16:07:37
I have sent a request for joining the xith-tk group, I guess that is needed for adding any files to the file list or cvs?

In my opinion this tool is a little small for justifying a downloadable package, but maybe that's easier for people. Which package name should be used for something like this? com.xith3d.something?

I registered on the xith.org tiki, but where is a good place to put something like this? In the FAQ maybe?

Terje
7  Java Game APIs & Engines / Xith3D Forums / Re: OK UI package now ported to SWT ! ! ! on: 2004-05-20 12:17:25
I agree with aNt, please post the changes to the overlays  so we can fix the events for our guis =)

Terje
8  Java Game APIs & Engines / Xith3D Forums / Re: Text2D for xith on: 2004-05-20 12:11:25
Okay, here's the code =)

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  
/*
 * Copyright (c) 2004 Terje Wiesener <wiesener@samfundet.no>
 *
 * This code may be freely used and distributed as long as this notice is kept intact.
 *
 * THE CODE IS SUPPLIED AS-IS, WITH NO GUARANTEE WHATSOEVER.
 *
 */

package com.agentus.diplom.util.xith3d;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.HashMap;

import com.xith3d.loaders.texture.TextureLoader;
import com.xith3d.scenegraph.Appearance;
import com.xith3d.scenegraph.Billboard;
import com.xith3d.scenegraph.GeometryArray;
import com.xith3d.scenegraph.Material;
import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.Texture;
import com.xith3d.scenegraph.Texture2D;
import com.xith3d.scenegraph.TransformGroup;
import com.xith3d.scenegraph.TransparencyAttributes;

/** Implementation of 2D text for Xith3d
 *
 * @author Terje Wiesener <wiesener@samfundet.no>
 *
 */

public class Text2D extends TransformGroup {
      private static final TextureLoader tl;
      private static final Graphics2D g;
      private static final Material mat;
      private static final TransparencyAttributes ta;
      private static final HashMap textures;
     
      static{
            tl = new TextureLoader();
            g = (new BufferedImage(100, 100,
                  BufferedImage.TYPE_INT_ARGB)).createGraphics();
            mat      = new Material();
            mat.setLightingEnable(false);
            ta = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.0f);
            textures = new HashMap();
      }
     
      public Text2D(String text) {
//            this(text, new Font("SansSerif", Font.BOLD, 20));//default font
           this(text, new Font("Dialog", Font.BOLD, 20));//default font
     }
     
      public Text2D(String text, Font font) {
            super();
            TextInstance ti = new TextInstance(text, font);
            Texture2D stringTex = (Texture2D)textures.get(ti);
           
            if (stringTex == null){//texture is not cached
                 Rectangle2D bounds = font.getStringBounds(text, g.getFontRenderContext());
                  int textWidth = (int) bounds.getWidth();
                  int textHeight = (int) bounds.getHeight();
                  int width = 64 * (int)(Math.ceil((float)textWidth / 64.0f));//make width a multiple of 64
                 int height = 128;
                 
                  BufferedImage bi = new BufferedImage(width, 128,
                              BufferedImage.TYPE_INT_ARGB);
                  Graphics2D g2 = (Graphics2D) bi.createGraphics();
                  g2.setColor(Color.WHITE);
                  g2.setFont(font);
                  g2.drawString(text, (width - textWidth) / 2, textHeight + 1);//draw in the top middle
                 
                  stringTex = (Texture2D) tl.constructTexture(bi, "RGBA",
                              false, Texture.BASE_LEVEL, Texture.BASE_LEVEL_LINEAR,
                              Texture.WRAP, false, TextureLoader.SCALE_DRAW_BEST);
                 
                  textures.put(ti, stringTex);//cache texture for later use
           }
            Appearance app = new Appearance();
            app.setMaterial(mat);
            app.setTexture(stringTex);
            app.setTransparencyAttributes(ta);
           
           
            Billboard billboard = new Billboard(GeometryArray.COORDINATES
                        | GeometryArray.TEXTURE_COORDINATE_2,
                        1.5f * ((float)stringTex.getWidth() / (float) stringTex.getHeight()), 1.5f);
            this.addChild(new Shape3D(billboard, app));
      }
     
      private class TextInstance {
            public Font font;
            public String text;
           
            public TextInstance(String text, Font font){
                  this.text = text;
                  this.font = font;
            }
           
            public int hashCode ()
            {
                  int result = 17;
                  result += text.hashCode();
                  result += font.hashCode();
                  return result;
            }
           
            public boolean equals ( Object other )
            {
                  if ( other == null ){
                        return false;
                  }
                  else if ( other instanceof TextInstance){
                        TextInstance otherText = (TextInstance) other;
                        if (!otherText.text.equals(this.text)) return false;
                        if (!otherText.font.equals(this.font)) return false;
                        return true;
                  }
                  else return false;
            }
      }
}


You'll probably notice that the default height of the text object is 1.5, this is because I use it to place labels over objects with a radius of 1.0 =)

Terje
9  Java Game APIs & Engines / Xith3D Forums / Re: OK UI package now ported to SWT ! ! ! on: 2004-05-16 00:34:35
Any progress here?

I love the idea of using overlays, but at the moment they are too buggy (wrong transforms, missing events, losing focus etc) to be of any real use...

Terje
10  Java Game APIs & Engines / Xith3D Forums / Text2D for xith on: 2004-05-15 20:25:28
Hey all

Since I couldn't find any way of rendering text in the scenegraph (only the swing overlay) I decided to create a class myself.

I designed it to be easy to use, so it subclasses TransformGroup. The reason for this is that it uses a Billboard, and the Billboard changes the transform of its parent so it's always facing the observer. That means, to put a text object in an already transformed node, only one line of code is needed, eg:

1  
2  
3  
//myTransform could be a translation etc
TransformGroup tg = new TransformGroup(myTransform);
tg.addChild(new Text2D("Hello World!"));


A screenshot of the class in action can be seen at http://diplomen.dyndns.org/text2d.png

If there is any interest in this, I'll post the code here for others to use.

Terje
11  Java Game APIs & Engines / Xith3D Forums / Re: Material.setDiffuse*Color() : copy or referenc on: 2004-05-12 12:34:04
I agree, the Javadoc is sparse at best Smiley

I think it's one of the areas of Xith3D that needs the most love and caring at the moment...

Terje
12  Java Game APIs & Engines / Xith3D Forums / Re: Scaling of swing overlay on: 2004-05-11 15:17:10
Update:

When setting fullscreen to true in the makeCanvas method of RenderPeer, everything seems to work ok.

This is of course a workaround, but I would like to be able to scale the window...

Terje
13  Java Game APIs & Engines / Xith3D Forums / Re: Material.setDiffuse*Color() : copy or referenc on: 2004-05-10 16:42:08
From http://xith.org/tutes/xith3d.pdf:

1.1.2 Reduced memory copies

The Xith3D scenegraph rarely copies the contents of objects when the values of a node
are set. In almost all cases where an attribute of a node is set with the value of an object,
the object reference supplied replaces the object reference that the node previously used.
So for example setting the ambient color of a material and passing it a Color3f object
does not copy the values of the object, it just assigns the pointer internally. Conversely,
if you use the method that passes in the floats, the data is copied into the underlying
object. So for example mat.setAmbientColor(float r, float g, float b, float a) will write
the data into the Color4f object inside the material.
14  Java Game APIs & Engines / Xith3D Forums / Scaling of swing overlay on: 2004-05-10 15:28:56
Hi

I am using a swing gui in my xith3d application. I have created the gui by subclassing the UIWindow class, and then I draw it to my canvas using:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
UIWindowManager windowMgr = new UIWindowManager(canvas);
            window = new InfoWindow(120, 200);
            windowMgr.addOverlay(window);
            windowMgr.setPosition(window,10, 10);
            windowMgr.setVisible(window, true);
            UIEventAdapter eventAdapter = new UIEventAdapter(windowMgr);
//        canvas.get3DPeer().getComponent().addKeyListener(eventAdapter);
       canvas.get3DPeer().getComponent().addMouseListener(eventAdapter);
        canvas.get3DPeer().getComponent().addMouseMotionListener(eventAdapter);
        canvas.get3DPeer().getComponent().setFocusable(true);

The gui is drawn, but with very noticeble artifacts, as if it has been scaled up or down. When trying to interact with the components, I constantly have to click a few pixels to the left of the component.

If I scale the window up or down, the gui is also scaled, but the "hotspots" for the interaction stay in the same location, so the more I scale the window up, the further away from the buttons I have to click.

Is this a bug, or is it like that by design? Did I miss something?

btw, I tried using the TestWindow class from the TerrainTest instead of my own, and I get the same results.

Terje
15  Java Game APIs & Engines / Xith3D Forums / IndexedQuadArray bug? on: 2004-05-10 15:12:58
Hi all

I've just started to use Xith3D for a project, and I've encountered a problem using the IndexedQuadArray class. I've created an array of coordinates (coords), an array of normals (normals), and two int arrays specifying which coordinates and normals to use.

When creating the geometry using IndexedQuadArray I get no errors, but when I create a shape from the geometry and render it, nothing is shown. However, if I traverse the arrays myself, and then use QuadArray instead, everything works fine.

See the code attached below for details.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
//Doesn't work:
           //IndexedQuadArray tube = new IndexedQuadArray(coords.length, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, coordIndices.length);
           //tube.setCoordinateIndices(0, coordIndices);
           //tube.setNormals(0, normals);
           //tube.setNormalIndices(0, normalIndices);
           
            //Works fine:
           Point3f[] myCoords = new Point3f[coordIndices.length];
            Vector3f[] myNorms = new Vector3f[coordIndices.length];
            for (int i = 0; i < coordIndices.length; i++){
                  myCoords[i] = coords[coordIndices[i]];
                  myNorms[i] = normals[normalIndices[i]];
            }
            QuadArray tube = new QuadArray(myCoords.length, GeometryArray.COORDINATES | GeometryArray.NORMALS);
            tube.setCoordinates(0, myCoords);
            tube.setNormals(0, myNorms);


Edit: Saw the option to format the code :)
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.

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

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

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

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

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

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

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

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

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

Riven (49 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!