// move speed
if (MouseDeltaZ > 0.0f)
moveSpeed *= 0.5f;
else
if (MouseDeltaZ < 0.0f)
moveSpeed /= 0.5f;
// move
if (BrumeKeyboard.IsPressed(BrumeKey.W))
camera.FPSMove(camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.S))
camera.FPSMove(-camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.D))
camera.FPSMove(camera.Right * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.A))
camera.FPSMove(-camera.Right * (fElapsedTime / moveSpeed));
Then add a simple cube to the scene :
override protected void GameInit()
{
...
...
// a simple cube
BrumeCubeColored theCube = new BrumeCubeColored(this, "The Cube", Color.Blue, Color.Red, Color.Green);
...
Notice that we checked for the existance of the camera and that we avoid to move it if debug console is opened (debugLevel 1 means that we are displaying FPS, debugLevel 2 the debug console is open).
Then we use BrumeKeyboard interface to move the camera accordingly to keyboard states :
In the source code above, we included another cool functionnality : the camera will move faster or slower when you action the mouse wheel (MouseDeltaZ property).
Download the included sample to get a better idea of the camera move.
override protected void GameInit()
{
// camera setup
BrumeVector cameraPos = new BrumeVector(3.0f, 0.0f, -3.0f);
BrumeVector cameraDir = new BrumeVector(-0.7f, 0.0f, 0.7f);
BrumeVector cameraUp = new BrumeVector(0.0f, 1.0f, 0.0f);
BrumeFPSCamera camera = new BrumeFPSCamera(this, "camera", cameraPos, cameraDir, cameraUp);
this.SetActiveCamera(camera);
// buffer clear color setup
this.BufferClearColor = Color.Black;
...
...
In the overriden method we get the active camera from Brume engine and we cast it to a FPS camera.
First we need to orient the camera from mouse. For this purpose Brume includes two properties "MouseDeltaX" and "MouseDeltaY" that inform you about mouse moves.
protected override void MoveScene(float fElapsedTime)
{
// retreives active camera
BrumeFPSCamera camera = (BrumeFPSCamera)this.ActiveCamera;
Tutorial : Moving Camera
Now to move our camera we will use two methods from BrumeFPSCamera :
- FPSOrient : that orients the camera given mouse deltas
- FPSMove : that moves the camera in a given direction
To implement the move, we will need to override the Brume "MoveScene" method.
This method is called before each frame rendering and it takes in parameter the frame elapsed time.
The elapsed time will help you to make the animation time independent.
This tutorial will show you how to move a FPS like camera using keyboard and mouse.
First create a new project named "TutorialCameraMove" as shown in "The Basics" tutorial. Once it's done, add the camera to the scene :
// if camera present and not in full console mode
if (camera != null && this.DebugConsole.debugLevel != 2)
{
// orient
camera.FPSOrient((float)this.MouseDeltaX / (float)2, (float)this.MouseDeltaY / (float)2);