fixing raycasting
This commit is contained in:
parent
45dbc32a56
commit
d09db0dcb2
37
src/main.c
37
src/main.c
@ -3,6 +3,7 @@
|
||||
#define SPEED 2
|
||||
|
||||
Line l;
|
||||
s16 angle = 0;
|
||||
|
||||
const u8 map[10][10] = {{1,1,1,1,1,1,1,1,1,1},
|
||||
{1,0,0,0,0,0,0,0,0,1},
|
||||
@ -17,16 +18,34 @@ const u8 map[10][10] = {{1,1,1,1,1,1,1,1,1,1},
|
||||
|
||||
void castRay(s16 angle){
|
||||
u8 r,mx,my,mp,dof;
|
||||
float rx,ry,ra,xo,yo;
|
||||
fix16 rx,ry,ra,xo,yo;
|
||||
s16 ind = (int)((float)angle/360.0f*1024.0f);
|
||||
fix16 dx = sinFix16(ind);
|
||||
fix16 dy = cosFix16(ind);
|
||||
fix16 dy = sinFix16(ind);
|
||||
fix16 dx = cosFix16(ind);
|
||||
fix16 tan = fix16Div(dy, dx);
|
||||
fix16 aTan = fix16Div(-1, tan);
|
||||
s16 tanInt = fix16ToInt(fix16Mul(dx, 100));
|
||||
char str[10];
|
||||
sprintf(str, "%d", 10);
|
||||
BMP_drawText(str, 20, 0);
|
||||
fix16 aTan = fix16Div(FIX16(-1), tan);
|
||||
s16 tanInt = fix16ToInt(fix16Mul(aTan, FIX16(100)));
|
||||
dof = 0;
|
||||
if(angle > 180) {
|
||||
ry = FIX16(l.pt1.y / 10);
|
||||
rx = fix16Add(fix16Mul(fix16Sub(FIX16(l.pt1.y), ry),aTan),FIX16(l.pt1.x));
|
||||
yo = FIX16(-10);
|
||||
xo = fix16Mul(fix16Neg(yo),aTan);
|
||||
}
|
||||
if(angle < 180) {
|
||||
ry = FIX16((l.pt1.y / 10)+10);
|
||||
rx = fix16Add(fix16Mul(fix16Sub(FIX16(l.pt1.y), ry),aTan),FIX16(l.pt1.x));
|
||||
yo = FIX16(10);
|
||||
xo = fix16Mul(fix16Neg(yo),aTan);
|
||||
}
|
||||
if(angle == 0 || angle == 180){
|
||||
rx = FIX16(l.pt1.x);
|
||||
ry = FIX16(l.pt1.y);
|
||||
dof = 8;
|
||||
}
|
||||
while(dof<8){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void mapscan(){
|
||||
@ -56,7 +75,7 @@ void render(){
|
||||
BMP_drawLine(&l);
|
||||
|
||||
mapscan();
|
||||
castRay(10);
|
||||
castRay(286);
|
||||
|
||||
//Flip the data to the screen - i.e. actually draw the complete image on screen
|
||||
BMP_flip(1);
|
||||
|
Loading…
Reference in New Issue
Block a user