[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,46 +160,45 @@ 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);
guMtxRotAxisDeg(rz, &_GRRaxisz, angz); guMtxRotAxisDeg(rz, &_GRRaxisz, angz);
guMtxConcat(ry, rx, m); guMtxConcat(ry, rx, m);
guMtxConcat(m, rz, m); guMtxConcat(m, rz, m);
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);
} }
guMtxConcat(_GRR_view, ObjTransformationMtx, mv); guMtxConcat(_GRR_view, ObjTransformationMtx, mv);
GX_LoadPosMtxImm(mv, GX_PNMTX0); GX_LoadPosMtxImm(mv, GX_PNMTX0);
guMtxInverse(mv, mvi); guMtxInverse(mv, mvi);
guMtxTranspose(mvi, mv); guMtxTranspose(mvi, mv);
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,44 +212,43 @@ 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);
guMtxRotAxisDeg(rz, &_GRRaxisz, angz); guMtxRotAxisDeg(rz, &_GRRaxisz, angz);
guMtxConcat(ry, rx, m); guMtxConcat(ry, rx, m);
guMtxConcat(m, rz, 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); guMtxInverse(mv, mvi);
GX_LoadPosMtxImm(mv, GX_PNMTX0); guMtxTranspose(mvi, mv);
GX_LoadNrmMtxImm(mv, GX_PNMTX0);
guMtxInverse(mv, mvi);
guMtxTranspose(mvi, mv);
GX_LoadNrmMtxImm(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

@ -39,35 +39,35 @@ int main() {
GRRLIB_Camera3dSettings(0.0f, 0.0f,13.0f, 0,1,0, 0,0,0); GRRLIB_Camera3dSettings(0.0f, 0.0f,13.0f, 0,1,0, 0,0,0);
GRRLIB_SetLightAmbient(0x333333FF); GRRLIB_SetLightAmbient(0x333333FF);
GRRLIB_SetLightDiff(0,(guVector){0.0f,0.0f,0.0f},20.0f,1.0f,0x00FFFFFF); 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(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(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(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_SetLightDiff(4,(guVector){-13.0f,0.0f,3.0f},20.0f,1.0f,0x00FF00FF);
GRRLIB_3dMode(0.1,1000,45,0,1); 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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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;