|
DesignSuper Spectator ArchitectureIf the server handles the client positions and knows all the information about the game, then it is only logical that this is where all the clients that want to spectate should be. So to design a big field of view, we created a pseudocamera, (a camera server if you will). PseudocameraA speudocamera can only be created by the server , as it only resides on the server. When it is created, it is initialised with its dimensions and its position that it will start off at. It creates a two dimensional array according to how many cameras need to be attached to it. So for a 3 x 1 screen, the array will be 3 across and 1 down, etc. The pseudo camera also has information about who its clients are, where ites clients are, where they are supposed to the looking, where the pseuodcamera is, where the pseudocamera is looking and the entire psedocamera field of view. When the first camera is joined to the pseudocamera, it sets that client to be the lead client. The lead client will have all the control over the pseudo camera. When the lead client joins, the servers asks it to send its screen dimensions, which lets the pseudo camera calulate fov_x and fov_y. It is assumed that all other clients that join that particluar pseudocamera have the screen height and width, this allows for the clients to have a seamless view. When the clients are connected, their position and their direction they are looking are relative to one another depending on their field of view, but more importantly the position and the looking direction of the pseudocamera. So when the clients are connected, and the lead camera moves the pseudocamera, instead of having the clients change position, the psedocamera is passed through pmove() and its final poistion is determined. Once the pseudocamera has its final coordinates, an updateclients function is called and updates the positions of all the clients that are connected to the pseudocamera. Clients not connected are not accected. This is done up not moving the clients, but copying the position vector of the camera to each of the clients. A little trickier was the looking part. Since the image originates from the one position, all the clients had the same position, but to get a precise view, all the clients had to be looking in different direction, this was done with mathematical calculations relative to how big the pseudocera was and how big its field of view was. So for a small field of view (or small dimensions) the clients were looking closer togeter, ie close to the center, but for a 3 x 1, one client would be in the center, one to the left and one to the right. But when the clients were asked to look up, there was again some maths involved. Imagine a globe, and the longitudes going up and down, the dintance between two longitudes at the equator is more than the distance between the two same two longitudes say in melbourne. So when the camera was rotated up, the clients needed to be looking further away from wach other to keep a consistant view. But as they look further, they need to be rolled more, so more mathematical calculations were involved to keep the camera looking further away from the center, be parallel to each other and still have their "frustrums" matched to keep a full flowing image. Camera ClientsAs mentioned, when the clients join the pseudocamera, only the lead camera (the first one joined) may have controls. So all the othe rclients now depend on the lead camera. The controls are the same as those in normal spectator mode, Clients can soom in, follow players or float around and do their own thing. When the clients wants to zoom, their individual screen dont get zoomed, instead the entire pseudocamera gets zoomed, a really cool feature. When the clients are following players, their controls are again lost, as if you are following the players, the meovement of the pseudocamera is done relative to the player being followed. The clients poisitons and the view angles are all determined by the pseudocamera, the pseudocamera knows who its clients are and where they sould be looking, so instead of the game server telling the clients where they should be, if they are joined to the pseudocamera, then the pseudocamera does all the updating for the clients. The pseudocaera also updates itself if the user performs functions such as zoom, moves and gives it any other user commands. |