ScummVM API documentation
xmodel.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
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 General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This file is based on WME.
24  * http://dead-code.org/redir.php?target=wme
25  * Copyright (c) 2003-2013 Jan Nedoma and contributors
26  */
27 
28 #ifndef WINTERMUTE_XMODEL_H
29 #define WINTERMUTE_XMODEL_H
30 
31 #include "engines/wintermute/base/base_object.h"
32 #include "engines/wintermute/base/base_sprite.h"
33 #include "engines/wintermute/coll_templ.h"
34 #include "engines/wintermute/math/rect32.h"
35 #include "engines/wintermute/video/video_theora_player.h"
36 #include "engines/wintermute/utils/utils.h"
37 
38 #include "math/matrix4.h"
39 #include "math/vector3d.h"
40 #include "math/vector4d.h"
41 
42 namespace Wintermute {
43 
44 class AnimationChannel;
45 class AnimationSet;
46 class FrameNode;
47 class Material;
48 class ShadowVolume;
49 class XFileData;
50 
52  Common::String _name;
53  Material *_material;
54 };
55 
56 #define X_NUM_ANIMATION_CHANNELS 10
57 
58 class XModel : public BaseObject {
59 private:
60  // the D3DX effect stuff is missing here
61  // at the moment I am not aware of whether this is used
62  // in Alpha Polaris or any other WME game
63  // if it is, then this would mean a decent amount of work
64  // since we would need to parse and emulate D3DX effects in OpenGL
65  class XModelMatSprite {
66  public:
67  char *_matName;
68  BaseSprite *_sprite;
69  VideoTheoraPlayer *_theora;
70 
71  XModelMatSprite() {
72  _matName = nullptr;
73  _sprite = nullptr;
74  _theora = nullptr;
75  }
76 
77  XModelMatSprite(const char *matName, BaseSprite *sprite) {
78  _theora = nullptr;
79  _matName = nullptr;
80  BaseUtils::setString(&_matName, matName);
81  _sprite = sprite;
82  }
83 
84  XModelMatSprite(const char *matName, VideoTheoraPlayer *theora) {
85  _sprite = nullptr;
86  _matName = nullptr;
87  BaseUtils::setString(&_matName, matName);
88  _theora = theora;
89  }
90 
91  ~XModelMatSprite() {
92  delete[] _matName;
93  delete _sprite;
94  delete _theora;
95  }
96 
97  bool setSprite(BaseSprite *sprite) {
98  delete _theora;
99  _theora = nullptr;
100  delete _sprite;
101  _sprite = sprite;
102 
103  return true;
104  }
105 
106  bool setTheora(VideoTheoraPlayer *theora) {
107  delete _theora;
108  delete _sprite;
109  _sprite = nullptr;
110  _theora = theora;
111 
112  return true;
113  }
114 
115  bool persist(BasePersistenceManager *persistMgr) {
116  persistMgr->transferCharPtr(TMEMBER(_matName));
117  persistMgr->transferPtr(TMEMBER(_sprite));
118 
119  persistMgr->transferPtr(TMEMBER(_theora));
120 
121  return true;
122  }
123  };
124 
125 public:
126  // default ticks per second for .X models seems to be 4800
127  // not sure if this is truly documented anywhere, though
128  // on the other hand, wme chooses the same value,
129  // so should be fine for our purposes
130  const static int kDefaultTicksPerSecond = 4800;
131 
132  DECLARE_PERSISTENT(XModel, BaseObject)
133 
134  XModel(BaseGame *inGame, BaseObject *owner);
135  virtual ~XModel();
136 
137  XModel *_parentModel;
138 
139  bool loadFromFile(const Common::String &filename, XModel *parentModel = nullptr);
140  bool mergeFromFile(const Common::String &filename);
141 
142  bool update() override;
143  bool render();
144  bool renderFlatShadowModel();
145  bool reset();
146 
147  bool updateShadowVol(ShadowVolume *shadow, Math::Matrix4 &modelMat, const Math::Vector3d &light, float extrusionDepth);
148 
149  bool playAnim(int channel, const Common::String &anim, uint32 transitionTime = 0, bool forceReset = false, uint32 stopTransitionTime = 0);
150  bool isAnimPending(char *animName = nullptr);
151  bool isAnimPending(int channel, const char *animName = nullptr);
152 
153  bool isTransparentAt(int x, int y);
154 
155  static bool loadName(BaseNamedObject *obj, XFileData *data);
156  static bool loadName(Common::String &targetStr, XFileData *data);
157 
158  bool loadAnimationSet(const Common::String &filename, XFileData *xobj);
159  bool loadAnimation(const Common::String &filename, XFileData *xobj, AnimationSet *parentAnimSet = nullptr);
160 
161  Math::Matrix4 _lastWorldMat;
162  Rect32 _boundingRect;
163  BaseObject *_owner;
164 
165  bool parseAnim(byte *buffer);
166  bool parseEvent(AnimationSet *anim, byte *buffer);
167  AnimationSet *getAnimationSetByName(const Common::String &name);
168 
169  bool stopAnim(int channel, uint32 transitionTime);
170  bool stopAnim(uint32 transitionTime);
171 
172  Math::Matrix4 *getBoneMatrix(const char *boneName);
173  FrameNode *getRootFrame();
174 
175  bool setMaterialSprite(const char *materialName, const char *spriteFilename);
176  bool setMaterialTheora(const char *materialName, const char *theoraFilename);
177  bool initializeSimple();
178 
179  bool invalidateDeviceObjects() override;
180  bool restoreDeviceObjects() override;
181 
182  bool unloadAnimation(const char *animName);
183 
184  uint32 _ticksPerSecond;
185 
186  BaseArray<AnimationSet *> _animationSets;
187 
188 private:
189  void cleanup(bool complete = true);
190  bool findBones(bool animOnly = false, XModel *parentModel = nullptr);
191 
192  void updateBoundingRect();
193  void static inline updateRect(Rect32 *rc, int32 x, int32 y);
194  Rect32 _drawingViewport;
195  Math::Matrix4 _lastViewMat;
196  Math::Matrix4 _lastProjMat;
197  int32 _lastOffsetX;
198  int32 _lastOffsetY;
199 
200  Math::Vector3d _BBoxStart;
201  Math::Vector3d _BBoxEnd;
202 
203  Common::Array<MaterialReference> _materialReferences;
204 
205 protected:
206  BaseArray<const char*> _mergedModels;
207  AnimationChannel *_channels[X_NUM_ANIMATION_CHANNELS];
208 
209  FrameNode *_rootFrame;
210 
211  BaseArray<XModelMatSprite *> _matSprites;
212 };
213 
214 } // namespace Wintermute
215 
216 #endif
Definition: base_game.h:75
Definition: str.h:59
Definition: base_persistence_manager.h:55
Definition: array.h:52
Definition: coll_templ.h:115
Definition: xanimation_set.h:42
Definition: xmodel.h:51
Definition: video_theora_player.h:41
Definition: xmodel.h:58
Definition: rect32.h:60
Definition: 3dshadow_volume.h:48
Definition: xanimation_channel.h:37
Definition: coll_templ.h:63
Definition: base_named_object.h:36
Definition: xframe_node.h:46
Definition: xmaterial.h:76
Definition: base_sprite.h:40
Definition: xfile_loader.h:452
Definition: base_object.h:57
Definition: achievements_tables.h:27