Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use velocity to determine animations rather than the "mode" attribute.

2009-07-08  Simon Goodall  <simon@worldforge.org>

	* src/WorldEntity.cpp: Use velocity to determine animations rather
	  than the "mode" attribute.
  • Loading branch information...
commit b987317a5d116ac8fcb34a62fe20a07f47e9be9c 1 parent 3d5e3de
@drsgoodall drsgoodall authored
Showing with 50 additions and 5 deletions.
  1. +5 −0 ChangeLog
  2. +45 −5 src/WorldEntity.cpp
View
5 ChangeLog
@@ -1,3 +1,8 @@
+2009-07-08 Simon Goodall <simon@worldforge.org>
+
+ * src/WorldEntity.cpp: Use velocity to determine animations rather
+ than the "mode" attribute.
+
2009-07-04 Simon Goodall <simon@worldforge.org>
* environment/TerrainRenderer.cpp, environment/TerrainRenderer.h,
View
50 src/WorldEntity.cpp
@@ -9,13 +9,15 @@
* frame.
*/
-//#include <set>
+#include "WorldEntity.h"
+
#include <sigc++/bind.h>
#include <sigc++/hide.h>
#include <sigc++/object_slot.h>
#include <Atlas/Objects/Operation.h>
+#include <wfmath/atlasconv.h>
#include <wfmath/axisbox.h>
#include <wfmath/quaternion.h>
#include <wfmath/vector.h>
@@ -28,14 +30,15 @@
#include "common/Log.h"
#include "common/Utility.h"
-#include "System.h"
-#include "Console.h"
+#include "environment/Environment.h"
+
#include "loaders/ObjectRecord.h"
#include "loaders/ModelSystem.h"
-#include "WorldEntity.h"
+
#include "ActionHandler.h"
+#include "Console.h"
+#include "System.h"
-#include "environment/Environment.h"
#ifdef DEBUG
static const bool debug = true;
@@ -53,11 +56,20 @@ static const std::string ATTR_right_hand_wield = "right_hand_wield";
static const std::string ATTR_say = "say";
static const std::string ATTR_status = "status";
static const std::string ATTR_terrain = "terrain";
+static const std::string ATTR_velocity = "velocity";
static const std::string MODE_floating = "floating";
static const std::string MODE_fixed = "fixed";
static const std::string MODE_swimming = "swimming";
+static const std::string MODE_IDLE = "idle";
+static const std::string MODE_STANDING = "standing";
+static const std::string MODE_WALKING = "walking";
+static const std::string MODE_RUNNING = "running";
+
+static const float SPEED_IDLE = 0.000001f;
+static const float SPEED_WALKING = 2.0f;
+
static const std::string TYPE_jetty = "jetty";
static const WFMath::Point<3> point_zero = WFMath::Point<3>(0.0f,0.0f,0.0f);
@@ -300,6 +312,8 @@ void WorldEntity::displayInfo() {
void WorldEntity::onAttrChanged(const std::string& str, const Atlas::Message::Element& v) {
if (str == ATTR_mode) {
+ /*
+ // This is now obsolete. We need to check velocity to determine animation.
const std::string &mode = v.asString();
static ActionHandler *ac = System::instance()->getActionHandler();
assert(ac);
@@ -309,6 +323,32 @@ void WorldEntity::onAttrChanged(const std::string& str, const Atlas::Message::El
if (record) record->animate(mode);
m_last_mode = mode;
}
+ */
+ } else if (str == ATTR_velocity) {
+ // Extract velocity into vector object
+ WFMath::Vector<3> vel;
+ vel.fromAtlas(v);
+ // Work out speed from velocity
+ float speed = vel.mag();
+
+ // Determine mode string from speed.
+ std::string mode = MODE_IDLE;
+ if (speed < SPEED_IDLE) {
+ mode = MODE_STANDING;
+ } else if (speed < SPEED_WALKING) {
+ mode = MODE_WALKING;
+ } else {
+ mode = MODE_RUNNING;
+ }
+
+ static ActionHandler *ac = System::instance()->getActionHandler();
+ assert(ac);
+ ac->handleAction(mode + "_" + type(), NULL);
+ if (mode != m_last_mode) {
+ SPtr<ObjectRecord> record = ModelSystem::getInstance().getObjectRecord(this);
+ if (record) record->animate(mode);
+ m_last_mode = mode;
+ }
} else if (str == ATTR_right_hand_wield) {
const std::string &id = v.asString();
if (id.empty()) {
Please sign in to comment.
Something went wrong with that request. Please try again.