Module Fps


module Fps: sig .. end
Provides first-person shooter behavior.

Yo, yo, yo:

An Fps.fps_ui_bridge receives mouse and keyboard events from Event.event_dispatcher. It then translates these events into calls of forward, rotate, tilt and rise of a fps_engine. Get an instance by calling Util.make_fps_ui_bridge.

Fps.fps_engine is charged with constraining these calls to legal movements. An implementation might for example only move forward if there isn't a wall in the way. fps_engine keeps track of the position and orientation according to these calls. Users may then render an avatar according to this position, or place the camera or whatever.

fps_engine is a virtual class, you will need to provide an implementation that understands the boundaries of your game. There are two provided implementations. The Fps.null_engine singleton stores no position data. The Fps.no_clipping_engine allows unconstrained movement.

fps_entity has the same type as fps_engine but is intended for 'dumb' objects that delegate to an fps_engine. For example, the player object knows nothing about walls, and the fps_engine doesn't know whether its moving around a player or a monster.

This code will set up a camera for the user to move around:


	open FatCaml.Scene
	open FatCaml.Application
	open FatCaml.Fps
	open FatCaml.Util

	let display_renderer = new default_renderer in
	
	let fps_ui = make_fps_ui_bridge () and
	    camera = new fps_camera in
	fps_ui#affect (camera :> fps_entity) ;

	display_renderer#set_camera (camera :> camera) ;
	display_singleton#set_renderer (display_renderer :> renderer) ;

If you want the camera to avoid walls, add the following:
	camera#set_engine (new my_fps_engine) ; 



type fps_state = {
   position : Vector.vector;
   tilt : float;
   rotation : float;
}
class virtual fps_engine : object .. end
Takes abstract movement commands (move forward, rotate, tilt), constrains them to some map, and stores a position and orientation.
class virtual fps_entity : fps_engine
Some objects have fps behavior but pass commands through to an fps_engine; these objects should inherit from fps_entity.
val null_engine : fps_engine
Goes nowhere, quietly.
class no_clipping_engine : object .. end
Follow commands without constraints from walls or anything.
class fps_ui_bridge : < key : < affect : Event.keyboard_listener -> 'a; .. >;
mouse : < affect : Event.mouse_listener -> 'b; .. >;
ticker : < affect : Event.frame_listener -> unit; .. >; .. > ->
object .. end
Transforms gui events into commands for Fps.fps_engine.
class fps_camera : object .. end
A Scene.camera that implements fps_entity.