From f9e3976fd5d9b7ce4fc382bcdf71c9e4edd55693 Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Thu, 29 Apr 2010 19:36:03 +0000 Subject: [PATCH] [CHG] Code formatting --- GRRLIB/GRRLIB/GRRLIB_3D.c | 116 ++++++++++++++-------------- GRRLIB/GRRLIB/grrlib/GRRLIB_pixel.h | 28 ++++--- examples/3D_Light2/source/main.c | 48 ++++++------ 3 files changed, 97 insertions(+), 95 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB_3D.c b/GRRLIB/GRRLIB/GRRLIB_3D.c index f1832c3..6f5295e 100644 --- a/GRRLIB/GRRLIB/GRRLIB_3D.c +++ b/GRRLIB/GRRLIB/GRRLIB_3D.c @@ -160,46 +160,45 @@ void GRRLIB_2dMode() { * @param scalz z scale of the object. */ void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) { -Mtx ObjTransformationMtx; -Mtx m, rx,ry,rz; -Mtx mv, mvi; + Mtx ObjTransformationMtx; + Mtx m, rx,ry,rz; + Mtx mv, mvi; - guMtxIdentity(ObjTransformationMtx); + guMtxIdentity(ObjTransformationMtx); - if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)){ - guMtxIdentity(m); - guMtxScaleApply(m, m, scalx, scaly, scalz); + if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)) { + guMtxIdentity(m); + guMtxScaleApply(m, m, scalx, scaly, scalz); - guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); - } + guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); + } - if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)){ - guMtxIdentity(m); - guMtxRotAxisDeg(rx, &_GRRaxisx, angx); - guMtxRotAxisDeg(ry, &_GRRaxisy, angy); - guMtxRotAxisDeg(rz, &_GRRaxisz, angz); - guMtxConcat(ry, rx, m); - guMtxConcat(m, rz, m); + if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)) { + guMtxIdentity(m); + guMtxRotAxisDeg(rx, &_GRRaxisx, angx); + guMtxRotAxisDeg(ry, &_GRRaxisy, angy); + guMtxRotAxisDeg(rz, &_GRRaxisz, angz); + guMtxConcat(ry, rx, m); + guMtxConcat(m, rz, m); - guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); - } + guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); + } - if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)){ - guMtxIdentity(m); - guMtxTransApply(m, m, posx, posy, posz); + if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)) { + guMtxIdentity(m); + guMtxTransApply(m, m, posx, posy, posz); - guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); - } + guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); + } - guMtxConcat(_GRR_view, ObjTransformationMtx, mv); - GX_LoadPosMtxImm(mv, GX_PNMTX0); + guMtxConcat(_GRR_view, ObjTransformationMtx, mv); + GX_LoadPosMtxImm(mv, GX_PNMTX0); - guMtxInverse(mv, mvi); - guMtxTranspose(mvi, mv); - GX_LoadNrmMtxImm(mv, GX_PNMTX0); + guMtxInverse(mv, mvi); + guMtxTranspose(mvi, mv); + GX_LoadNrmMtxImm(mv, GX_PNMTX0); } - /** * Set the view matrix to draw object (in this order scale, trans AND rotate). * @param posx x position of the object. @@ -213,44 +212,43 @@ Mtx mv, mvi; * @param scalz z scale of the object. */ void GRRLIB_ObjectViewInv(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) { -Mtx ObjTransformationMtx; -Mtx m, rx,ry,rz; -Mtx mv, mvi; + Mtx ObjTransformationMtx; + Mtx m, rx,ry,rz; + Mtx mv, mvi; - guMtxIdentity(ObjTransformationMtx); + guMtxIdentity(ObjTransformationMtx); - if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)){ - guMtxIdentity(m); - guMtxScaleApply(m, m, scalx, scaly, scalz); + if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)) { + guMtxIdentity(m); + guMtxScaleApply(m, m, scalx, scaly, scalz); + + guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); + } - guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); - } + if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)) { + guMtxIdentity(m); + guMtxTransApply(m, m, posx, posy, posz); - if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)){ - guMtxIdentity(m); - guMtxTransApply(m, m, posx, posy, posz); + guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); + } - guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); - } + if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)) { + guMtxIdentity(m); + guMtxRotAxisDeg(rx, &_GRRaxisx, angx); + guMtxRotAxisDeg(ry, &_GRRaxisy, angy); + guMtxRotAxisDeg(rz, &_GRRaxisz, angz); + guMtxConcat(ry, rx, m); + guMtxConcat(m, rz, m); - if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)){ - guMtxIdentity(m); - guMtxRotAxisDeg(rx, &_GRRaxisx, angx); - guMtxRotAxisDeg(ry, &_GRRaxisy, angy); - guMtxRotAxisDeg(rz, &_GRRaxisz, angz); - guMtxConcat(ry, rx, m); - guMtxConcat(m, rz, m); + guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); + } - guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); - } + guMtxConcat(_GRR_view, ObjTransformationMtx, mv); + GX_LoadPosMtxImm(mv, GX_PNMTX0); - - guMtxConcat(_GRR_view, ObjTransformationMtx, mv); - GX_LoadPosMtxImm(mv, GX_PNMTX0); - - guMtxInverse(mv, mvi); - guMtxTranspose(mvi, mv); - GX_LoadNrmMtxImm(mv, GX_PNMTX0); + guMtxInverse(mv, mvi); + guMtxTranspose(mvi, mv); + GX_LoadNrmMtxImm(mv, GX_PNMTX0); } /** diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB_pixel.h b/GRRLIB/GRRLIB/grrlib/GRRLIB_pixel.h index 3b2d9b4..b42acdf 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB_pixel.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB_pixel.h @@ -25,6 +25,11 @@ THE SOFTWARE. * Inline functions for manipulating pixels in textures. */ +#define _SHIFTL(v, s, w) \ + ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) +#define _SHIFTR(v, s, w) \ + ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) + /** * Return the color value of a pixel from a GRRLIB_texImg. * @param x Specifies the x-coordinate of the pixel in the texture. @@ -69,31 +74,30 @@ void GRRLIB_SetPixelTotexImg (const int x, const int y, * Reads a pixel directly from the FrontBuffer. * @param x The x-coordinate within the FB. * @param y The y-coordinate within the FB. + * @return The color of a pixel in RGBA format. */ INLINE u32 GRRLIB_GetPixelFromFB (int x, int y) { - GXColor peekColor; - u32 MyColor; + u32 regval,val; - GX_PeekARGB(x, y, &peekColor); - MyColor = RGBA(peekColor.r,peekColor.g,peekColor.b,peekColor.a); + regval = 0xc8000000|(_SHIFTL(x,2,10)); + regval = (regval&~0x3FF000)|(_SHIFTL(y,12,10)); + val = *(u32*)regval; - return (MyColor); + return RGBA(_SHIFTR(val,16,8), _SHIFTR(val,8,8), val&0xff, _SHIFTR(val,24,8)); } /** * Writes a pixel directly from the FrontBuffer. * @param x The x-coordinate within the FB. * @param y The y-coordinate within the FB. + * @param pokeColor The color of the pixel in RGBA format. */ INLINE void GRRLIB_SetPixelToFB (int x, int y, u32 pokeColor) { - GXColor MyColor; + u32 regval; - MyColor.r=R(pokeColor); - MyColor.g=G(pokeColor); - MyColor.b=B(pokeColor); - MyColor.a=A(pokeColor); - - GX_PokeARGB(x, y, MyColor); + regval = 0xc8000000|(_SHIFTL(x,2,10)); + regval = (regval&~0x3FF000)|(_SHIFTL(y,12,10)); + *(u32*)regval = _SHIFTL(A(pokeColor),24,8) | _SHIFTL(R(pokeColor),16,8) | _SHIFTL(G(pokeColor),8,8) | (B(pokeColor)&0xff); } diff --git a/examples/3D_Light2/source/main.c b/examples/3D_Light2/source/main.c index 3122ec4..f1f5a4f 100644 --- a/examples/3D_Light2/source/main.c +++ b/examples/3D_Light2/source/main.c @@ -39,35 +39,35 @@ int main() { GRRLIB_Camera3dSettings(0.0f, 0.0f,13.0f, 0,1,0, 0,0,0); - GRRLIB_SetLightAmbient(0x333333FF); - GRRLIB_SetLightDiff(0,(guVector){0.0f,0.0f,0.0f},20.0f,1.0f,0x00FFFFFF); - GRRLIB_SetLightDiff(1,(guVector){0.0f,13.0f,3.0f},20.0f,1.0f,0xFF00FFFF); - GRRLIB_SetLightDiff(2,(guVector){0.0f,-13.0f,3.0f},20.0f,1.0f,0xFFFF00FF); - GRRLIB_SetLightDiff(3,(guVector){13.0f,0.0f,3.0f},20.0f,1.0f,0xFF0000FF); - GRRLIB_SetLightDiff(4,(guVector){-13.0f,0.0f,3.0f},20.0f,1.0f,0x00FF00FF); + GRRLIB_SetLightAmbient(0x333333FF); + GRRLIB_SetLightDiff(0,(guVector){0.0f,0.0f,0.0f},20.0f,1.0f,0x00FFFFFF); + GRRLIB_SetLightDiff(1,(guVector){0.0f,13.0f,3.0f},20.0f,1.0f,0xFF00FFFF); + GRRLIB_SetLightDiff(2,(guVector){0.0f,-13.0f,3.0f},20.0f,1.0f,0xFFFF00FF); + GRRLIB_SetLightDiff(3,(guVector){13.0f,0.0f,3.0f},20.0f,1.0f,0xFF0000FF); + GRRLIB_SetLightDiff(4,(guVector){-13.0f,0.0f,3.0f},20.0f,1.0f,0x00FF00FF); GRRLIB_3dMode(0.1,1000,45,0,1); - GRRLIB_ObjectViewInv(1.0f, -1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectViewInv(-1.0f, -1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectViewInv(1.0f, 1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectViewInv(-1.0f, 1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(1.0f, -1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(-1.0f, -1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(1.0f, 1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(-1.0f, 1.0f, 1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectViewInv(1.0f, -1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectViewInv(-1.0f, -1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectViewInv(1.0f, 1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectViewInv(-1.0f, 1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(1.0f, -1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(-1.0f, -1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(1.0f, 1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); + GRRLIB_ObjectViewInv(-1.0f, 1.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); - GRRLIB_ObjectView(0.0f, 0.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); - GRRLIB_DrawCube(3.0,true,0xFFFFFF44); + GRRLIB_ObjectView(0.0f, 0.0f, -1.0f, a, a*2, a*3, 1.0f, 1.0f, 1.0f); + GRRLIB_DrawCube(3.0, true, 0xFFFFFF44); a+=0.6f;