Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interface_v3 / interface_3d_scene.h
blob16578d740723313b8885ffdae92217a768da28f8
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2018 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
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/>.
22 #ifndef RZ_INTERFACE_SCENE_3D_H
23 #define RZ_INTERFACE_SCENE_3D_H
25 #include "nel/gui/interface_group.h"
26 #include "nel/3d/u_point_light.h"
27 #include "nel/3d/u_particle_system_instance.h"
28 #include "nel/3d/u_skeleton.h"
30 class CCharacter3D;
32 class CInterface3DCharacter;
33 class CInterface3DShape;
34 class CInterface3DIG;
35 class CInterface3DCamera;
36 class CInterface3DLight;
37 class CInterface3DFX;
39 namespace NL3D
41 class UParticleSystemInstance;
42 class UAnimationSet;
43 class USkeleton;
46 /**
47 * class managing all 3d elements
48 * \author Matthieu 'TrapII' Besson
49 * \author Nevrax France
50 * \date 2003
52 class CInterface3DScene : public CInterfaceGroup
55 public:
57 CInterface3DScene(const TCtorParam &param);
58 virtual ~CInterface3DScene();
60 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
62 virtual void checkCoords();
64 virtual void updateCoords ();
66 virtual void draw ();
68 virtual bool handleEvent (const NLGUI::CEventDescriptor &eventDesc);
70 virtual CInterfaceElement* getElement (const std::string &id);
72 NL3D::UScene *getScene() { return _Scene; }
74 std::string getCurrentCamera() const;
75 void setCurrentCamera(const std::string &sCameraName);
77 std::string getCurrentClusterSystem () const;
78 void setCurrentClusterSystem(const std::string &sCameraName);
80 float getRotFactor() const { return _RotZFactor; }
81 void setRotFactor(float f) { _RotZFactor = f; }
83 void setFlareContext(uint context) { _Scene->setFlareContext(context); }
85 float getDistLimitMin() const { return _DistLimitMin;}
86 void setDistLimitMin(float limitMin) { _DistLimitMin = limitMin;}
88 float getDistLimitMax() const { return _DistLimitMax;}
89 void setDistLimitMax(float limitMax) { _DistLimitMax = limitMax;}
91 int luaGetElement(CLuaState &ls);
93 REFLECT_EXPORT_START(CInterface3DScene, CInterfaceGroup)
94 REFLECT_LUA_METHOD ("getElement", luaGetElement);
95 REFLECT_STRING ("curcam", getCurrentCamera, setCurrentCamera);
96 REFLECT_STRING ("curcs", getCurrentClusterSystem, setCurrentClusterSystem);
97 REFLECT_FLOAT ("rotzfactor", getRotFactor, setRotFactor);
98 REFLECT_FLOAT ("distlimitmin", getDistLimitMin, setDistLimitMin);
99 REFLECT_FLOAT ("distlimitmax", getDistLimitMax, setDistLimitMax);
100 REFLECT_EXPORT_END
102 void remove(NL3D::UInstanceGroup *pIG);
104 uint getCharacter3DCount() const { return (uint)_Characters.size(); }
105 CInterface3DCharacter *getCharacter3D(uint index);
107 CInterface3DCamera *getCamera(uint index);
109 protected:
111 // If this value is not NULL the current scene is just a view onto another one
112 CInterface3DScene *_Ref3DScene;
114 // Parsed properties
115 NL3D::UScene *_Scene; // The scene containing all the 3D elements
116 uint _CurrentCamera;
117 uint _CurrentCS; // Current Cluster System
118 // The AutoAnimSet (if some auto_anim)
119 NL3D::UAnimationSet *_AutoAnimSet;
121 std::vector<CInterface3DCharacter*> _Characters;
122 std::vector<CInterface3DShape*> _Shapes;
123 std::vector<CInterface3DIG*> _IGs;
124 std::vector<CInterface3DCamera*> _Cameras;
125 std::vector<CInterface3DLight*> _Lights;
126 std::vector<CInterface3DFX*> _FXs;
128 // Mouse event handling
129 bool _UserInteraction;
130 float _RotZLimitMin, _RotZLimitMax;
131 float _RotZFactor;
132 float _RotYLimitMin, _RotYLimitMax;
133 float _RotYFactor;
135 float _DistLimitMin, _DistLimitMax;
136 float _DistFactor;
138 bool _MouseLDown, _MouseRDown;
139 sint32 _MouseLDownX, _MouseRDownX;
140 sint32 _MouseLDownY, _MouseRDownY;
142 void mouseLMove (sint32 dx, sint32 dy);
143 void mouseRMove (sint32 dx, sint32 dy);
148 * class managing character 3d elements
149 * \author Matthieu 'TrapII' Besson
150 * \author Nevrax France
151 * \date 2003
153 class CInterface3DCharacter : public CInterfaceElement
155 public:
156 CInterface3DCharacter();
157 virtual ~CInterface3DCharacter();
159 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
161 virtual void checkCoords();
163 void setClusterSystem (NL3D::UInstanceGroup *pIG);
165 float getRotX () const;
166 float getRotY () const;
167 float getRotZ () const;
169 void setRotX (float f);
170 void setRotY (float f);
171 void setRotZ (float f);
173 float getPosX () const;
174 float getPosY () const;
175 float getPosZ () const;
177 void setPosX (float f);
178 void setPosY (float f);
179 void setPosZ (float f);
181 float getHeadX () const;
182 float getHeadY () const;
183 float getHeadZ () const;
185 void setHeadX (float /* f */) {}
186 void setHeadY (float /* f */) {}
187 void setHeadZ (float /* f */) {}
189 sint32 getAnim () const {return 0;}
190 void setAnim (sint32 anim);
192 CCharacter3D * getCharacter3D() { return _Char3D; }
194 void setPeople(const std::string & people);
195 std::string getPeople() const;
197 void setSex(bool male);
198 bool getSex() const;
200 void setupCharacter3D(sint32 slot);
201 int luaSetupCharacter3D(CLuaState &ls);
203 // active/inactive LOD of skeleton
204 int luaEnableLOD(CLuaState &ls);
207 REFLECT_EXPORT_START(CInterface3DCharacter, CInterfaceElement)
208 REFLECT_LUA_METHOD("setupCharacter3D", luaSetupCharacter3D);
209 REFLECT_LUA_METHOD("enableLOD", luaEnableLOD);
210 REFLECT_FLOAT ("headx", getHeadX, setHeadX);
211 REFLECT_FLOAT ("heady", getHeadY, setHeadY);
212 REFLECT_FLOAT ("headz", getHeadZ, setHeadZ);
213 REFLECT_FLOAT ("posx", getPosX, setPosX);
214 REFLECT_FLOAT ("posy", getPosY, setPosY);
215 REFLECT_FLOAT ("posz", getPosZ, setPosZ);
216 REFLECT_FLOAT ("rotx", getRotX, setRotX);
217 REFLECT_FLOAT ("roty", getRotY, setRotY);
218 REFLECT_FLOAT ("rotz", getRotZ, setRotZ);
219 REFLECT_SINT32 ("anim", getAnim, setAnim);
220 REFLECT_STRING ("people", getPeople, setPeople);
221 REFLECT_BOOL ("sex", getSex, setSex);
222 REFLECT_EXPORT_END
224 protected:
225 CCharacter3D *_Char3D;
226 std::string _DBLink;
230 * class managing shape instance 3d elements
231 * \author Matthieu 'TrapII' Besson
232 * \author Nevrax France
233 * \date 2003
235 class CInterface3DShape : public CInterfaceElement
237 public:
238 CInterface3DShape()
240 _Instance = NULL;
241 _PlayListManager = NULL;
242 _AnimationSet = NULL;
243 _PlayList = NULL;
244 _Pos = NLMISC::CVector(0,0,0);
245 _Rot = NLMISC::CVector(0,0,0);
248 virtual ~CInterface3DShape();
250 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
251 virtual void checkCoords();
253 NL3D::UInstance getShape() { return _Instance; }
255 float getPosX () const;
256 float getPosY () const;
257 float getPosZ () const;
259 void setPosX (float f);
260 void setPosY (float f);
261 void setPosZ (float f);
263 float getRotX () const;
264 float getRotY () const;
265 float getRotZ () const;
267 void setRotX (float f);
268 void setRotY (float f);
269 void setRotZ (float f);
271 std::string getName() const;
272 void setName (const std::string &ht);
274 std::string getTextures() const;
275 void setTextures (const std::string &textures);
277 std::string getSkeleton() const;
278 void setSkeleton (const std::string &skeleton);
280 std::string getAnim() const;
281 void setAnim (const std::string &anim);
283 float getBBoxSizeX () const;
284 float getBBoxSizeY () const;
285 float getBBoxSizeZ () const;
289 REFLECT_EXPORT_START(CInterface3DShape, CInterfaceElement)
290 REFLECT_FLOAT("getBBoxSizeX", getBBoxSizeX, setPosX);
291 REFLECT_FLOAT("getBBoxSizeY", getBBoxSizeY, setPosX);
292 REFLECT_FLOAT("getBBoxSizeZ", getBBoxSizeZ, setPosX);
293 REFLECT_FLOAT ("posx", getPosX, setPosX);
294 REFLECT_FLOAT ("posy", getPosY, setPosY);
295 REFLECT_FLOAT ("posz", getPosZ, setPosZ);
296 REFLECT_FLOAT ("rotx", getRotX, setRotX);
297 REFLECT_FLOAT ("roty", getRotY, setRotY);
298 REFLECT_FLOAT ("rotz", getRotZ, setRotZ);
299 REFLECT_STRING ("name", getName, setName);
300 REFLECT_STRING("textures", getTextures, setTextures);
301 REFLECT_STRING("skeleton", getSkeleton, setSkeleton);
302 REFLECT_STRING("anim", getAnim, setAnim);
303 REFLECT_EXPORT_END
305 protected:
307 NL3D::UInstance _Instance;
308 NLMISC::CVector _Pos;
309 NLMISC::CVector _Rot;
310 std::string _Name;
311 std::string _Textures;
312 std::string _SkeletonName;
313 std::string _Anim;
314 NL3D::USkeleton _Skeleton;
315 NL3D::UPlayListManager *_PlayListManager;
316 NL3D::UAnimationSet *_AnimationSet;
317 NL3D::UPlayList *_PlayList;
321 * class managing instance group 3d elements
322 * \author Matthieu 'TrapII' Besson
323 * \author Nevrax France
324 * \date 2003
326 class CInterface3DIG : public CInterfaceElement
328 public:
329 CInterface3DIG()
331 _IG = NULL;
332 _Pos = NLMISC::CVector(0,0,0);
333 _Rot = NLMISC::CVector(0,0,0);
336 virtual ~CInterface3DIG();
338 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
340 NL3D::UInstanceGroup *getIG() { return _IG; }
342 float getPosX () const;
343 float getPosY () const;
344 float getPosZ () const;
346 void setPosX (float f);
347 void setPosY (float f);
348 void setPosZ (float f);
350 float getRotX () const;
351 float getRotY () const;
352 float getRotZ () const;
354 void setRotX (float f);
355 void setRotY (float f);
356 void setRotZ (float f);
358 std::string getName() const;
359 void setName (const std::string &ht);
361 REFLECT_EXPORT_START(CInterface3DIG, CInterfaceElement)
362 REFLECT_FLOAT ("posx", getPosX, setPosX);
363 REFLECT_FLOAT ("posy", getPosY, setPosY);
364 REFLECT_FLOAT ("posz", getPosZ, setPosZ);
365 REFLECT_FLOAT ("rotx", getRotX, setRotX);
366 REFLECT_FLOAT ("roty", getRotY, setRotY);
367 REFLECT_FLOAT ("rotz", getRotZ, setRotZ);
368 REFLECT_STRING ("name", getName, setName);
369 REFLECT_EXPORT_END
371 protected:
373 NL3D::UInstanceGroup *_IG;
374 NLMISC::CVector _Pos;
375 NLMISC::CVector _Rot;
376 std::string _Name;
380 * class managing camera 3d elements
381 * \author Matthieu 'TrapII' Besson
382 * \author Nevrax France
383 * \date 2003
385 class CInterface3DCamera : public CInterfaceElement
388 public:
390 CInterface3DCamera()
392 _Rot = NLMISC::CVector(0,0,0);
393 _Pos = NLMISC::CVector(0,0,0);
394 _Target = NLMISC::CVector(0,0,1);
395 _FOV = 36.0f;
396 _Roll = 0;
397 _Dist = 0;
400 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
401 float getFOV() { return _FOV; }
402 NLMISC::CVector getPos() { return _Pos; }
403 NLMISC::CVector getTarget() { return _Target; }
405 void setRoll(float f) { _Roll = f; }
406 float getRoll() const { return _Roll; }
407 void setFOV(float f) { _FOV = f; }
408 float getFOV() const { return _FOV; }
410 void setPosX(float f) { _Pos.x = f; _Dist = (_Pos-_Target).norm(); }
411 void setPosY(float f) { _Pos.y = f; _Dist = (_Pos-_Target).norm(); }
412 void setPosZ(float f) { _Pos.z = f; _Dist = (_Pos-_Target).norm(); }
414 float getPosX() const { return _Pos.x; }
415 float getPosY() const { return _Pos.y; }
416 float getPosZ() const { return _Pos.z; }
418 void setTgtX(float f) { _Target.x = f; _Dist = (_Pos-_Target).norm(); }
419 void setTgtY(float f) { _Target.y = f; _Dist = (_Pos-_Target).norm(); }
420 void setTgtZ(float f) { _Target.z = f; _Dist = (_Pos-_Target).norm(); }
422 float getTgtX() const { return _Target.x; }
423 float getTgtY() const { return _Target.y; }
424 float getTgtZ() const { return _Target.z; }
426 float getRotZ() const { return _Rot.z; }
427 void setRotZ(float f) { _Rot.z = f; }
429 float getRotY() const { return _Rot.y; }
430 void setRotY(float f) { _Rot.y = f; }
432 float getDist() const { return _Dist; }
433 void setDist(float f) { _Dist = f; }
435 REFLECT_EXPORT_START(CInterface3DCamera, CInterfaceElement)
436 REFLECT_FLOAT ("posx", getPosX, setPosX);
437 REFLECT_FLOAT ("posy", getPosY, setPosY);
438 REFLECT_FLOAT ("posz", getPosZ, setPosZ);
439 REFLECT_FLOAT ("tgtx", getTgtX, setTgtX);
440 REFLECT_FLOAT ("tgty", getTgtY, setTgtY);
441 REFLECT_FLOAT ("tgtz", getTgtZ, setTgtZ);
442 REFLECT_FLOAT ("rotz", getRotZ, setRotZ);
443 REFLECT_FLOAT ("roty", getRotY, setRotY);
444 REFLECT_FLOAT ("dist", getDist, setDist);
445 REFLECT_FLOAT ("fov", getFOV, setFOV);
446 REFLECT_FLOAT ("roll", getRoll, setRoll);
447 REFLECT_EXPORT_END
449 void reset(); // Reset user interaction
451 protected:
453 NLMISC::CVector _Rot;
454 float _Dist;
456 NLMISC::CVector _Pos;
457 NLMISC::CVector _Target;
458 float _Roll;
459 float _FOV;
463 * class managing light 3d elements
464 * \author Matthieu 'TrapII' Besson
465 * \author Nevrax France
466 * \date 2003
468 class CInterface3DLight : public CInterfaceElement
470 public:
471 CInterface3DLight()
473 _Pos = NLMISC::CVector(0,0,0);
474 _Near = 1.0f;
475 _Far = 4.0f;
476 _Color = NLMISC::CRGBA(255,255,255);
477 _Light = NULL;
480 virtual ~CInterface3DLight();
482 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
484 float getPosX() const { return _Pos.x; }
485 float getPosY() const { return _Pos.y; }
486 float getPosZ() const { return _Pos.z; }
488 void setPosX(float f);
489 void setPosY(float f);
490 void setPosZ(float f);
492 float getNear() const { return _Near; }
493 float getFar() const { return _Far; }
495 void setNear(float f);
496 void setFar(float f);
498 sint32 getColR() const { return _Color.R; }
499 sint32 getColG() const { return _Color.G; }
500 sint32 getColB() const { return _Color.B; }
502 void setColR(sint32 f);
503 void setColG(sint32 f);
504 void setColB(sint32 f);
506 REFLECT_EXPORT_START(CInterface3DLight, CInterfaceElement)
507 REFLECT_FLOAT ("posx", getPosX, setPosX);
508 REFLECT_FLOAT ("posy", getPosY, setPosY);
509 REFLECT_FLOAT ("posz", getPosZ, setPosZ);
510 REFLECT_FLOAT ("near", getNear, setNear);
511 REFLECT_FLOAT ("far", getFar, setFar);
512 REFLECT_SINT32 ("colr", getColR, setColR);
513 REFLECT_SINT32 ("colg", getColG, setColG);
514 REFLECT_SINT32 ("colb", getColB, setColB);
515 REFLECT_EXPORT_END
517 protected:
519 NLMISC::CVector _Pos;
520 float _Near, _Far;
521 NLMISC::CRGBA _Color;
523 NL3D::UPointLight _Light;
528 * class managing fx 3d elements
529 * \author Matthieu 'TrapII' Besson
530 * \author Nevrax France
531 * \date 2003
533 class CInterface3DFX : public CInterfaceElement
535 public:
536 CInterface3DFX()
538 _Pos = NLMISC::CVector(0,0,0);
539 _FX = NULL;
542 virtual ~CInterface3DFX();
544 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
546 virtual void checkCoords();
548 NL3D::UParticleSystemInstance getPS() { return _FX; }
550 float getPosX () const;
551 float getPosY () const;
552 float getPosZ () const;
554 void setPosX (float f);
555 void setPosY (float f);
556 void setPosZ (float f);
558 float getRotX () const;
559 float getRotY () const;
560 float getRotZ () const;
562 void setRotX (float f);
563 void setRotY (float f);
564 void setRotZ (float f);
566 std::string getName() const;
567 void setName (const std::string &ht);
569 bool getStarted() const;
570 void setStarted (bool b);
572 REFLECT_EXPORT_START(CInterface3DFX, CInterfaceElement)
573 REFLECT_FLOAT ("posx", getPosX, setPosX);
574 REFLECT_FLOAT ("posy", getPosY, setPosY);
575 REFLECT_FLOAT ("posz", getPosZ, setPosZ);
576 REFLECT_FLOAT ("rotx", getRotX, setRotX);
577 REFLECT_FLOAT ("roty", getRotY, setRotY);
578 REFLECT_FLOAT ("rotz", getRotZ, setRotZ);
579 REFLECT_STRING ("name", getName, setName);
580 REFLECT_BOOL ("started", getStarted, setStarted);
581 REFLECT_EXPORT_END
583 protected:
585 NL3D::UParticleSystemInstance _FX;
587 NLMISC::CVector _Pos;
588 NLMISC::CVector _Rot;
589 std::string _Name;
593 #endif // RZ_INTERFACE_SCENE_3D_H
595 /* end of interface_3d_scene.h */