Continue block collisions
This commit is contained in:
parent
011cd891c1
commit
fa66324833
4 changed files with 100 additions and 36 deletions
53
racing.h
53
racing.h
|
@ -61,18 +61,22 @@ TPE_Vec3 _LCR_racingBlockEnvFunc(TPE_Vec3 point, const uint8_t *block)
|
|||
{
|
||||
uint8_t bx, by, bz;
|
||||
LCR_mapBlockGetCoords(block,&bx,&by,&bz);
|
||||
|
||||
TPE_Vec3 blockOffset = TPE_vec3(
|
||||
(((int) bx) - LCR_MAP_SIZE_BLOCKS / 2) * LCR_PHYSICS_UNIT,
|
||||
(((int) by) - LCR_MAP_SIZE_BLOCKS / 2) * (LCR_PHYSICS_UNIT / 2),
|
||||
(((int) bz) - LCR_MAP_SIZE_BLOCKS / 2) * LCR_PHYSICS_UNIT);
|
||||
|
||||
TPE_Vec3 center = TPE_vec3(
|
||||
(((int) bx) - LCR_MAP_SIZE_BLOCKS / 2) * LCR_PHYSICS_UNIT
|
||||
+ LCR_PHYSICS_UNIT / 2,
|
||||
(((int) by) - LCR_MAP_SIZE_BLOCKS / 2) * (LCR_PHYSICS_UNIT / 2)
|
||||
+ LCR_PHYSICS_UNIT / 4,
|
||||
(((int) bz) - LCR_MAP_SIZE_BLOCKS / 2) * LCR_PHYSICS_UNIT
|
||||
+ LCR_PHYSICS_UNIT / 2);
|
||||
point = TPE_vec3Minus(point,blockOffset); // shift to origin
|
||||
|
||||
point = TPE_vec3Minus(point,center); // shift to origin
|
||||
uint8_t transform =
|
||||
LCR_mapBlockOppositeTransform(LCR_mapBlockGetTransform(block));
|
||||
|
||||
// TODO: transform
|
||||
LCR_TRANSFORM_COORDS(transform,point.x,point.y,point.z,(LCR_PHYSICS_UNIT / 2),
|
||||
(LCR_PHYSICS_UNIT / 4))
|
||||
|
||||
point = TPE_vec3Minus(point,TPE_vec3(
|
||||
LCR_PHYSICS_UNIT / 2,LCR_PHYSICS_UNIT / 4,LCR_PHYSICS_UNIT / 2));
|
||||
|
||||
switch (block[0])
|
||||
{
|
||||
|
@ -121,9 +125,15 @@ TPE_Vec3 _LCR_racingBlockEnvFunc(TPE_Vec3 point, const uint8_t *block)
|
|||
case LCR_BLOCK_RAMP_14:
|
||||
{
|
||||
TPE_Unit sides[6];
|
||||
sides[0] = -1 * LCR_PHYSICS_UNIT / 2; sides[1] = -1 * LCR_PHYSICS_UNIT / 2;
|
||||
sides[2] = LCR_PHYSICS_UNIT / 2; sides[3] = -1 * LCR_PHYSICS_UNIT / 2;
|
||||
sides[4] = LCR_PHYSICS_UNIT / 2; sides[5] = LCR_PHYSICS_UNIT / 2;
|
||||
sides[0] = -1 * LCR_PHYSICS_UNIT / 2;
|
||||
sides[1] = -1 * LCR_PHYSICS_UNIT / 4;
|
||||
|
||||
sides[2] = LCR_PHYSICS_UNIT / 2;
|
||||
sides[3] = -1 * LCR_PHYSICS_UNIT / 4;
|
||||
|
||||
sides[4] = LCR_PHYSICS_UNIT / 2;
|
||||
sides[5] = -1 * LCR_PHYSICS_UNIT / 4 +
|
||||
LCR_rampHeight4ths(block[0]) * (LCR_PHYSICS_UNIT / 8);
|
||||
|
||||
point = TPE_envAATriPrism(point,TPE_vec3(0,0,0),sides,LCR_PHYSICS_UNIT,2);
|
||||
break;
|
||||
|
@ -134,16 +144,17 @@ TPE_Vec3 _LCR_racingBlockEnvFunc(TPE_Vec3 point, const uint8_t *block)
|
|||
break;
|
||||
}
|
||||
|
||||
// TODO: untransform
|
||||
point = TPE_vec3Plus(point,
|
||||
TPE_vec3(LCR_PHYSICS_UNIT / 2,LCR_PHYSICS_UNIT / 4,LCR_PHYSICS_UNIT / 2));
|
||||
|
||||
point = TPE_vec3Plus(point,center); // shift back
|
||||
transform = LCR_mapBlockOppositeTransform(transform);
|
||||
|
||||
LCR_TRANSFORM_COORDS(transform,point.x,point.y,point.z,LCR_PHYSICS_UNIT,
|
||||
(LCR_PHYSICS_UNIT / 2))
|
||||
|
||||
point = TPE_vec3Plus(point,blockOffset); // shift back
|
||||
|
||||
return point;
|
||||
|
||||
/*
|
||||
return TPE_envAABox(point,center,TPE_vec3(LCR_PHYSICS_UNIT / 2,
|
||||
LCR_PHYSICS_UNIT / 4,LCR_PHYSICS_UNIT / 2));
|
||||
*/
|
||||
}
|
||||
|
||||
TPE_Vec3 _LCR_racingEnvironmentFunction(TPE_Vec3 point, TPE_Unit maxDist)
|
||||
|
@ -154,6 +165,10 @@ TPE_Vec3 _LCR_racingEnvironmentFunction(TPE_Vec3 point, TPE_Unit maxDist)
|
|||
(LCR_PHYSICS_UNIT * LCR_MAP_SIZE_BLOCKS) / 2,
|
||||
LCR_PHYSICS_UNIT * LCR_MAP_SIZE_BLOCKS)),point)
|
||||
|
||||
// without this check we might try to get block outside the map
|
||||
if (_pBest.x == point.x && _pBest.y == point.y && _pBest.z == point.z)
|
||||
return _pBest;
|
||||
|
||||
if (maxDist <= LCR_PHYSICS_UNIT / 4) // considering half of square height
|
||||
{
|
||||
/* Here we only check the 8 closest blocks => relatively fast. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue