From 9915c9ec58a0c1bbf4f687364a861e19429b3083 Mon Sep 17 00:00:00 2001 From: slack Date: Fri, 31 Oct 2008 02:03:50 +0100 Subject: [PATCH] Entity class is barely functional now. Changed game.cc to use the new class :) --- Makefile | 2 +- entity.cc | 38 ++++++++++++++++++++++++++++++++++++++ entity.h | 3 ++- game.cc | 25 ++++++++++++++----------- gfx.cc | 1 + 5 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 entity.cc diff --git a/Makefile b/Makefile index 5c2958b..dd98463 100644 --- 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 index 0000000..6f79367 --- /dev/null +++ b/entity.cc @@ -0,0 +1,38 @@ +#include "entity.h" +#include "gfx.h" + +#include +#include + +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); +} + + + + diff --git a/entity.h b/entity.h index a798806..7fc6d9a 100644 --- a/entity.h +++ b/entity.h @@ -1,6 +1,7 @@ #if !defined(ENTITY_H) #define ENTITY_H +#include #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 0afe5f9..8c6d0e6 100644 --- a/game.cc +++ b/game.cc @@ -2,6 +2,7 @@ #include "gfx.h" #include "model.h" #include "texture.h" +#include "entity.h" #include #include @@ -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 e8ec012..cce683d 100644 --- 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); } -- 2.34.1