2021SC@SDUSC
上次的input模块是在engine中的对input模块功能的整合和初始化,这次我将观察input模块的具体功能,包括其具体的代码实现。
input模块主要由这几部分代码组成,包括cpp和cs。
1.Enum.h:
这一部分的内容主要涉及鼠标光标的输入:
API_ENUM() enum class CursorLockMode
{
/// <summary>
/// The default mode.
/// </summary>
None = 0,
/// <summary>
/// Cursor position is locked to the center of the game window.
/// </summary>
Locked = 1,
};
鼠标按键的输入:
API_ENUM() enum class MouseButton
{
/// <summary>
/// No button.
/// </summary>
None = 0,
/// <summary>
/// Left button.
/// </summary>
Left = 1,
/// <summary>
/// Middle button.
/// </summary>
Middle = 2,
/// <summary>
/// Right button.
/// </summary>
Right = 3,
/// <summary>
/// Extended button 1 (or XButton1).
/// </summary>
Extended1 = 4,
/// <summary>
/// Extended button 2 (or XButton2).
/// </summary>
Extended2 = 5,
MAX
};
可以看到对左键初始化为1,右键初始化为3,滚轮中键初始化为2,同时增加Extended1和Extended2作为不同厂商鼠标款的可能设计的侧键。
手柄或者控制器摇杆:
API_ENUM() enum class GamepadAxis
{
/// <summary>
/// No axis.
/// </summary>
None = 0,
/// <summary>
/// The X-Axis of the left thumb stick.
/// </summary>
LeftStickX = 1,
/// <summary>
/// The Y-Axis of the left thumb stick.
/// </summary>
LeftStickY = 2,
/// <summary>
/// The X-Axis of the right thumb stick.
/// </summary>
RightStickX = 3,
/// <summary>
/// The Y-Axis of the right thumb stick.
/// </summary>
RightStickY = 4,
/// <summary>
/// The left trigger.
/// </summary>
LeftTrigger = 5,
/// <summary>
/// The right trigger.
/// </summary>
RightTrigger = 6,
MAX
};
其中LeftStickX为左摇杆的x轴方向输入,trigger为遥杆的按下。
控制器按钮:
API_ENUM() enum class GamepadButton
{
/// <summary>
/// No buttons.
/// </summary>
None = 0,
/// <summary>
/// PadUp button (DPad / Directional Pad).
/// </summary>
DPadUp = 1,
/// <summary>
/// PadDown button (DPad / Directional Pad).
/// </summary>
DPadDown = 2,
/// <summary>
/// PadLeft button (DPad / Directional Pad).
/// </summary>
DPadLeft = 3,
/// <summary>
/// PadRight button (DPad / Directional Pad).
/// </summary>
DPadRight = 4,
/// <summary>
/// Start button.
/// </summary>
Start = 5,
/// <summary>
/// Back button.
/// </summary>
Back = 6,
/// <summary>
/// Left thumbstick button.
/// </summary>
LeftThumb = 7,
/// <summary>
/// Right thumbstick button.
/// </summary>
RightThumb = 8,
/// <summary>
/// Left shoulder button.
/// </summary>
LeftShoulder = 9,
/// <summary>
/// Right shoulder button.
/// </summary>
RightShoulder = 10,
/// <summary>
/// Left trigger button.
/// </summary>
LeftTrigger = 11,
/// <summary>
/// Right trigger button.
/// </summary>
RightTrigger = 12,
/// <summary>
/// A (face button down).
/// </summary>
A = 13,
/// <summary>
/// B (face button right).
/// </summary>
B = 14,
/// <summary>
/// X (face button left).
/// </summary>
X = 15,
/// <summary>
/// Y (face button up).
/// </summary>
Y = 16,
/// <summary>
/// The left stick up.
/// </summary>
LeftStickUp = 17,
/// <summary>
/// The left stick down.
/// </summary>
LeftStickDown = 18,
/// <summary>
/// The left stick left.
/// </summary>
LeftStickLeft = 19,
/// <summary>
/// The left stick right.
/// </summary>
LeftStickRight = 20,
/// <summary>
/// The right stick up.
/// </summary>
RightStickUp = 21,
/// <summary>
/// The right stick down.
/// </summary>
RightStickDown = 22,
/// <summary>
/// The right stick left.
/// </summary>
RightStickLeft = 23,
/// <summary>
/// The right stick right.
/// </summary>
RightStickRight = 24,
MAX
};
这部分涉及控制器的各种按钮,由于游戏硬件厂商一般会在这些按钮上达成一些统一的标准,所以在游戏引擎时只需要考虑常见的按钮即可。
按钮的输入模式:
API_ENUM() enum class InputActionMode
{
/// <summary>
/// User is pressing the key/button.
/// </summary>
Pressing = 0,
/// <summary>
/// User pressed the key/button (but wasn't pressing it in the previous frame).
/// </summary>
Press = 1,
/// <summary>
/// User released the key/button (was pressing it in the previous frame).
/// </summary>
Release = 2,
};
显然,包括按(按的过程pressing)、按下(按下的动作press)、松开(按后松开的动作release)这些输入模式的预先设计。
输入轴的类型:
API_ENUM() enum class InputAxisType
{
/// <summary>
/// The mouse X-Axis (mouse delta position scaled by the sensitivity).
/// </summary>
MouseX = 0,
/// <summary>
/// The mouse Y-Axis (mouse delta position scaled by the sensitivity).
/// </summary>
MouseY = 1,
/// <summary>
/// The mouse wheel (mouse wheel delta scaled by the sensitivity).
/// </summary>
MouseWheel = 2,
/// <summary>
/// The gamepad X-Axis of the left thumb stick.
/// </summary>
GamepadLeftStickX = 3,
/// <summary>
/// The gamepad Y-Axis of the left thumb stick.
/// </summary>
GamepadLeftStickY = 4,
/// <summary>
/// The gamepad X-Axis of the right thumb stick.
/// </summary>
GamepadRightStickX = 5,
/// <summary>
/// The gamepad Y-Axis of the right thumb stick.
/// </summary>
GamepadRightStickY = 6,
/// <summary>
/// The gamepad left trigger.
/// </summary>
GamepadLeftTrigger = 7,
/// <summary>
/// The gamepad right trigger.
/// </summary>
GamepadRightTrigger = 8,
/// <summary>
/// The keyboard only mode. For key inputs.
/// </summary>
KeyboardOnly = 9,
};
这部分就包括鼠标xy轴的移动,游戏手柄扳机的触发、键盘外禁用的预先设计。