[ADD] GRRLIB_DrawPart to draw a specific part of a Texture.

This commit is contained in:
N0NameN0 2009-11-07 13:26:03 +00:00
parent 3aa0b23d8f
commit c86e2a8d70
2 changed files with 90 additions and 0 deletions

View file

@ -237,6 +237,92 @@ void GRRLIB_DrawTile (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
}
/**
* Draw a part of a texture
* @param xpos Specifies the x-coordinate of the upper-left corner.
* @param ypos Specifies the y-coordinate of the upper-left corner.
* @param partx Specifies the x-coordinate of the upper-left corner in the Texture.
* @param party Specifies the y-coordinate of the upper-left corner in the Texture.
* @param partw Specifies the width in the Texture.
* @param parth Specifies the height in the Texture.
* @param tex The texture containing the tile to draw.
* @param degrees Angle of rotation.
* @param scaleX Specifies the x-coordinate scale. -1 could be used for flipping the texture horizontally.
* @param scaleY Specifies the y-coordinate scale. -1 could be used for flipping the texture vertically.
* @param color Color in RGBA format.
* @param frame Specifies the frame to draw.
*/
void GRRLIB_DrawPart (const f32 xpos, const f32 ypos, const f32 partx, const f32 party, const f32 partw, const f32 parth, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color) {
GXTexObj texObj;
f32 width, height;
Mtx m, m1, m2, mv;
f32 s1, s2, t1, t2;
if (tex == NULL || tex->data == NULL) return ;
// The 0.001f/x is the frame correction formula by spiffen
s1 = (partx /tex->w) +(0.001f /tex->w);
s2 = ((partx + partw)/tex->w) -(0.001f /tex->w);
t1 = (party /tex->h) +(0.001f /tex->h);
t2 = ((party + parth)/tex->h) -(0.001f /tex->h);
GX_InitTexObj(&texObj, tex->data,
tex->w, tex->h,
GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
if (GRRLIB_Settings.antialias == false)
GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR,
0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
GX_LoadTexObj(&texObj, GX_TEXMAP0);
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
width = partw * 0.5f;
height = parth * 0.5f;
guMtxIdentity (m1);
guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0f);
guMtxRotAxisDeg(m2, &axis, degrees);
guMtxConcat (m2, m1, m);
guMtxTransApply(m, m,
xpos +width +tex->handlex
-tex->offsetx +( scaleX *(-tex->handley *sin(-DegToRad(degrees))
-tex->handlex *cos(-DegToRad(degrees))) ),
ypos +height +tex->handley
-tex->offsety +( scaleY *(-tex->handley *cos(-DegToRad(degrees))
+tex->handlex *sin(-DegToRad(degrees))) ),
0);
guMtxConcat(GXmodelView2D, m, mv);
GX_LoadPosMtxImm(mv, GX_PNMTX0);
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
GX_Position3f32(-width, -height, 0);
GX_Color1u32 (color);
GX_TexCoord2f32(s1, t1);
GX_Position3f32(width, -height, 0);
GX_Color1u32 (color);
GX_TexCoord2f32(s2, t1);
GX_Position3f32(width, height, 0);
GX_Color1u32 (color);
GX_TexCoord2f32(s2, t2);
GX_Position3f32(-width, height, 0);
GX_Color1u32 (color);
GX_TexCoord2f32(s1, t2);
GX_End();
GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
}
/**
* Draw a tile in a quad.
* @param pos Vector array of the 4 points.

View file

@ -111,6 +111,10 @@ void GRRLIB_DrawTile (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color, const int frame) ;
void GRRLIB_DrawPart (const f32 xpos, const f32 ypos, const f32 partx, const f32 party, const f32 partw, const f32 parth, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color);
void GRRLIB_DrawTileQuad (const guVector pos[4], GRRLIB_texImg *tex,
const u32 color, const int frame) ;