mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
items: move Item_TestBoundsCollide to trx
This commit is contained in:
parent
92f31152e9
commit
baff3bfc16
11 changed files with 41 additions and 63 deletions
|
@ -510,3 +510,33 @@ void Item_PlayAnimSFX(
|
|||
|
||||
Sound_Effect(data->effect_num, &item->pos, play_mode);
|
||||
}
|
||||
|
||||
bool Item_TestBoundsCollide(
|
||||
const ITEM *const src_item, const ITEM *const dst_item,
|
||||
const int32_t radius)
|
||||
{
|
||||
const BOUNDS_16 *const src_bounds = &Item_GetBestFrame(src_item)->bounds;
|
||||
const BOUNDS_16 *const dst_bounds = &Item_GetBestFrame(dst_item)->bounds;
|
||||
|
||||
if (src_item->pos.y + src_bounds->min.y
|
||||
>= dst_item->pos.y + dst_bounds->max.y
|
||||
|| src_item->pos.y + src_bounds->max.y
|
||||
<= dst_item->pos.y + dst_bounds->min.y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int32_t c = Math_Cos(src_item->rot.y);
|
||||
const int32_t s = Math_Sin(src_item->rot.y);
|
||||
const int32_t dx = dst_item->pos.x - src_item->pos.x;
|
||||
const int32_t dz = dst_item->pos.z - src_item->pos.z;
|
||||
const int32_t rx = (c * dx - s * dz) >> W2V_SHIFT;
|
||||
const int32_t rz = (c * dz + s * dx) >> W2V_SHIFT;
|
||||
|
||||
// clang-format off
|
||||
return (
|
||||
rx >= src_bounds->min.x - radius &&
|
||||
rx <= src_bounds->max.x + radius &&
|
||||
rz >= src_bounds->min.z - radius &&
|
||||
rz <= src_bounds->max.z + radius);
|
||||
// clang-format on
|
||||
}
|
||||
|
|
|
@ -151,3 +151,8 @@ void Lara_TakeDamage(const int16_t damage, const bool hit_status)
|
|||
{
|
||||
Item_TakeDamage(Lara_GetItem(), damage, hit_status);
|
||||
}
|
||||
|
||||
bool Lara_TestBoundsCollide(const ITEM *const item, const int32_t radius)
|
||||
{
|
||||
return Item_TestBoundsCollide(item, Lara_GetItem(), radius);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "game/lara/misc.h"
|
||||
|
||||
#include "game/items.h"
|
||||
#include "game/lara/common.h"
|
||||
#include "game/lara/const.h"
|
||||
#include "game/rooms.h"
|
||||
|
|
|
@ -50,3 +50,6 @@ void Item_Translate(ITEM *item, int32_t x, int32_t y, int32_t z);
|
|||
|
||||
void Item_Animate(ITEM *item);
|
||||
void Item_PlayAnimSFX(const ITEM *item, const ANIM_COMMAND_EFFECT_DATA *data);
|
||||
|
||||
bool Item_TestBoundsCollide(
|
||||
const ITEM *src_item, const ITEM *dst_item, int32_t radius);
|
||||
|
|
|
@ -11,3 +11,5 @@ OBJECT_MESH *Lara_GetMesh(LARA_MESH mesh);
|
|||
void Lara_SetMesh(LARA_MESH mesh, OBJECT_MESH *mesh_ptr);
|
||||
const ANIM_FRAME *Lara_GetHitFrame(const ITEM *item);
|
||||
void Lara_TakeDamage(int16_t damage, bool hit_status);
|
||||
|
||||
bool Lara_TestBoundsCollide(const ITEM *item, int32_t radius);
|
||||
|
|
|
@ -196,30 +196,6 @@ bool Item_Test3DRange(int32_t x, int32_t y, int32_t z, int32_t range)
|
|||
&& (SQUARE(x) + SQUARE(y) + SQUARE(z) < SQUARE(range));
|
||||
}
|
||||
|
||||
bool Item_TestBoundsCollide(ITEM *src_item, ITEM *dst_item, int32_t radius)
|
||||
{
|
||||
const BOUNDS_16 *const src_bounds = &Item_GetBestFrame(src_item)->bounds;
|
||||
const BOUNDS_16 *const dst_bounds = &Item_GetBestFrame(dst_item)->bounds;
|
||||
if (dst_item->pos.y + dst_bounds->max.y
|
||||
<= src_item->pos.y + src_bounds->min.y
|
||||
|| dst_item->pos.y + dst_bounds->min.y
|
||||
>= src_item->pos.y + src_bounds->max.y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int32_t c = Math_Cos(dst_item->rot.y);
|
||||
const int32_t s = Math_Sin(dst_item->rot.y);
|
||||
const int32_t x = src_item->pos.x - dst_item->pos.x;
|
||||
const int32_t z = src_item->pos.z - dst_item->pos.z;
|
||||
const int32_t rx = (c * x - s * z) >> W2V_SHIFT;
|
||||
const int32_t rz = (c * z + s * x) >> W2V_SHIFT;
|
||||
const int32_t min_x = dst_bounds->min.x - radius;
|
||||
const int32_t max_x = dst_bounds->max.x + radius;
|
||||
const int32_t min_z = dst_bounds->min.z - radius;
|
||||
const int32_t max_z = dst_bounds->max.z + radius;
|
||||
return rx >= min_x && rx <= max_x && rz >= min_z && rz <= max_z;
|
||||
}
|
||||
|
||||
bool Item_TestPosition(
|
||||
const ITEM *const src_item, const ITEM *const dst_item,
|
||||
const OBJECT_BOUNDS *const bounds)
|
||||
|
|
|
@ -11,7 +11,6 @@ int16_t Item_Spawn(const ITEM *item, GAME_OBJECT_ID obj_id);
|
|||
|
||||
bool Item_IsNearItem(const ITEM *item, const XYZ_32 *pos, int32_t distance);
|
||||
bool Item_Test3DRange(int32_t x, int32_t y, int32_t z, int32_t range);
|
||||
bool Item_TestBoundsCollide(ITEM *src_item, ITEM *dst_item, int32_t radius);
|
||||
bool Item_TestPosition(
|
||||
const ITEM *src_item, const ITEM *dst_item, const OBJECT_BOUNDS *bounds);
|
||||
void Item_AlignPosition(ITEM *src_item, ITEM *dst_item, XYZ_32 *vec);
|
||||
|
|
|
@ -701,11 +701,6 @@ bool Lara_IsNearItem(const XYZ_32 *pos, int32_t distance)
|
|||
return Item_IsNearItem(g_LaraItem, pos, distance);
|
||||
}
|
||||
|
||||
bool Lara_TestBoundsCollide(ITEM *item, int32_t radius)
|
||||
{
|
||||
return Item_TestBoundsCollide(g_LaraItem, item, radius);
|
||||
}
|
||||
|
||||
bool Lara_TestPosition(const ITEM *item, const OBJECT_BOUNDS *const bounds)
|
||||
{
|
||||
return Item_TestPosition(g_LaraItem, item, bounds);
|
||||
|
|
|
@ -26,7 +26,6 @@ void Lara_SwapMeshExtra(void);
|
|||
bool Lara_IsNearItem(const XYZ_32 *pos, int32_t distance);
|
||||
void Lara_UseItem(GAME_OBJECT_ID obj_id);
|
||||
|
||||
bool Lara_TestBoundsCollide(ITEM *item, int32_t radius);
|
||||
bool Lara_TestPosition(const ITEM *item, const OBJECT_BOUNDS *bounds);
|
||||
void Lara_AlignPosition(ITEM *item, XYZ_32 *vec);
|
||||
bool Lara_MovePosition(ITEM *item, XYZ_32 *vec);
|
||||
|
|
|
@ -188,36 +188,6 @@ int16_t Item_GetHeight(const ITEM *const item)
|
|||
return height;
|
||||
}
|
||||
|
||||
int32_t Item_TestBoundsCollide(
|
||||
const ITEM *const src_item, const ITEM *const dst_item,
|
||||
const int32_t radius)
|
||||
{
|
||||
const BOUNDS_16 *const src_bounds = &Item_GetBestFrame(src_item)->bounds;
|
||||
const BOUNDS_16 *const dst_bounds = &Item_GetBestFrame(dst_item)->bounds;
|
||||
|
||||
if (src_item->pos.y + src_bounds->max.y
|
||||
<= dst_item->pos.y + dst_bounds->min.y
|
||||
|| src_item->pos.y + src_bounds->min.y
|
||||
>= dst_item->pos.y + dst_bounds->max.y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int32_t c = Math_Cos(src_item->rot.y);
|
||||
const int32_t s = Math_Sin(src_item->rot.y);
|
||||
const int32_t dx = dst_item->pos.x - src_item->pos.x;
|
||||
const int32_t dz = dst_item->pos.z - src_item->pos.z;
|
||||
const int32_t rx = (c * dx - s * dz) >> W2V_SHIFT;
|
||||
const int32_t rz = (c * dz + s * dx) >> W2V_SHIFT;
|
||||
|
||||
// clang-format off
|
||||
return (
|
||||
rx >= src_bounds->min.x - radius &&
|
||||
rx <= src_bounds->max.x + radius &&
|
||||
rz >= src_bounds->min.z - radius &&
|
||||
rz <= src_bounds->max.z + radius);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
int32_t Item_TestPosition(
|
||||
const int16_t *const bounds_in, const ITEM *const src_item,
|
||||
const ITEM *const dst_item)
|
||||
|
|
|
@ -8,8 +8,6 @@ void Item_Control(void);
|
|||
void Item_ClearKilled(void);
|
||||
void Item_ShiftCol(ITEM *item, COLL_INFO *coll);
|
||||
void Item_UpdateRoom(ITEM *item, int32_t height);
|
||||
int32_t Item_TestBoundsCollide(
|
||||
const ITEM *src_item, const ITEM *dst_item, int32_t radius);
|
||||
int32_t Item_TestPosition(
|
||||
const int16_t *bounds, const ITEM *src_item, const ITEM *dst_item);
|
||||
void Item_AlignPosition(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue