mirror of
https://gitlab.com/drummyfish/anarch.git
synced 2024-12-21 23:08:49 -05:00
Fix bug
This commit is contained in:
parent
0ec3940342
commit
7987b341b9
3
TODO.txt
3
TODO.txt
@ -14,10 +14,9 @@
|
|||||||
|
|
||||||
bugs:
|
bugs:
|
||||||
|
|
||||||
- sprite positioning inccuracy
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
||||||
- texture coords of floor walls should start from the floor? NO, CAUSES ISSUES
|
- texture coords of floor walls should start from the floor? NO, CAUSES ISSUES
|
||||||
- vertical visual noise when standing on elevator
|
- vertical visual noise when standing on elevator
|
||||||
|
- sprite positioning inccuracy
|
||||||
|
|
||||||
|
39
raycastlib.h
39
raycastlib.h
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
author: Miloslav "drummyfish" Ciz
|
author: Miloslav "drummyfish" Ciz
|
||||||
license: CC0 1.0
|
license: CC0 1.0
|
||||||
version: 0.85
|
version: 0.86
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#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.x = worldPosition.x - camera.position.x;
|
||||||
toPoint.y = worldPosition.y - camera.position.y;
|
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
|
// rotate the point
|
||||||
(d * RCL_vectorsAngleCos(cameraDir,toPoint)) / RCL_UNITS_PER_SQUARE;
|
|
||||||
|
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 -
|
result.position.y = camera.resolution.y / 2 -
|
||||||
(camera.resolution.y *
|
(camera.resolution.y *
|
||||||
RCL_perspectiveScale(height - camera.height,result.depth))
|
RCL_perspectiveScale(height - camera.height,result.depth))
|
||||||
/ RCL_UNITS_PER_SQUARE + camera.shear;
|
/ 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user