Physics implementation.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/proto2/Physics.cc Thu Nov 13 16:00:40 2008 +0000
@@ -0,0 +1,52 @@
+#include "Physics.hh"
+
+PhysicsWorld::PhysicsWorld (Vector dimensions) : dimensions(dimensions) {}
+
+void PhysicsWorld::addObject (PhysicsObject *object) {
+ objects.push_back(object);
+}
+
+void PhysicsWorld::tick () {
+
+}
+
+PhysicsObject::PhysicsObject (mass, position, velocity, force)
+ : mass(mass), position(position), velocity(velocity), force(force) {}
+
+void PhysicsObject::updatePosition () {
+
+ // Calculate gravity's influence on the velocity vector
+ this->velocity += GRAVITY_FORCEi / mass * 1.0i / mass * 1.0ff;
+
+ Vector newPosition = position + velocity * PHYSICS_TICK_MS;
+
+ //TODO Handle the object as a square or a polygon
+ if(newPosition.x < 0 || (newPosition.x > PHYSICS_WORLD_WIDTH)
+ || (newPosition.y < 0) || (newPosition.y >= PHYSICS_WORLD_HEIGHT)) {
+
+ // CRASH!
+ this->velocity *= -1;
+ } else {
+ this->position = newPosition;
+ }
+}
+
+void PhysicsObject::applyForce (Vector force) {
+ this->velocity += force / mass * 1.0f; // The last factor denotes the time.
+ // It should be scaled somehow.
+}
+
+void PhysicsObjectu::updatePhysics (Vector position, Vector velocity, Vector force) {
+ this->position = position;
+ this->velocity = velocity;
+ this->force = force;
+}
+
+Vector PhysicsObject::getPosition () {
+ return this->position;
+}
+
+void PhysicsObject::tick () {
+
+}
+