Skip to content

Commit

Permalink
begin line renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
UNSTOP4BLE committed Jul 10, 2024
1 parent 9ed435f commit 58235f4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 66 deletions.
86 changes: 44 additions & 42 deletions src/psp/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,38 @@ void Mat4::setTranslation(Vec3<float> vec) {
}

void Mat4::setRotation(Vec3<float> vec) {
/*
Mat4 multiplied;
Mat4 copy;
int s, c;
if (vec.x) {
s = sin(vec.x);
c = cos(vec.x);
multiplied.m[1] = {
c, -s, 0,
s, c, 0,
0, 0, 1
};
this->multiply(multiplied, copy);
this->m[0] = copy.m[0];
}
if (vec.y) {
s = sin(vec.y);
c = cos(vec.y);
multiplied.m[2] = {
c, 0, s,
0, 1, 0,
-s, 0, c
};
this->multiply(multiplied, copy);
this->m[2] = copy.m[2];
}
if (vec.z) {
s = sin(vec.z);
c = cos(vec.z);
multiplied.m[3] = {
1, 0, 0,
0, c, -s,
0, s, c
};
this->multiply(multiplied, copy);
this->m[3] = copy.m[3];
}
*/
Mat4 rot, temp;

float cosX = cos(vec.x), sinX = sin(vec.x);
float cosY = cos(vec.y), sinY = sin(vec.y);
float cosZ = cos(vec.z), sinZ = sin(vec.z);

rot.setIdentity();
rot.m[1][1] = cosX;
rot.m[1][2] = -sinX;
rot.m[2][1] = sinX;
rot.m[2][2] = cosX;

multiply(rot, temp);
*this = temp;

rot.setIdentity();
rot.m[0][0] = cosY;
rot.m[0][2] = sinY;
rot.m[2][0] = -sinY;
rot.m[2][2] = cosY;

multiply(rot, temp);
*this = temp;

rot.setIdentity();
rot.m[0][0] = cosZ;
rot.m[0][1] = -sinZ;
rot.m[1][0] = sinZ;
rot.m[1][1] = cosZ;

multiply(rot, temp);
*this = temp;
}

void Mat4::setScale(Vec3<float> vec) {
Expand Down Expand Up @@ -101,8 +91,20 @@ PSPRenderer::~PSPRenderer(void) {
sceGuTerm();
}

void PSPRenderer::drawLines(const Line *prims, size_t count) {
int flags = 0
| GU_COLOR_8888 // 24bpp vertex colors
| GU_VERTEX_32BITF // float vertices
| GU_TRANSFORM_3D // use matrices
| GU_VERTICES(2); // 2 vertices per line

sceGuDrawArray(GU_LINES, flags, count, indices, vertices);
}


void PSPRenderer::clear(Color color) {
sceGuClearColor(color);
sceGuClear(GU_COLOR_BUFFER_BIT);
}

void PSPRenderer::swapBuffers(void) {
Expand Down
20 changes: 18 additions & 2 deletions src/psp/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@ template<typename T> struct Vec2 {
T x, y;
};


using Color = uint32_t; // RGBA color

union Color {
public:
uint32_t value;
struct {
uint8_t r, g, b, a;
};
};

struct Line {
public:
Vec3<float> a, b;
Color color;
};

struct LineVertex {
public:
Color color;
Vec3<float> pos;
};
using Line = LineVertex[2];


struct Triangle {
public:
Vec3<float> verts[3];
Expand Down Expand Up @@ -66,7 +81,6 @@ class Renderer {
int screenwidth;
int screenheight;

Renderer(int width, int height, int numBuffers) {(void) width; (void) height; (void) numBuffers; }
virtual ~Renderer(void) {}

virtual void drawLines(const Line *prims, size_t count) {(void) prims; (void) count; }
Expand All @@ -91,6 +105,8 @@ class PSPRenderer : public Renderer {
PSPRenderer(int width, int height, int numBuffers);
~PSPRenderer(void);

void drawLines(const Line *prims, size_t count);

void clear(Color color);
void swapBuffers(void);
void waitForVSync(void);
Expand Down
1 change: 0 additions & 1 deletion src/psp/me.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions src/psp/me.h

This file was deleted.

0 comments on commit 58235f4

Please sign in to comment.