30 #include <SDL_timer.h> 33 #include "glm/gtc/type_ptr.hpp" 34 #include "glm/gtc/matrix_transform.hpp" 35 #include "glm/gtx/matrix_interpolation.hpp" 67 _positionRelative(false),
70 _drawSkeletonInvisible(false) {
104 for (NodeList::iterator n = (*s)->nodeList.begin(); n != (*s)->nodeList.end(); ++n)
113 GfxMan.registerAnimatedModel(
this);
117 GfxMan.unregisterAnimatedModel(
this);
136 if ((x < minX) || (x > maxX))
138 if ((y < minY) || (y > maxY))
155 bool Model::isIn(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2)
const {
187 for (NodeList::iterator n = (*s)->nodeList.begin(); n != (*s)->nodeList.end(); ++n)
188 (*n)->setEnvironmentMap(environmentMap);
270 glm::mat4 orientation;
273 orientation = glm::rotate(orientation,
277 if (x != 0 || y != 0 || z != 0)
278 orientation = glm::rotate(orientation,
283 glm::axisAngle(orientation, axis, angle);
330 StateMap::iterator s =
_stateMap.find(name);
410 StateMap::const_iterator s =
_stateMap.find(stateName);
414 State *state = s->second;
416 NodeMap::iterator n = state->
nodeMap.find(node);
417 if (n == state->
nodeMap.end()) {
428 StateMap::const_iterator s =
_stateMap.find(stateName);
432 State *state = s->second;
434 NodeMap::const_iterator n = state->
nodeMap.find(node);
435 if (n == state->
nodeMap.end()) {
448 for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
461 for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
482 std::map<Common::UString, Model *>::iterator m =
_attachedModels.find(nodeName);
490 _attachedModels.insert(std::pair<Common::UString, Model *>(nodeName, model));
577 const float cameraX = -
CameraMan.getPosition()[0];
578 const float cameraY = -
CameraMan.getPosition()[1];
579 const float cameraZ = -
CameraMan.getPosition()[2];
581 const float x =
ABS(center[3][0] - cameraX);
582 const float y =
ABS(center[3][1] - cameraY);
583 const float z =
ABS(center[3][2] - cameraZ);
595 for (std::map<Common::UString, Model *>::iterator m =
_attachedModels.begin();
597 m->second->flushNodeBuffers();
604 for (NodeList::iterator n = nodes.begin();
607 (*n)->flushBuffers();
612 std::map<Common::UString, Model *>::iterator m =
_attachedModels.find(node);
623 c->second->manageAnimations(dt);
626 for (std::map<Common::UString, Model *>::iterator m =
_attachedModels.begin();
628 m->second->manageAnimations(dt);
677 (*n)->renderImmediate(transform);
692 (*n)->queueRender(transform);
700 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
705 float minX, minY, minZ, maxX, maxY, maxZ;
706 object.
getMin(minX, minY, minZ);
707 object.getMax(maxX, maxY, maxZ);
710 _boundTransform *= glm::translate(glm::mat4(), glm::vec3((maxX + minX) * 0.5f, (maxY + minY) * 0.5f, (maxZ + minZ) * 0.5f));
711 _boundTransform *= glm::scale(glm::mat4(), glm::vec3((maxX - minX) * 0.5f, (maxY - minY) * 0.5f, (maxZ - minZ) * 0.5f));
720 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
725 float minX, minY, minZ, maxX, maxY, maxZ;
726 object.
getMin(minX, minY, minZ);
727 object.getMax(maxX, maxY, maxZ);
774 tform = glm::translate(tform, glm::vec3((maxX + minX) * 0.5f, (maxY + minY) * 0.5f, (maxZ + minZ) * 0.5f));
775 tform = glm::scale(tform, glm::vec3((maxX - minX) * 0.5f, (maxY - minY) * 0.5f, (maxZ - minZ) * 0.5f));
786 glDisable(GL_DEPTH_TEST);
792 glEnable(GL_DEPTH_TEST);
794 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
817 for (NodeList::iterator n = (*s)->rootNodes.begin(); n != (*s)->rootNodes.end(); ++n)
818 (*n)->orderChildren();
821 c->second->playDefaultAnimation();
837 stateNames->push_back((*s)->name);
844 stateNames->unique();
859 (*n)->createAbsoluteBound(position);
864 float minX, minY, minZ, maxX, maxY, maxZ;
868 _center[0] = minX + ((maxX - minX) / 2.0f);
869 _center[1] = minY + ((maxY - minY) / 2.0f);
870 _center[2] = minZ + ((maxZ - minZ) / 2.0f);
894 if (usedCount != allocatedCount)
895 warning(
"Model::readArrayDef(): usedCount != allocatedCount (%d, %d)",
896 usedCount, allocatedCount);
905 const size_t pos = stream.
seek(offset);
907 values.resize(count);
908 for (
uint32 i = 0; i < count; i++)
916 uint32 offset,
uint32 count, std::vector<uint32> &values);
919 uint32 offset,
uint32 count, std::vector<float> &values);
static void readValue(Common::SeekableReadStream &stream, uint32 &value)
Shader::ShaderRenderable _boundRenderable
const Common::UString & getState() const
Return the name of the current state.
A node within an animation.
virtual void show()
Show the object.
NodeMap nodeMap
The nodes within the state, indexed by name.
void getPosition(float &x, float &y, float &z) const
Get the current position of the model.
float getHeight() const
Get the height of the model's bounding box.
bool isIn(float x, float y) const
void playAnimation(const Common::UString &anim, bool restart=true, float length=0.0f, float speed=1.0f)
Play a named animation.
Only render transparent parts.
Model * getAttachedModel(const Common::UString &node)
Common::BoundingBox _absoluteBoundBox
The model's box after translate/rotate.
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
virtual void hide()
Hide the object.
An element of the front GUI.
#define START_IGNORE_IMPLICIT_FALLTHROUGH
void scale(float x, float y, float z)
Scale the model, relative to its current scale.
A class holding an UTF-8 string.
#define TextureMan
Shortcut for accessing the texture manager.
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
An animation to be applied to a model.
void advanceTime(float dt)
Advance time (used by renderables with animations).
double _distance
The distance of the object from the viewer.
Utility functions for debug output.
#define SurfaceMan
Shortcut for accessing the shader manager.
float getDepth() const
Get the depth of the bounding box.
float getWidth() const
Get the width of the model's bounding box.
std::map< Common::UString, Model * > _attachedModels
The Aurora texture manager.
Common::UString name
The state's name.
A real object in the game world.
float getAnimationScale(const Common::UString &anim)
Determine what animation scaling applies.
NodeList rootNodes
The nodes in the state without a parent.
void hide()
Hide the object.
static std::list< ModelNode * > kEmptyNodeList
static const Common::UString kNoState
State * _currentState
The current state.
void move(float x, float y, float z)
Move the model, relative to its current position.
void unlockFrameIfVisible()
void lockFrameIfVisible()
std::list< Common::UString > _stateNames
All state names.
void setSurface(Shader::ShaderSurface *surface, bool rebuildProgram=true)
const Common::UString & getName() const
Get the model's name.
void addDefaultAnimation(const Common::UString &name, uint8 probability)
A bounding box around 3D points.
void clearDefaultAnimations()
void addAnimationChannel(AnimationChannelName name)
void setMesh(Mesh::Mesh *mesh)
void playDefaultAnimation()
Common::UString _name
The model's name.
float getHeight() const
Get the height of the bounding box.
void setState(const Common::UString &name="")
Set the current animation state.
void createAbsolutePosition()
Common::BoundingBox _boundBox
The model's bounding box.
void getMin(float &x, float &y, float &z) const
void setOrientation(float x, float y, float z, float angle)
Set the current orientation of the model.
void drawBound(bool enabled)
Should a bounding box be drawn around this model?
float _position[3]
Model's position.
AnimationMap _animationMap
Map of all animations in this model.
ModelType
The display type of a model.
ModelType _type
The model's type.
bool _drawSkeletonInvisible
void getMax(float &x, float &y, float &z) const
float getWidth() const
Get the width of the bounding box.
void getScale(float &x, float &y, float &z) const
Get the current scale of the model.
"GGraphics", global, non-engine graphics.
static void readArray(Common::SeekableReadStream &stream, uint32 offset, uint32 count, std::vector< T > &values)
Model(ModelType type=kModelTypeObject)
A node within a 3D model.
void createStateNamesList(std::list< Common::UString > *stateNames=0)
Create the list of all state names.
void rotate(float x, float y, float z, float angle)
Rotate the model, relative to its current orientation.
void transform(const glm::mat4 &m)
bool hasNode(const Common::UString &node) const
Does the specified node exist in the current state?
bool isIn(float x, float y) const
Is that point within the model's bounding box?
The global shader material manager.
The global shader surface manager.
const std::list< ModelNode * > & getNodes()
Get all nodes in the current state.
#define MaterialMan
Shortcut for accessing the shader material manager.
void absolutize()
Apply the origin transformations directly to the coordinates.
NodeList nodeList
The nodes within the state.
void getAbsolutePosition(float &x, float &y, float &z) const
Get the position of the node after translate/rotate.
void warning(const char *s,...)
void setPosition(float x, float y, float z)
Set the current position of the model.
void playDefaultAnimation()
StateMap _stateMap
All states within this model, index by name.
AnimationChannel * getAnimationChannel(AnimationChannelName name)
Basic reading stream interfaces.
std::list< ModelNode * > NodeList
float _scale[3]
Model's scale.
#define STOP_IGNORE_IMPLICIT_FALLTHROUGH
void render(RenderPass pass)
Render the object.
FORCEINLINE float readIEEEFloatLE()
Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it...
#define MeshMan
Shortcut for accessing the shader manager.
void add(float x, float y, float z)
An object that can be displayed by the graphics manager.
AnimationChannelMap _animationChannels
float _orientation[4]
Model's orientation.
void createBound()
Create the model's bounding box.
float getDepth() const
Get the depth of the model's bounding box.
void getTooltipAnchor(float &x, float &y, float &z) const
Get the point where the feedback tooltip is anchored.
void show()
Show the object.
void playAnimation(const Common::UString &anim, bool restart=true, float length=0.0f, float speed=1.0f)
bool isVisible() const
Is the object visible?
const std::list< Common::UString > & getStates() const
Return a list of all animation state names.
static void readArrayDef(Common::SeekableReadStream &stream, uint32 &offset, uint32 &count)
void setEnvironmentMap(const Common::UString &environmentMap="")
Change the environment map on this model.
float _center[3]
Model's center.
void getOrientation(float &x, float &y, float &z, float &angle) const
Get the current orientation of the model.
Model * _superModel
The actual super model.
glm::mat4 _absolutePosition
void manageAnimations(float dt)
#define CameraMan
Shortcut for accessing the camera manager.
Compiler-specific defines to mark an implicit switch-case fallthrough.
static float rad2deg(float rad)
bool hasAnimation(const Common::UString &anim) const
Does this model have this named animation?
void finalize()
Finalize the loading procedure.
void addDefaultAnimation(const Common::UString &anim, uint8 probability)
ModelType getType() const
Return the model's type.
uint16 getNodeNumber() const
Animation * getAnimation(const Common::UString &anim)
Get the animation from its name.
friend class AnimationChannel
void flushNodeBuffers()
Apply buffered changes to model nodes position and geometry.
void calculateDistance()
Calculate the object's distance.
void queueRender(const glm::mat4 &parentTransform)
Queue the object for later rendering.
Model * _attachedModel
The model that is attached to this node.
ModelNode * getNode(const Common::UString &node)
Get the specified node, from the current state.
StateList _stateList
All states within this model.
void renderImmediate(const glm::mat4 &tform, float alpha=1.0f)
float _animationScale
The scale of the animation.
static float deg2rad(float deg)
void clearDefaultAnimations()
Interface for a seekable & readable data stream.
void setScale(float x, float y, float z)
Set the current scale of the model.
#define GfxMan
Shortcut for accessing the graphics manager.
void drawSkeleton(bool enabled, bool showInvisible)
Should a skeleton showing the nodes and their relation be drawn inside the model? ...
void attachModel(const Common::UString &nodeName, Model *model)
Add another model as a child to the named node.
Only render opaque parts.
void renderImmediate(const glm::mat4 &parentTransform)
For shader based systems, don't sort anything, render this right_now.
void setSkinned(bool skinned)
Set the flag if the model has skinned animations.
glm::mat4 _boundTransform
void setMaterial(Shader::ShaderMaterial *material, bool rebuildProgram=true)
#define RenderMan
Shortcut for accessing the render manager.