You are here

Report #1 - Introduction

1. ACTIVITIES

1.1 Class Web Page

This activity was just to get familiarized with the class web page for delivering the reports and code.

[ACTIVITY DONE]

1.2 Reports Management Page & Use

[ACTIVITY DONE]

1.3 Download and Compilation of WorldServer3D Code

In the beginning, it was experienced some problems when trying to run the generated JAR file and it was easily fixed uploading some libraries to the server.

The generated JAR file of WorkServer3D compatible with Java Web Start can be found here.

[ACTIVITY DONE]

1.4 Basic Controller Project for Accessing the Virtual World

A basic controller was created for connecting to WorldServer3D. It implemented the creature creation and its movements according to commands entered in a text terminal.

In a first moment, it was tried to connect to WorldServer3D using socket connection but the implementation was not so trivial. Later was used the WS3DProxy package that made the implementation simple, not only regarding the connectivity but also regarding using all the existent abstractions that represent many WorldServer3D objects.

The basic controller code is shown in the lines following but can also be downloaded here.

A JavaWebStart version of the client, with a GUI for navigation, can be found here.

  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
import worldclient3d;
import java.util.Scanner;
import ws3dproxy.model.Creature;
import ws3dproxy.CommandExecException;
import ws3dproxy.WS3DProxy;

/**
 * Very simple example of class for connecting to WorldServer3D, creating a
 * creature and moving the creature.
 * @author Hirley Dayan
 */
public class WorldClient3D {

    WS3DProxy ws3dproxy;
    private static WorldClient3D wc = null;
    private static Creature creature = null;

    /**
     * Main class
     * @param args
     */
    public static void main(String[] args) {

        String command;
        String[] commandV;
        
        Scanner in = new Scanner(System.in);

        while (true) {
            System.out.print("enter command> ");
            command = in.nextLine();
            commandV = command.split(" ");
            if (commandV != null && commandV.length > 0){    
                switch (commandV[0]) {
                    case "disconnect":
                    case "connect":
                        connect("127.0.0.1", 4011);
                        break;
                    case "create.creature":
                        createCreature();
                        break;
                    case "move":
                        if(commandV.length > 3){
                            move(Double.valueOf(commandV[1]),
                                    Double.valueOf(commandV[2]),
                                    Double.valueOf(commandV[3]));
                        }
                        break;
                    case "move.to":
                        if(commandV.length > 3){
                            moveTo(Double.valueOf(commandV[1]),
                                    Double.valueOf(commandV[2]),
                                    Double.valueOf(commandV[3]));
                        }
                        break;
                    default:
                        System.out.println("Don't know what to do.");
                }
            }
        }
    }

    /**
     * The constructor
     * @param host host address
     * @param port host port
     */
    public WorldClient3D(String host, int port) {
        ws3dproxy = new WS3DProxy(host, port);
    }


    /**
     * Get proxy
     * @return proxy
     */
    public WS3DProxy getProxy() {
        return ws3dproxy;
    }
    
    /**
     * Connect to remote WorldServer3D
     * @param host host address
     * @param port host port
     * @return WorldClient3D object
     */
    private static WorldClient3D connect(String host, int port){
        if (wc == null) {
            wc = new WorldClient3D(host, port);
        } else {
            System.out.println("Already connected.");
        }
        return wc;
    }

    /**
     * Create creature.
     * @return creature object
     */
    private static Creature createCreature() {
        if (wc != null) {
            if (creature == null) {
                try {
                    creature = wc.getProxy().createCreature();
                } catch (CommandExecException ex) {
                    System.out.println("Error on creating creature.");
                }
            } else {
                System.out.println("Creature already created.");
            }
        } else {
            System.out.print("Cannot create creature. ");
            System.out.println("Connect first. ");
        }
        return creature;
    }
    
    /**
     * Move creature.
     * @param vr linear velocity of the right wheel
     * @param vl linear velocity of the left wheel
     * @param w the new pitch of the creature in rad
     */
    private static void move(double vr, double vl, double w){
        if (creature != null){
            try {
                creature.move(vr, vl, w);
            } catch (CommandExecException ex) {
                System.out.println("Error on moving creature.");
            }
        } else {
            System.out.println("There is no creature to move.");
        }
    }

    /**
     * Move creature.
     * @param v
     * @param x
     * @param y
     */
    private static void moveTo(double v, double x, double y){
        if (creature != null){
            try {
                creature.moveto(v, x, y);
            } catch (CommandExecException ex) {
                System.out.println("Error on moving creature.");
            }
        } else {
            System.out.println("There is no creature to move.");
        }
    }
}

[ACTIVITY DONE]

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer