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();
154 /// when user moves and speed factor is 0, show warning message
155 void checkSpeedFactor();
162 /// Return the string associated to the motion Mode.
163 std::string
modeStr() const;
164 /// Return the motion Mode.
165 TMoveMode
mode() const {return _Mode
;}
166 /// Change the current motion Mode.
167 void mode(const TMoveMode mode
);
169 /// Update the motion.
172 /// Lock or unlock the motion.
173 void locked(bool l
) {_Locked
= l
;}
174 bool locked() {return _Locked
;}
176 /// Begin Free Look. Additionaly, cancel any follow/moteTo of the user
177 void startFreeLook();
179 /// Stop Free Look (can be called multiple times if needed). Additionaly, the mouse/pointer is restored
182 bool getFreeLook() const { return _FreeLook
; }
184 /// Is the camera inside the character.
185 bool isInternalView() {return _InternalView
;}
187 /// Update keyboard rotation
188 void keyboardRotationLR (bool left
, bool right
);
189 void keyboardRotationUD (bool up
, bool down
);
190 void keyboardRotationCameraLR (bool left
, bool right
);
192 void startCombat() {_CameraAuto
= true;}
194 /// Enable/Disable Autowalk
195 void autowalkState(bool enable
);
196 /// Return the autowalk state ('true'=enable).
197 bool autowalkState() const {return ((_DirectionMove
& autowalk
)!=0);}
200 static void updateVelocity (float deltaTime
, float acceleration
, float brake
, float speedMax
, float &speed
);
203 // get the camera Delta Yaw
204 float getCameraDeltaYaw() const {return _UserCameraDeltaYaw
;}
206 // just reset the camera Delta Yaw (instantaneously)
207 void resetCameraDeltaYaw();
209 // reset the camera Delta Yaw (smooth over time, canceled by user)
210 void resetSmoothCameraDeltaYaw();
212 // append to the camera Delta Yaw (NB: any smooth reset is then canceled)
213 void appendCameraDeltaYaw(float dYaw
);
215 // reset the camera Delta Yaw and change the user front so the final Yaw remains the same
216 void applyCameraDeltaYawToUser();
218 // true if there is currently a smooth reset of the cameraDeltaYaw (in force mode)
219 bool isResetSmoothCDYForced() const {return _ResetSmoothCameraDeltaYaw
==ResetCDYForced
;}
221 // capture the mouse, prevent the free look from being trigger on a long click
222 void captureMouse() { _MouseCaptured
= true; }
223 void releaseMouse() { _MouseCaptured
= false; }
224 bool isMouseCaptured() { return _MouseCaptured
; }
226 /// user has to release forward key before he can go forward again
227 void needReleaseForward();
229 /// return true if user do forward or backward move action with key or mouth
230 bool isMoving() { return _DirectionMove
!= none
; }
234 bool _MouseCaptured
; // no free look allowed when mouse is captures
236 // Is the camera controled by the user or not.
239 bool _LastFrameForward
;
240 bool _LastFrameBackward
;
241 bool _LastFrameAutowalk
;
242 bool _LastFrameStrafeLeft
;
243 bool _LastFrameStrafeRight
;
244 bool _LastFrameTurnLeft
;
245 bool _LastFrameTurnRight
;
246 bool _LastFrameLeftButtonDown
;
247 // NB: modified only when not in freelook mode
248 float _LastFrameMousePosX
;
249 float _LastFrameMousePosY
;
250 bool _CurrentFrameFreeLookCalled
;
251 /// Used to lock motion.
254 /// Are we in displacement or not ?
255 uint32 _DirectionMove
;
262 /// speed in translation
266 float _FlyVerticalVelocity
;
267 float _FlyFrontVelocity
;
268 float _FlyLateralVelocity
;
269 float _RotateUserLRVelocity
;
270 float _RotateUserUDVelocity
;
271 float _RotateCameraLRVelocity
;
277 NLMISC::CVector _Start
;
279 NLMISC::CVector _Destination
;
297 /// "true" if the character has a destination to go.
310 float _UserCameraDeltaYaw
;
311 // Forced mode is related to moveTo/follow feature
312 enum TResetCDY
{ResetCDYOff
=0, ResetCDYOn
, ResetCDYForced
};
313 TResetCDY _ResetSmoothCameraDeltaYaw
;
315 /// when true user has to release forward key before he can go forward again
316 bool _NeedReleaseForward
;
318 /// when true the next forward action will cancel any moveto
319 bool _NextForwardCancelMoveTo
;
321 NLMISC::CRefPtr
<NLMISC::CCDBNodeLeaf
> _UiVarMkMoveDB
;
324 /// User Controls (mouse, keyboard, interfaces, ...)
325 extern CUserControls UserControls
;
328 #endif // CL_USER_CONTROLS_H
330 /* End of user_controls.h */