This commit is contained in:
Miloslav Číž 2019-10-07 02:40:50 +02:00
parent 0ec3940342
commit 7987b341b9
2 changed files with 17 additions and 25 deletions

View File

@ -14,10 +14,9 @@
bugs:
- sprite positioning inccuracy
done:
- texture coords of floor walls should start from the floor? NO, CAUSES ISSUES
- vertical visual noise when standing on elevator
- sprite positioning inccuracy

View File

@ -26,7 +26,7 @@
author: Miloslav "drummyfish" Ciz
license: CC0 1.0
version: 0.85
version: 0.86
*/
#include <stdint.h>
@ -1629,35 +1629,28 @@ RCL_PixelInfo RCL_mapToScreen(RCL_Vector2D worldPosition, RCL_Unit height,
toPoint.x = worldPosition.x - camera.position.x;
toPoint.y = worldPosition.y - camera.position.y;
RCL_Vector2D cameraDir = RCL_angleToDirection(camera.direction);
RCL_Unit middleColumn = camera.resolution.x / 2;
result.depth = // adjusted distance
(d * RCL_vectorsAngleCos(cameraDir,toPoint)) / RCL_UNITS_PER_SQUARE;
// rotate the point
RCL_Unit cos = RCL_cosInt(camera.direction);
RCL_Unit sin = RCL_sinInt(camera.direction);
RCL_Unit tmp = toPoint.x;
toPoint.x = (toPoint.x * cos - toPoint.y * sin) / RCL_UNITS_PER_SQUARE;
toPoint.y = (tmp * sin + toPoint.y * cos) / RCL_UNITS_PER_SQUARE;
result.depth = toPoint.x;
result.position.x =
middleColumn + (-1 * toPoint.y * middleColumn) / RCL_nonZero(result.depth);
result.position.y = camera.resolution.y / 2 -
(camera.resolution.y *
RCL_perspectiveScale(height - camera.height,result.depth))
/ RCL_UNITS_PER_SQUARE + camera.shear;
RCL_Unit middleColumn = camera.resolution.x / 2;
// compute the third side of the triangle
RCL_Unit a = RCL_sqrtInt(d * d - result.depth * result.depth);
RCL_Unit tmp = cameraDir.x; // rotate vector 90 degrees
cameraDir.x = cameraDir.y;
cameraDir.y = -1 * tmp;
/* decide whether the point is in the left or right part of screen, using
dot product (non-normalized, as we only need to compare to 0) */
if ((toPoint.x * cameraDir.x + toPoint.y * cameraDir.y) <= 0)
a *= -1;
result.position.x =
middleColumn + (a * middleColumn) / RCL_nonZero(result.depth);
return result;
}