Moved free camera controls to numpad; added 'camtype %d', 'camspeed %f', 'freecam'

master
krzys-h 2015-09-04 18:34:49 +02:00
parent 2fe8fc5a91
commit e956311626
6 changed files with 58 additions and 6 deletions

View File

@ -132,6 +132,13 @@ void CInput::EventProcess(Event& event)
if (data->slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 1.0f; if (data->slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 1.0f;
if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f; if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f;
if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f; if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f;
if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 1.0f;
if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = -1.0f;
if (data->key == KEY(KP4) ) m_cameraKeyMotion.x = -1.0f;
if (data->key == KEY(KP6) ) m_cameraKeyMotion.x = 1.0f;
if (data->key == KEY(KP8) ) m_cameraKeyMotion.y = 1.0f;
if (data->key == KEY(KP2) ) m_cameraKeyMotion.y = -1.0f;
} }
else if (event.type == EVENT_KEY_UP) else if (event.type == EVENT_KEY_UP)
{ {
@ -143,6 +150,13 @@ void CInput::EventProcess(Event& event)
if (data->slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 0.0f; if (data->slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 0.0f;
if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f; if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f;
if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f; if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f;
if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 0.0f;
if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = 0.0f;
if (data->key == KEY(KP4) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP6) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP8) ) m_cameraKeyMotion.y = 0.0f;
if (data->key == KEY(KP2) ) m_cameraKeyMotion.y = 0.0f;
} }
else if (event.type == EVENT_JOY_AXIS) else if (event.type == EVENT_JOY_AXIS)
{ {
@ -171,6 +185,7 @@ void CInput::EventProcess(Event& event)
} }
event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f));
event.cameraInput = m_cameraKeyMotion;
} }
void CInput::MouseMove(Math::IntPoint pos) void CInput::MouseMove(Math::IntPoint pos)
@ -204,6 +219,7 @@ void CInput::ResetKeyStates()
m_kmodState = 0; m_kmodState = 0;
m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
m_cameraKeyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
for(int i=0; i<INPUT_SLOT_MAX; i++) for(int i=0; i<INPUT_SLOT_MAX; i++)
m_keyPresses[i] = false; m_keyPresses[i] = false;
} }

View File

@ -154,6 +154,8 @@ private:
//! Motion vector set by joystick axes //! Motion vector set by joystick axes
Math::Vector m_joyMotion; Math::Vector m_joyMotion;
//! Camera controls on the numpad
Math::Vector m_cameraKeyMotion;
//! Bindings for user inputs //! Bindings for user inputs
InputBinding m_inputBindings[INPUT_SLOT_MAX]; InputBinding m_inputBindings[INPUT_SLOT_MAX];

View File

@ -720,6 +720,7 @@ struct Event
: type(std::move(other.type)), : type(std::move(other.type)),
rTime(std::move(other.rTime)), rTime(std::move(other.rTime)),
motionInput(std::move(other.motionInput)), motionInput(std::move(other.motionInput)),
cameraInput(std::move(other.cameraInput)),
kmodState(std::move(other.kmodState)), kmodState(std::move(other.kmodState)),
mousePos(std::move(other.mousePos)), mousePos(std::move(other.mousePos)),
mouseButtonsState(std::move(other.mouseButtonsState)), mouseButtonsState(std::move(other.mouseButtonsState)),
@ -732,6 +733,7 @@ struct Event
type = std::move(other.type); type = std::move(other.type);
rTime = std::move(other.rTime); rTime = std::move(other.rTime);
motionInput = std::move(other.motionInput); motionInput = std::move(other.motionInput);
cameraInput = std::move(other.cameraInput);
kmodState = std::move(other.kmodState); kmodState = std::move(other.kmodState);
mousePos = std::move(other.mousePos); mousePos = std::move(other.mousePos);
mouseButtonsState = std::move(other.mouseButtonsState); mouseButtonsState = std::move(other.mouseButtonsState);
@ -762,6 +764,7 @@ struct Event
clone.type = type; clone.type = type;
clone.rTime = rTime; clone.rTime = rTime;
clone.motionInput = motionInput; clone.motionInput = motionInput;
clone.cameraInput = cameraInput;
clone.kmodState = kmodState; clone.kmodState = kmodState;
clone.mousePos = mousePos; clone.mousePos = mousePos;
clone.mouseButtonsState = mouseButtonsState; clone.mouseButtonsState = mouseButtonsState;
@ -787,6 +790,10 @@ struct Event
//! Scope: all system events //! Scope: all system events
Math::Vector motionInput; Math::Vector motionInput;
//! Motion vector set by numeric keyboard (managed by CInput)
//! Scope: all system events
Math::Vector cameraInput;
//! Current state of keyboard modifier keys: bitmask made of KEY_MOD(...) macro values (from common/key.h) //! Current state of keyboard modifier keys: bitmask made of KEY_MOD(...) macro values (from common/key.h)
//! Scope: all system events //! Scope: all system events
unsigned int kmodState; unsigned int kmodState;

View File

@ -1234,19 +1234,19 @@ bool CCamera::EventFrameFree(const Event &event)
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed); m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed);
// Up/Down // Up/Down
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, event.motionInput.y * event.rTime * factor * m_speed); m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, event.cameraInput.y * event.rTime * factor * m_speed);
// Left/Right // Left/Right
if ( event.kmodState & KEY_MOD(CTRL) ) if ( event.kmodState & KEY_MOD(CTRL) )
{ {
if ( event.motionInput.x < 0.0f ) if ( event.cameraInput.x < 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -event.motionInput.x * event.rTime * factor * m_speed); m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -event.cameraInput.x * event.rTime * factor * m_speed);
if ( event.motionInput.x > 0.0f ) if ( event.cameraInput.x > 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, event.motionInput.x * event.rTime * factor * m_speed); m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, event.cameraInput.x * event.rTime * factor * m_speed);
} }
else else
{ {
m_directionH -= event.motionInput.x * event.rTime * 0.7f * m_speed; m_directionH -= event.cameraInput.x * event.rTime * 0.7f * m_speed;
} }
// PageUp/PageDown // PageUp/PageDown
@ -1711,5 +1711,10 @@ Math::Vector CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat,
return eye;*/ return eye;*/
} }
void CCamera::SetCameraSpeed(float speed)
{
m_speed = speed;
}
} }

View File

@ -218,6 +218,8 @@ public:
//! Returns the default sprite to use for the mouse //! Returns the default sprite to use for the mouse
EngineMouseType GetMouseDef(Math::Point pos); EngineMouseType GetMouseDef(Math::Point pos);
void SetCameraSpeed(float speed);
protected: protected:
//! Changes the camera according to the mouse moved //! Changes the camera according to the mouse moved
bool EventMouseMove(const Event &event); bool EventMouseMove(const Event &event);

View File

@ -1204,6 +1204,26 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
int camtype;
if (sscanf(cmd, "camtype %d", &camtype) > 0)
{
m_camera->SetType(static_cast<Gfx::CameraType>(camtype));
return;
}
float camspeed;
if (sscanf(cmd, "camspeed %f", &camspeed) > 0)
{
m_camera->SetCameraSpeed(camspeed);
return;
}
if (strcmp(cmd, "freecam") == 0)
{
m_camera->SetType(Gfx::CAM_TYPE_FREE);
return;
}
if (strcmp(cmd, "noclip") == 0) if (strcmp(cmd, "noclip") == 0)
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();