Diagonal Textures

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
ragnarok2040
DC Developer
DC Developer
Posts: 462
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Diagonal Textures

Post by ragnarok2040 »

Code: Select all

|====================================================|
| 1        1 = 0.5,0.0 2 = 1.0,0.5                   |
|3 2                               up-right          |
| 4        3 = 0.0,0.5 4 = 0.5,1.0                   |
|====================================================|
I'm trying to figure out how to draw a texture diagonally, I didn't feel like using 30 or so ship images, so I'm doing it by changing the u,v values for each vertex of the polygon I'm mapping it on.

1 = (u1,v1) 2= (u2,v2) 3= (u3,v3) 4= (u4,v4)

This displays it diagonally, but messed up on the sides (the corner between 3,1, and the corner between 2,4). I'm pretty sure I don't have the correct u,v coords for each vertex. I have up, down, left, right working, tho. :D

Is there a formula or anything to figure this out?
Tangent
DC Developer
DC Developer
Posts: 100
Joined: Fri Jan 17, 2003 3:01 pm
Location: Pits of Insanity
Has thanked: 0
Been thanked: 0
Contact:

Post by Tangent »

Have you considered trying to rotate the polygon?
There are 10 kinds of people in the world: those who understand binary, and those who don't.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Rotate the ship polygon itself - it's much easier. I'll see if I can find some code to do it. How are you rendering stuff - KGL or PVR?
ragnarok2040
DC Developer
DC Developer
Posts: 462
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Post by ragnarok2040 »

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 :P, just starting out graphics programming.

/me says thanks to Sayten
Post Reply