SdkCameraMan         Intro to the SdkCameraMan Camera Controller

Introduction

Want basic fly-cam or orbit-cam controls in your sample? With SdkCameraMan, it's easy!

Requirements

SdkCameraMan requires that you use OIS in buffered mode, so make sure you have the necessary dependencies and handlers set up. Then, just include "SdkCameraMan.h" from the OGRE source or SDK, and you're done.

Setting Up

SdkCameraMan is a {LEX()}camera{LEX} controller, not a camera. This means you'll still have to create your own OGRE camera. Once this is done, create an instance of the SdkCameraMan class, and pass in your camera. Be sure to use the OgreBites namespace (SdkCameraMan part of the OgreBites Samples Framework).

mCameraMan = new SdkCameraman(mCamera);

Destroy your camera controller like so:

delete mCameraMan;
mCameraMan = 0;

Our Once you have your camera controller, make sure you relay your OIS events to it.

bool mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{
    /* normal mouse processing here... */
    mCameraMan->injectMouseDown(evt, id);
    return true;
}

bool mouseReleased(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{
    /* normal mouse processing here... */
    mCameraMan->injectMouseUp(evt, id);
    return true;
}

bool mouseMoved(const OIS::MouseEvent& evt)
{
    /* normal mouse processing here... */
    mCameraMan->injectMouseMove(evt);
    return true;
}

bool keyPressed(const OIS::KeyEvent& evt)
{
    /* normal key processing here... */
    mCameraMan->injectKeyDown(evt);
    return true;
}

bool keyReleased(const OIS::KeyEvent& evt)
{
    /* normal key processing here... */
    mCameraMan->injectKeyUp(evt);
    return true;
}


If you are using the Free Look camera style then you must call SdkCameraMan::frameRenderingQueued in your frameRenderingQueued method.

bool frameRenderingQueued(const Ogre::FrameEvent& evt)
{
    mCameraMan->frameRenderingQueued(evt);
    return true;
}

You should now have a fly-cam working.

Camera Styles

SdkCameraMan comes with two styles of camera movement, enumerated under the type CameraStyle. You can check which style is currently enabled with SdkCameraMan::getStyle.

Free Look

This is a first-person flying camera. The WASD keys control movement, and the mouse is used to look around. Hold down the left Shift key to move at 20 times the normal speed. The camera has a fixed yaw axis. This camera style is enabled by default. To enable it manually, use SdkCameraMan::setStyle(CS_FREELOOK). When in this camera mode, you can use SdkCameraMan::setTopSpeed and SdkCameraMan::getTopSpeed to set/get the camera's top speed in units per second. We use a top speed instead of just a speed, because the camera gradually reaches the top speed when moving. This creates a smoother, less jerky experience. Similarly, the camera slows to a stop. To stop immediately, you can use SdkCameraMan::manualStop. In this style of camera movement, you can also manually set the camera's position and orientation at any time with no adverse effects.

Orbit

In this style of control, the camera orbits around an object of interest. The user clicks and drags the left mouse button to swing the camera around, and drags the right mouse button to zoom in and out from the target. Targets are specified by SceneNodes. To enable this style, use SdkCameraMan::setStyle(CS_ORBIT). When in this camera mode, your target by default is the scene root node. To set or get the target, use SdkCameraMan::setTarget and SdkCameraMan::getTarget. Make sure you don't accidentally destroy your target SceneNode! In this camera mode, you can't just move the camera around freely, because it is constrained by a target. Therefore, the camera's current state must be specified relatively to the target. This is done using SdkCameraMan::setYawPitchDist, which allows you to specify the camera's precise angle and distance from the target.

Manual

This isn't exactly a style. When you want to have full control over the camera without using a particular style, you can use SdkCameraMan::setStyle(CS_MANUAL). You can set/get the controlled camera using SdkCameraMan::setCamera and SdkCameraMan::getCamera.

Drag Look

This isn't exactly a style, either. Basically, when you need to use free-look mode, but you also need a cursor for GUI controls, a common solution is to only enter free-look mode when click-and-dragging. When in free-look mode, the cursor is hidden. This kind of control requires a cooperation between the camera controller and the GUI. Luckily, SdkSample::setDragLook allows you to enable or disable this type of control.