Just about got the "Barrel" sample converted to C#, just have to add Simon, easy - it's math that's not my strong point! But I think the answer will help me with the rest of the conversions.
The scanlines aren't scaling properly to create the tunnel effect. I know the problem will have to do with my interpretation of when to convert between float and int. Something else that's throwing me off is the way that lerp is using 5 parameters, but all implementations I can find use 3, which makes sense to me - point a, and b, and how far between. So I don't understand how the 5 parameters are used (and couldn't find any examples on the net so far).
I've attached the project (Barrel.csproj is the concern), and also pasted the section of the problem code for your convenience.
/* raster effects (virtual HBLANK) */
static void MyRasterEffects(int line)
{
float angle;
float factor;
int size;
int index;
int dx;
angle = lerp(line, 0, Vres - 1, 0.0f, M_PI);
factor = (float)((1.0 - System.Math.Sin((double)angle)) * 0.4 + 1.0);
size = (int)((float)Hres * factor);
dx = (int)(((float)(size - Hres) / 2) / factor);
transform.sx = factor;
background.SetTransform(transform.angle, transform.dx, transform.dy, transform.sx, transform.sy);
if (line < 70)
{
index = (int)lerp(line, 0, 70, 0, 7);
background.Palette = palettes[index];
}
else if (line > 170)
{
index = (int)lerp(line, 170, Vres, 7, 0);
background.Palette = palettes[index];
}
else
background.Palette = palettes[7];
}
/* linear interploation */
static float lerp(int x, int x0, int x1, float fx0, float fx1)
{
return fx0 + (fx1 - fx0) * (float)((x - x0) / (x1 - x0));
}
The scanlines aren't scaling properly to create the tunnel effect. I know the problem will have to do with my interpretation of when to convert between float and int. Something else that's throwing me off is the way that lerp is using 5 parameters, but all implementations I can find use 3, which makes sense to me - point a, and b, and how far between. So I don't understand how the 5 parameters are used (and couldn't find any examples on the net so far).
I've attached the project (Barrel.csproj is the concern), and also pasted the section of the problem code for your convenience.
/* raster effects (virtual HBLANK) */
static void MyRasterEffects(int line)
{
float angle;
float factor;
int size;
int index;
int dx;
angle = lerp(line, 0, Vres - 1, 0.0f, M_PI);
factor = (float)((1.0 - System.Math.Sin((double)angle)) * 0.4 + 1.0);
size = (int)((float)Hres * factor);
dx = (int)(((float)(size - Hres) / 2) / factor);
transform.sx = factor;
background.SetTransform(transform.angle, transform.dx, transform.dy, transform.sx, transform.sy);
if (line < 70)
{
index = (int)lerp(line, 0, 70, 0, 7);
background.Palette = palettes[index];
}
else if (line > 170)
{
index = (int)lerp(line, 170, Vres, 7, 0);
background.Palette = palettes[index];
}
else
background.Palette = palettes[7];
}
/* linear interploation */
static float lerp(int x, int x0, int x1, float fx0, float fx1)
{
return fx0 + (fx1 - fx0) * (float)((x - x0) / (x1 - x0));
}