[CHG] Code formatting

This commit is contained in:
Crayon2000 2010-04-29 19:36:03 +00:00
parent 04cec42e7c
commit f9e3976fd5
3 changed files with 97 additions and 95 deletions

View file

@ -160,20 +160,20 @@ void GRRLIB_2dMode() {
* @param scalz z scale of the object. * @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) { void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) {
Mtx ObjTransformationMtx; Mtx ObjTransformationMtx;
Mtx m, rx,ry,rz; Mtx m, rx,ry,rz;
Mtx mv, mvi; Mtx mv, mvi;
guMtxIdentity(ObjTransformationMtx); guMtxIdentity(ObjTransformationMtx);
if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)){ if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)) {
guMtxIdentity(m); guMtxIdentity(m);
guMtxScaleApply(m, m, scalx, scaly, scalz); guMtxScaleApply(m, m, scalx, scaly, scalz);
guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx);
} }
if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)){ if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)) {
guMtxIdentity(m); guMtxIdentity(m);
guMtxRotAxisDeg(rx, &_GRRaxisx, angx); guMtxRotAxisDeg(rx, &_GRRaxisx, angx);
guMtxRotAxisDeg(ry, &_GRRaxisy, angy); guMtxRotAxisDeg(ry, &_GRRaxisy, angy);
@ -184,7 +184,7 @@ Mtx mv, mvi;
guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx);
} }
if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)){ if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)) {
guMtxIdentity(m); guMtxIdentity(m);
guMtxTransApply(m, m, posx, posy, posz); guMtxTransApply(m, m, posx, posy, posz);
@ -199,7 +199,6 @@ Mtx mv, mvi;
GX_LoadNrmMtxImm(mv, GX_PNMTX0); GX_LoadNrmMtxImm(mv, GX_PNMTX0);
} }
/** /**
* Set the view matrix to draw object (in this order scale, trans AND rotate). * Set the view matrix to draw object (in this order scale, trans AND rotate).
* @param posx x position of the object. * @param posx x position of the object.
@ -213,27 +212,27 @@ Mtx mv, mvi;
* @param scalz z scale of the object. * @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) { void GRRLIB_ObjectViewInv(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) {
Mtx ObjTransformationMtx; Mtx ObjTransformationMtx;
Mtx m, rx,ry,rz; Mtx m, rx,ry,rz;
Mtx mv, mvi; Mtx mv, mvi;
guMtxIdentity(ObjTransformationMtx); guMtxIdentity(ObjTransformationMtx);
if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)){ if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)) {
guMtxIdentity(m); guMtxIdentity(m);
guMtxScaleApply(m, m, scalx, scaly, scalz); guMtxScaleApply(m, m, scalx, scaly, scalz);
guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx);
} }
if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)){ if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)) {
guMtxIdentity(m); guMtxIdentity(m);
guMtxTransApply(m, m, posx, posy, posz); guMtxTransApply(m, m, posx, posy, posz);
guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx);
} }
if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)){ if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)) {
guMtxIdentity(m); guMtxIdentity(m);
guMtxRotAxisDeg(rx, &_GRRaxisx, angx); guMtxRotAxisDeg(rx, &_GRRaxisx, angx);
guMtxRotAxisDeg(ry, &_GRRaxisy, angy); guMtxRotAxisDeg(ry, &_GRRaxisy, angy);
@ -244,7 +243,6 @@ Mtx mv, mvi;
guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx);
} }
guMtxConcat(_GRR_view, ObjTransformationMtx, mv); guMtxConcat(_GRR_view, ObjTransformationMtx, mv);
GX_LoadPosMtxImm(mv, GX_PNMTX0); GX_LoadPosMtxImm(mv, GX_PNMTX0);

View file

@ -25,6 +25,11 @@ THE SOFTWARE.
* Inline functions for manipulating pixels in textures. * 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. * Return the color value of a pixel from a GRRLIB_texImg.
* @param x Specifies the x-coordinate of the pixel in the texture. * @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. * Reads a pixel directly from the FrontBuffer.
* @param x The x-coordinate within the FB. * @param x The x-coordinate within the FB.
* @param y The y-coordinate within the FB. * @param y The y-coordinate within the FB.
* @return The color of a pixel in RGBA format.
*/ */
INLINE INLINE
u32 GRRLIB_GetPixelFromFB (int x, int y) { u32 GRRLIB_GetPixelFromFB (int x, int y) {
GXColor peekColor; u32 regval,val;
u32 MyColor;
GX_PeekARGB(x, y, &peekColor); regval = 0xc8000000|(_SHIFTL(x,2,10));
MyColor = RGBA(peekColor.r,peekColor.g,peekColor.b,peekColor.a); 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. * Writes a pixel directly from the FrontBuffer.
* @param x The x-coordinate within the FB. * @param x The x-coordinate within the FB.
* @param y The y-coordinate within the FB. * @param y The y-coordinate within the FB.
* @param pokeColor The color of the pixel in RGBA format.
*/ */
INLINE INLINE
void GRRLIB_SetPixelToFB (int x, int y, u32 pokeColor) { void GRRLIB_SetPixelToFB (int x, int y, u32 pokeColor) {
GXColor MyColor; u32 regval;
MyColor.r=R(pokeColor); regval = 0xc8000000|(_SHIFTL(x,2,10));
MyColor.g=G(pokeColor); regval = (regval&~0x3FF000)|(_SHIFTL(y,12,10));
MyColor.b=B(pokeColor); *(u32*)regval = _SHIFTL(A(pokeColor),24,8) | _SHIFTL(R(pokeColor),16,8) | _SHIFTL(G(pokeColor),8,8) | (B(pokeColor)&0xff);
MyColor.a=A(pokeColor);
GX_PokeARGB(x, y, MyColor);
} }

View file

@ -67,7 +67,7 @@ int main() {
GRRLIB_DrawSphere(objscal,objqual,objqual,true,0xFFFFFFFF); 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_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_DrawCube(3.0, true, 0xFFFFFF44);
a+=0.6f; a+=0.6f;