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
--- /dev/null
+#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);
+}
+
+
+
+
#if !defined(ENTITY_H)
#define ENTITY_H
+#include <psptypes.h>
#include "texture.h"
#include "model.h"
{}
void draw() const;
- void update_position();
+ void update_position(float dt);
bool collides(const Entity& other);
};
#include "gfx.h"
#include "model.h"
#include "texture.h"
+#include "entity.h"
#include <pspgu.h>
#include <pspgum.h>
{
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);
{
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();
}
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);
}