From c86e2a8d70f6c8ac1cc89c1d6d06d5011c5a3cef Mon Sep 17 00:00:00 2001 From: N0NameN0 Date: Sat, 7 Nov 2009 13:26:03 +0000 Subject: [PATCH] [ADD] GRRLIB_DrawPart to draw a specific part of a Texture. --- GRRLIB/GRRLIB/GRRLIB_render.c | 86 ++++++++++++++++++++++++++++++ GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h | 4 ++ 2 files changed, 90 insertions(+) diff --git a/GRRLIB/GRRLIB/GRRLIB_render.c b/GRRLIB/GRRLIB/GRRLIB_render.c index dfb963a..1d08102 100644 --- a/GRRLIB/GRRLIB/GRRLIB_render.c +++ b/GRRLIB/GRRLIB/GRRLIB_render.c @@ -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. diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h index d9d6eb6..4cf108d 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h @@ -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) ;