I'm using the pvr to do it, DCGrendel gave me some code to do rotation, but I don't really understand it.
Code: Select all
typedef struct ship_s {
int type;
float x,y,z;
float rot;
} ship_t;
ship_t player_ship;
...
player_ship.rot = 0;
u1=sinf(player_ship.rot-45);
u2=sinf(player_ship.rot+135);
v1=cosf(player_ship.rot-45);
v2=cosf(player_ship.rot+135);
x1=player_ship.x+u1;
x2=player_ship.x+u2;
y1=player_ship.x+v1;
y2=player_ship.x+v2;
u1+=0.5f;
u2+=0.5f;
v1+=0.5f;
v2+=0.5f;
render_object(texture, tx, ty, x1, y1, player_ship.z, x2, y2, u1, v1, u2, v2);
uhm, ok, to move the ship, you do mx+=sin(player_ship.rot); my+=cos(player_ship.rot);
to rotate it you + or - player_ship.rot
I pretty much have it figured out, but I don't really know how to implement the u1,v1 and u2,v2 in the draw function.
This is how I have it setup right now:
Code: Select all
void draw_ship(int x2, int y2, int z2, float u1, float v1, float u2, float v2, float u3, float v3, float u4, float v4, char *ship_tex)
{
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert2;
pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, 64, 64, ship_tex, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
vert2.argb = PVR_PACK_COLOR(1,1,1,1);
vert2.oargb = 0;
vert2.flags = PVR_CMD_VERTEX;
vert2.x = 1 + x2;
vert2.y = 1 + y2;
vert2.z = z2;
vert2.u = u1;
vert2.v = v1;
pvr_prim(&vert2, sizeof(vert2));
vert2.x = 64 + x2;
vert2.y = 1 + y2;
vert2.z = z2;
vert2.u = u2;
vert2.v = v2;
pvr_prim(&vert2, sizeof(vert2));
vert2.x = 1 + x2;
vert2.y = 64 + y2;
vert2.z = z2;
vert2.u = u3;
vert2.v = v3;
pvr_prim(&vert2, sizeof(vert2));
vert2.x = 64 + x2;
vert2.y = 64 + y2;
vert2.z = z2;
vert2.u = u4;
vert2.v = v4;
vert2.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert2, sizeof(vert2));
}
With u1,v1 u2,v2 and etc. for each vertex point, it was easier to figure out what they should be, heh.
*EDIT*
Nevermind, found out that it was easier to rotate the poly than the textures
, just starting out graphics programming.
/me says thanks to Sayten