Code: Select all
bool CDemo::OnEvent(SEvent event)
{
core::vector3df model_rotate;
scene::ICameraSceneNode* camera = 0;
scene::ISceneManager* sm = device->getSceneManager();
camera = sm->getActiveCamera();
core::line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start + (camera->getTarget() - line.start).normalize() * 75.0f;
model_rotate.Z = 0;
model_rotate.X = 0;
model_rotate.Y = 0;
switch(event.KeyInput.Key)
{
case KEY_KEY_A:
{
++Big_Rotate;
if (Big_Rotate > 359) {
Big_Rotate = 1;
}
break;
}
case KEY_KEY_S:
{
--Big_Rotate;
if (Big_Rotate < 1) {
Big_Rotate = 359;
}
}
}
model_rotate.Y = Big_Rotate;
model_rotate.X = 20;
model3->setPosition(line.end);
model3->setRotation(model_rotate);
With the code above you can change the position of the player like a gun turret...etc...
Haven't figured out how to connect it to the FPS camera in terms of rotation.
Big_Rotate is defined as an int and initialized to 1. Was trying to use:
model_rotate.X = 20; to tilt the gun. It's not the best way to do it, but I think it maybe an easier way to do it.
I've seen other 3rd person shooter code examples, but they seemed kinda lengthy and sometimes would't compile at all.