Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
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  Game Development / Newbie & Debugging Questions / Re: Shifting from Java 2D to Java3D Physics on: 2011-05-20 20:55:47
No,it's not the code is working perfect with in java 2D.
2  Game Development / Newbie & Debugging Questions / Re: Shifting from Java 2D to Java3D Physics on: 2011-05-20 00:48:03
many thanks for your reply,

as far as my poor knowledge about Java3d, the values should be 1 and 20 or less for Xs and Ys, but the values are like 300 and 400 and above than these...
and trouble means

some time the balls are drawing but not moving

some time going out of the panel

some time moving on little area

some time just stick at one place...

 these all happening on my hit and tries to decrease the values but  still i m not getting the normal results.


for me these values are causing all problems as these are set with respect to 2D , but i m unable to fix these:

 
1  
2  
3  
4  
5  
6  
7  
8  
        private static final float BOX_WIDTH = 640;
        private static final float BOX_HEIGHT = 480;

  // Get the ball's bounds, offset by the radius of the ball
       float minX = 0.0f + radius;
       float minY = 0.0f + radius;
       float maxX = 0.0f + BOX_WIDTH - 1.0f - radius;
       float maxY = 0.0f + BOX_HEIGHT - 1.0f - radius;
3  Game Development / Newbie & Debugging Questions / Shifting from Java 2D to Java3D Physics on: 2011-05-18 22:17:57
Hi Experts,


I am new to  game physics and really bad in physics and mathematical calculations, i am trying to adapt a simple 2d balls Simulation code for the 3d simulation with java3D library, but i have this problem:

Two things i noted down the values generated by engine,

for
X/Y are too high and minX / minY/ maxY /maxX values are causing troubles and i m unable to select/define/set the default correct/suitable values considering the 3D graphics scaling/resolution while they are set with respect to 2d screen coordinates,


 that is my only problem.


please help,

this is 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  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
 package Library;
   
    import java.awt.*;
   
    public class Ball extends GameObject {
   
       private float x, y; // Ball's center (x, y)
       private float speedX, speedY; // Ball's speed per step in x and y
       private float radius; // Ball's radius
       private Color color; // Ball's color
       // Collision detected by collision detection and response algorithm?
       boolean collisionDetected = false;
       public static boolean run = false;

   // If collision detected, the next state of the ball.
   // Otherwise, meaningless.
   private float nextX, nextY;
   private float nextSpeedX, nextSpeedY;
   
   private static final float BOX_WIDTH = 640;
   private static final float BOX_HEIGHT = 480;

   /**
    * Constructor The velocity is specified in polar coordinates of speed and
    * moveAngle (for user friendliness), in Graphics coordinates with an
    * inverted y-axis.
    */

   public Ball(String name1,float x, float y, float radius, float speed,
         float angleInDegree, Color color) {
      this.x = x;
      this.y = y;
      // Convert velocity from polar to rectangular x and y.
      this.speedX = speed * (float) Math.cos(Math.toRadians(angleInDegree));
      this.speedY = speed * (float) Math.sin(Math.toRadians(angleInDegree));
      this.radius = radius;
      this.color = color1;
   }

   public void move()  {
      if (collisionDetected) {
         // Collision detected, use the values computed.
         x = nextX;
         y = nextY;
         speedX = nextSpeedX;
         speedY = nextSpeedY;
      } else {
         // No collision, move one step and no change in speed.
         x += speedX;
         y += speedY;
      }
      collisionDetected = false; // Clear the flag for the next step
   }

   public void collideWith()  {
      // Get the ball's bounds, offset by the radius of the ball
      float minX = 0.0f + radius;
      float minY = 0.0f + radius;
      float maxX = 0.0f + BOX_WIDTH - 1.0f - radius;
      float maxY = 0.0f + BOX_HEIGHT - 1.0f - radius;

      double gravAmount = 0.9811111f;
      double gravDir = (90 / 57.2960285258);

      // Try moving one full step
      nextX = x + speedX;
      nextY = y + speedY;
      System.out.println("In serializedBall in collision.");

      // If collision detected. Reflect on the x or/and y axis
      // and place the ball at the point of impact.
      if (speedX != 0) {
         if (nextX > maxX) { // Check maximum-X bound
            collisionDetected = true;
            nextSpeedX = -speedX; // Reflect
            nextSpeedY = speedY; // Same
            nextX = maxX;
            nextY = (maxX - x) * speedY / speedX + y; // speedX non-zero
         } else if (nextX < minX) { // Check minimum-X bound
            collisionDetected = true;
            nextSpeedX = -speedX; // Reflect
            nextSpeedY = speedY; // Same
            nextX = minX;
            nextY = (minX - x) * speedY / speedX + y; // speedX non-zero
         }
      }
      // In case the ball runs over both the borders.
      if (speedY != 0) {
         if (nextY > maxY) { // Check maximum-Y bound
            collisionDetected = true;
            nextSpeedX = speedX; // Same
            nextSpeedY = -speedY; // Reflect
            nextY = maxY;
            nextX = (maxY - y) * speedX / speedY + x; // speedY non-zero
         } else if (nextY < minY) { // Check minimum-Y bound
            collisionDetected = true;
            nextSpeedX = speedX; // Same
            nextSpeedY = -speedY; // Reflect
            nextY = minY;
            nextX = (minY - y) * speedX / speedY + x; // speedY non-zero
         }
      }

      speedX += Math.cos(gravDir) * gravAmount;
      speedY += Math.sin(gravDir) * gravAmount;
   }

        public float getSpeed()  {
      return (float) Math.sqrt(speedX * speedX + speedY * speedY);
   }

   public float getMoveAngle()  {
      return (float) Math.toDegrees(Math.atan2(speedY, speedX));
   }

   public float getRadius()  {
      return radius;
   }
   
   public float getX() {
      return x;
   }

   public float getY() {
      return y;
   }
   
   public void setX(float f) {
      x =  f;
   }

   public void setY(float f) {
      y =  f;
   }
    }

 here how i m drawing the balls:

  
1  
2  
3  
4  
5  
6  
 for (int i = 0; i < currentNumBalls; i++) {
             printTG(objTrans[i], "SteerTG");
             trans[i]
                   .setTranslation(new Vector3f(ball[i].getX(), ball[i].getY(), 0.0f));
             objTrans[i].setTransform(trans[i]);
          }
4  Java Game APIs & Engines / Java 3D / Re: Collision Detection - different object types, or multiple Shape3D objects on: 2011-05-16 22:44:51
see here :
http://www.java-tips.org/other-api-tips/java3d/collision-detection-with-java3d.html
5  Game Development / Networking & Multiplayer / The Simplest and Easiest Game Network layer with KRYONET on: 2011-05-02 16:41:54
Hi all,
Hope u all are fine =), I created a simple network layer with kryonet, this can work as a sample application for kryonet.

Game state:

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  
package org.multiuser.simulation.ballPhysics;
/**
 *
 * @author Jibbylala
 */

public class BallState {
   /**
    *
    */

   private float X;
   private float Y;

   public BallState() {
     
   }
   
   public BallState(int x, int y) {
      this.X = x;
      this.Y = y;
   }
   
   public void setX(float f)
   {
      this.X = f;
   }
   
   public void setY(float y)
   {
      this.Y = y;
   }
   
     @Override
       public String toString() {
           
               return "Ball X (" + X + ")"+ ", Y(" + Y + ")";
         
       }
}

The Client:
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  
package org.physics.balls;

import java.io.IOException;

import org.multiuser.simulation.ballPhysics.BallState;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;

/**
 *
 * @author Jibbylala
 */

public class SimulationClient {

   private Client simulationClient;

   private boolean connected = false;

   public SimulationClient() {

      try {
         simulationClient = new Client();
         simulationClient.start();

         Kryo kryo = simulationClient.getKryo();
         kryo.register(BallState.class);

         simulationClient.addListener(new Listener() {
            public void received(Connection connection, Object object) {
               if (object instanceof BallState) {
                  BallState ball = (BallState) object;
                  System.out
                        .println("Received Ball : " + ball.toString());
               }
            }
         });
      } catch (Exception e) {
         e.printStackTrace();
      }

      new Thread("Connect") {
         public void run() {
            try {
               simulationClient.connect(5000, Common.DEFAULT_IP,
                     Common.DEFAULT_PORT_TCP);
            } catch (IOException ex) {
               ex.printStackTrace();
               System.exit(1);
            }

         }
      }.start();

   }

   public static void main(String[] argv) {
      try {
         new SimulationClient();

      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

The Server:
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  
package org.physics.balls;

import java.awt.Color;

import java.io.IOException;

import java.util.Random;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;

import org.multiuser.simulation.ballPhysics.BallState;

/**
 *
 * @author Jibbylala
 */


public class SimulationServer implements Runnable {

   

        public static final int BOX_WIDTH = 640;
   public static final int BOX_HEIGHT = 480;  
        public static final int BALLS = 1;

        private static BallState BS = new BallState(10, 5);
        public boolean running = true;
   private volatile boolean Play = true;
   private long mFrameDelay = 564;
   private Box box; // The container box
   private Ball[] balls = new Ball[BALLS];

   private int port = 54555;

   private Server server;

   public SimulationServer() throws Exception {

      server = new Server();

      Thread gameThread = new Thread(this);

      Kryo kryo = server.getKryo();
      server.addListener(new Listener() {
         public void received(Connection c, Object object) {

         }

         public void disconnected(Connection c) {

         }
      });

      server.bind(port);
      server.start();
      gameThread.start();
      // keep server running
      while (running) {
         Thread.sleep(100);
      }
      System.out.println("server started");
   }

   @Override
   public void run() {
      while (Play == true) {
         System.out.println("Sending game state process start");
         int radius = 40;
         Random rand = new Random();
         int angleInDegree = rand.nextInt(360);
         box = new Box(0, 0, BOX_WIDTH, BOX_HEIGHT);
         balls[0] = new Ball(BS, "ball" + 0, 0, 50, 40, 14, angleInDegree,
               Color.yellow);

         for (int i = 0; i < BALLS; i++) {
            balls[i].move();
            try {
               balls[i].collideWith(box);
               System.out.println("Sending object state : " + BS);
               server.sendToAllTCP(BS);
            } catch (IOException e) {
               e.printStackTrace();
            }
         }
         try {
            Thread.sleep(mFrameDelay);
         } catch (InterruptedException ie) {
         }
      }
   }

       public static void main(String[] args) {
      try {
         new SimulationServer();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

}



enjoy!


P.S: I m sending this time single object, I will update this for sending the multiple objects (array of objects) and some complex objects, which exploit KRYO Serialization capabilities.
6  Game Development / Networking & Multiplayer / Re: JAVA3D and RMI (Moving sprites with RMI not working) on: 2011-04-29 16:40:43
finally, they would end up in an object or array of objects, how would i sent the array with IO socket or channels javaNIO?
7  Game Development / Networking & Multiplayer / Re: JAVA3D and RMI (Moving sprites with RMI not working) on: 2011-04-28 14:31:58
The path to success doesn't generally involve skipping fundamental steps. Smiley

if the fundamental steps can reach me to achieve this silly scenario:
http://stackoverflow.com/questions/5370279/sending-receiving-object-references-or-part-of-object-with-javanio

i would really happy =)
8  Game Development / Newbie & Debugging Questions / Re: IndexoutofBoundException[kryonet] on: 2011-04-28 11:19:09
what do you mean by not using java RMI, i m already using kryonet instead of javaRMI, so what u wanna convey.


P.S : about there suggestion to create a simple case is quite trivial, but going far from them is not that much trivial and achieving the robust solutions, u can see my this post, is it kryonet  able to give me the solution for this scenario :

http://stackoverflow.com/questions/5370279/sending-receiving-object-references-or-part-of-object-with-javanio

and more importantly what would the complexity level  as far as implementation is concerned,

i tried that with javaNIO but find that way harder to go further. if kryonet will gave me such solution for that with moderate implementation efforts, i would be glad but till now i m not seeing.
9  Game Development / Newbie & Debugging Questions / IndexoutofBoundException[kryonet] on: 2011-04-27 22:00:26
Hi all,
inspite of my best efforts i m unable to run to move a ball with
kryo ,i m beginner java programmer can somebody please pointing me
where i m wrong in adapting kryonet as i did lot of efforts and tries
but this code is not working and everytime coming with some
exception,am i doing so much obvious mistake as i m exhausted with
trying different ways and started hit and try approach will this kind
of project will be complicated with kryonet,




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  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
package com.esotericsoftware.kryonet;

import java.awt.Color;
import java.awt.Point;

public interface IBall {
   public void setColor (Color newColor);

   public Color getColor ();

   public void setMotion (double dx, double dy);

   public int radius ();

   public Point location ();

   public double changeX ();

   public double changeY ();

   public void move ();
}



package com.esotericsoftware.kryonet;

import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JLabel;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Server;
import com.esotericsoftware.kryonet.rmi.ObjectSpace;
import com.esotericsoftware.minlog.Log;

// This class is the server for a simple chat client/server example that uses RMI.
// It is recommended to review the non-RMI chat example first.
// While this example uses only RMI, RMI can be mixed with non-RMI KryoNet usage.
// RMI has more overhead (usually 4 bytes) then just sending an object.
public class BallServer {
   Server server;

   public BallServer () throws IOException {
      server = new Server();

      // Register the classes that will be sent over the network.
      Common.registerMessages(server.getKryo()); // just another way/try
      Common.register(server);
      server.start();
      server.bind(Common.DEFAULT_PORT_TCP, Common.DEFAULT_PORT_UDP);

      Ball requestBall = new Ball(new Point(300, 200), 15);

      final ObjectSpace objectSpace = new ObjectSpace();
      objectSpace.register(42, requestBall);
      // new ObjectSpace().register(Common.BALL, requestBall);

      server.addListener(new Listener(){
         public void connected (Connection connection) {
            objectSpace.addConnection(connection);
         }
      });
     
      // For serialization
      Kryo kryo = server.getKryo();
      kryo.register(IBall.class);

      // Open a window to provide an easy way to stop the server.
      JFrame frame = new JFrame("Ball Server");
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      frame.addWindowListener(new WindowAdapter() {
         public void windowClosed (WindowEvent evt) {
            server.stop();
         }
      });
      frame.getContentPane().add(new JLabel("Close to stop the chat server."));
      frame.setSize(320, 200);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
   }

   public static void main (String[] args) throws IOException {
      Log.set(Log.LEVEL_DEBUG);
      new BallServer();
   }
}





package com.esotericsoftware.kryonet;

import java.awt.*;
import java.io.IOException;

import javax.swing.*;



import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.rmi.ObjectSpace;

import java.util.Random;

public class BallWorldClient extends JFrame implements Runnable {

   private volatile boolean Play;

   public static final int FrameWidth = 600;
   public static final int FrameHeight = 400;
   MyKeyListener pit;
   private static final long serialVersionUID = 1L;

   private Client client;
   
   private IBall ball;

   private Random rand = new Random(System.currentTimeMillis());

   BallWorldClient (Color ballColor) {

      setSize(FrameWidth, FrameHeight);
      setTitle("Ball World");
     
      pit = new MyKeyListener();
      pit.setPreferredSize(new Dimension(FrameWidth, FrameHeight));
      setContentPane(pit);

      pack();
   setVisible(true);

   setBackground(Color.white);

      try {
         client = new Client();

         Common.registerMessages(client.getKryo());
         Common.register(client);
         client.start();

         new Thread("Connect") {
            public void run () {
               try {
                  client.connect(50000, Common.DEFAULT_IP, Common.DEFAULT_PORT_TCP, Common.DEFAULT_PORT_UDP);
               } catch (IOException ex) {
                  ex.printStackTrace();
                  System.exit(1);
               }

            }
         }.start();

         //ball1 = new Client();

         ObjectSpace objectSpace = new ObjectSpace();

         Kryo kryo = client.getKryo();
         kryo.register(Ball.class);
         kryo.register(IBall.class);

//         Ball requestBall = new Ball(new Point(300, 200), 15);
//
////         Common.registerMessages(ball1.getKryo());
////         Common.register(ball1);
//         objectSpace.register(42, requestBall);

         ball = ObjectSpace.getRemoteObject(client, 42, IBall.class);
         ball.setColor (ballColor);
          ball.setMotion(3.0, 6.0);
         client.sendTCP(ball);

//         client.addListener(new Listener() {
//            public void received(Connection connection, Object object) {
//               if (object instanceof Ball) {
//                  final Ball ball1 = (Ball) object;
//                  new Thread("Connect1") {
//                     public void run () {
//                        for (int i = 0; i < 1000; i++)
//                        runball();
//                     }
//                  }.start();
//                  
//
//               }
//            }
//         });

      } catch (Exception e) {
         e.printStackTrace();
         Play = false;
      }
      start();

   }

   public void start () {
      Play = true;
      Thread t = new Thread(this);
      t.start();
   }

   public void stop () {
      Play = false;
   }

   public void run () {

      while (Play == true) {

         repaint();
         runball();
         try {
            Thread.sleep(50);
         } catch (InterruptedException ie) {
            stop();
         }
      }
   }

   public void runball () {
      try {
         ball.move();
         Point pos = ball.location();
         if ((pos.x < ball.radius()) || (pos.x > FrameWidth - ball.radius())) ball.setMotion(-ball.changeX(), ball.changeY());

         if ((pos.y < ball.radius()) || (pos.y > FrameHeight - ball.radius())) ball.setMotion(ball.changeX(), -ball.changeY());
          repaint ();
         try {
            Thread.sleep(50);
         } catch (Exception e) {
            System.exit(0);
         }
      } catch (Exception e) { // System.out.println ("Exception: " + e);
         e.printStackTrace();
      }
   }

   public void drawworld(Graphics g) {

      try {
         g.setColor(ball.getColor());
         g.fillOval(ball.location().x - ball.radius(), ball.location().y - ball.radius(), ball.radius() * 2, ball.radius() * 2);
      } catch (Exception e) { // System.out.println ("Exception: " + e);
         e.printStackTrace();
      }
   }
   

   public static void main (String[] args) {

      javax.swing.SwingUtilities.invokeLater(new Runnable() {
         public void run () {

            BallWorldClient world = new BallWorldClient(Color.red);
         }
      });
   }
   
   
   public class MyKeyListener extends JPanel {

      /**
       *
       */

      private static final long serialVersionUID = 1L;

      public void paintComponent(Graphics g) {
         super.paintComponent(g);

         drawworld(g);

      }

   }
   
}




package com.esotericsoftware.kryonet;

import java.awt.Color;
import java.awt.Point;
import java.nio.ByteBuffer;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.serialize.FieldSerializer;
import com.esotericsoftware.kryo.serialize.IntSerializer;
import com.esotericsoftware.kryo.serialize.SimpleSerializer;
import com.esotericsoftware.kryonet.rmi.ObjectSpace;

public class Common {

   public static final String DEFAULT_IP = "127.0.0.1";

   public static final int DEFAULT_PORT_TCP = 54555;
   public static final int DEFAULT_PORT_UDP = 54777;

// public static final int DEFAULT_PORT_TCP=6456;
// public static final int DEFAULT_PORT_UDP=6466;
   static public final short BALL = 1;

   static public final int port = 54777;

   /**
    * Registers all messages used in the game with JGN which optimizes them
    */

   public static void registerMessages (Kryo kryo) {
      ObjectSpace.registerClasses(kryo);
      kryo.register(IBall.class);
      kryo.register(Ball.class);
      kryo.register(Point.class, new SimpleSerializer<Point>() {
         public Point read (ByteBuffer buffer) {
            return new Point(IntSerializer.get(buffer, true), IntSerializer.get(buffer, true));
         }

         public void write (ByteBuffer buffer, Point point) {
            IntSerializer.put(buffer, point.x, true);
            IntSerializer.put(buffer, point.y, true);
         }
      });
      kryo.register(Color.class, new SimpleSerializer<Color>() {
         public Color read (ByteBuffer buffer) {
            return new Color(buffer.getInt());
         }

         public void write (ByteBuffer buffer, Color color) {
            buffer.putInt(color.getRGB());
         }
      });
   }

//

   static public void register (EndPoint endPoint) {
      Kryo kryo = endPoint.getKryo();
      ObjectSpace.registerClasses(kryo);
      kryo.register(String[].class);
      kryo.register(IBall.class);
      kryo.register(Ball.class);
   }
}



package com.esotericsoftware.kryonet;

import java.awt.Color;
import java.awt.Point;

public class Ball implements IBall {

   protected Point loc ;
   protected int rad = 15;
   protected double changeInX = 0.0;
   protected double changeInY = 0.0;
   protected Color color ;


   public Ball (Point lc, int r) {
      loc = lc;
      rad = r;
   }

   public void setColor (Color newColor) {
      color = newColor;
   }

   public Color getColor () {
      return color;
   }

   public void setMotion (double dx, double dy) {
      changeInX = dx;
      changeInY = dy;
   }

   public int radius () {
      return 15;
   }

   public Point location () {
      return loc;
   }

   public double changeX () {
      return changeInX;
   }

   public double changeY () {
      return changeInY;
   }

   public void move () {
      loc.translate((int)changeInX, (int)changeInY);
   }
}



java.lang.IndexOutOfBoundsException: Index: 482, Size: 482
   at java.util.ArrayList.RangeCheck(ArrayList.java:547)
   at java.util.ArrayList.get(ArrayList.java:322)
   at com.esotericsoftware.kryonet.rmi.ObjectSpace$RemoteInvocationHandler.waitForResponse(ObjectSpace.java:344)
   at com.esotericsoftware.kryonet.rmi.ObjectSpace$RemoteInvocationHandler.invoke(ObjectSpace.java:329)
   at $Proxy0.location(Unknown Source)
   at com.esotericsoftware.kryonet.BallWorldClient.runball(BallWorldClient.java:135)
   at com.esotericsoftware.kryonet.BallWorldClient.run(BallWorldClient.java:123)
   at java.lang.Thread.run(Thread.java:662)
java.lang.IndexOutOfBoundsException: Index: 483, Size: 483
   at java.util.ArrayList.RangeCheck(ArrayList.java:547)
   at java.util.ArrayList.get(ArrayList.java:322)
   at com.esotericsoftware.kryonet.rmi.ObjectSpace$RemoteInvocationHandler.waitForResponse(ObjectSpace.java:344)
   at com.esotericsoftware.kryonet.rmi.ObjectSpace$RemoteInvocationHandler.invoke(ObjectSpace.java:329)
   at $Proxy0.getColor(Unknown Source)
   at com.esotericsoftware.kryonet.BallWorldClient.drawworld(BallWorldClient.java:153)
   at com.esotericsoftware.kryonet.BallWorldClient$MyKeyListener.paintComponent(BallWorldClient.java:192)
   at javax.swing.JComponent.paint(JComponent.java:1029)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paint(JComponent.java:1038)
   at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paintToOffscreen(JComponent.java:5131)
   at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
   at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
   at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
   at javax.swing.JComponent.paint(JComponent.java:1015)
   at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
   at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
   at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
   at java.awt.Container.paint(Container.java:1780)
   at java.awt.Window.paint(Window.java:3375)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
   at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
   at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



lot of thanks in advance  ,
wishes,
jibbylala
10  Java Game APIs & Engines / Java 3D / losing initial value for Y axis value on setting X and Z on: 2010-12-22 16:57:06
hello all,

i have a beginner question :

i have a robot

which i m setting on (0,1.45,0)  and then i m moving it like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public  boolean moveBy(double x, double z)
    /* Move the sprite by offsets x and z, but only if within the floor
     and there is no obstacle nearby. */

    {
        if (isActive()) {
            Point3d nextLoc = tryMove(new Vector3d(x, 0, z));
            if (obs.nearObstacle(nextLoc, radius*OBS_FACTOR))
                return false;
            else {
                doMove( new Vector3d(x, 0, z) );   // inefficient recalc
                return true;
            }
        }
        else    // not active
            return false;
    }  // end of moveBy()


Accessing TG for that robot,  return me always 0 at y axis (x,0,y)

1  
2  
3  
4  
public TransformGroup getTG()
    {
        return objectTG;
 }


but i want the same value,  when i get that TG after applying movement on this robot as shown

like(x,1.45,y)

so what i can do before return TG or where that y value which i set as initial for y why it's returning y=0.

i want "y" the always same return which i set initially; irrespective of the x and z of TG.

thanks,
Jibbylala
11  Game Development / Networking & Multiplayer / Why in this design ;CHANNEL is null in some cases and NOT null in some cases? on: 2010-12-13 03:27:06
Dear experts,

i have  strange problem atleast for me :


   
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
 private void makeContact()throws IOException, InterruptedException
      /* Contact the server, and set up a TourWatcher to monitor the
         server. */

      {
        try {
           TP.start();
        }
        catch(Exception e)
        { System.out.println("No contact with server"+e);
          System.exit(0);
        }  
      }  // end of makeContact()

     
here it's not working when i m sending message from here, channel is null:

   
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
 sceneBG.addChild( new CheckerFloor().getBG() );  // add the floor
   
        makeScenery(tourFnm);      // add scenery and obstacles
       
       
        TP = new TourProxy("localhost",this,obs);
        makeContact();     // contact server (after Obstacles object created)
        ***TP.sendMessage("create " + userName + " " + xPosn + " " + zPosn);*** //not working
        addTourist(userName, xPosn, zPosn);      
       
        sceneBG.compile();   // fix the scene
      } // end of createSceneGraph()


here from this class constrcutor it is working:

   
1  
2  
3  
4  
5  
6  
7  
8  
9  
 public TourSprite(String userName, String fnm, Obstacles obs,
           double xPosn, double zPosn, TourProxy tp) throws IOException
      { super(userName, fnm, obs);
        setPosition(xPosn, zPosn);
       // out = o;
        this.tp1 = tp;
        ***tp1.sendMessage("create " + userName + " " + xPosn + " " + zPosn);***//working from here
       // out.println("create " + userName + " " + xPosn + " " + zPosn);
      }  // end of TourSprite()


when i m calling message as i shown from then "channel" in my TourProxy class is "NULL" and the message is not going to server
 but when i m passing this TP to the class TourSprite which i don't need but i m using that just for this purpose the send message is working and there is no problem the channel is NOT null, why it is like that and what is the solution.

PS:i feel that this problem is because of  some thread suspension while 3d GUI rendering is also happening and networking stuff is also going on...

Code Reference: The killer game programming, Chapter 32.   Networked Tour3D here:http://fivedots.coe.psu.ac.th/~ad/jg/ch21/index.html.

thanks in advance for any reviews

jibbylala

 its cross link : http://www.java-gaming.org/index.php/topic,23495.0.html considering the problem  particularly related to  Rendering with java3d.
12  Game Development / Networking & Multiplayer / Re: JAVA3D and RMI (Moving sprites with RMI not working) on: 2010-11-19 00:44:48
and actually it's not that much hard problem its raising, my problem is not related to RMI i thought , i m calling remote methods and getting back the objects(Transform3d)

 i thought it's not matter of  technology u used when the application would have more features and the design will get complicated; these problems will definitely come.

i need some reviews on design i heard about callbacks and i wanted to know whether that is what i need or i need to implement observer pattern for client site as only one class on client site is getting updates and i m feeling others don't have those updates so they are not updating their selves.

but i just need some expert eyes on this  Sad as testing all of these possibilities are taking time and i m also new to java3D library also and its also bothering me to implement what i have written.
13  Game Development / Networking & Multiplayer / Re: JAVA3D and RMI (Moving sprites with RMI not working) on: 2010-11-19 00:26:44
OK lets say  i consider your advice,  can i have some generic network layer  based on TCP/IP which can be valid for different real time MP games(because i heard there are constraints also in TCP/IP than other people will say why not UDP)  and if how much complex that would be  and how much time will it take to develop (yaw its subjective question)?
14  Game Development / Networking & Multiplayer / Re: JAVA3D and RMI (Moving sprites with RMI not working) on: 2010-11-18 21:49:27
and secondly the aim is to have a "generic network layer" for variety of games , and this will going to be really long journey if now i start with TCPIP...and heard that are lot of low level concepts involve which really need time to understand and grasp Sad
thanks
 Smiley
15  Game Development / Networking & Multiplayer / Re: JAVA3D and RMI (Moving sprites with RMI not working) on: 2010-11-18 21:28:16
yes you are right but now i m on the way and i m totally unaware of other technologies for networking and have no time to start from scratch
thanks
J
16  Game Development / Networking & Multiplayer / Re: JAVA3D and RMI (Moving sprites with RMI not working) on: 2010-11-18 20:47:03
i m glad to have atleast some reply  Smiley
actually my aim is to create the multiuser game/environment leveraging JAVA3D and all its all capabilities that'S why i approach that application from book but ok i can have a look how u r using RMI.    
but
i m disappointed that nobody is interested in my question Sad

thanks
jibby lala
17  Game Development / Networking & Multiplayer / JAVA3D and RMI failing on: 2010-11-17 04:58:57
Dear experts,

My intention was to create RMI version of  Networked Tour3D

example in the 3d book here:http://fivedots.coe.psu.ac.th/~ad/jg/ch21/index.html.

which is about moving sprites on multiple client and navigate together through virtual world simultaneously but i  m failing.

i refactor the  class Sprite3d  to get the Transform3d from remote object on server so when all clients get the same transform 3d all change their position hence "Network tour of sprites in virtual worlds' can be achieved .

i m  beginner programmer  and i dived into these advanced things and now i have no idea, why it is not working may be i m doing some  silly mistake. I don't know what to do  and  now  the code is much i can't paste all on some forum.

this is code in which the methods are calling remote but sprites are NOT moving simulataneously :

this is class which is getting the tranform3d from server other class on client site are calling this class for getting the objectgroup or transformgroup

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  
this is remote class from where i m getting the transform3d:

 

[code]package ServerSite;

// Sprite3D.java
// Andrew Davison, April 2005, ad@fivedots.coe.psu.ac.th

/* Sprite3D loads a 3D image, placing it at (0,0,0).
   We assume that the object's actual position is (0,0) in the XZ plane.
   The Y position will vary but probably the base of the object is
   touching the XZ plane.

   Movements are restricted to the XZ plane and rotations
   around the Y-axis.

   An object cannot move off the floor, or travel through obstacles
   (as defined in the Obstacles object).

   Very sinmilar to Sprite3D in Tour3D.
   New net-related code:
     - a userName above the sprite that stays oriented along +z axis;
     - return a detachable branchgroup for the scene;
     - store the current rotation around the y-axis, and methods to return
       and set it.
 */



import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.text.DecimalFormat;
import java.util.Enumeration;
import java.util.Vector;
import javax.media.j3d.*;
import javax.vecmath.*;

public class Sprite3DImpl extends UnicastRemoteObject implements  Sprite3D
{

    private static final long serialVersionUID = 1L;
    private MySerTransform3D t3d, toMove, toRot;    // for manipulating objectTG's transform
    private double currRotation;

    private DecimalFormat df;   // for simpler output during debugging

    public Sprite3DImpl()throws RemoteException {
        super();
        t3d = new MySerTransform3D();
        toMove = new MySerTransform3D();
        toRot = new MySerTransform3D();

        df = new DecimalFormat("0.###");  // 3 dp
        currRotation = 0.0;
        System.err.println("In remote constructor");
    }

    public void doMove(Vector3d theMove)throws RemoteException
    //  // Move the sprite by the amount in theMove
    {
        toMove.setTranslation(theMove);    // overwrite previous trans
        t3d.mul(toMove);
        System.err.println("In remote doMove");
    }  // end of doMove()

    public Point3d tryMove(Vector3d theMove)throws RemoteException
    /* Calculate the effect of the given translation but
     do not update the sprite's position until it's been
     tested.
     */

    {
        toMove.setTranslation(theMove);
        t3d.mul(toMove);
        Vector3d trans = new Vector3d();
        t3d.get( trans );
        // printTuple(trans, "nextLoc");
        System.err.println("In remote tryMove");
        return new Point3d( trans.x, trans.y, trans.z);

    }  // end of tryMove()

    public void doRotateY(double radians)throws RemoteException
    // Rotate the sprite by radians amount around its y-axis
    {
        toRot.rotY(radians);   // overwrite previous rotation
        t3d.mul(toRot);
        System.err.println("In remote doRotateY");
    } // end of doRotateY()

    public void setCR(double radians)throws RemoteException
    {
        currRotation += radians;
    } // end of setCurrRotation()

    public Point3d getCurrLoc()throws RemoteException
    {  
        Vector3d trans = new Vector3d();
        t3d.get( trans );
        System.err.println("In remote getCurrLoc");
        // printTuple(trans, "currLoc");
        return new Point3d( trans.x, trans.y, trans.z);
    }
    public void setCurrRotation(double rot)throws RemoteException
    {
        double rotChange = rot - currRotation;
        doRotateY(rotChange);
        System.err.println("In remote setCurrRotation");
    } // end of setCurrRotation()


    public double getCurrRotation()throws RemoteException
    {  System.err.println("In remote getCurrRotation");
    return currRotation;  }


    private void setT3d(MySerTransform3D t3d)throws RemoteException {
        this.t3d = t3d;
    }
    public MySerTransform3D getT3d() throws RemoteException{
        if(t3d!=null){
            return t3d;}
        else
            System.err.println("t3d is null");
        return t3d;
    }
    private void setToMove(MySerTransform3D toMove) throws RemoteException{
        this.toMove = toMove;
    }
    public MySerTransform3D getToMove()throws RemoteException {
        return toMove;
    }
    private void setToRot(MySerTransform3D toRot)throws RemoteException {
        this.toRot = toRot;
    }

    public MySerTransform3D getToRot()throws RemoteException {
        return  toRot;
    }
   
    private void printTuple(Tuple3d t, String id)throws RemoteException
    // used for debugging
    {
        System.out.println(id + " x: " + df.format(t.x) +
                ", " + id + " y: " + df.format(t.y) +
                ", " + id + " z: " + df.format(t.z));
    }  // end of printTuple()
}  // end of Sprite3D class
 


 

Other classes include behavior class and WrapNetTour3D according to changed design because of RMI may be there is some issue in those but first i would like to confirm and have some review on these main classes  and why it is not working and how it can be implemented with RMI.(other files and code everything you can look at the link)

If somebody need i can send the whole project because i just wanted that working and i thought i did the major changes and spent lot of time on it.

 

please help i would be really thankful

jibby lala[/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.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (10 views)
2014-11-28 16:25:09

PocketCrafter7 (11 views)
2014-11-28 16:24:29

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

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

toopeicgaming1999 (17 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!