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