[Orxonox-commit 2221] r6937 - code/branches/presentation3/src/orxonox/graphics
decapitb at orxonox.net
decapitb at orxonox.net
Thu May 20 16:34:49 CEST 2010
Author: decapitb
Date: 2010-05-20 16:34:49 +0200 (Thu, 20 May 2010)
New Revision: 6937
Added:
code/branches/presentation3/src/orxonox/graphics/AnimatedModel.cc
code/branches/presentation3/src/orxonox/graphics/AnimatedModel.h
Modified:
code/branches/presentation3/src/orxonox/graphics/CMakeLists.txt
code/branches/presentation3/src/orxonox/graphics/Model.h
Log:
Predefined Armature-Animated Models supported.
Added: code/branches/presentation3/src/orxonox/graphics/AnimatedModel.cc
===================================================================
--- code/branches/presentation3/src/orxonox/graphics/AnimatedModel.cc (rev 0)
+++ code/branches/presentation3/src/orxonox/graphics/AnimatedModel.cc 2010-05-20 14:34:49 UTC (rev 6937)
@@ -0,0 +1,126 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Benjamin de Capitani
+ * Co-authors:
+ * ...
+ *
+ */
+ #include "AnimatedModel.h"
+ #include <OgreEntity.h>
+#include <Ogre.h>
+#include <deque>
+
+#include "core/CoreIncludes.h"
+#include "core/GameMode.h"
+#include "core/XMLPort.h"
+#include "Scene.h"
+
+namespace orxonox
+{
+ CreateFactory(AnimatedModel);
+
+ AnimatedModel::AnimatedModel(BaseObject* creator) : Model(creator)
+ {
+ RegisterObject(AnimatedModel);
+ }
+
+
+ AnimatedModel::~AnimatedModel()
+ {
+ if (this->isInitialized() && this->mesh_.getEntity())
+ this->detachOgreObject(this->mesh_.getEntity());
+ }
+
+ void AnimatedModel::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(AnimatedModel, XMLPort, xmlelement, mode);
+ XMLPortParam(AnimatedModel,"anims",setAnims,getAnims, xmlelement,mode).defaultValues("");
+ XMLPortParam(AnimatedModel,"loop", setAnimLoop,getAnimLoop, xmlelement,mode).defaultValues(true);
+ XMLPortParam(AnimatedModel,"enabled", setAnimEnabled,getAnimEnabled, xmlelement,mode).defaultValues(true);
+ }
+
+
+ void AnimatedModel::changedMesh()
+ {
+ if (GameMode::showsGraphics())
+ {
+ if (this->mesh_.getEntity())
+ this->detachOgreObject(this->mesh_.getEntity());
+
+ this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
+
+ if (this->mesh_.getEntity())
+ {
+ this->attachOgreObject(this->mesh_.getEntity());
+ this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
+ this->setAnimationState(this->bAnimLoop_, this->bAnimEnabled_, this->anims_);
+ this->mesh_.setVisible(this->isVisible());
+ }
+ }
+ }
+
+ void AnimatedModel::changedAnimationState()
+ {
+ this->setAnimationState(this->bAnimLoop_, this->bAnimEnabled_, this->anims_);
+ }
+ void AnimatedModel::setAnimationState(bool loop, bool enabled, const std::string& state)
+ {
+ if(state!="")
+ {
+ if(this->mesh_.getEntity()->getAnimationState(state))
+ {
+ Ogre::AnimationState* as = this->mesh_.getEntity()->getAnimationState(state);
+ as->setLoop(loop);
+ as->setEnabled(enabled);
+ this->anims_ = state;
+ }
+ }
+ }
+
+ void AnimatedModel::setAnimLoop(bool loop)
+ {
+ this->bAnimLoop_ = loop;
+ }
+ void AnimatedModel::setAnimEnabled(bool enabled)
+ {
+ this->bAnimEnabled_ = enabled;
+ }
+ void AnimatedModel::tick(float dt)
+ {
+ if(this->mesh_.getEntity()->getAnimationState(anims_))
+ {
+// Test to change Material at runtime!
+
+// Ogre::MaterialPtr mat = this->mesh_.getEntity()->getSubEntity(0)->getMaterial();
+// mat->setDiffuse(0.4, 0.3, 0.1, 0.1);
+// mat->setAmbient(0.3, 0.7, 0.8);
+// mat->setSpecular(0.5, 0.5, 0.5, 0.1);
+// Ogre::SceneBlendType sbt = Ogre::SBT_ADD;
+//
+// mat->setSceneBlending(sbt);
+
+ Ogre::AnimationState* as = this->mesh_.getEntity()->getAnimationState(anims_);
+ as->addTime(dt);
+ }
+}
+}
Added: code/branches/presentation3/src/orxonox/graphics/AnimatedModel.h
===================================================================
--- code/branches/presentation3/src/orxonox/graphics/AnimatedModel.h (rev 0)
+++ code/branches/presentation3/src/orxonox/graphics/AnimatedModel.h 2010-05-20 14:34:49 UTC (rev 6937)
@@ -0,0 +1,77 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _AnimatedModel_H__
+#define _AnimatedModel_H__
+#include "Model.h"
+#include "tools/interfaces/Tickable.h"
+#include "OrxonoxPrereqs.h"
+#include <deque>
+#include <string>
+#include "tools/Mesh.h"
+#include "worldentities/StaticEntity.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport AnimatedModel : public Model, public Tickable
+ {
+ public:
+ AnimatedModel(BaseObject* creator);
+ virtual ~AnimatedModel();
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ void registerVariables();
+
+ virtual void changedAnimationState();
+ virtual void setAnimationState(bool loop, bool enabled, const std::string& state);
+ virtual void setAnimEnabled(bool enabled);
+ virtual void setAnimLoop(bool loop);
+ virtual void tick(float dt);
+ virtual void changedMesh();
+
+
+ inline void setAnims(const std::string& anims)
+ { this->anims_ = anims; this->changedAnimationState(); }
+ inline const std::string& getAnims() const
+ { return this->anims_; }
+
+ inline const std::string& getAnimationState() const
+ { return this->anims_; }
+ inline const bool& getAnimLoop() const
+ { return this->bAnimLoop_; }
+ inline const bool& getAnimEnabled() const
+ { return this->bAnimEnabled_; }
+
+ private:
+ std::string anims_;
+ bool bAnimEnabled_;
+ bool bAnimLoop_;
+ };
+}
+
+#endif /* _AnimatedModel_H__ */
Modified: code/branches/presentation3/src/orxonox/graphics/CMakeLists.txt
===================================================================
--- code/branches/presentation3/src/orxonox/graphics/CMakeLists.txt 2010-05-20 14:10:54 UTC (rev 6936)
+++ code/branches/presentation3/src/orxonox/graphics/CMakeLists.txt 2010-05-20 14:34:49 UTC (rev 6937)
@@ -5,6 +5,7 @@
GlobalShader.cc
MeshLodInformation.cc
Model.cc
+ AnimatedModel.cc
ParticleEmitter.cc
ParticleSpawner.cc
COMPILATION_BEGIN GraphicsCompilation.cc
Modified: code/branches/presentation3/src/orxonox/graphics/Model.h
===================================================================
--- code/branches/presentation3/src/orxonox/graphics/Model.h 2010-05-20 14:10:54 UTC (rev 6936)
+++ code/branches/presentation3/src/orxonox/graphics/Model.h 2010-05-20 14:34:49 UTC (rev 6937)
@@ -61,7 +61,7 @@
inline bool getCastShadows() const
{ return this->bCastShadows_; }
- private:
+ protected:
void changedMesh();
void changedShadows();
More information about the Orxonox-commit
mailing list