1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef CL_USER_CONTROLS_H
24 #define CL_USER_CONTROLS_H
31 #include "nel/misc/types_nl.h"
32 #include "nel/misc/time_nl.h"
33 #include "nel/misc/vector.h"
45 * Class to manage the motion.
46 * \author Guillaume PUZIN
47 * \author Nevrax France
52 friend class CAHForward
;
53 friend class CAHBackward
;
54 friend class CAHToggleAutoWalk
;
59 InterfaceMode
= 0, // Interface Mode (with mouse displayed)
60 AIMode
, // Mode for the AI.
61 DeathMode
, // Mode for the Death.
62 MountMode
, // Mode for the Mount.
63 ThirdMode
, // Third Person View Mode
65 nbMode
// Not really a mode, just here to know how many modes are there.
79 NLMISC::TTime _LeftClickStart
;
80 NLMISC::TTime _LeftClickEnd
;
81 NLMISC::TTime _RightClickStart
;
82 NLMISC::TTime _RightClickEnd
;
83 NLMISC::TTime _TimeBeforeMouseSlide
;
84 NLMISC::TTime _TimeLongClick
;
87 /// Initialize all the components.
90 /// Just manage the free look.
91 void freeLook(bool fullMode
);
92 /// Just manage the camera look
93 void cameraLook(bool fullMode
);
94 /// common to freeLook and cameraLook
95 void getMouseAngleMove(float &dx
, float &dy
);
97 /// Manage interactions in interactive mode (start).
98 void interfaceModeStart();
99 /// Manage interactions in interactive mode (stop).
100 void interfaceModeStop();
101 /// Manage interactions in interactive mode.
102 void interfaceMode();
104 /// Manage the AI Mode (start).
106 /// Manage the AI Mode (stop).
108 /// Manage the AI Mode.
111 /// Manage the Death Mode (start).
112 void deathModeStart();
113 /// Manage the Death Mode (stop).
114 void deathModeStop();
115 /// Manage the Death Mode.
118 /// Manage the Mount Mode (start).
119 void mountModeStart();
120 /// Manage the Mount Mode (stop).
121 void mountModeStop();
122 /// Manage the Mount Mode.
125 /// Manage the Third Person View Mode (start).
126 void thirdModeStart();
127 /// Manage the Third Person View Mode (stop).
128 void thirdModeStop();
129 /// Manage the Third Person View Mode.
132 /// Manage some common actions.
134 /// Move the caracter according to the inputs
136 /// Calculate the destination point when clicking on the ground in "Free Head" Mode.
137 void findDestination(float x
, float y
);
140 /// Update the cursor position.
141 void updateCursorPosition();
142 /// Manage some common view setup.
143 void commonSetView();
145 // Execute action depending on the cursor position (left/right click).
146 void execActionCursorPos(bool rightClick
, bool dblClick
);
148 // test merge the camera Yaw and user Yaw. Only in some cases
149 void testApplyCameraYawToUser();
151 /// when user moves, some actions must be cancelled
152 void cancelActionsWhenMoving();
160 /// Return the string associated to the motion Mode.
161 std::string
modeStr() const;
162 /// Return the motion Mode.
163 TMoveMode
mode() const {return _Mode
;}
164 /// Change the current motion Mode.
165 void mode(const TMoveMode mode
);
167 /// Update the motion.
170 /// Lock or unlock the motion.
171 void locked(bool l
) {_Locked
= l
;}
172 bool locked() {return _Locked
;}
174 /// Begin Free Look. Additionaly, cancel any follow/moteTo of the user
175 void startFreeLook();
177 /// Stop Free Look (can be called multiple times if needed). Additionaly, the mouse/pointer is restored
180 /// Is the camera inside the character.
181 bool isInternalView() {return _InternalView
;}
183 /// Update keyboard rotation
184 void keyboardRotationLR (bool left
, bool right
);
185 void keyboardRotationUD (bool up
, bool down
);
186 void keyboardRotationCameraLR (bool left
, bool right
);
188 void startCombat() {_CameraAuto
= true;}
190 /// Enable/Disable Autowalk
191 void autowalkState(bool enable
);
192 /// Return the autowalk state ('true'=enable).
193 bool autowalkState() const {return ((_DirectionMove
& autowalk
)!=0);}
196 static void updateVelocity (float deltaTime
, float acceleration
, float brake
, float speedMax
, float &speed
);
199 // get the camera Delta Yaw
200 float getCameraDeltaYaw() const {return _UserCameraDeltaYaw
;}
202 // just reset the camera Delta Yaw (instantaneously)
203 void resetCameraDeltaYaw();
205 // reset the camera Delta Yaw (smooth over time, canceled by user)
206 void resetSmoothCameraDeltaYaw();
208 // append to the camera Delta Yaw (NB: any smooth reset is then canceled)
209 void appendCameraDeltaYaw(float dYaw
);
211 // reset the camera Delta Yaw and change the user front so the final Yaw remains the same
212 void applyCameraDeltaYawToUser();
214 // true if there is currently a smooth reset of the cameraDeltaYaw (in force mode)
215 bool isResetSmoothCDYForced() const {return _ResetSmoothCameraDeltaYaw
==ResetCDYForced
;}
217 // capture the mouse, prevent the free look from being trigger on a long click
218 void captureMouse() { _MouseCaptured
= true; }
219 void releaseMouse() { _MouseCaptured
= false; }
220 bool isMouseCaptured() { return _MouseCaptured
; }
222 /// user has to release forward key before he can go forward again
223 void needReleaseForward();
225 /// return true if user do forward or backward move action with key or mouth
226 bool isMoving() { return _DirectionMove
!= none
; }
230 bool _MouseCaptured
; // no free look allowed when mouse is captures
232 // Is the camera controled by the user or not.
235 bool _LastFrameForward
;
236 bool _LastFrameBackward
;
237 bool _LastFrameAutowalk
;
238 bool _LastFrameStrafeLeft
;
239 bool _LastFrameStrafeRight
;
240 bool _LastFrameTurnLeft
;
241 bool _LastFrameTurnRight
;
242 bool _LastFrameLeftButtonDown
;
243 // NB: modified only when not in freelook mode
244 float _LastFrameMousePosX
;
245 float _LastFrameMousePosY
;
246 bool _CurrentFrameFreeLookCalled
;
247 /// Used to lock motion.
250 /// Are we in displacement or not ?
251 uint32 _DirectionMove
;
258 /// speed in translation
262 float _FlyVerticalVelocity
;
263 float _FlyFrontVelocity
;
264 float _FlyLateralVelocity
;
265 float _RotateUserLRVelocity
;
266 float _RotateUserUDVelocity
;
267 float _RotateCameraLRVelocity
;
273 NLMISC::CVector _Start
;
275 NLMISC::CVector _Destination
;
293 /// "true" if the character has a destination to go.
306 float _UserCameraDeltaYaw
;
307 // Forced mode is related to moveTo/follow feature
308 enum TResetCDY
{ResetCDYOff
=0, ResetCDYOn
, ResetCDYForced
};
309 TResetCDY _ResetSmoothCameraDeltaYaw
;
311 /// when true user has to release forward key before he can go forward again
312 bool _NeedReleaseForward
;
314 /// when true the next forward action will cancel any moveto
315 bool _NextForwardCancelMoveTo
;
317 NLMISC::CRefPtr
<NLMISC::CCDBNodeLeaf
> _UiVarMkMoveDB
;
320 /// User Controls (mouse, keyboard, interfaces, ...)
321 extern CUserControls UserControls
;
324 #endif // CL_USER_CONTROLS_H
326 /* End of user_controls.h */