diff --git a/costume.cpp b/costume.cpp index e8e87de9bbf..d4dd609ddfd 100644 --- a/costume.cpp +++ b/costume.cpp @@ -124,7 +124,6 @@ public: protected: std::string _filename; ResPtr _obj; - ResPtr _previousCmap; Model::HierNode *_hier; Matrix4 _matrix; }; @@ -216,7 +215,6 @@ ModelComponent::ModelComponent(Costume::Component *parent, int parentID, const c } else { _filename = filename; } - _previousCmap = NULL; if (prevComponent != NULL) { MainModelComponent *mmc = dynamic_cast(prevComponent); @@ -231,13 +229,9 @@ void ModelComponent::init() { // constructor before if (_obj == NULL) { CMap *cmap = this->cmap(); - // If we still don't have the necessary colormap - // then try the one from the previous costume - if (cmap == NULL && _previousCmap != NULL) - cmap = _previousCmap; - - // Get the default colormap if we still haven't - // found a valid colormap + + // Get the default colormap if we haven't found + // a valid colormap if (cmap == NULL) { if (debugLevel == DEBUG_MODEL || debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL) warning("No colormap specified for %s, using %s\n", _filename.c_str(), DEFAULT_COLORMAP); @@ -246,7 +240,12 @@ void ModelComponent::init() { } _obj = g_resourceloader->loadModel(_filename.c_str(), *cmap); _hier = _obj->copyHierarchy(); - reset(); + // Use parent availablity to decide whether to default the + // component to being visible + if (_parent == NULL || !_parent->visible()) + setKey(1); + else + setKey(0); } // If we're the child of a mesh component, put our nodes in the @@ -262,32 +261,13 @@ void ModelComponent::init() { } void ModelComponent::setKey(int val) { - MainModelComponent *mmc; - ModelComponent *moc; - MeshComponent *mc; - - _hier->_hierVisible = (val != 0); - // If we're making a model component visible then assume - // that the parent mesh object should also become visible - if (_parent == NULL || val == 0) - return; - mc = dynamic_cast(_parent); - if (mc == NULL) - return; - mc->node()->_meshVisible = true; - // Do the same thing with the parent of the mesh object - // but DO NOT handle the parent if it's a MMDL - if (mc->parent() == NULL) - return; - moc = dynamic_cast(mc->parent()); - mmc = dynamic_cast(mc->parent()); - if (moc == NULL || mmc != NULL) - return; - moc->_hier->_hierVisible = true; + _visible = (val != 0); + _hier->_hierVisible = _visible; } void ModelComponent::reset() { - _hier->_hierVisible = false; + _visible = false; + _hier->_hierVisible = _visible; } // Reset the hierarchy nodes for any keyframe animations (which @@ -318,11 +298,29 @@ ModelComponent::~ModelComponent() { delete[] _hier; } +void translateObject(Model::HierNode *node, bool reset) { + if (node->_parent != NULL) + translateObject(node->_parent, reset); + + if(reset) + g_driver->translateViewpoint(); + else + g_driver->translateViewpoint(node->_animPos / node->_totalWeight, node->_animPitch / node->_totalWeight, node->_animYaw / node->_totalWeight, node->_animRoll / node->_totalWeight); +} + void ModelComponent::draw() { - if (_parent == NULL) - // Otherwise it was already drawn by - // being included in the parent's hierarchy - _hier->draw(); + // If the object was drawn by being a component + // of it's parent then don't draw it + if (_parent != NULL && _parent->visible()) + return; + // Need to translate object to be in accordance + // with the setup of the parent + if (_hier->_parent != NULL) + translateObject(_hier->_parent, false); + _hier->draw(); + // Need to un-translate when done + if (_hier->_parent != NULL) + translateObject(_hier->_parent, true); } MainModelComponent::MainModelComponent(Costume::Component *parent, int parentID, const char *filename, Costume::Component *prevComponent, tag32 tag) : @@ -341,7 +339,8 @@ MainModelComponent::MainModelComponent(Costume::Component *parent, int parentID, void MainModelComponent::init() { ModelComponent::init(); - _hier->_hierVisible = true; + _visible = true; + _hier->_hierVisible = _visible; } void MainModelComponent::update() { @@ -353,7 +352,8 @@ void MainModelComponent::update() { } void MainModelComponent::reset() { - _hier->_hierVisible = true; + _visible = true; + _hier->_hierVisible = _visible; } MainModelComponent::~MainModelComponent() { @@ -721,6 +721,8 @@ Costume::~Costume() { } Costume::Component::Component(Component *parent, int parentID, tag32 tag) { + _visible = -1; + _previousCmap = NULL; _cmap = NULL; _cost = NULL; _parent = NULL; @@ -738,8 +740,16 @@ void Costume::Component::setColormap(CMap *c) { mc->resetColormap(); } +bool Costume::Component::visible() { + if (_visible == -1 && _parent != NULL) + return _parent->visible(); + return _visible; +} + CMap *Costume::Component::cmap() { - if (_cmap == NULL && _parent != NULL) + if (_cmap == NULL && _previousCmap != NULL) + return _previousCmap; + else if (_cmap == NULL && _parent != NULL) return _parent->cmap(); else if (_cmap == NULL && _parent == NULL && _cost != NULL) return _cost->_cmap; diff --git a/costume.h b/costume.h index a56926774ac..7d1d4e5a047 100644 --- a/costume.h +++ b/costume.h @@ -63,6 +63,7 @@ public: tag32 tag() { return _tag; } CMap *cmap(); void setColormap(CMap *c); + bool visible(); Component *parent() { return _parent; } virtual void setMatrix(Matrix4) { }; virtual void init() { } @@ -75,9 +76,9 @@ public: virtual ~Component() { } protected: - ResPtr _cmap; + ResPtr _cmap, _previousCmap; tag32 _tag; - int _parentID; + int _parentID, _visible; Component *_parent, *_child, *_sibling; Matrix4 _matrix; Costume *_cost; diff --git a/driver.h b/driver.h index cf5b5ab72ab..6938c93ea71 100644 --- a/driver.h +++ b/driver.h @@ -65,6 +65,9 @@ public: virtual void set3DMode() = 0; + virtual void translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) = 0; + virtual void translateViewpoint() = 0; + virtual void drawHierachyNode(const Model::HierNode *node) = 0; virtual void drawModelFace(const Model::Face *face, float *vertices, float *vertNormals, float *textureVerts) = 0; diff --git a/driver_gl.cpp b/driver_gl.cpp index 69d09105b8b..d61e0433d35 100644 --- a/driver_gl.cpp +++ b/driver_gl.cpp @@ -146,16 +146,23 @@ void DriverGL::drawModelFace(const Model::Face *face, float *vertices, float *ve glDisable( GL_ALPHA_TEST ); } +void DriverGL::translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + glTranslatef(pos.x(), pos.y(), pos.z()); + glRotatef(yaw, 0, 0, 1); + glRotatef(pitch, 1, 0, 0); + glRotatef(roll, 0, 1, 0); +} + +void DriverGL::translateViewpoint() { + glPopMatrix(); +} + void DriverGL::drawHierachyNode(const Model::HierNode *node) { + translateViewpoint(node->_animPos / node->_totalWeight, node->_animPitch / node->_totalWeight, node->_animYaw / node->_totalWeight, node->_animRoll / node->_totalWeight); if (node->_hierVisible) { - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - glTranslatef(node->_animPos.x() / node->_totalWeight, node->_animPos.y() / node->_totalWeight, node->_animPos.z() / node->_totalWeight); - glRotatef(node->_animYaw / node->_totalWeight, 0, 0, 1); - glRotatef(node->_animPitch / node->_totalWeight, 1, 0, 0); - glRotatef(node->_animRoll / node->_totalWeight, 0, 1, 0); - if (node->_mesh != NULL && node->_meshVisible) { glPushMatrix(); glTranslatef(node->_pivot.x(), node->_pivot.y(), node->_pivot.z()); @@ -168,8 +175,8 @@ void DriverGL::drawHierachyNode(const Model::HierNode *node) { node->_child->draw(); glMatrixMode(GL_MODELVIEW); } - glPopMatrix(); } + translateViewpoint(); if (node->_sibling != NULL) node->_sibling->draw(); diff --git a/driver_gl.h b/driver_gl.h index 2359cbbd7a7..198e700661a 100644 --- a/driver_gl.h +++ b/driver_gl.h @@ -49,6 +49,9 @@ public: void set3DMode(); + void translateViewpoint(Vector3d pos, float pitch, float yaw, float roll); + void translateViewpoint(); + void drawHierachyNode(const Model::HierNode *node); void drawModelFace(const Model::Face *face, float *vertices, float *vertNormals, float *textureVerts); diff --git a/driver_tinygl.cpp b/driver_tinygl.cpp index b29b8b57f4a..ed844b3a199 100644 --- a/driver_tinygl.cpp +++ b/driver_tinygl.cpp @@ -199,15 +199,22 @@ void DriverTinyGL::drawModelFace(const Model::Face *face, float *vertices, float tglEnd(); } +void DriverTinyGL::translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) { + tglPushMatrix(); + + tglTranslatef(pos.x(), pos.y(), pos.z()); + tglRotatef(yaw, 0, 0, 1); + tglRotatef(pitch, 1, 0, 0); + tglRotatef(roll, 0, 1, 0); +} + +void DriverTinyGL::translateViewpoint() { + tglPopMatrix(); +} + void DriverTinyGL::drawHierachyNode(const Model::HierNode *node) { + translateViewpoint(node->_animPos / node->_totalWeight, node->_animPitch / node->_totalWeight, node->_animYaw / node->_totalWeight, node->_animRoll / node->_totalWeight); if (node->_hierVisible) { - tglPushMatrix(); - - tglTranslatef(node->_animPos.x() / node->_totalWeight, node->_animPos.y() / node->_totalWeight, node->_animPos.z() / node->_totalWeight); - tglRotatef(node->_animYaw / node->_totalWeight, 0, 0, 1); - tglRotatef(node->_animPitch / node->_totalWeight, 1, 0, 0); - tglRotatef(node->_animRoll / node->_totalWeight, 0, 1, 0); - if (node->_mesh != NULL && node->_meshVisible) { tglPushMatrix(); tglTranslatef(node->_pivot.x(), node->_pivot.y(), node->_pivot.z()); @@ -220,8 +227,8 @@ void DriverTinyGL::drawHierachyNode(const Model::HierNode *node) { node->_child->draw(); tglMatrixMode(TGL_MODELVIEW); } - tglPopMatrix(); } + translateViewpoint(); if (node->_sibling != NULL) node->_sibling->draw(); diff --git a/driver_tinygl.h b/driver_tinygl.h index 5a856ca10f4..2a2d6088db1 100644 --- a/driver_tinygl.h +++ b/driver_tinygl.h @@ -50,6 +50,9 @@ public: void set3DMode(); + void translateViewpoint(Vector3d pos, float pitch, float yaw, float roll); + void translateViewpoint(); + void drawHierachyNode(const Model::HierNode *node); void drawModelFace(const Model::Face *face, float *vertices, float *vertNormals, float *textureVerts); diff --git a/imuse/imuse_tables.cpp b/imuse/imuse_tables.cpp index 4b08b1a9a00..304010566a8 100644 --- a/imuse/imuse_tables.cpp +++ b/imuse/imuse_tables.cpp @@ -120,8 +120,8 @@ ImuseTable grimStateMusicTable[] = { {3, 1165, 94, 4, 24, 20, 64, "1125 - Hector Steps Out.IMC"}, {3, 1166, 94, 4, 24, 127, 10, "1125 - Hector Steps Out.IMC"}, {3, 1167, 0, 0, 60, 127, 0, "1167 - Dillopede Elev.IMC"}, - {3, 1168, 0, 0, 60, 127, 0, "1168 - Dillopede Elev.IMC"}, - {3, 1169, 0, 0, 60, 127, 0, "1169 - Dillopede Elev.IMC"}, + {3, 1168, 0, 0, 60, 127, 0, "1167 - Dillopede Elev.IMC"}, + {3, 1169, 0, 0, 60, 127, 0, "1167 - Dillopede Elev.IMC"}, {3, 1170, 0, 0, 24, 105, 0, "1170 - Extendo Bridge.IMC"}, {3, 1171, 0, 0, 24, 105, 0, "1170 - Extendo Bridge.IMC"}, {3, 1172, 0, 0, 24, 105, 0, "1170 - Extendo Bridge.IMC"},