To get used to the methods and members of the classes in Irrlicht I thought I'd might first try out a first person camera.
So pure theoretically my code seems right, but the results are far from good. the camera flickers around, I'm getting very fast changes of view,...
I've been looking at it for quite some time now, but I can't figure it out. Anyone cares to give me a hint?
Code: Select all
void update(u32 delta) {
// check input first
check_keyboard_input(delta);
check_mouse_input(delta);
core::vector3df v = camera->getPosition(); v += dvector;
camera->setPosition(v);
v.X += sin(rotation->Y)<0 ? -abs(cos(rotation->Y)) : abs(cos(rotation->Y));
v.Y += cos(rotation->X)<0 ? -abs(sin(rotation->X)) : abs(sin(rotation->X));
v.Z += sin(rotation->X)<0 ? -abs(cos(rotation->X)) : abs(cos(rotation->X));
camera->setTarget(v);
dvector.X = 0; dvector.Y = 0; dvector.Z = 0;
}
void check_mouse_input(u32 dt) {
core::vector2di dv = reg->getMouseState().get_position_rel();
if (dv.X != 0) {
rotation->X -= dv.X * s32(dt) * MOUSE_SENSITIVITY;
if (rotation->X > core::PI/2)
rotation->X = core::PI/2;
if (rotation->X < -core::PI/2)
rotation->X = -core::PI/2;
}
if (dv.Y != 0) {
rotation->Y += dv.Y * s32(dt) * MOUSE_SENSITIVITY;
}
reg->getMouseState().reset_rel();
}
Thanks