@@ -124,6 +124,8 @@ double spriteDistance[numSprites];
124
124
125
125
double lookVert = 0 ;
126
126
127
+ double eyePos = 0 ;
128
+
127
129
// lookVert should have values between -LOOK_UP_MAX and LOOK_UP_MAX
128
130
#define LOOK_UP_MAX 128
129
131
@@ -338,7 +340,7 @@ int main(int /*argc*/, char */*argv*/[])
338
340
339
341
// Horizontal distance from the camera to the floor for the current row.
340
342
// 0.5 is the z position exactly in the middle between floor and ceiling.
341
- float rowDistance = posZ / p;
343
+ float rowDistance = ( posZ + eyePos) / p;
342
344
343
345
// calculate the real world step vector we have to add for each x (parallel to camera plane)
344
346
// adding step by step avoids multiplications with a weight in the inner loop
@@ -396,7 +398,7 @@ int main(int /*argc*/, char */*argv*/[])
396
398
397
399
// Horizontal distance from the camera to the floor for the current row.
398
400
// 0.5 is the z position exactly in the middle between floor and ceiling.
399
- float rowDistance = posZ / p;
401
+ float rowDistance = ( posZ - eyePos) / p;
400
402
401
403
// calculate the real world step vector we have to add for each x (parallel to camera plane)
402
404
// adding step by step avoids multiplications with a weight in the inner loop
@@ -538,8 +540,8 @@ int main(int /*argc*/, char */*argv*/[])
538
540
int lineHeight = (int )(h / perpWallDist);
539
541
540
542
// calculate lowest and highest pixel to fill in current stripe
541
- int drawStart = -lineHeight / 2 + h / 2 + lookVert;
542
- int drawEnd = lineHeight / 2 + h / 2 + lookVert;
543
+ int drawStart = -lineHeight / 2 + h / 2 + lookVert + eyePos/perpWallDist ;
544
+ int drawEnd = lineHeight / 2 + h / 2 + lookVert + eyePos/perpWallDist ;
543
545
544
546
// calculate value of wallX
545
547
double wallX; // where exactly the wall was hit
@@ -644,8 +646,8 @@ int main(int /*argc*/, char */*argv*/[])
644
646
// calculate height of the sprite on screen
645
647
int spriteHeight = abs (int (h / (transformY))) / vDiv; // using "transformY" instead of the real distance prevents fisheye
646
648
// calculate lowest and highest pixel to fill in current stripe
647
- int drawStartY = -spriteHeight / 2 + h / 2 + vMoveScreen + lookVert;
648
- int drawEndY = spriteHeight / 2 + h / 2 + vMoveScreen + lookVert;
649
+ int drawStartY = -spriteHeight / 2 + h / 2 + vMoveScreen + lookVert + eyePos/transformY ;
650
+ int drawEndY = spriteHeight / 2 + h / 2 + vMoveScreen + lookVert + eyePos/transformY ;
649
651
650
652
// calculate width of the sprite
651
653
int spriteWidth = abs (int (h / (transformY))) / uDiv; // same as height of sprite, given that it's square
@@ -804,6 +806,30 @@ int main(int /*argc*/, char */*argv*/[])
804
806
lookVert = 0 ;
805
807
}
806
808
}
809
+ if (keyDown (SDLK_x)) {
810
+ if (eyePos == 0 )
811
+ eyePos = 128 ;
812
+ } else if (keyDown (SDLK_c)) {
813
+ if (eyePos <= 0 && eyePos > -128 ) {
814
+ eyePos -= frameTime * 400 ;
815
+ if (eyePos < -128 ) {
816
+ eyePos = -128 ;
817
+ }
818
+ }
819
+ } else {
820
+ if (eyePos < 0 ) {
821
+ eyePos += frameTime * 400 ;
822
+ if (eyePos > 0 ) {
823
+ eyePos = 0 ;
824
+ }
825
+ }
826
+ }
827
+ if (eyePos > 0 ) {
828
+ eyePos -= frameTime * 400 ;
829
+ if (eyePos < 0 ) {
830
+ eyePos = 0 ;
831
+ }
832
+ }
807
833
if (keyDown (SDLK_ESCAPE))
808
834
{
809
835
break ;
0 commit comments