a few minutes of work into the entity class :P
authorslack <slack@codemaniacs.com>
Thu, 23 Oct 2008 01:42:37 +0000 (03:42 +0200)
committerslack <slack@codemaniacs.com>
Thu, 23 Oct 2008 01:42:37 +0000 (03:42 +0200)
Makefile
entity.h
game.cc
gfx.cc
gfx.h

index fea16dc3132c5c22d743fff3d321da73820228d4..5c2958b0f8bd0e08152ada78e5fb33675c627609 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 TARGET = laz0r
 OBJS = main.o game.o gfx.o model.o texture.o
 
-PSP_FW_VERSION=401
+PSP_FW_VERSION=500
 BUILD_PRX=1
 
 INCDIR = 
index 71fa1470337489169c3849ea0c05c95c9baf96de..a798806855d1d1e5f5a5b60233222aa3096386d4 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -12,6 +12,25 @@ class Entity
        ScePspFVector3 position;
        ScePspFVector3 velocity;
 
+       float radius; //< for collision detection
+
+       public:
+       Entity(Model *model, Texture *texture,
+                       ScePspFMatrix4 initial_transform,
+                       ScePspFVector3 position,
+                       ScePspFVector3 velocity,
+                       float radius)
+               :model(model),
+               texture(texture),
+               initial_transform(initial_transform),
+               position(position),
+               velocity(velocity),
+               radius(radius)
+       {}
+
+       void draw() const;
+       void update_position();
+       bool collides(const Entity& other);
 };
 
 #endif
diff --git a/game.cc b/game.cc
index 0305bbd54cb88c0f2cf0fba9ebb7f083700d64bb..0afe5f9a362cb8a5998878f19d6330b70a95aa93 100644 (file)
--- a/game.cc
+++ b/game.cc
@@ -16,17 +16,14 @@ int game_main(int argc, char **argv)
 {
        GFX.init();
 
-       //Model cube("colors-noUV.lob");
-       Model cube("data/shipdawhip.lob");
+       Model ship("data/shipdawhip.lob");
        Texture texture("data/shipdawhip.ltx");
-       //sceKernelDcacheWritebackRange(cube.vertices, cube.num_vertices * sizeof(Vertex));
-       //sceKernelDcacheWritebackRange(cube.indices, cube.num_faces * sizeof(unsigned short));
-       //sceKernelDcacheWritebackRange(&cube, sizeof(cube));
+       
        sceKernelDcacheWritebackInvalidateAll(); 
 
        GFX.perspective(75.0f, 16.0f/9.0f, 0.5f, 1000.0f);
 
-       ScePspFVector3 camera_pos    = {10,0,-50};
+       ScePspFVector3 camera_pos    = {10,0,-60};
        ScePspFVector3 camera_center = {-40, 0, 40};
        ScePspFVector3 camera_up     = {0, 1, 0};
        GFX.look_at(&camera_pos, &camera_center, &camera_up);
@@ -43,8 +40,7 @@ int game_main(int argc, char **argv)
                sceGumRotateZ(-3.14159f/2.0f);
                sceGuColor(GU_COLOR(1.0f,1.0f,1.0f,0.0f));
                GFX.bind_texture(texture);
-               sceGumDrawArray(GU_TRIANGLES, cube.vtype | GU_TRANSFORM_3D, 
-                               cube.num_faces*3, cube.indices, cube.vertices);
+               GFX.draw_model(ship);
        
                
                GFX.end_frame();        
diff --git a/gfx.cc b/gfx.cc
index a8d9eed098909f3a982da9d9f7f9f0ca364e8e22..e8ec0121236733b4acd56f60e2e8c0c78c7cb7cb 100644 (file)
--- a/gfx.cc
+++ b/gfx.cc
@@ -142,4 +142,10 @@ void Gfx::bind_texture(const Texture& t)
        sceGuTexImage(0, t.width, t.height, t.width, t.pixels); 
 }
 
+void Gfx::draw_model(const Model& m)
+{
+       sceGumDrawArray(GU_TRIANGLES, m.vtype | GU_TRANSFORM_3D, 
+                       m.num_faces*3, m.indices, m.vertices);
+}
+
 
diff --git a/gfx.h b/gfx.h
index 175f410dd45c7cefdf7667b4c5db1fe562087175..95f15344dd9637a846957cb60557739adff518c6 100644 (file)
--- a/gfx.h
+++ b/gfx.h
@@ -3,6 +3,7 @@
 
 #include "singleton.h"
 #include "texture.h"
+#include "model.h"
 #include <psptypes.h>
 
 class Gfx: public Singleton<Gfx>
@@ -38,6 +39,9 @@ class Gfx: public Singleton<Gfx>
 
        // Texture
        void bind_texture(const Texture& t);
+
+       // Model
+       void draw_model(const Model& m);
 };
 
 #define GFX Gfx::Instance()