Entity class is barely functional now.
authorslack <slack@codemaniacs.com>
Fri, 31 Oct 2008 01:03:50 +0000 (02:03 +0100)
committerslack <slack@codemaniacs.com>
Fri, 31 Oct 2008 01:03:50 +0000 (02:03 +0100)
Changed game.cc to use the new class :)

Makefile
entity.cc [new file with mode: 0644]
entity.h
game.cc
gfx.cc

index 5c2958b0f8bd0e08152ada78e5fb33675c627609..dd98463e8c5a08a93505fcad2b2d367132750d62 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 TARGET = laz0r
-OBJS = main.o game.o gfx.o model.o texture.o
+OBJS = main.o game.o gfx.o model.o texture.o entity.o
 
 PSP_FW_VERSION=500
 BUILD_PRX=1
diff --git a/entity.cc b/entity.cc
new file mode 100644 (file)
index 0000000..6f79367
--- /dev/null
+++ b/entity.cc
@@ -0,0 +1,38 @@
+#include "entity.h"
+#include "gfx.h"
+
+#include <pspgu.h>
+#include <pspgum.h>
+
+void Entity::draw() const
+{
+       GFX.bind_texture(*texture);
+       // TODO: Move these calls to somewhere in the GFX class
+       sceGumMatrixMode(GU_MODEL);
+       sceGumTranslate(&position);
+       sceGumLoadMatrix(&initial_transform);
+       GFX.draw_model(*model);
+}
+
+void Entity::update_position(float dt)
+{
+       position.x += dt * velocity.x;
+       position.y += dt * velocity.y;
+       position.z += dt * velocity.z;
+}
+
+
+// if distance between the centers > sum of radii --> collision
+bool Entity::collides(const Entity& other)
+{
+       ScePspFVector3 difference = {position.x-other.position.x, 
+               position.y - other.position.y,
+               position.z - other.position.z};
+       float dst_squared = gumDotProduct(&difference, &difference);
+       float sum_of_radii = radius + other.radius;
+       return (dst_squared < sum_of_radii*sum_of_radii);
+}
+
+
+
+
index a798806855d1d1e5f5a5b60233222aa3096386d4..7fc6d9a1023b23156f9a5ac6dc53c845f6086f2d 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -1,6 +1,7 @@
 #if !defined(ENTITY_H)
 #define ENTITY_H
 
+#include <psptypes.h>
 #include "texture.h"
 #include "model.h"
 
@@ -29,7 +30,7 @@ class Entity
        {}
 
        void draw() const;
-       void update_position();
+       void update_position(float dt);
        bool collides(const Entity& other);
 };
 
diff --git a/game.cc b/game.cc
index 0afe5f9a362cb8a5998878f19d6330b70a95aa93..8c6d0e6c8b644ef424bfec887c6cbae633534db5 100644 (file)
--- a/game.cc
+++ b/game.cc
@@ -2,6 +2,7 @@
 #include "gfx.h"
 #include "model.h"
 #include "texture.h"
+#include "entity.h"
 
 #include <pspgu.h>
 #include <pspgum.h>
@@ -16,9 +17,17 @@ int game_main(int argc, char **argv)
 {
        GFX.init();
 
-       Model ship("data/shipdawhip.lob");
-       Texture texture("data/shipdawhip.ltx");
-       
+       Model ship_model("data/shipdawhip.lob");
+       Texture ship_texture("data/shipdawhip.ltx");
+       ScePspFMatrix4 transform;
+       gumLoadIdentity(&transform);
+       gumRotateZ(&transform, -3.14159f/2.0f);
+       ScePspFVector3 position={0.0f, 0.0f, 0.0f};
+       ScePspFVector3 velocity={0.0f, 0.0f, 0.0f};
+       float radius = 1.0f;
+
+       Entity ship(&ship_model, &ship_texture, transform, position, velocity, radius);
+
        sceKernelDcacheWritebackInvalidateAll(); 
 
        GFX.perspective(75.0f, 16.0f/9.0f, 0.5f, 1000.0f);
@@ -34,14 +43,8 @@ int game_main(int argc, char **argv)
        {
                GFX.begin_frame();
                i++;
-               sceGumLoadIdentity();
-               //sceGumRotateX(-3.14159f/2.0f);
-               //sceGumRotateY(-3.14159f/2.0f);
-               sceGumRotateZ(-3.14159f/2.0f);
-               sceGuColor(GU_COLOR(1.0f,1.0f,1.0f,0.0f));
-               GFX.bind_texture(texture);
-               GFX.draw_model(ship);
-       
+
+               ship.draw();    
                
                GFX.end_frame();        
        }
diff --git a/gfx.cc b/gfx.cc
index e8ec0121236733b4acd56f60e2e8c0c78c7cb7cb..cce683de45ea790c20c2aa1025b71d64fad6a8b7 100644 (file)
--- a/gfx.cc
+++ b/gfx.cc
@@ -138,6 +138,7 @@ void Gfx::look_at(float eye_x, float eye_y, float eye_z,
 
 void Gfx::bind_texture(const Texture& t)
 {
+       sceGuColor(GU_COLOR(1.0f,1.0f,1.0f,0.0f));
        sceGuTexMode(t.mode, 0, 0, t.swizzled? 1: 0);
        sceGuTexImage(0, t.width, t.height, t.width, t.pixels); 
 }