Cafu Engine
CompModel.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GUISYS_COMPONENT_MODEL_HPP_INCLUDED
8 #define CAFU_GUISYS_COMPONENT_MODEL_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 class AnimPoseT;
14 class CafuModelT;
15 
16 
17 namespace cf
18 {
19  namespace GuiSys
20  {
21  /// This component adds a 3D model to its window.
23  {
24  public:
25 
26  /// The constructor.
28 
29  /// The copy constructor.
30  /// @param Comp The component to create a copy of.
31  ComponentModelT(const ComponentModelT& Comp);
32 
33  /// The destructor.
35 
36  // Base class overrides.
37  ComponentModelT* Clone() const;
38  const char* GetName() const { return "Model"; }
39  void UpdateDependencies(WindowT* Window);
40  void Render() const;
41  void OnClockTickEvent(float t);
42 
43 
44  // The TypeSys related declarations for this class.
45  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
46  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
47  static const cf::TypeSys::TypeInfoT TypeInfo;
48 
49 
50  protected:
51 
52  // The Lua API methods of this class.
53  static int GetNumAnims(lua_State* LuaState);
54  static int SetAnim(lua_State* LuaState);
55  static int GetNumSkins(lua_State* LuaState);
56  static int toString(lua_State* LuaState);
57 
58  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
59  static const char* DocClass;
60  static const cf::TypeSys::MethsDocT DocMethods[];
61  static const cf::TypeSys::VarsDocT DocVars[];
62 
63 
64  private:
65 
66  /// A variable of type std::string, specifically for model file names. It updates the related
67  /// model instance in the parent ComponentModelT whenever a new model file name is set.
68  class VarModelNameT : public TypeSys::VarT<std::string>
69  {
70  public:
71 
72  VarModelNameT(const char* Name, const std::string& Value, const char* Flags[], ComponentModelT& Comp);
73  VarModelNameT(const VarModelNameT& Var, ComponentModelT& Comp);
74 
75  // Base class overrides.
76  std::string GetExtraMessage() const { return m_ExtraMsg; }
77  void Serialize(cf::Network::OutStreamT& Stream) const; ///< See base class documentation for details!
78  void Deserialize(cf::Network::InStreamT& Stream);
79  void Set(const std::string& v);
80 
81 
82  private:
83 
84  ComponentModelT& m_Comp; ///< The parent ComponentModelT that contains this variable.
85  std::string m_ExtraMsg; ///< If the model could not be loaded in Set(), this message contains details about the problem.
86  };
87 
88 
89  /// A variable of type int, specifically for model animation sequence numbers. It updates the
90  /// related model pose in the parent ComponentModelT whenever a new sequence number is set.
91  class VarModelAnimNrT : public TypeSys::VarT<int>
92  {
93  public:
94 
95  VarModelAnimNrT(const char* Name, const int& Value, const char* Flags[], ComponentModelT& Comp);
96  VarModelAnimNrT(const VarModelAnimNrT& Var, ComponentModelT& Comp);
97 
98  // Base class overrides.
99  void Set(const int& v);
100  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const;
101 
102 
103  private:
104 
105  ComponentModelT& m_Comp; ///< The parent ComponentModelT that contains this variable.
106  };
107 
108 
109  /// A variable of type int, specifically for model skin numbers.
110  class VarModelSkinNrT : public TypeSys::VarT<int>
111  {
112  public:
113 
114  VarModelSkinNrT(const char* Name, const int& Value, const char* Flags[], ComponentModelT& Comp);
115  VarModelSkinNrT(const VarModelSkinNrT& Var, ComponentModelT& Comp);
116 
117  // Base class overrides.
118  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const;
119 
120 
121  private:
122 
123  ComponentModelT& m_Comp; ///< The parent ComponentModelT that contains this variable.
124  };
125 
126 
127  void FillMemberVars(); ///< A helper method for the constructors.
128  std::string SetModel(const std::string& FileName, std::string& Msg); ///< m_ModelName::Set() delegates here.
129  int SetAnimNr(int AnimNr, float BlendTime, bool ForceLoop); ///< m_ModelAnimNr::Set() and SetAnim(LuaState) delegate here.
130 
131  VarModelNameT m_ModelName; ///< The file name of the model.
132  VarModelAnimNrT m_ModelAnimNr; ///< The animation sequence number of the model.
133  VarModelSkinNrT m_ModelSkinNr; ///< The skin used for rendering the model.
134  TypeSys::VarT<Vector3fT> m_ModelPos; ///< The position of the model in world space.
135  TypeSys::VarT<float> m_ModelScale; ///< The scale factor applied to the model coordinates when converted to world space.
136  TypeSys::VarT<Vector3fT> m_ModelAngles; ///< The angles around the axes that determine the orientation of the model in world space.
137  TypeSys::VarT<Vector3fT> m_CameraPos; ///< The position of the camera in world space.
138 
139  const CafuModelT* m_Model; ///< The model instance, updated by changes to m_ModelName.
140  AnimPoseT* m_Pose; ///< The pose of the model.
141  };
142  }
143 }
144 
145 #endif
ComponentModelT * Clone() const
The virtual copy constructor.
Definition: CompModel.cpp:242
This class represents a native Cafu model.
Definition: Model_cmdl.hpp:45
void OnClockTickEvent(float t)
This method handles clock-tick events.
Definition: CompModel.cpp:319
void UpdateDependencies(WindowT *Window)
This method is called whenever something "external" to this component has changed: ...
Definition: CompModel.cpp:248
This is a "wrapper" around a normal C++ variable.
Definition: SetCompVar.hpp:15
This is the base class for the components that a window is composed/aggregated of.
Definition: CompBase.hpp:51
This class is used for reading data from a StateT instance (deserialization).
Definition: State.hpp:207
~ComponentModelT()
The destructor.
Definition: CompModel.cpp:235
ComponentModelT()
The constructor.
Definition: CompModel.cpp:185
void Render() const
This method implements the graphical output of this component.
Definition: CompModel.cpp:284
This class is used for writing data into a StateT instance (serialization).
Definition: State.hpp:81
This class represents a window of the GuiSys.
Definition: Window.hpp:54
This component adds a 3D model to its window.
Definition: CompModel.hpp:22
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompModel.hpp:58
const char * GetName() const
Returns the name of this component.
Definition: CompModel.hpp:38
This class describes a specific pose of an associated model.
Definition: AnimPose.hpp:35
Definition: TypeSys.hpp:52
Definition: TypeSys.hpp:57
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
Definition: TypeSys.hpp:68