diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 14dc529a..27175c34 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -36,6 +36,7 @@ in_files = [ "src/pc/network/network_player.h", "include/behavior_table.h", "src/pc/lua/smlua_obj_utils.h", + "src/pc/lua/smlua_misc_utils.h", "src/game/object_helpers.c", "src/game/obj_behaviors.c", "src/game/obj_behaviors_2.c", diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py index 9ea47094..222f9070 100644 --- a/autogen/convert_structs.py +++ b/autogen/convert_structs.py @@ -16,6 +16,7 @@ in_files = [ 'src/game/object_helpers.h', 'src/game/mario_step.h', 'src/pc/lua/smlua_anim_utils.h', + 'src/pc/lua/smlua_misc_utils.h', 'src/game/spawn_sound.h', ] diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 7243d9b1..5a9cc8d7 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -617,6 +617,11 @@
+- smlua_misc_utils.h + - [collision_find_surface_on_ray](#collision_find_surface_on_ray) + +
+ - smlua_obj_utils.h - [obj_get_first](#obj_get_first) - [obj_get_first_with_behavior_id](#obj_get_first_with_behavior_id) @@ -11383,6 +11388,37 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+--- +# functions from smlua_misc_utils.h + +
+ + +## [collision_find_surface_on_ray](#collision_find_surface_on_ray) + +### Lua Example +`local RayIntersectionInfoValue = collision_find_surface_on_ray(startX, startY, startZ, endX, endY, endZ)` + +### Parameters +| Field | Type | +| ----- | ---- | +| startX | `number` | +| startY | `number` | +| startZ | `number` | +| endX | `number` | +| endY | `number` | +| endZ | `number` | + +### Returns +[RayIntersectionInfo](structs.md#RayIntersectionInfo) + +### C Prototype +`struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ);` + +[:arrow_up_small:](#) + +
+ --- # functions from smlua_obj_utils.h diff --git a/docs/lua/structs.md b/docs/lua/structs.md index 094c6b9f..07936a68 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -39,6 +39,7 @@ - [ParallelTrackingPoint](#ParallelTrackingPoint) - [PlayerCameraState](#PlayerCameraState) - [PlayerGeometry](#PlayerGeometry) +- [RayIntersectionInfo](#RayIntersectionInfo) - [SPTask](#SPTask) - [SoundState](#SoundState) - [SpawnInfo](#SpawnInfo) @@ -1604,6 +1605,17 @@
+## [RayIntersectionInfo](#RayIntersectionInfo) + +| Field | Type | Access | +| ----- | ---- | ------ | +| hitPos | [Vec3f](structs.md#Vec3f) | read-only | +| surface | [Surface](structs.md#Surface) | | + +[:arrow_up_small:](#) + +
+ ## [SoundState](#SoundState) | Field | Type | Access | diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index 5b22134f..efb2a77b 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -11,6 +11,7 @@ #include "src/game/object_helpers.h" #include "src/game/mario_step.h" #include "src/pc/lua/smlua_anim_utils.h" +#include "src/pc/lua/smlua_misc_utils.h" #include "src/game/spawn_sound.h" #include "include/object_fields.h" @@ -1404,6 +1405,12 @@ static struct LuaObjectField sPlayerGeometryFields[LUA_PLAYER_GEOMETRY_FIELD_COU { "waterHeight", LVT_F32, offsetof(struct PlayerGeometry, waterHeight), false, LOT_NONE }, }; +#define LUA_RAY_INTERSECTION_INFO_FIELD_COUNT 2 +static struct LuaObjectField sRayIntersectionInfoFields[LUA_RAY_INTERSECTION_INFO_FIELD_COUNT] = { + { "hitPos", LVT_COBJECT, offsetof(struct RayIntersectionInfo, hitPos), true, LOT_VEC3F }, + { "surface", LVT_COBJECT_P, offsetof(struct RayIntersectionInfo, surface), false, LOT_SURFACE }, +}; + #define LUA_SOUND_STATE_FIELD_COUNT 4 static struct LuaObjectField sSoundStateFields[LUA_SOUND_STATE_FIELD_COUNT] = { { "animFrame1", LVT_S8, offsetof(struct SoundState, animFrame1), false, LOT_NONE }, @@ -1599,6 +1606,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN] { LOT_PARALLELTRACKINGPOINT, sParallelTrackingPointFields, LUA_PARALLEL_TRACKING_POINT_FIELD_COUNT }, { LOT_PLAYERCAMERASTATE, sPlayerCameraStateFields, LUA_PLAYER_CAMERA_STATE_FIELD_COUNT }, { LOT_PLAYERGEOMETRY, sPlayerGeometryFields, LUA_PLAYER_GEOMETRY_FIELD_COUNT }, + { LOT_RAYINTERSECTIONINFO, sRayIntersectionInfoFields, LUA_RAY_INTERSECTION_INFO_FIELD_COUNT }, { LOT_SOUNDSTATE, sSoundStateFields, LUA_SOUND_STATE_FIELD_COUNT }, { LOT_SPAWNINFO, sSpawnInfoFields, LUA_SPAWN_INFO_FIELD_COUNT }, { LOT_SPAWNPARTICLESINFO, sSpawnParticlesInfoFields, LUA_SPAWN_PARTICLES_INFO_FIELD_COUNT }, diff --git a/src/pc/lua/smlua_cobject_autogen.h b/src/pc/lua/smlua_cobject_autogen.h index 0eaceeb1..967b5e92 100644 --- a/src/pc/lua/smlua_cobject_autogen.h +++ b/src/pc/lua/smlua_cobject_autogen.h @@ -42,6 +42,7 @@ enum LuaObjectAutogenType { LOT_PARALLELTRACKINGPOINT, LOT_PLAYERCAMERASTATE, LOT_PLAYERGEOMETRY, + LOT_RAYINTERSECTIONINFO, LOT_SOUNDSTATE, LOT_SPAWNINFO, LOT_SPAWNPARTICLESINFO, diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 18d4b3e1..bb9a0b7d 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -20,6 +20,7 @@ #include "src/pc/network/network_player.h" #include "include/behavior_table.h" #include "src/pc/lua/smlua_obj_utils.h" +#include "src/pc/lua/smlua_misc_utils.h" ////////////////////// @@ -7263,6 +7264,31 @@ int smlua_func_save_file_get_total_star_count(lua_State* L) { return 1; } + //////////////////////// + // smlua_misc_utils.h // +//////////////////////// + +int smlua_func_collision_find_surface_on_ray(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 6)) { return 0; } + + f32 startX = smlua_to_number(L, 1); + if (!gSmLuaConvertSuccess) { return 0; } + f32 startY = smlua_to_number(L, 2); + if (!gSmLuaConvertSuccess) { return 0; } + f32 startZ = smlua_to_number(L, 3); + if (!gSmLuaConvertSuccess) { return 0; } + f32 endX = smlua_to_number(L, 4); + if (!gSmLuaConvertSuccess) { return 0; } + f32 endY = smlua_to_number(L, 5); + if (!gSmLuaConvertSuccess) { return 0; } + f32 endZ = smlua_to_number(L, 6); + if (!gSmLuaConvertSuccess) { return 0; } + + smlua_push_object(L, LOT_RAYINTERSECTIONINFO, collision_find_surface_on_ray(startX, startY, startZ, endX, endY, endZ)); + + return 1; +} + /////////////////////// // smlua_obj_utils.h // /////////////////////// @@ -8455,6 +8481,9 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "save_file_get_star_flags", smlua_func_save_file_get_star_flags); smlua_bind_function(L, "save_file_get_total_star_count", smlua_func_save_file_get_total_star_count); + // smlua_misc_utils.h + smlua_bind_function(L, "collision_find_surface_on_ray", smlua_func_collision_find_surface_on_ray); + // smlua_obj_utils.h smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first); smlua_bind_function(L, "obj_get_first_with_behavior_id", smlua_func_obj_get_first_with_behavior_id); diff --git a/src/pc/lua/smlua_misc_utils.c b/src/pc/lua/smlua_misc_utils.c new file mode 100644 index 00000000..f5a91f7b --- /dev/null +++ b/src/pc/lua/smlua_misc_utils.c @@ -0,0 +1,14 @@ +#include "types.h" + +#include "smlua.h" +#include "smlua_misc_utils.h" +#include "src/engine/surface_collision.h" +#include "pc/debuglog.h" + +struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ) { + static struct RayIntersectionInfo info = { 0 }; + Vec3f orig = { startX, startY, startZ }; + Vec3f end = { endX, endY, endZ }; + find_surface_on_ray(orig, end, &info.surface, info.hitPos); + return &info; +} diff --git a/src/pc/lua/smlua_misc_utils.h b/src/pc/lua/smlua_misc_utils.h new file mode 100644 index 00000000..0e9aa1e6 --- /dev/null +++ b/src/pc/lua/smlua_misc_utils.h @@ -0,0 +1,11 @@ +#ifndef SMLUA_MISC_UTILS_H +#define SMLUA_MISC_UTILS_H + +struct RayIntersectionInfo { + struct Surface* surface; + Vec3f hitPos; +}; + +struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ); + +#endif