Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
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  
  sharedCopy behaviour?  (Read 640 times)
0 Members and 1 Guest are viewing this topic.
Offline StefanD2

Senior Newbie




Java games rock!


« Posted 2004-02-22 10:26:01 »

Hi,

just tried to make a simple 3D maze viewer. Therefore I used only cubes as elements (com.xith3d. test.Cube). At first I tried to create one default cube and used sharedCopy to clone them (just moving the clones to their wanted positions). As far as I do understand it by reading the javadoc sharedcopy will copy an object's geometry and appearance but nothing more.
Guess what happened: As soon as the first cube (the one the others are duplicated from) leaves the view all other will be hidden also. Did I miss something or is sharedCopy not to be used for such a purpose?.

Nevertheless it worked by creating all new objects and sharing appearance objects by hand ...
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #1 - Posted 2004-02-22 13:21:36 »

Try to make a test that uses SharedGroup and Link - it should work.

As of using sharedCopy, I would again ask for a test case and an issue filled in IssueZilla.

Yuri

Yuri Vl. Gushchin
JProof Group
Offline StefanD2

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-02-22 17:18:52 »

Hi Yuri,

you are right I should have posted an example. You can find it at:
http://www.m42.de/projects/xith3d/sharedcopy.zip
Any required additional lib should be in http://www.m42.de/projects/xith3d/xith_libs.zip.
(I am sorry not to have a working jnlp environment at the moment - therefore it is a bit more complicated than it could be).

It uses Xith3DCamera for camera movement and some basic code I got from JDC's demos.

The relevant class is Levelold (sharedCopy is used in method getFullLevelNode):

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  
package de.game.pac3d.xith3d.level;

import com.xith3d.scenegraph.*;
import com.xith3d.test.Cube;

import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;
import javax.vecmath.Point3f;
import java.io.*;
import java.util.Vector;
import java.util.Hashtable;

/**
 * Created by IntelliJ IDEA.
 * User: Stefan
 * Date: 01.02.2004
 * Time: 13:40:06
 *
 *        __I__
 *    .-'"  .  "'-.
 *  .'  / . ' . \  '.
 * /_.-..-..-..-..-._\ .--------------------------------.
 *          #  _,,_   ( I hear it might rain code today )
 *          #/`    `\ /'-------------------------------'
 *          / / 6 6\ \
 *          \/\  Y /\/       /\-/\
 *          #/ `'U` \       /a a  \               _
 *        , (  \   | \     =\ Y  =/-~~~~~~-,_____/ )
 *        |\|\_/#  \_/       '^--'          ______/
 *        \/'.  \  /'\         \           /
 *         \    /=\  /         ||  |---'\  \
 *         /____)/____)       (_(__|   ((__|
 *
 */

public class Levelold
{
      public static final int SIZE = 65536;
      public static final float ITEM_LENGTH = 1f / SIZE;

      Hashtable elements;
      char fields[][];

      // boundary of field - surounding walkable level
     private final char BOUNDARY = '#';

      public Levelold(String name)
      {
            elements = new Hashtable();

            Vector lines = new Vector();
            int width = 0;

            BufferedReader myReader = null;
            try
            {
                  String data =
                        "####################" + "\n" +
                        "#                  #" + "\n" +
                        "# ABC   DEF   GHI  #" + "\n" +
                        "#                  #" + "\n" +
                        "#                  #" + "\n" +
                        "# ABC   DEF   GHI  #" + "\n" +
                        "# ABC   DEF   GHI  #" + "\n" +
                        "# ABC   DEF   GHI  #" + "\n" +
                        "#                  #" + "\n" +
                        "#       J J        #" + "\n" +
                        "#       J J        #" + "\n" +
                        "#                  #" + "\n" +
                        "# ABC   DEF   GHI  #" + "\n" +
                        "# ABC   DEF   GHI  #" + "\n" +
                        "#                  #" + "\n" +
                        "#                  #" + "\n" +
                        "# ABC   DEF   GHI  #" + "\n" +
                        "#    ..            #" + "\n" +
                        "#    .  S          #" + "\n" +
                              "####################" + "\n";

                  myReader = new BufferedReader(new StringReader(data));
                  String line = null;
                  while ((line = myReader.readLine()) != null)
                  {
                        line = line.trim();
                        if ("".equals(line) || line.startsWith("//"))
                        {
                              continue;
                        }

                        //width is number of chars in first line
                       // height depends upon
                       if (width == 0)
                        {
                              width = line.length();
                        }

                        lines.add(line);
                        System.out.println("line=" + line);
                  }
            }
            catch (FileNotFoundException e)
            {
                  e.printStackTrace();
                  throw new RuntimeException(e);
            }
            catch (IOException e)
            {
                  e.printStackTrace();
                  throw new RuntimeException(e);
            }

            // finally close
           try
            {
                  if (myReader != null)
                  {
                        myReader.close();
                  }
            }
            catch (IOException e)
            {
                  e.printStackTrace();
                  throw new RuntimeException(e);
            }

            // build level field
           int height = lines.size();
            fields = new char[height][width];
            for (int y = 0; y < height; y++)
            {
                  String line = (String) lines.elementAt(y);
                  for (int x = 0; x < width; x++)
                  {
                        // handle incomplete lines as normal but add boundaries for missing chars
                       char c = BOUNDARY;
                        // normally get char from file
                       if (x < line.length())
                        {
                              c = line.charAt(x);
                        }

                        fields[y][x] = c;
                        updateElements(c);
                  }
            }
      }

      private void updateElements(char aX)
      {
            String key = "" + aX;
            if (elements.contains(key))
            {
                  return;
            }

            Shape3D myShape3D = getShape3DFor(key);
            if (myShape3D != null)
            {
                  elements.put(key, myShape3D);
            }
            System.out.println("Key=" + key);
      }

      private Shape3D getShape3DFor(String aKey)
      {
            // currently we do allow empty spaces
           if (" ".equals(aKey))
            {
                  return null;
            }

            Shape3D myShape3D = new Shape3D();

            myShape3D.setGeometry(createPrimitive(aKey));
            myShape3D.setAppearance(createAppearance(aKey));
            myShape3D.setCompiled(false);

            return myShape3D;
      }

      private Appearance createAppearance(String aKey)
      {
            Color3f myColor3f = new Color3f((float) Math.random(),
                                            (float) Math.random(),
                                            (float) Math.random());
            ColoringAttributes myColoringAttributes = new ColoringAttributes(myColor3f,
                                                                             ColoringAttributes.NICEST);
            Appearance myAppearance = new Appearance();
            myAppearance.setColoringAttributes(myColoringAttributes);
            return myAppearance;
      }

      private Geometry createPrimitive(String aKey)
      {
            if (".".equals(aKey))
            {
                  Point3f[] coords = new Point3f[]
                  {
                        new Point3f(-.5f, -.5f, -.5f),
                        new Point3f(.5f, -.5f, -.5f),
                        new Point3f(.5f, -.5f, .5f),
                  };

                  TriangleArray g = new TriangleArray(coords.length,
                                                      GeometryArray.COORDINATES);
                  g.setCoordinates(0, coords);
                  return g;

            }

            // default
           Geometry g = Cube.createCubeViaTriangles(0, 0, 0, 1, false);
            return g;
      }

      public Node getFullLevelNode()
      {
            Group myGroup = new Group();

            Node firstNode = (Node) elements.get("" + BOUNDARY);
            int maxY = fields.length;
            int maxX = fields[0].length;

            for (int y = 0; y < maxY; y++)
            {
                  for (int x = 0; x < maxX; x++)
                  {
                        // space again nothing to do
                       if (fields[y][x] == ' ')
                        {
                              continue;
                        }
                        // move objects to correct place
                       Transform3D move = new Transform3D();
                        move.set(new Vector3f(x, 0, y));
                        TransformGroup myTransformGroup = new TransformGroup(move);
                        // add the node itself
                       Node node = firstNode.sharedCopy(((Node) elements.get("" + fields[y][x])));
                        //Node node = getShape3DFor("" + fields[y][x]);
                       myTransformGroup.addChild(node);

                        myGroup.addChild(myTransformGroup);
                        System.out.println("X=" + x + " Y=" + y);
                  }
            }

            return myGroup;
      }
}


Simply start it (required jars:displaySettings.jar;joal.jar;jogl.jar;junit.jar;log4j.jar;vecmath.jar;xith3d.jar;xith_utilities.jar,
- main class is de.game.pac3d.xith3d.Xith3DFrameold) and you will see a black window. By pressing 'Cursor down' you can see a colored line coming in sight. Go forward again and it vanishes ...
To see the whole view use 'Page up' or 'Page down' to see the level from above or below (it's a 20x20 field)

I am not sure if I am doing something unexpected or if it is an error. That is why I have not filled an IssueZilla but asked in this forum.
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 (16 views)
2014-07-30 21:08:39

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

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

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

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

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

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

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

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

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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