All pastes #618024 Raw Edit

Simple Top Down Cam

public text v1 · immutable
·published 2007-07-13 18:07 UTC
rendered paste body
#ifndef _INCLUDE_CTD_CAMERA_
#define _INCLUDE_CTD_CAMERA_

#define MIN_HEIGHT 5.0f
#define MAX_HEIGHT 15.0f
#define PARENT_DIST 3.0f

#include "CGraphics.h"

class CTDCamera
{
    private:
        ICameraSceneNode* camera;

    public:
        CTDCamera(CGraphics* graphics, ISceneNode* parent);

        void zoom(f32 delta);
        void updateTarget();
};

#endif


CTDCamera::CTDCamera(CGraphics* graphics, ISceneNode* parent)
{
    camera = graphics->getIrrlicht()->getSceneManager()->addCameraSceneNode();

    camera->setParent(parent);
    camera->setPosition(vector3df(0, MIN_HEIGHT, -PARENT_DIST));

    this->updateTarget();
}

//Theres no need to call that from outside the class
void CTDCamera::updateTarget()
{
    camera->setTarget(vector3df(0,0,0));
    camera->updateAbsolutePosition();
}

void CTDCamera::zoom(f32 delta)
{
    if((camera->getPosition().Y + delta) > MAX_HEIGHT || (camera->getPosition().Y + delta) < MIN_HEIGHT)
        return;

    vector3df newPos =  camera->getPosition();
    newPos.Y += delta;

    camera->setPosition(newPos);

    this->updateTarget();
}