Code: Select all
const int W = 800, H = 600;
const float minwidth = .1, maxwidth = .9, minheight = .1, maxheight = .9;
vector3df rot = vector3df(0, 0, 0), mov = vector3df(0, 0, 0);
float rotspeed = 1, movspeed = .5;
if(receiver.mx < W * minwidth) rot.Y -= rotspeed;
if(receiver.mx > W * maxwidth) rot.Y += rotspeed;
if(receiver.my < H * minheight) rot.X -= rotspeed;
if(receiver.my > H * maxheight) rot.X += rotspeed;
vector3df camdir = camera->getTarget() - camera->getPosition();
camdir.normalize();
vector3df camright = camdir.crossProduct(vector3df(0, 1, 0));
if(receiver.IsKeyDown(KEY_KEY_W)) mov += camdir;
if(receiver.IsKeyDown(KEY_KEY_A)) mov -= camright;
if(receiver.IsKeyDown(KEY_KEY_S)) mov -= camdir;
if(receiver.IsKeyDown(KEY_KEY_D)) mov += camright;
camera->setRotation(camera->getRotation() + rot);
camera->setPosition(camera->getPosition() + mov);