video zooming works

This commit is contained in:
dborth 2008-10-09 06:48:46 +00:00
parent 826af5846d
commit 09ad69dbf4
9 changed files with 118 additions and 93 deletions

View File

@ -271,8 +271,8 @@ int FileSelector (int method)
p = PAD_ButtonsDown (0); p = PAD_ButtonsDown (0);
ph = PAD_ButtonsHeld (0); ph = PAD_ButtonsHeld (0);
#ifdef HW_RVL #ifdef HW_RVL
wm_ay = WPAD_StickY (0, 0); wm_ay = WPAD_Stick (0, 0, 0);
wm_sx = WPAD_StickX (0, 1); wm_sx = WPAD_Stick (0, 1, 1);
wp = WPAD_ButtonsDown (0); wp = WPAD_ButtonsDown (0);
wh = WPAD_ButtonsHeld (0); wh = WPAD_ButtonsHeld (0);

View File

@ -82,14 +82,13 @@ unsigned int ncpadmap[] = {
WPAD_BUTTON_2, WPAD_BUTTON_1 WPAD_BUTTON_2, WPAD_BUTTON_1
}; };
#ifdef HW_RVL
/**************************************************************************** /****************************************************************************
* WPAD_StickX * WPAD_Stick
* *
* Get X value from Wii Joystick (classic, nunchuk) input * Get X/Y value from Wii Joystick (classic, nunchuk) input
***************************************************************************/ ***************************************************************************/
s8 WPAD_StickX(u8 chan,u8 right) s8 WPAD_Stick(u8 chan, u8 right, int axis)
{ {
float mag = 0.0; float mag = 0.0;
float ang = 0.0; float ang = 0.0;
@ -123,63 +122,19 @@ s8 WPAD_StickX(u8 chan,u8 right)
break; break;
} }
/* calculate X value (angle need to be converted into radian) */ /* calculate x/y value (angle need to be converted into radian) */
if (mag > 1.0) mag = 1.0; if (mag > 1.0) mag = 1.0;
else if (mag < -1.0) mag = -1.0; else if (mag < -1.0) mag = -1.0;
double val = mag * sin((PI * ang)/180.0f); double val;
if(axis == 0) // x-axis
val = mag * sin((PI * ang)/180.0f);
else // y-axis
val = mag * cos((PI * ang)/180.0f);
return (s8)(val * 128.0f); return (s8)(val * 128.0f);
} }
/****************************************************************************
* WPAD_StickY
*
* Get Y value from Wii Joystick (classic, nunchuk) input
***************************************************************************/
s8 WPAD_StickY(u8 chan, u8 right)
{
float mag = 0.0;
float ang = 0.0;
WPADData *data = WPAD_Data(chan);
switch (data->exp.type)
{
case WPAD_EXP_NUNCHUK:
case WPAD_EXP_GUITARHERO3:
if (right == 0)
{
mag = data->exp.nunchuk.js.mag;
ang = data->exp.nunchuk.js.ang;
}
break;
case WPAD_EXP_CLASSIC:
if (right == 0)
{
mag = data->exp.classic.ljs.mag;
ang = data->exp.classic.ljs.ang;
}
else
{
mag = data->exp.classic.rjs.mag;
ang = data->exp.classic.rjs.ang;
}
break;
default:
break;
}
/* calculate X value (angle need to be converted into radian) */
if (mag > 1.0) mag = 1.0;
else if (mag < -1.0) mag = -1.0;
double val = mag * cos((PI * ang)/180.0f);
return (s8)(val * 128.0f);
}
#endif
/**************************************************************************** /****************************************************************************
* DecodeJoy * DecodeJoy
* *
@ -196,10 +151,10 @@ u32 DecodeJoy(unsigned short pad)
u32 J = 0; u32 J = 0;
#ifdef HW_RVL #ifdef HW_RVL
signed char wm_ax = WPAD_StickX ((u8)pad, 0); signed char wm_ax = WPAD_Stick ((u8)pad, 0, 0);
signed char wm_ay = WPAD_StickY ((u8)pad, 0); signed char wm_ay = WPAD_Stick ((u8)pad, 0, 1);
u32 wp = WPAD_ButtonsHeld (pad); u32 wp = WPAD_ButtonsHeld (pad);
signed char wm_sx = WPAD_StickX (0,1); // CC right joystick signed char wm_sx = WPAD_Stick (0,1,0); // CC right joystick
u32 exp_type; u32 exp_type;
if ( WPAD_Probe(pad, &exp_type) != 0 ) exp_type = WPAD_EXP_NONE; if ( WPAD_Probe(pad, &exp_type) != 0 ) exp_type = WPAD_EXP_NONE;
@ -280,7 +235,7 @@ u32 DecodeJoy(unsigned short pad)
} }
#endif #endif
// Zoom feature // Turbo feature
if( if(
(gc_px > 70) (gc_px > 70)
#ifdef HW_RVL #ifdef HW_RVL
@ -317,12 +272,25 @@ u32 GetJoy()
int pad = 0; int pad = 0;
s8 gc_px = PAD_SubStickX (0); s8 gc_px = PAD_SubStickX (0);
s8 gc_py = PAD_SubStickY (0);
#ifdef HW_RVL #ifdef HW_RVL
s8 wm_sx = WPAD_StickX (0,1); s8 wm_sx = WPAD_Stick (0,1,0);
s8 wm_sy = WPAD_Stick (0,1,1);
u32 wm_pb = WPAD_ButtonsHeld (0); // wiimote / expansion button info u32 wm_pb = WPAD_ButtonsHeld (0); // wiimote / expansion button info
#endif #endif
// Check for video zoom
if (GCSettings.NGCZoom)
{
if (gc_py < -36 || gc_py > 36)
zoom ((float) gc_py / -36);
#ifdef HW_RVL
if (wm_sy < -36 || wm_sy > 36)
zoom ((float) wm_sy / -36);
#endif
}
// request to go back to menu // request to go back to menu
if ((gc_px < -70) if ((gc_px < -70)
#ifdef HW_RVL #ifdef HW_RVL

View File

@ -22,8 +22,7 @@ extern unsigned int wmpadmap[];
extern unsigned int ccpadmap[]; extern unsigned int ccpadmap[];
extern unsigned int ncpadmap[]; extern unsigned int ncpadmap[];
s8 WPAD_StickX(u8 chan,u8 right); s8 WPAD_Stick(u8 chan,u8 right, int axis);
s8 WPAD_StickY(u8 chan, u8 right);
u32 GetJoy(); u32 GetJoy();

View File

@ -94,7 +94,7 @@ LoadManager ()
/**************************************************************************** /****************************************************************************
* Preferences Menu * Preferences Menu
***************************************************************************/ ***************************************************************************/
static int prefmenuCount = 9; static int prefmenuCount = 10;
static char prefmenu[][50] = { static char prefmenu[][50] = {
"Load Method", "Load Method",
@ -105,6 +105,7 @@ static char prefmenu[][50] = {
"Auto Load", "Auto Load",
"Auto Save", "Auto Save",
"Verify MC Saves", "Verify MC Saves",
"Enable Zooming",
"Save Preferences", "Save Preferences",
"Back to Main Menu" "Back to Main Menu"
@ -148,6 +149,9 @@ PreferencesMenu ()
GCSettings.SaveMethod++; GCSettings.SaveMethod++;
if(GCSettings.SaveMethod == METHOD_MC_SLOTB) if(GCSettings.SaveMethod == METHOD_MC_SLOTB)
GCSettings.SaveMethod++; GCSettings.SaveMethod++;
prefmenu[6][0] = 0;
#else
sprintf (prefmenu[6], "Verify MC Saves %s", GCSettings.VerifySaves == true ? " ON" : "OFF");
#endif #endif
// correct load/save methods out of bounds // correct load/save methods out of bounds
@ -186,7 +190,8 @@ PreferencesMenu ()
else if (GCSettings.AutoSave == 2) sprintf (prefmenu[5],"Auto Save SNAPSHOT"); else if (GCSettings.AutoSave == 2) sprintf (prefmenu[5],"Auto Save SNAPSHOT");
else if (GCSettings.AutoSave == 3) sprintf (prefmenu[5],"Auto Save BOTH"); else if (GCSettings.AutoSave == 3) sprintf (prefmenu[5],"Auto Save BOTH");
//sprintf (prefmenu[6], "Verify MC Saves %s", GCSettings.VerifySaves == true ? " ON" : "OFF"); sprintf (prefmenu[7], "Enable Zooming %s",
GCSettings.NGCZoom == true ? " ON" : "OFF");
ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences", 16); ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences", 16);
@ -223,11 +228,15 @@ PreferencesMenu ()
break; break;
case 7: case 7:
GCSettings.NGCZoom ^= 1;
break;
case 8:
SavePrefs(GCSettings.SaveMethod, NOTSILENT); SavePrefs(GCSettings.SaveMethod, NOTSILENT);
break; break;
case -1: /*** Button B ***/ case -1: /*** Button B ***/
case 8: case 9:
quit = 1; quit = 1;
break; break;
@ -243,12 +252,13 @@ PreferencesMenu ()
int int
GameMenu () GameMenu ()
{ {
int gamemenuCount = 7; int gamemenuCount = 8;
char gamemenu[][50] = { char gamemenu[][50] = {
"Return to Game", "Return to Game",
"Reset Game", "Reset Game",
"Load SRAM", "Save SRAM", "Load SRAM", "Save SRAM",
"Load Game Snapshot", "Save Game Snapshot", "Load Game Snapshot", "Save Game Snapshot",
"Reset Zoom",
"Back to Main Menu" "Back to Main Menu"
}; };
@ -275,6 +285,9 @@ GameMenu ()
gamemenu[3][0] = '\0'; gamemenu[3][0] = '\0';
gamemenu[5][0] = '\0'; gamemenu[5][0] = '\0';
} }
// disable Reset Zoom if Zooming is off
if(!GCSettings.NGCZoom)
gamemenu[6][0] = '\0';
ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu"); ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu");
@ -306,8 +319,13 @@ GameMenu ()
SaveBatteryOrState(GCSettings.SaveMethod, 1, NOTSILENT); SaveBatteryOrState(GCSettings.SaveMethod, 1, NOTSILENT);
break; break;
case 6: // Reset Zoom
zoom_reset ();
quit = retval = 1;
break;
case -1: // Button B case -1: // Button B
case 6: // Return to previous menu case 7: // Return to previous menu
retval = 0; retval = 0;
quit = 1; quit = 1;
break; break;

View File

@ -538,7 +538,7 @@ RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x)
gc_ay = PAD_StickY (0); gc_ay = PAD_StickY (0);
p = PAD_ButtonsDown (0); p = PAD_ButtonsDown (0);
#ifdef HW_RVL #ifdef HW_RVL
wm_ay = WPAD_StickY (0,0); wm_ay = WPAD_Stick (0,0,1);
wp = WPAD_ButtonsDown (0); wp = WPAD_ButtonsDown (0);
#endif #endif

View File

@ -45,6 +45,7 @@ struct SGCSettings{
char smbgcid[20]; char smbgcid[20];
char smbsvid[20]; char smbsvid[20];
char smbshare[20]; char smbshare[20];
int NGCZoom; // 0 - off, 1 - on
int VerifySaves; int VerifySaves;
}; };

View File

@ -46,4 +46,5 @@ DefaultSettings ()
GCSettings.smbgcid[0] = 0; GCSettings.smbgcid[0] = 0;
GCSettings.VerifySaves = 0; GCSettings.VerifySaves = 0;
GCSettings.NGCZoom = 0; // zooming default off
} }

View File

@ -40,6 +40,8 @@ static int texturesize;
GXTexObj texobj; GXTexObj texobj;
static Mtx view; static Mtx view;
static int vwidth, vheight, oldvwidth, oldvheight; static int vwidth, vheight, oldvwidth, oldvheight;
static int video_vaspect, video_haspect;
float zoom_level = 1;
#define HASPECT 80 #define HASPECT 80
#define VASPECT 45 #define VASPECT 45
@ -73,6 +75,27 @@ static camera cam = { {0.0F, 0.0F, 0.0F},
{0.0F, 0.0F, -0.5F} {0.0F, 0.0F, -0.5F}
}; };
/****************************************************************************
* Drawing screen
***************************************************************************/
void
clearscreen ()
{
int colour = COLOR_BLACK;
whichfb ^= 1;
VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], colour);
memcpy (xfb[whichfb], &bg, 1280 * 480);
}
void
showscreen ()
{
VIDEO_SetNextFramebuffer (xfb[whichfb]);
VIDEO_Flush ();
VIDEO_WaitVSync ();
}
/**************************************************************************** /****************************************************************************
* StartGX * StartGX
****************************************************************************/ ****************************************************************************/
@ -157,6 +180,7 @@ void InitialiseVideo ()
VIDEO_SetNextFramebuffer(xfb[0]); VIDEO_SetNextFramebuffer(xfb[0]);
GX_Start(); GX_Start();
clearscreen();
} }
/**************************************************************************** /****************************************************************************
@ -211,12 +235,6 @@ static void draw_square(Mtx v)
void GX_Render_Init(int width, int height, int haspect, int vaspect) void GX_Render_Init(int width, int height, int haspect, int vaspect)
{ {
/*** Set new aspect (now with crap AR hack!) ***/
square[0] = square[9] = (-haspect - 7);
square[3] = square[6] = (haspect + 7);
square[1] = square[4] = (vaspect + 7);
square[7] = square[10] = (-vaspect - 7);
/*** Allocate 32byte aligned texture memory ***/ /*** Allocate 32byte aligned texture memory ***/
texturesize = (width * height) * 2; texturesize = (width * height) * 2;
@ -229,6 +247,8 @@ void GX_Render_Init(int width, int height, int haspect, int vaspect)
/*** Setup for first call to scaler ***/ /*** Setup for first call to scaler ***/
vwidth = vheight = oldvwidth = oldvheight = -1; vwidth = vheight = oldvwidth = oldvheight = -1;
video_vaspect = vaspect;
video_haspect = haspect;
} }
/**************************************************************************** /****************************************************************************
* GX_Render * GX_Render
@ -254,7 +274,22 @@ void GX_Render(int width, int height, u8 * buffer, int pitch)
if ((oldvheight != vheight) || (oldvwidth != vwidth)) if ((oldvheight != vheight) || (oldvwidth != vwidth))
{ {
/** Update scaling **/ // Update scaling
int xscale = video_haspect;
int yscale = video_vaspect;
// change zoom
xscale *= zoom_level;
yscale *= zoom_level;
// Set new aspect (now with crap AR hack!)
square[0] = square[9] = (-xscale - 7);
square[3] = square[6] = (xscale + 7);
square[1] = square[4] = (yscale + 7);
square[7] = square[10] = (-yscale - 7);
GX_InvVtxCache (); // update vertex cache
oldvwidth = vwidth; oldvwidth = vwidth;
oldvheight = vheight; oldvheight = vheight;
draw_init(); draw_init();
@ -263,7 +298,6 @@ void GX_Render(int width, int height, u8 * buffer, int pitch)
GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);
} }
GX_InvVtxCache();
GX_InvalidateTexAll(); GX_InvalidateTexAll();
GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL); GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
@ -316,25 +350,27 @@ void GX_Render(int width, int height, u8 * buffer, int pitch)
SMBTimer++; SMBTimer++;
} }
/**************************************************************************** /****************************************************************************
* Drawing screen * Zoom Functions
***************************************************************************/ ***************************************************************************/
void void
clearscreen (int c) zoom (float speed)
{ {
int colour = COLOR_BLACK; if (zoom_level > 1)
zoom_level += (speed / -100.0);
else
zoom_level += (speed / -200.0);
whichfb ^= 1; if (zoom_level < 0.5) zoom_level = 0.5;
VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], colour); else if (zoom_level > 10.0) zoom_level = 10.0;
memcpy (xfb[whichfb], &bg, 1280 * 480);
oldvheight = 0; // update video
} }
void void
showscreen () zoom_reset ()
{ {
VIDEO_SetNextFramebuffer (xfb[whichfb]); zoom_level = 1.0;
VIDEO_Flush ();
VIDEO_WaitVSync ();
}
oldvheight = 0; // update video
}

View File

@ -18,7 +18,9 @@ void InitialiseVideo ();
void GX_Start(); void GX_Start();
void GX_Render_Init(int width, int height, int haspect, int vaspect); void GX_Render_Init(int width, int height, int haspect, int vaspect);
void GX_Render(int width, int height, u8 * buffer, int pitch); void GX_Render(int width, int height, u8 * buffer, int pitch);
void clearscreen (int colour = COLOR_BLACK); void clearscreen ();
void showscreen (); void showscreen ();
void zoom (float speed);
void zoom_reset ();
#endif #endif