Add collision_find_surface_on_ray_precision
This commit is contained in:
parent
bcdb6be53a
commit
52b4d51508
|
@ -7621,6 +7621,18 @@ function collision_find_surface_on_ray(startX, startY, startZ, dirX, dirY, dirZ)
|
||||||
-- ...
|
-- ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param startX number
|
||||||
|
--- @param startY number
|
||||||
|
--- @param startZ number
|
||||||
|
--- @param dirX number
|
||||||
|
--- @param dirY number
|
||||||
|
--- @param dirZ number
|
||||||
|
--- @param precision number
|
||||||
|
--- @return RayIntersectionInfo
|
||||||
|
function collision_find_surface_on_ray_precision(startX, startY, startZ, dirX, dirY, dirZ, precision)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
--- @return WallCollisionData
|
--- @return WallCollisionData
|
||||||
function collision_get_temp_wall_collision_data()
|
function collision_get_temp_wall_collision_data()
|
||||||
-- ...
|
-- ...
|
||||||
|
|
|
@ -475,6 +475,32 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [collision_find_surface_on_ray_precision](#collision_find_surface_on_ray_precision)
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local RayIntersectionInfoValue = collision_find_surface_on_ray_precision(startX, startY, startZ, dirX, dirY, dirZ, precision)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| startX | `number` |
|
||||||
|
| startY | `number` |
|
||||||
|
| startZ | `number` |
|
||||||
|
| dirX | `number` |
|
||||||
|
| dirY | `number` |
|
||||||
|
| dirZ | `number` |
|
||||||
|
| precision | `number` |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
[RayIntersectionInfo](structs.md#RayIntersectionInfo)
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`struct RayIntersectionInfo* collision_find_surface_on_ray_precision(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 precision);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
## [collision_get_temp_wall_collision_data](#collision_get_temp_wall_collision_data)
|
## [collision_get_temp_wall_collision_data](#collision_get_temp_wall_collision_data)
|
||||||
|
|
||||||
### Lua Example
|
### Lua Example
|
||||||
|
|
|
@ -1596,6 +1596,7 @@
|
||||||
- [collision_find_ceil](functions-5.md#collision_find_ceil)
|
- [collision_find_ceil](functions-5.md#collision_find_ceil)
|
||||||
- [collision_find_floor](functions-5.md#collision_find_floor)
|
- [collision_find_floor](functions-5.md#collision_find_floor)
|
||||||
- [collision_find_surface_on_ray](functions-5.md#collision_find_surface_on_ray)
|
- [collision_find_surface_on_ray](functions-5.md#collision_find_surface_on_ray)
|
||||||
|
- [collision_find_surface_on_ray_precision](functions-5.md#collision_find_surface_on_ray_precision)
|
||||||
- [collision_get_temp_wall_collision_data](functions-5.md#collision_get_temp_wall_collision_data)
|
- [collision_get_temp_wall_collision_data](functions-5.md#collision_get_temp_wall_collision_data)
|
||||||
- [get_water_surface_pseudo_floor](functions-5.md#get_water_surface_pseudo_floor)
|
- [get_water_surface_pseudo_floor](functions-5.md#get_water_surface_pseudo_floor)
|
||||||
- [smlua_collision_util_get](functions-5.md#smlua_collision_util_get)
|
- [smlua_collision_util_get](functions-5.md#smlua_collision_util_get)
|
||||||
|
|
|
@ -1190,8 +1190,7 @@ void find_surface_on_ray_cell(s16 cellX, s16 cellZ, Vec3f orig, Vec3f normalized
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos)
|
void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos, f32 precision) {
|
||||||
{
|
|
||||||
f32 max_length;
|
f32 max_length;
|
||||||
s16 cellZ, cellX;
|
s16 cellZ, cellX;
|
||||||
f32 fCellZ, fCellX;
|
f32 fCellZ, fCellX;
|
||||||
|
@ -1223,9 +1222,6 @@ void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Ve
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// increase collision checking precision (normally 1)
|
|
||||||
f32 precision = 3;
|
|
||||||
|
|
||||||
// Get cells we cross using DDA
|
// Get cells we cross using DDA
|
||||||
if (absx(dir[0]) >= absx(dir[2]))
|
if (absx(dir[0]) >= absx(dir[2]))
|
||||||
step = precision * absx(dir[0]) / CELL_SIZE;
|
step = precision * absx(dir[0]) / CELL_SIZE;
|
||||||
|
|
|
@ -52,6 +52,6 @@ f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor);
|
||||||
f32 find_water_level(f32 x, f32 z);
|
f32 find_water_level(f32 x, f32 z);
|
||||||
f32 find_poison_gas_level(f32 x, f32 z);
|
f32 find_poison_gas_level(f32 x, f32 z);
|
||||||
void debug_surface_list_info(f32 xPos, f32 zPos);
|
void debug_surface_list_info(f32 xPos, f32 zPos);
|
||||||
void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos);
|
void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos, f32 precision);
|
||||||
|
|
||||||
#endif // SURFACE_COLLISION_H
|
#endif // SURFACE_COLLISION_H
|
||||||
|
|
|
@ -553,7 +553,7 @@ static void newcam_collision(void) {
|
||||||
offset[1],
|
offset[1],
|
||||||
offset[2] * 1.2f,
|
offset[2] * 1.2f,
|
||||||
};
|
};
|
||||||
find_surface_on_ray(newcam_pos_target, move, &surf, hitpos);
|
find_surface_on_ray(newcam_pos_target, move, &surf, hitpos, 3.0f);
|
||||||
vec3f_copy(offset, hitpos);
|
vec3f_copy(offset, hitpos);
|
||||||
vec3f_sub(offset, newcam_pos_target);
|
vec3f_sub(offset, newcam_pos_target);
|
||||||
if (surf) {
|
if (surf) {
|
||||||
|
@ -576,7 +576,7 @@ static void newcam_collision(void) {
|
||||||
|
|
||||||
struct Surface* surf;
|
struct Surface* surf;
|
||||||
Vec3f hitpos;
|
Vec3f hitpos;
|
||||||
find_surface_on_ray(camorig, camray, &surf, hitpos);
|
find_surface_on_ray(camorig, camray, &surf, hitpos, 3.0f);
|
||||||
|
|
||||||
if (surf == NULL) {
|
if (surf == NULL) {
|
||||||
allhit = false;
|
allhit = false;
|
||||||
|
@ -594,7 +594,7 @@ static void newcam_collision(void) {
|
||||||
struct Surface *surf = NULL;
|
struct Surface *surf = NULL;
|
||||||
Vec3f hitpos;
|
Vec3f hitpos;
|
||||||
|
|
||||||
find_surface_on_ray(newcam_lookat, camdir, &surf, hitpos);
|
find_surface_on_ray(newcam_lookat, camdir, &surf, hitpos, 3.0f);
|
||||||
|
|
||||||
if (surf) {
|
if (surf) {
|
||||||
// offset the hit pos by the hit normal
|
// offset the hit pos by the hit normal
|
||||||
|
|
|
@ -12181,7 +12181,7 @@ static u8 rom_hack_cam_can_see_mario(Vec3f desiredPos) {
|
||||||
camdir[2] = target[2] - desiredPos[2];
|
camdir[2] = target[2] - desiredPos[2];
|
||||||
|
|
||||||
Vec3f hitpos;
|
Vec3f hitpos;
|
||||||
find_surface_on_ray(desiredPos, camdir, &surf, hitpos);
|
find_surface_on_ray(desiredPos, camdir, &surf, hitpos, 3.0f);
|
||||||
if (surf == NULL) {
|
if (surf == NULL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12200,7 +12200,7 @@ void rom_hack_cam_walk(Vec3f pos, Vec3f dir, f32 dist) {
|
||||||
|
|
||||||
struct Surface* surf = NULL;
|
struct Surface* surf = NULL;
|
||||||
Vec3f hitpos;
|
Vec3f hitpos;
|
||||||
find_surface_on_ray(pos, movement, &surf, hitpos);
|
find_surface_on_ray(pos, movement, &surf, hitpos, 3.0f);
|
||||||
|
|
||||||
if (surf == NULL) {
|
if (surf == NULL) {
|
||||||
pos[0] += movement[0];
|
pos[0] += movement[0];
|
||||||
|
|
|
@ -20528,7 +20528,7 @@ int smlua_func_mod_storage_save_number(lua_State* L) {
|
||||||
|
|
||||||
const char* key = smlua_to_string(L, 1);
|
const char* key = smlua_to_string(L, 1);
|
||||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "mod_storage_save_number"); return 0; }
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "mod_storage_save_number"); return 0; }
|
||||||
double value = smlua_to_number(L, 2);
|
f32 value = smlua_to_number(L, 2);
|
||||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "mod_storage_save_number"); return 0; }
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "mod_storage_save_number"); return 0; }
|
||||||
|
|
||||||
lua_pushboolean(L, mod_storage_save_number(key, value));
|
lua_pushboolean(L, mod_storage_save_number(key, value));
|
||||||
|
@ -28410,6 +28410,35 @@ int smlua_func_collision_find_surface_on_ray(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smlua_func_collision_find_surface_on_ray_precision(lua_State* L) {
|
||||||
|
if (L == NULL) { return 0; }
|
||||||
|
|
||||||
|
int top = lua_gettop(L);
|
||||||
|
if (top != 7) {
|
||||||
|
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "collision_find_surface_on_ray_precision", 7, top);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
f32 startX = smlua_to_number(L, 1);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "collision_find_surface_on_ray_precision"); return 0; }
|
||||||
|
f32 startY = smlua_to_number(L, 2);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "collision_find_surface_on_ray_precision"); return 0; }
|
||||||
|
f32 startZ = smlua_to_number(L, 3);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "collision_find_surface_on_ray_precision"); return 0; }
|
||||||
|
f32 dirX = smlua_to_number(L, 4);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "collision_find_surface_on_ray_precision"); return 0; }
|
||||||
|
f32 dirY = smlua_to_number(L, 5);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "collision_find_surface_on_ray_precision"); return 0; }
|
||||||
|
f32 dirZ = smlua_to_number(L, 6);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 6, "collision_find_surface_on_ray_precision"); return 0; }
|
||||||
|
f32 precision = smlua_to_number(L, 7);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 7, "collision_find_surface_on_ray_precision"); return 0; }
|
||||||
|
|
||||||
|
smlua_push_object(L, LOT_RAYINTERSECTIONINFO, collision_find_surface_on_ray_precision(startX, startY, startZ, dirX, dirY, dirZ, precision));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int smlua_func_collision_get_temp_wall_collision_data(UNUSED lua_State* L) {
|
int smlua_func_collision_get_temp_wall_collision_data(UNUSED lua_State* L) {
|
||||||
if (L == NULL) { return 0; }
|
if (L == NULL) { return 0; }
|
||||||
|
|
||||||
|
@ -32449,8 +32478,8 @@ int smlua_func_find_surface_on_ray(lua_State* L) {
|
||||||
if (L == NULL) { return 0; }
|
if (L == NULL) { return 0; }
|
||||||
|
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
if (top != 4) {
|
if (top != 5) {
|
||||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "find_surface_on_ray", 4, top);
|
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "find_surface_on_ray", 5, top);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32474,8 +32503,10 @@ int smlua_func_find_surface_on_ray(lua_State* L) {
|
||||||
hit_pos[1] = smlua_get_number_field(4, "y");
|
hit_pos[1] = smlua_get_number_field(4, "y");
|
||||||
hit_pos[2] = smlua_get_number_field(4, "z");
|
hit_pos[2] = smlua_get_number_field(4, "z");
|
||||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "find_surface_on_ray"); return 0; }
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "find_surface_on_ray"); return 0; }
|
||||||
|
f32 precision = smlua_to_number(L, 5);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "find_surface_on_ray"); return 0; }
|
||||||
|
|
||||||
find_surface_on_ray(orig, dir, hit_surface, hit_pos);
|
find_surface_on_ray(orig, dir, hit_surface, hit_pos, precision);
|
||||||
|
|
||||||
smlua_push_number_field(1, "x", orig[0]);
|
smlua_push_number_field(1, "x", orig[0]);
|
||||||
smlua_push_number_field(1, "y", orig[1]);
|
smlua_push_number_field(1, "y", orig[1]);
|
||||||
|
@ -34160,6 +34191,7 @@ void smlua_bind_functions_autogen(void) {
|
||||||
smlua_bind_function(L, "collision_find_ceil", smlua_func_collision_find_ceil);
|
smlua_bind_function(L, "collision_find_ceil", smlua_func_collision_find_ceil);
|
||||||
smlua_bind_function(L, "collision_find_floor", smlua_func_collision_find_floor);
|
smlua_bind_function(L, "collision_find_floor", smlua_func_collision_find_floor);
|
||||||
smlua_bind_function(L, "collision_find_surface_on_ray", smlua_func_collision_find_surface_on_ray);
|
smlua_bind_function(L, "collision_find_surface_on_ray", smlua_func_collision_find_surface_on_ray);
|
||||||
|
smlua_bind_function(L, "collision_find_surface_on_ray_precision", smlua_func_collision_find_surface_on_ray_precision);
|
||||||
smlua_bind_function(L, "collision_get_temp_wall_collision_data", smlua_func_collision_get_temp_wall_collision_data);
|
smlua_bind_function(L, "collision_get_temp_wall_collision_data", smlua_func_collision_get_temp_wall_collision_data);
|
||||||
smlua_bind_function(L, "get_water_surface_pseudo_floor", smlua_func_get_water_surface_pseudo_floor);
|
smlua_bind_function(L, "get_water_surface_pseudo_floor", smlua_func_get_water_surface_pseudo_floor);
|
||||||
smlua_bind_function(L, "smlua_collision_util_get", smlua_func_smlua_collision_util_get);
|
smlua_bind_function(L, "smlua_collision_util_get", smlua_func_smlua_collision_util_get);
|
||||||
|
|
|
@ -161,7 +161,15 @@ struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY
|
||||||
static struct RayIntersectionInfo info = { 0 };
|
static struct RayIntersectionInfo info = { 0 };
|
||||||
Vec3f orig = { startX, startY, startZ };
|
Vec3f orig = { startX, startY, startZ };
|
||||||
Vec3f dir = { dirX, dirY, dirZ };
|
Vec3f dir = { dirX, dirY, dirZ };
|
||||||
find_surface_on_ray(orig, dir, &info.surface, info.hitPos);
|
find_surface_on_ray(orig, dir, &info.surface, info.hitPos, 3.0f);
|
||||||
|
return &info;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct RayIntersectionInfo* collision_find_surface_on_ray_precision(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 precision) {
|
||||||
|
static struct RayIntersectionInfo info = { 0 };
|
||||||
|
Vec3f orig = { startX, startY, startZ };
|
||||||
|
Vec3f dir = { dirX, dirY, dirZ };
|
||||||
|
find_surface_on_ray(orig, dir, &info.surface, info.hitPos, precision);
|
||||||
return &info;
|
return &info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,9 +115,8 @@ struct GlobalObjectCollisionData {
|
||||||
extern struct GlobalObjectCollisionData gGlobalObjectCollisionData;
|
extern struct GlobalObjectCollisionData gGlobalObjectCollisionData;
|
||||||
|
|
||||||
struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ);
|
struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ);
|
||||||
|
struct RayIntersectionInfo* collision_find_surface_on_ray_precision(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 precision);
|
||||||
struct Surface* collision_find_floor(f32 x, f32 y, f32 z);
|
struct Surface* collision_find_floor(f32 x, f32 y, f32 z);
|
||||||
|
|
||||||
struct Surface* collision_find_ceil(f32 x, f32 y, f32 z);
|
struct Surface* collision_find_ceil(f32 x, f32 y, f32 z);
|
||||||
|
|
||||||
struct Surface* get_water_surface_pseudo_floor(void);
|
struct Surface* get_water_surface_pseudo_floor(void);
|
||||||
|
|
Loading…
Reference in New Issue