Skip to content

Commit

Permalink
[add] vehicle, vehicle wheel, and joint apis
Browse files Browse the repository at this point in the history
  • Loading branch information
begla committed Nov 20, 2023
1 parent 90ac3be commit 901a369
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
46 changes: 46 additions & 0 deletions iolite_c_api/iolite_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,52 @@ struct io_component_voxel_shape_i // NOLINT
io_vec3_t (*get_angular_velocity)(io_ref_t shape);
};

//----------------------------------------------------------------------------//
#define IO_COMPONENT_VEHICLE_API_NAME "io_component_vehicle_i"
//----------------------------------------------------------------------------//

// Provides access to vehicle components
//----------------------------------------------------------------------------//
struct io_component_vehicle_i // NOLINT
{
// Base interface functions.
io_component_base_i base;
};

//----------------------------------------------------------------------------//
#define IO_COMPONENT_VEHICLE_WHEEL_API_NAME "io_component_vehicle_wheel_i"
//----------------------------------------------------------------------------//

// Provides access to vehicle wheel components
//----------------------------------------------------------------------------//
struct io_component_vehicle_wheel_i // NOLINT
{
// Base interface functions.
io_component_base_i base;

// Sets the torque (revolutions per second).
void (*set_torque)(io_ref_t vehicle_wheel, float torque);
// Gets the torque (revolutions per second).
float (*get_torque)(io_ref_t vehicle_wheel);

// Sets the steering angle (in radians).
void (*set_steering_angle)(io_ref_t vehicle_wheel, float steering_angle);
// Gets the steering angle (in radians).
float (*get_steering_angle)(io_ref_t vehicle_wheel);
};

//----------------------------------------------------------------------------//
#define IO_COMPONENT_JOINT_API_NAME "io_component_joint_i"
//----------------------------------------------------------------------------//

// Provides access to joint components
//----------------------------------------------------------------------------//
struct io_component_joint_i // NOLINT
{
// Base interface functions.
io_component_base_i base;
};

//----------------------------------------------------------------------------//
#define IO_COMPONENT_CHARACTER_CONTROLLER_API_NAME \
"io_component_character_controller_i"
Expand Down
61 changes: 61 additions & 0 deletions iolite_plugins/lua_plugin/init_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,67 @@ void script_init_state(sol::state& s)
// clang-format on
};

s["Vehicle"] = s.create_table();
s["Vehicle"]["load"] = [&s]() {
// clang-format off

SHARED_COMPONENT_INTERFACE_IMPL(s["Vehicle"], io_component_vehicle);

// @namespace Vehicle
// @category Vehicle_Component Functions to interact with vehicles.
// @copy_category Interface

// clang-format on
};

s["VehicleWheel"] = s.create_table();
s["VehicleWheel"]["load"] = [&s]() {
// clang-format off

SHARED_COMPONENT_INTERFACE_IMPL(s["VehicleWheel"], io_component_vehicle_wheel);

// @namespace VehicleWheel
// @category Vehicle_Wheel_Component Functions to interact with vehicle wheels.
// @copy_category Interface

// @function set_steering_angle
// @summary Sets the steering angle.
// @param component Ref The wheel in question.
// @param steering_angle float The steering angle in radians.
s["VehicleWheel"]["set_steering_angle"] = io_component_vehicle_wheel->set_steering_angle;
// @function get_steering_angle
// @summary Returns the steering angle.
// @param component Ref The wheel in question.
// @return float value The steering angle in radians.
s["VehicleWheel"]["get_steering_angle"] = io_component_vehicle_wheel->get_steering_angle;

// @function set_torque
// @summary Sets the torque.
// @param component Ref The wheel in question.
// @param torque float The torque (as revolutions per second).
s["VehicleWheel"]["set_torque"] = io_component_vehicle_wheel->set_torque;
// @function get_torque
// @summary Returns the torque.
// @param component Ref The wheel in question.
// @return float value The torque (as revolutions per second).
s["VehicleWheel"]["get_torque"] = io_component_vehicle_wheel->get_torque;

// clang-format on
};

s["Joint"] = s.create_table();
s["Joint"]["load"] = [&s]() {
// clang-format off

SHARED_COMPONENT_INTERFACE_IMPL(s["Joint"], io_component_joint);

// @namespace Joint
// @category Joint_Component Functions to interact with vehicles.
// @copy_category Interface

// clang-format on
};

s["CameraController"] = s.create_table();
s["CameraController"]["load"] = [&s]() {
// clang-format off
Expand Down
11 changes: 11 additions & 0 deletions iolite_plugins/lua_plugin/lua_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const io_component_character_controller_i* io_component_character_controller =
{};
const io_component_camera_controller_i* io_component_camera_controller = {};
const io_component_particle_i* io_component_particle = {};
const io_component_vehicle_i* io_component_vehicle = {};
const io_component_vehicle_wheel_i* io_component_vehicle_wheel = {};
const io_component_joint_i* io_component_joint = {};

// Interfaces we provide
//----------------------------------------------------------------------------//
Expand Down Expand Up @@ -522,6 +525,14 @@ IO_API_EXPORT int IO_API_CALL load_plugin(void* api_manager)
io_component_particle =
(const io_component_particle_i*)io_api_manager->find_first(
IO_COMPONENT_PARTICLE_API_NAME);
io_component_vehicle =
(const io_component_vehicle_i*)io_api_manager->find_first(
IO_COMPONENT_VEHICLE_API_NAME);
io_component_vehicle_wheel =
(const io_component_vehicle_wheel_i*)io_api_manager->find_first(
IO_COMPONENT_VEHICLE_WHEEL_API_NAME);
io_component_joint = (const io_component_joint_i*)io_api_manager->find_first(
IO_COMPONENT_JOINT_API_NAME);

// Factory plugin intefaces
io_plugin_terrain = (const io_plugin_terrain_i*)io_api_manager->find_first(
Expand Down
3 changes: 3 additions & 0 deletions iolite_plugins/lua_plugin/lua_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ extern const io_component_character_controller_i*
io_component_character_controller;
extern const io_component_camera_controller_i* io_component_camera_controller;
extern const io_component_particle_i* io_component_particle;
extern const io_component_vehicle_i* io_component_vehicle;
extern const io_component_vehicle_wheel_i* io_component_vehicle_wheel;
extern const io_component_joint_i* io_component_joint;

// Custom data types
//----------------------------------------------------------------------------//
Expand Down

0 comments on commit 901a369

Please sign in to comment.