Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/entity.cc26
-rw-r--r--src/core/entity.h35
2 files changed, 39 insertions, 22 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 1e90b2a..b3d58a3 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -91,7 +91,6 @@ Entity::Entity(unsigned int flags) :
entity_moduletypeid = 0;
entity_radius = 1.0f;
- entity_direction = 0;
entity_shape = Diamond;
entity_created = true;
@@ -118,7 +117,7 @@ Entity::Entity(std::istream & is)
is >> entity_color;
is >> s; // shape
is >> entity_radius;
- is >> entity_direction;
+ is >> entity_axis;
entity_shape = (Shape) s ;
char c;
@@ -155,7 +154,7 @@ void Entity::serialize(std::ostream & os) const
<< entity_color << " "
<< entity_shape << " "
<< entity_radius << " "
- << entity_direction << " "
+ << entity_axis << " "
<< "\"" << entity_name << "\" "
<< "\"" << entity_modelname << "\"";
}
@@ -207,9 +206,8 @@ void EntityDynamic::frame(float seconds)
if (entity_speed == 0)
return;
- // location avoid sin/cos calculations
- entity_location.x += cosf(entity_direction * M_PI / 180) * entity_speed * seconds;
- entity_location.y += sinf(entity_direction * M_PI / 180) * entity_speed * seconds;
+ entity_location += entity_axis.forward() * entity_speed * seconds;
+
entity_dirty = true;
}
@@ -229,13 +227,13 @@ void EntityDynamic::recieve_client_update(std::istream &is)
void EntityDynamic::serialize_server_update(std::ostream & os) const
{
- os << entity_location << " " << entity_direction << " " << entity_speed;
+ os << entity_location << " " << entity_axis << " " << entity_speed;
}
void EntityDynamic::recieve_server_update(std::istream &is)
{
is >> entity_location;
- is >> entity_direction;
+ is >> entity_axis;
is >> entity_speed;
}
@@ -335,6 +333,18 @@ void EntityControlable::set_direction(float direction)
}
}
+void EntityControlable::set_pitch(float pitch)
+{
+ if ((flags() & Static) == Static)
+ return;
+
+ if (target_pitch != pitch) {
+ target_pitch = pitch;
+ entity_dirty = true;
+ }
+}
+
+
/*----- EntityGlobe ------------------------------------------------ */
EntityGlobe::EntityGlobe(unsigned int flags) :
diff --git a/src/core/entity.h b/src/core/entity.h
index 20242a9..86b5ab3 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -15,6 +15,7 @@ class EntityControlable;
#include "core/model.h"
#include "core/player.h"
+#include "math/axis.h"
#include "math/mathlib.h"
#include <iostream>
@@ -73,11 +74,11 @@ public:
inline bool dirty() const { return entity_dirty; }
/// entity location
- inline math::Vector3f const & location() const { return entity_location; }
-
- /// direction the entity is facing, in degrees.
- inline float direction() const { return entity_direction; }
+ inline math::Vector3f & location() { return entity_location; }
+ /// local coordinate system of the entity
+ inline math::Axis & axis() { return entity_axis; }
+
/// base color of the entity
inline math::Color const & color() const { return entity_color; }
@@ -129,18 +130,15 @@ public:
static void list();
/* entity_ variables can be set by the module */
+ math::Vector3f entity_location;
+ math::Axis entity_axis;
+
float entity_radius;
std::string entity_name;
std::string entity_modelname;
Model *entity_model;
- Shape entity_shape;
- math::Vector3f entity_location;
+ Shape entity_shape;
math::Color entity_color;
- /*
- * A direction of 0 degrees means the entity is looking
- * along the positive X-axis. Positive angle is along the negative Z-axis.
- */
- float entity_direction;
unsigned int entity_moduletypeid;
unsigned int entity_flags;
@@ -200,7 +198,7 @@ public:
/// runs one game frame for the entity
/**
* The default implementation will update the position() of the entity,
- * determined by its speed() and direction()
+ * determined by its speed() and axis()
*/
virtual void frame(float seconds);
@@ -251,10 +249,13 @@ public:
virtual void recieve_server_update(std::istream &is);
/// set the target thrust
- void set_thrust(float t);
+ void set_thrust(float thrust);
/// set the target direction
- void set_direction(float t);
+ void set_direction(float direction);
+
+ /// set the target pitch
+ void set_pitch(float pitch);
/// runs one game frame for the entity
/**
@@ -273,7 +274,13 @@ public:
/// target thrust as set by the client
float target_thrust;
/// target direction as set by the client
+ /** target_direction must be in the [-1, 1] range
+ */
float target_direction;
+ /// target pitch as set by the client
+ /** target_pitch must be in the [-1, 1] range
+ */
+ float target_pitch;
};
/// a Globe entity