mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-21 20:39:57 +01:00
Fix runtime errors
This commit is contained in:
parent
8271f50df0
commit
365e1eb326
2 changed files with 12 additions and 4 deletions
|
@ -87,9 +87,9 @@ void drawTeleport(int16_t x, int16_t y, S3L_ScreenCoord size)
|
|||
int16_t halfSize = size / 2;
|
||||
|
||||
S3L_ScreenCoord x0 = S3L_max(0,x - halfSize);
|
||||
S3L_ScreenCoord x1 = S3L_min(S3L_RESOLUTION_X - 1,x + halfSize);
|
||||
S3L_ScreenCoord x1 = S3L_min(S3L_RESOLUTION_X,x + halfSize);
|
||||
S3L_ScreenCoord y0 = S3L_max(0,y - halfSize);
|
||||
S3L_ScreenCoord y1 = S3L_min(S3L_RESOLUTION_Y - 1,y + halfSize);
|
||||
S3L_ScreenCoord y1 = S3L_min(S3L_RESOLUTION_Y,y + halfSize);
|
||||
|
||||
for (S3L_ScreenCoord j = y0; j < y1; ++j)
|
||||
for (S3L_ScreenCoord i = x0; i < x1; ++i)
|
||||
|
@ -162,7 +162,10 @@ void draw()
|
|||
|
||||
project3DPointToScreen(teleportPoint,scene.camera,&screenPoint);
|
||||
|
||||
if (screenPoint.z < S3L_zBufferRead(screenPoint.x,screenPoint.y))
|
||||
if (screenPoint.w > 0 &&
|
||||
screenPoint.x >= 0 && screenPoint.x <= S3L_RESOLUTION_X &&
|
||||
screenPoint.y >= 0 && screenPoint.y <= S3L_RESOLUTION_Y &&
|
||||
screenPoint.z < S3L_zBufferRead(screenPoint.x,screenPoint.y))
|
||||
drawTeleport(screenPoint.x,screenPoint.y,screenPoint.w);
|
||||
|
||||
clock_t nowT = clock();
|
||||
|
|
|
@ -612,7 +612,12 @@ void S3L_newFrame();
|
|||
void S3L_zBufferClear();
|
||||
void S3L_stencilBufferClear();
|
||||
|
||||
/** Writes a value (not necessarily depth! depends on the format of z-buffer)
|
||||
to z-buffer (if enabled). Does NOT check boundaries! */
|
||||
void S3L_zBufferWrite(S3L_ScreenCoord x, S3L_ScreenCoord y, S3L_Unit value);
|
||||
|
||||
/** Reads a value (not necessarily depth! depends on the format of z-buffer)
|
||||
from z-buffer (if enabled). Does NOT check boundaries! */
|
||||
S3L_Unit S3L_zBufferRead(S3L_ScreenCoord x, S3L_ScreenCoord y);
|
||||
|
||||
static inline void S3L_rotate2DPoint(S3L_Unit *x, S3L_Unit *y, S3L_Unit angle);
|
||||
|
@ -1465,7 +1470,7 @@ void project3DPointToScreen(
|
|||
result->z = point.z;
|
||||
|
||||
result->w =
|
||||
(point.z < 0) ? 0 :
|
||||
(point.z <= 0) ? 0 :
|
||||
(
|
||||
(s * camera.focalLength * S3L_RESOLUTION_X) /
|
||||
(point.z * S3L_FRACTIONS_PER_UNIT)
|
||||
|
|
Loading…
Reference in a new issue