вот мой исходный код:
Код: Выделить всё
//STOPPPED VIDEO AT 7:40
//fixed rescaling error
//removed input lag and changed movement functions
#include
#include
#include
#include
#define PI 3.1415926535
#define P2 PI/2
#define P3 3*PI/2
#define DR 0.0174533 //one degree in radians
typedef struct
{
int w,a,d,s; //button state on off
}ButtonKeys; ButtonKeys Keys;
//TEXTURES
int All_Textures[]= //all 32x32 textures
{
//Checkerboard
0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
0,0,0,0,0,1,1,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
0,0,1,1,1,1,1,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
0,0,1,1,1,1,1,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
0,0,0,0,0,1,1,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0,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//else, if ray doesnt hit wall, see next line
else{rx+=xo; ry+=yo; dof+=1;}
}
//vertical line check
dof=0;
float disV=1000000,vx=px,vy=py;
float nTan=-tan(ra);
//if looking left
if(ra>P2 && ra>6)6)>6; mp=my*mapX+mx;
//stop if ray hits wall
if(mp>0 && mp0){vx=rx; vy=ry; disV=dist(px,py,vx,vy,ra); dof=8;}
//else, if ray doesnt hit wall, see next line
else{rx+=xo; ry+=yo; dof+=1;}
}
//shading
float shade=1;
//vertical wall hit
if(disV180){tx=31-tx;}
for(y=0;y
Подробнее здесь: [url]https://stackoverflow.com/questions/79108688/raycaster-is-not-mirroring-textures-on-the-y-axis[/url]