From: slack Date: Thu, 23 Oct 2008 01:42:37 +0000 (+0200) Subject: a few minutes of work into the entity class :P X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=1e591fbf313b4b3106a5e9eee4b679e9b3a04789;p=laz0r.git a few minutes of work into the entity class :P --- diff --git a/Makefile b/Makefile index fea16dc..5c2958b 100644 --- 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 = diff --git a/entity.h b/entity.h index 71fa147..a798806 100644 --- 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 0305bbd..0afe5f9 100644 --- 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 a8d9eed..e8ec012 100644 --- 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 175f410..95f1534 100644 --- a/gfx.h +++ b/gfx.h @@ -3,6 +3,7 @@ #include "singleton.h" #include "texture.h" +#include "model.h" #include class Gfx: public Singleton @@ -38,6 +39,9 @@ class Gfx: public Singleton // Texture void bind_texture(const Texture& t); + + // Model + void draw_model(const Model& m); }; #define GFX Gfx::Instance()