mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-21 20:29:59 +01:00
Render correctly inside doors
This commit is contained in:
parent
b672387bee
commit
fe5617e168
1 changed files with 55 additions and 23 deletions
36
raycastlib.h
36
raycastlib.h
|
@ -128,7 +128,10 @@ typedef struct
|
||||||
Unit distance; /**< Euclidean distance to the hit position, or -1 if
|
Unit distance; /**< Euclidean distance to the hit position, or -1 if
|
||||||
no collision happened. */
|
no collision happened. */
|
||||||
Unit textureCoord; ///< Normalized (0 to UNITS_PER_SQUARE - 1) tex coord.
|
Unit textureCoord; ///< Normalized (0 to UNITS_PER_SQUARE - 1) tex coord.
|
||||||
Unit type; ///< Integer identifying type of square.
|
Unit arrayValue; /** Value returned by array function (most often this
|
||||||
|
will be the floor height). */
|
||||||
|
Unit type; /**< Integer identifying type of square (number
|
||||||
|
returned by type function, e.g. texture index).*/
|
||||||
uint8_t direction; ///< Direction of hit.
|
uint8_t direction; ///< Direction of hit.
|
||||||
Unit doorRoll; ///< Holds value of door roll.
|
Unit doorRoll; ///< Holds value of door roll.
|
||||||
} HitResult;
|
} HitResult;
|
||||||
|
@ -203,6 +206,21 @@ PixelInfo mapToScreen(Vector2D worldPosition, Unit height, Camera camera);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Casts a single ray and returns a list of collisions.
|
Casts a single ray and returns a list of collisions.
|
||||||
|
|
||||||
|
@param ray ray to be cast
|
||||||
|
@param arrayFunc function that will be used to determine collisions (hits)
|
||||||
|
with the ray (squares for which this function returns different values
|
||||||
|
are considered to have a collision between them), this will typically
|
||||||
|
be a function returning floor height
|
||||||
|
@param typeFunc optional (can be 0) function - if provided, it will be used
|
||||||
|
to mark the hit result with the number returned by this function
|
||||||
|
(it can be e.g. a texture index)
|
||||||
|
@param hitResults array in which the hit results will be stored (has to be
|
||||||
|
preallocated with at space for at least as many hit results as
|
||||||
|
maxHits specified with the constraints parameter)
|
||||||
|
@param hitResultsLen in this variable the number of hit results will be
|
||||||
|
returned
|
||||||
|
@param constraints specifies constraints for the ray cast
|
||||||
*/
|
*/
|
||||||
void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, ArrayFunction typeFunc,
|
void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, ArrayFunction typeFunc,
|
||||||
HitResult *hitResults, uint16_t *hitResultsLen, RayConstraints constraints);
|
HitResult *hitResults, uint16_t *hitResultsLen, RayConstraints constraints);
|
||||||
|
@ -682,8 +700,8 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, ArrayFunction typeFunc,
|
||||||
|
|
||||||
HitResult h;
|
HitResult h;
|
||||||
|
|
||||||
|
h.arrayValue = currentType;
|
||||||
h.doorRoll = 0;
|
h.doorRoll = 0;
|
||||||
|
|
||||||
h.position = currentPos;
|
h.position = currentPos;
|
||||||
h.square = currentSquare;
|
h.square = currentSquare;
|
||||||
h.distance = dist(initialPos,currentPos);
|
h.distance = dist(initialPos,currentPos);
|
||||||
|
@ -996,6 +1014,19 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
|
|
||||||
if (_rollFunction != 0)
|
if (_rollFunction != 0)
|
||||||
{
|
{
|
||||||
|
if (hit.arrayValue == 0)
|
||||||
|
{
|
||||||
|
// standing inside door square, looking out => move to the next hit
|
||||||
|
|
||||||
|
if (hitCount > 1)
|
||||||
|
hit = hits[1];
|
||||||
|
else
|
||||||
|
goOn = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// normal hit, check the door roll
|
||||||
|
|
||||||
Unit doorRoll = hit.doorRoll;
|
Unit doorRoll = hit.doorRoll;
|
||||||
|
|
||||||
int8_t unrolled = doorRoll >= 0 ?
|
int8_t unrolled = doorRoll >= 0 ?
|
||||||
|
@ -1024,6 +1055,7 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p.hit = hit;
|
p.hit = hit;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue