From 0f7ee0caa3c05dc3fafdec3abf760308f2591af9 Mon Sep 17 00:00:00 2001 From: Cyril Date: Tue, 12 Sep 2017 16:16:56 +0200 Subject: [PATCH] add_static_collider event added, deactivations update --- src/otbullet/discrete_dynamics_world.h | 6 +- src/otbullet/otbullet.hpp | 2 + src/otbullet/otbullet.intergen.cpp | 560 +++++++++--------- src/otbullet/physics.h | 755 +++++++++++++------------ src/otbullet/physics.js.h | 120 ++-- src/otbullet/rigid_body.cpp | 6 +- src/otbullet/wrapper.cpp | 16 + 7 files changed, 749 insertions(+), 716 deletions(-) diff --git a/src/otbullet/discrete_dynamics_world.h b/src/otbullet/discrete_dynamics_world.h index 5a8fbda413..3d26d7343b 100644 --- a/src/otbullet/discrete_dynamics_world.h +++ b/src/otbullet/discrete_dynamics_world.h @@ -240,6 +240,11 @@ class discrete_dynamics_world : public btDiscreteDynamicsWorld return _stats; } + const void * get_context() { return _context; } + + void get_obb(const btCollisionShape * cs, const btTransform& t, double3& cen, float3x3& basis); + + protected: virtual void internalSingleStepSimulation(btScalar timeStep) override; @@ -253,7 +258,6 @@ class discrete_dynamics_world : public btDiscreteDynamicsWorld fn_process_tree_collision _tree_collision; void process_tree_collisions(btScalar time_step); - void get_obb(const btCollisionShape * cs, const btTransform& t, double3& cen, float3x3& basis); void oob_to_aabb(const btVector3& src_cen, const btMatrix3x3& src_basis, const btVector3& dst_cen, diff --git a/src/otbullet/otbullet.hpp b/src/otbullet/otbullet.hpp index 673dbe9bc1..d8c1bcdd28 100644 --- a/src/otbullet/otbullet.hpp +++ b/src/otbullet/otbullet.hpp @@ -123,6 +123,8 @@ class physics : public policy_intrusive_base float3* norm, double3* hitpoint); + ifc_event void add_static_collider(const void * context, btCollisionObject * obj, const double3& cen, const float3x3& basis); + ifc_event void log(const coid::token& text); private: diff --git a/src/otbullet/otbullet.intergen.cpp b/src/otbullet/otbullet.intergen.cpp index ffff02ef2e..b4a9fc7fe0 100644 --- a/src/otbullet/otbullet.intergen.cpp +++ b/src/otbullet/otbullet.intergen.cpp @@ -1,276 +1,284 @@ - -//@file interface dispatcher generated by intergen v6 -//See LICENSE file for copyright and license information - -#include "physics.h" -#include "otbullet.hpp" - -#include -#include -#include -#include - - -static_assert(intergen_interface::VERSION == 6, "interface must be rebuilt with a different intergen version"); - -using namespace coid; - -static_assert( std::is_base_of::value, "class 'physics' must be derived from policy_intrusive_base"); -static_assert( std::is_base_of::value, "class 'physics' must be derived from policy_intrusive_base"); - -//////////////////////////////////////////////////////////////////////////////// -// interface physics of class physics - -namespace bt { - -/// -class physics_dispatcher : public physics -{ -private: - - static coid::binstring* _capture; - static uint16 _instid; - static ifn_t* _vtable1; - static ifn_t* _vtable2; - - static ifn_t* get_vtable() - { - if (_vtable1) return _vtable1; - - _vtable1 = new ifn_t[34]; - _vtable1[0] = reinterpret_cast(static_cast(&::physics::step_simulation)); - _vtable1[1] = reinterpret_cast(static_cast(&::physics::ray_test)); - _vtable1[2] = reinterpret_cast(static_cast(&::physics::fixed_object)); - _vtable1[3] = reinterpret_cast(static_cast(&::physics::create_rigid_body)); - _vtable1[4] = reinterpret_cast(static_cast(&::physics::destroy_rigid_body)); - _vtable1[5] = reinterpret_cast(static_cast(&::physics::add_rigid_body)); - _vtable1[6] = reinterpret_cast(static_cast(&::physics::remove_rigid_body)); - _vtable1[7] = reinterpret_cast(static_cast(&::physics::pause_rigid_body)); - _vtable1[8] = reinterpret_cast(static_cast(&::physics::set_rigid_body_mass)); - _vtable1[9] = reinterpret_cast(static_cast(&::physics::set_rigid_body_gravity)); - _vtable1[10] = reinterpret_cast(static_cast(&::physics::set_rigid_body_transform)); - _vtable1[11] = reinterpret_cast(static_cast(&::physics::predict_rigid_body_transform)); - _vtable1[12] = reinterpret_cast(static_cast(&::physics::create_collision_object)); - _vtable1[13] = reinterpret_cast(static_cast(&::physics::destroy_collision_object)); - _vtable1[14] = reinterpret_cast(static_cast(&::physics::update_collision_object)); - _vtable1[15] = reinterpret_cast(static_cast(&::physics::set_collision_info)); - _vtable1[16] = reinterpret_cast(static_cast(&::physics::add_collision_object)); - _vtable1[17] = reinterpret_cast(static_cast(&::physics::remove_collision_object)); - _vtable1[18] = reinterpret_cast(static_cast(&::physics::create_compound_shape)); - _vtable1[19] = reinterpret_cast(static_cast(&::physics::add_child_shape)); - _vtable1[20] = reinterpret_cast(static_cast(&::physics::update_child)); - _vtable1[21] = reinterpret_cast(static_cast(&::physics::recalc_compound_shape)); - _vtable1[22] = reinterpret_cast(static_cast(&::physics::destroy_compound_shape)); - _vtable1[23] = reinterpret_cast(static_cast(&::physics::create_shape)); - _vtable1[24] = reinterpret_cast(static_cast(&::physics::add_convex_point)); - _vtable1[25] = reinterpret_cast(static_cast(&::physics::close_convex_shape)); - _vtable1[26] = reinterpret_cast(static_cast(&::physics::destroy_shape)); - _vtable1[27] = reinterpret_cast(static_cast(&::physics::get_stats)); - _vtable1[28] = reinterpret_cast(static_cast(&::physics::get_stats_ptr)); - _vtable1[29] = reinterpret_cast(static_cast(&::physics::set_debug_draw_enabled)); - _vtable1[30] = reinterpret_cast(static_cast(&::physics::set_debug_drawer_mode)); - _vtable1[31] = reinterpret_cast(static_cast(&::physics::debug_draw_world)); - _vtable1[32] = reinterpret_cast(static_cast&)>(&::physics::query_volume_sphere)); - _vtable1[33] = reinterpret_cast(static_cast&)>(&::physics::query_volume_frustum)); - return _vtable1; - } - - #define VT_CALL2(R,F,I) ((*reinterpret_cast(this)).*(reinterpret_cast(_vtable1[I]))) - - - static ifn_t* get_vtable_intercept() - { - if (_vtable2) return _vtable2; - ifn_t* vtable1 = get_vtable(); - - _vtable2 = new ifn_t[34]; - _vtable2[0] = vtable1[0]; - _vtable2[1] = vtable1[1]; - _vtable2[2] = vtable1[2]; - _vtable2[3] = vtable1[3]; - _vtable2[4] = vtable1[4]; - _vtable2[5] = vtable1[5]; - _vtable2[6] = vtable1[6]; - _vtable2[7] = vtable1[7]; - _vtable2[8] = vtable1[8]; - _vtable2[9] = vtable1[9]; - _vtable2[10] = vtable1[10]; - _vtable2[11] = vtable1[11]; - _vtable2[12] = vtable1[12]; - _vtable2[13] = vtable1[13]; - _vtable2[14] = vtable1[14]; - _vtable2[15] = vtable1[15]; - _vtable2[16] = vtable1[16]; - _vtable2[17] = vtable1[17]; - _vtable2[18] = vtable1[18]; - _vtable2[19] = vtable1[19]; - _vtable2[20] = vtable1[20]; - _vtable2[21] = vtable1[21]; - _vtable2[22] = vtable1[22]; - _vtable2[23] = vtable1[23]; - _vtable2[24] = vtable1[24]; - _vtable2[25] = vtable1[25]; - _vtable2[26] = vtable1[26]; - _vtable2[27] = vtable1[27]; - _vtable2[28] = vtable1[28]; - _vtable2[29] = vtable1[29]; - _vtable2[30] = vtable1[30]; - _vtable2[31] = vtable1[31]; - _vtable2[32] = vtable1[32]; - _vtable2[33] = vtable1[33]; - return _vtable2; - } - -protected: - - COIDNEWDELETE("bt::physics_dispatcher"); - - physics_dispatcher() - {} - - bool intergen_bind_capture( coid::binstring* capture, uint instid ) override - { - if (instid >= 0xffU) - return false; - - _instid = uint16(instid << 8U); - _capture = capture; - _vtable = _capture ? get_vtable_intercept() : get_vtable(); - return true; - } - - void intergen_capture_dispatch( uint mid, coid::binstring& bin ) override - { - switch(mid) { - case UMAX32: - default: throw coid::exception("unknown method id in physics capture dispatcher"); - } - } - - ///Cleanup routine called from ~physics() - static void _cleaner_callback( physics* m, intergen_interface* ifc ) { - ::physics* host = m->host<::physics>(); - if (host) host->_ifc_host = ifc; - } - - static iref _generic_interface_creator( ::physics* host, physics* __here__) - { - //cast to dispatch to sidestep protected access restrictions - physics_dispatcher* __disp__ = static_cast(__here__); - if (!__disp__) - __disp__ = new physics_dispatcher; - - __disp__->_host.create(host); - __disp__->_vtable = _capture ? get_vtable_intercept() : get_vtable(); - if (!host->_ifc_host) { - __disp__->_cleaner = &_cleaner_callback; - host->_ifc_host = __disp__; - } - - return __disp__; - } - -public: - - // creator methods - - static iref create( physics* __here__, double r, void* context ) - { - iref< ::physics> __host__ = ::physics::create(r, context); - if (!__host__) - return 0; - return _generic_interface_creator(__host__.get(), __here__); - } - - static iref get( physics* __here__ ) - { - iref< ::physics> __host__ = ::physics::get(); - if (!__host__) - return 0; - return _generic_interface_creator(__host__.get(), __here__); - } - - ///Register interface creators in the global registry - static void register_interfaces( bool on ) - { - interface_register::register_interface_creator( - "bt::physics@wrapper", - on ? (void*)&_generic_interface_creator : nullptr); - - interface_register::register_interface_creator( - "bt::physics.create@3023259009", - on ? (void*)&create : nullptr); - interface_register::register_interface_creator( - "bt::physics.get@3023259009", - on ? (void*)&get : nullptr); - } -}; - -coid::binstring* physics_dispatcher::_capture = 0; -uint16 physics_dispatcher::_instid = 0xffffU; -intergen_interface::ifn_t* physics_dispatcher::_vtable2 = 0; -intergen_interface::ifn_t* physics_dispatcher::_vtable1 = 0; - - -//auto-register the available interface creators -LOCAL_SINGLETON_DEF(ifc_autoregger) physics_autoregger = new ifc_autoregger(&physics_dispatcher::register_interfaces); - -void* force_register_physics() { - LOCAL_SINGLETON_DEF(ifc_autoregger) autoregger = new ifc_autoregger(&physics_dispatcher::register_interfaces); - return autoregger.get(); -} - -} //namespace bt - -// events - - -bool physics::terrain_collisions( const void* context, const double3& center, float radius, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame ) -{ - if (!_ifc_host) - throw coid::exception() << "terrain_collisions" << " handler not implemented"; - else - return _ifc_host->iface()->terrain_collisions(context, center, radius, lod_dimension, data, trees, tree_batches, frame); -} - -bool physics::terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame, bool& is_above_tm ) -{ - if (!_ifc_host) - throw coid::exception() << "terrain_collisions_aabb" << " handler not implemented"; - else - return _ifc_host->iface()->terrain_collisions_aabb(context, center, basis, lod_dimension, data, trees, tree_batches, frame, is_above_tm); -} - -float3 physics::tree_collisions( btRigidBody* obj, bt::tree_collision_contex& ctx, float time_step, coid::slotalloc& tree_batches ) -{ - if (!_ifc_host) - throw coid::exception() << "tree_collisions" << " handler not implemented"; - else - return _ifc_host->iface()->tree_collisions(obj, ctx, time_step, tree_batches); -} - -float physics::terrain_ray_intersect( const void* context, const double3& from, const float3& dir, const float2& minmaxlen, float3* norm, double3* pos ) -{ - if (!_ifc_host) - throw coid::exception() << "terrain_ray_intersect" << " handler not implemented"; - else - return _ifc_host->iface()->terrain_ray_intersect(context, from, dir, minmaxlen, norm, pos); -} - -float physics::elevation_above_terrain( const double3& pos, float maxlen, float3* norm, double3* hitpoint ) -{ - if (!_ifc_host) - throw coid::exception() << "elevation_above_terrain" << " handler not implemented"; - else - return _ifc_host->iface()->elevation_above_terrain(pos, maxlen, norm, hitpoint); -} - -void physics::log( const coid::token& text ) -{ - if (!_ifc_host) - throw coid::exception() << "log" << " handler not implemented"; - else - return _ifc_host->iface()->log(text); -} - - + +//@file interface dispatcher generated by intergen v6 +//See LICENSE file for copyright and license information + +#include "physics.h" +#include "otbullet.hpp" + +#include +#include +#include +#include + + +static_assert(intergen_interface::VERSION == 6, "interface must be rebuilt with a different intergen version"); + +using namespace coid; + +static_assert( std::is_base_of::value, "class 'physics' must be derived from policy_intrusive_base"); +static_assert( std::is_base_of::value, "class 'physics' must be derived from policy_intrusive_base"); + +//////////////////////////////////////////////////////////////////////////////// +// interface physics of class physics + +namespace bt { + +/// +class physics_dispatcher : public physics +{ +private: + + static coid::binstring* _capture; + static uint16 _instid; + static ifn_t* _vtable1; + static ifn_t* _vtable2; + + static ifn_t* get_vtable() + { + if (_vtable1) return _vtable1; + + _vtable1 = new ifn_t[34]; + _vtable1[0] = reinterpret_cast(static_cast(&::physics::step_simulation)); + _vtable1[1] = reinterpret_cast(static_cast(&::physics::ray_test)); + _vtable1[2] = reinterpret_cast(static_cast(&::physics::fixed_object)); + _vtable1[3] = reinterpret_cast(static_cast(&::physics::create_rigid_body)); + _vtable1[4] = reinterpret_cast(static_cast(&::physics::destroy_rigid_body)); + _vtable1[5] = reinterpret_cast(static_cast(&::physics::add_rigid_body)); + _vtable1[6] = reinterpret_cast(static_cast(&::physics::remove_rigid_body)); + _vtable1[7] = reinterpret_cast(static_cast(&::physics::pause_rigid_body)); + _vtable1[8] = reinterpret_cast(static_cast(&::physics::set_rigid_body_mass)); + _vtable1[9] = reinterpret_cast(static_cast(&::physics::set_rigid_body_gravity)); + _vtable1[10] = reinterpret_cast(static_cast(&::physics::set_rigid_body_transform)); + _vtable1[11] = reinterpret_cast(static_cast(&::physics::predict_rigid_body_transform)); + _vtable1[12] = reinterpret_cast(static_cast(&::physics::create_collision_object)); + _vtable1[13] = reinterpret_cast(static_cast(&::physics::destroy_collision_object)); + _vtable1[14] = reinterpret_cast(static_cast(&::physics::update_collision_object)); + _vtable1[15] = reinterpret_cast(static_cast(&::physics::set_collision_info)); + _vtable1[16] = reinterpret_cast(static_cast(&::physics::add_collision_object)); + _vtable1[17] = reinterpret_cast(static_cast(&::physics::remove_collision_object)); + _vtable1[18] = reinterpret_cast(static_cast(&::physics::create_compound_shape)); + _vtable1[19] = reinterpret_cast(static_cast(&::physics::add_child_shape)); + _vtable1[20] = reinterpret_cast(static_cast(&::physics::update_child)); + _vtable1[21] = reinterpret_cast(static_cast(&::physics::recalc_compound_shape)); + _vtable1[22] = reinterpret_cast(static_cast(&::physics::destroy_compound_shape)); + _vtable1[23] = reinterpret_cast(static_cast(&::physics::create_shape)); + _vtable1[24] = reinterpret_cast(static_cast(&::physics::add_convex_point)); + _vtable1[25] = reinterpret_cast(static_cast(&::physics::close_convex_shape)); + _vtable1[26] = reinterpret_cast(static_cast(&::physics::destroy_shape)); + _vtable1[27] = reinterpret_cast(static_cast(&::physics::get_stats)); + _vtable1[28] = reinterpret_cast(static_cast(&::physics::get_stats_ptr)); + _vtable1[29] = reinterpret_cast(static_cast(&::physics::set_debug_draw_enabled)); + _vtable1[30] = reinterpret_cast(static_cast(&::physics::set_debug_drawer_mode)); + _vtable1[31] = reinterpret_cast(static_cast(&::physics::debug_draw_world)); + _vtable1[32] = reinterpret_cast(static_cast&)>(&::physics::query_volume_sphere)); + _vtable1[33] = reinterpret_cast(static_cast&)>(&::physics::query_volume_frustum)); + return _vtable1; + } + + #define VT_CALL2(R,F,I) ((*reinterpret_cast(this)).*(reinterpret_cast(_vtable1[I]))) + + + static ifn_t* get_vtable_intercept() + { + if (_vtable2) return _vtable2; + ifn_t* vtable1 = get_vtable(); + + _vtable2 = new ifn_t[34]; + _vtable2[0] = vtable1[0]; + _vtable2[1] = vtable1[1]; + _vtable2[2] = vtable1[2]; + _vtable2[3] = vtable1[3]; + _vtable2[4] = vtable1[4]; + _vtable2[5] = vtable1[5]; + _vtable2[6] = vtable1[6]; + _vtable2[7] = vtable1[7]; + _vtable2[8] = vtable1[8]; + _vtable2[9] = vtable1[9]; + _vtable2[10] = vtable1[10]; + _vtable2[11] = vtable1[11]; + _vtable2[12] = vtable1[12]; + _vtable2[13] = vtable1[13]; + _vtable2[14] = vtable1[14]; + _vtable2[15] = vtable1[15]; + _vtable2[16] = vtable1[16]; + _vtable2[17] = vtable1[17]; + _vtable2[18] = vtable1[18]; + _vtable2[19] = vtable1[19]; + _vtable2[20] = vtable1[20]; + _vtable2[21] = vtable1[21]; + _vtable2[22] = vtable1[22]; + _vtable2[23] = vtable1[23]; + _vtable2[24] = vtable1[24]; + _vtable2[25] = vtable1[25]; + _vtable2[26] = vtable1[26]; + _vtable2[27] = vtable1[27]; + _vtable2[28] = vtable1[28]; + _vtable2[29] = vtable1[29]; + _vtable2[30] = vtable1[30]; + _vtable2[31] = vtable1[31]; + _vtable2[32] = vtable1[32]; + _vtable2[33] = vtable1[33]; + return _vtable2; + } + +protected: + + COIDNEWDELETE("bt::physics_dispatcher"); + + physics_dispatcher() + {} + + bool intergen_bind_capture( coid::binstring* capture, uint instid ) override + { + if (instid >= 0xffU) + return false; + + _instid = uint16(instid << 8U); + _capture = capture; + _vtable = _capture ? get_vtable_intercept() : get_vtable(); + return true; + } + + void intergen_capture_dispatch( uint mid, coid::binstring& bin ) override + { + switch(mid) { + case UMAX32: + default: throw coid::exception("unknown method id in physics capture dispatcher"); + } + } + + ///Cleanup routine called from ~physics() + static void _cleaner_callback( physics* m, intergen_interface* ifc ) { + ::physics* host = m->host<::physics>(); + if (host) host->_ifc_host = ifc; + } + + static iref _generic_interface_creator( ::physics* host, physics* __here__) + { + //cast to dispatch to sidestep protected access restrictions + physics_dispatcher* __disp__ = static_cast(__here__); + if (!__disp__) + __disp__ = new physics_dispatcher; + + __disp__->_host.create(host); + __disp__->_vtable = _capture ? get_vtable_intercept() : get_vtable(); + if (!host->_ifc_host) { + __disp__->_cleaner = &_cleaner_callback; + host->_ifc_host = __disp__; + } + + return __disp__; + } + +public: + + // creator methods + + static iref create( physics* __here__, double r, void* context ) + { + iref< ::physics> __host__ = ::physics::create(r, context); + if (!__host__) + return 0; + return _generic_interface_creator(__host__.get(), __here__); + } + + static iref get( physics* __here__ ) + { + iref< ::physics> __host__ = ::physics::get(); + if (!__host__) + return 0; + return _generic_interface_creator(__host__.get(), __here__); + } + + ///Register interface creators in the global registry + static void register_interfaces( bool on ) + { + interface_register::register_interface_creator( + "bt::physics@wrapper", + on ? (void*)&_generic_interface_creator : nullptr); + + interface_register::register_interface_creator( + "bt::physics.create@3573161280", + on ? (void*)&create : nullptr); + interface_register::register_interface_creator( + "bt::physics.get@3573161280", + on ? (void*)&get : nullptr); + } +}; + +coid::binstring* physics_dispatcher::_capture = 0; +uint16 physics_dispatcher::_instid = 0xffffU; +intergen_interface::ifn_t* physics_dispatcher::_vtable2 = 0; +intergen_interface::ifn_t* physics_dispatcher::_vtable1 = 0; + + +//auto-register the available interface creators +LOCAL_SINGLETON_DEF(ifc_autoregger) physics_autoregger = new ifc_autoregger(&physics_dispatcher::register_interfaces); + +void* force_register_physics() { + LOCAL_SINGLETON_DEF(ifc_autoregger) autoregger = new ifc_autoregger(&physics_dispatcher::register_interfaces); + return autoregger.get(); +} + +} //namespace bt + +// events + + +bool physics::terrain_collisions( const void* context, const double3& center, float radius, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame ) +{ + if (!_ifc_host) + throw coid::exception() << "terrain_collisions" << " handler not implemented"; + else + return _ifc_host->iface()->terrain_collisions(context, center, radius, lod_dimension, data, trees, tree_batches, frame); +} + +bool physics::terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame, bool& is_above_tm ) +{ + if (!_ifc_host) + throw coid::exception() << "terrain_collisions_aabb" << " handler not implemented"; + else + return _ifc_host->iface()->terrain_collisions_aabb(context, center, basis, lod_dimension, data, trees, tree_batches, frame, is_above_tm); +} + +float3 physics::tree_collisions( btRigidBody* obj, bt::tree_collision_contex& ctx, float time_step, coid::slotalloc& tree_batches ) +{ + if (!_ifc_host) + throw coid::exception() << "tree_collisions" << " handler not implemented"; + else + return _ifc_host->iface()->tree_collisions(obj, ctx, time_step, tree_batches); +} + +float physics::terrain_ray_intersect( const void* context, const double3& from, const float3& dir, const float2& minmaxlen, float3* norm, double3* pos ) +{ + if (!_ifc_host) + throw coid::exception() << "terrain_ray_intersect" << " handler not implemented"; + else + return _ifc_host->iface()->terrain_ray_intersect(context, from, dir, minmaxlen, norm, pos); +} + +float physics::elevation_above_terrain( const double3& pos, float maxlen, float3* norm, double3* hitpoint ) +{ + if (!_ifc_host) + throw coid::exception() << "elevation_above_terrain" << " handler not implemented"; + else + return _ifc_host->iface()->elevation_above_terrain(pos, maxlen, norm, hitpoint); +} + +void physics::add_static_collider( const void* context, btCollisionObject* obj, const double3& cen, const float3x3& basis ) +{ + if (!_ifc_host) + throw coid::exception() << "add_static_collider" << " handler not implemented"; + else + return _ifc_host->iface()->add_static_collider(context, obj, cen, basis); +} + +void physics::log( const coid::token& text ) +{ + if (!_ifc_host) + throw coid::exception() << "log" << " handler not implemented"; + else + return _ifc_host->iface()->log(text); +} + + diff --git a/src/otbullet/physics.h b/src/otbullet/physics.h index a7cc307934..437504ed77 100644 --- a/src/otbullet/physics.h +++ b/src/otbullet/physics.h @@ -1,14 +1,14 @@ -#pragma once - -#ifndef __INTERGEN_GENERATED__physics_H__ -#define __INTERGEN_GENERATED__physics_H__ - -//@file Interface file for physics interface generated by intergen -//See LICENSE file for copyright and license information - -#include -#include - +#pragma once + +#ifndef __INTERGEN_GENERATED__physics_H__ +#define __INTERGEN_GENERATED__physics_H__ + +//@file Interface file for physics interface generated by intergen +//See LICENSE file for copyright and license information + +#include +#include + #include "physics_cfg.h" #include @@ -28,368 +28,371 @@ namespace bt { struct ot_world_physics_stats; } extern bt::physics* BT; - -class physics; - - -namespace bt { - -//////////////////////////////////////////////////////////////////////////////// -///Interface for the physics module -class physics - : public intergen_interface -{ -public: - - // --- interface methods --- - - void step_simulation( double step ); - - void ray_test( const double from[3], const double to[3], void* cb ); - - btRigidBody* fixed_object(); - - btRigidBody* create_rigid_body( float mass, btCollisionShape* shape, void* usr1, void* usr2 ); - - void destroy_rigid_body( btRigidBody*& obj ); - - void add_rigid_body( btRigidBody* obj, unsigned int group, unsigned int mask, btActionInterface* action, bt::constraint_info* constraint ); - - void remove_rigid_body( btRigidBody* obj, btActionInterface* action, bt::constraint_info* constraint ); - - void pause_rigid_body( btRigidBody* obj, bool pause ); - - void set_rigid_body_mass( btRigidBody* obj, float mass, const float inertia[3] ); - - void set_rigid_body_gravity( btRigidBody* obj, const double gravity[3] ); - - void set_rigid_body_transform( btRigidBody* obj, const btTransform& tr, const double gravity[3] ); - - void predict_rigid_body_transform( btRigidBody* obj, double dt, ifc_out btTransform& tr ); - - btCollisionObject* create_collision_object( btCollisionShape* shape, void* usr1, void* usr2 ); - - void destroy_collision_object( btCollisionObject*& obj ); - - void update_collision_object( btCollisionObject* obj, const btTransform& tr, bool update_aabb ); - - void set_collision_info( btCollisionObject* obj, unsigned int group, unsigned int mask ); - - void add_collision_object( btCollisionObject* obj, unsigned int group, unsigned int mask, bool inactive ); - - void remove_collision_object( btCollisionObject* obj ); - - btCompoundShape* create_compound_shape(); - - void add_child_shape( btCompoundShape* group, btCollisionShape* child, const btTransform& tr ); - - void update_child( btCompoundShape* group, int index, const btTransform& tr ); - - void recalc_compound_shape( btCompoundShape* shape ); - - void destroy_compound_shape( ifc_inout btCompoundShape*& shape ); - - btCollisionShape* create_shape( bt::EShape sh, const float hvec[3] ); - - void add_convex_point( btCollisionShape* shape, const float point[3] ); - - void close_convex_shape( btCollisionShape* shape ); - - void destroy_shape( ifc_inout btCollisionShape*& shape ); - - bt::ot_world_physics_stats get_stats(); - - bt::ot_world_physics_stats* get_stats_ptr(); - - void set_debug_draw_enabled( btIDebugDraw* debug_drawer ); - - void set_debug_drawer_mode( int debug_mode ); - - void debug_draw_world(); - - void query_volume_sphere( const double3& pos, float rad, ifc_inout coid::dynarray& result ); - - void query_volume_frustum( const double3& pos, const float4* f_planes_norms, uint8 nplanes, bool include_partial, ifc_inout coid::dynarray& result ); - - -protected: - // --- interface events (callbacks from host to client) --- - // --- overload these to handle host events --- - - friend class ::physics; - - virtual bool terrain_collisions( const void* context, const double3& center, float radius, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame ){ throw coid::exception("handler not implemented"); } - - virtual bool terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame, bool& is_above_tm ){ throw coid::exception("handler not implemented"); } - - virtual float3 tree_collisions( btRigidBody* obj, bt::tree_collision_contex& ctx, float time_step, coid::slotalloc& tree_batches ){ throw coid::exception("handler not implemented"); } - - virtual float terrain_ray_intersect( const void* context, const double3& from, const float3& dir, const float2& minmaxlen, float3* norm, double3* pos ){ throw coid::exception("handler not implemented"); } - - virtual float elevation_above_terrain( const double3& pos, float maxlen, float3* norm, double3* hitpoint ){ throw coid::exception("handler not implemented"); } - - virtual void log( const coid::token& text ) {} - - virtual void force_bind_script_events() {} - -public: - // --- host helpers to check presence of handlers in scripts --- - - virtual bool is_bound_terrain_collisions() { return true; } - virtual bool is_bound_terrain_collisions_aabb() { return true; } - virtual bool is_bound_tree_collisions() { return true; } - virtual bool is_bound_terrain_ray_intersect() { return true; } - virtual bool is_bound_elevation_above_terrain() { return true; } - virtual bool is_bound_log() { return true; } - -public: - // --- creators --- - - static iref create( double r, void* context ) { - return create(0, r, context); - } - - template - static iref create( T* _subclass_, double r, void* context ); - - static iref get() { - return get(0); - } - - template - static iref get( T* _subclass_ ); - - // --- internal helpers --- - - virtual ~physics() { - if (_cleaner) _cleaner(this,0); - } - - static const int HASHID = 3023259009; - - int intergen_hash_id() const override final { return HASHID; } - - bool iface_is_derived( int hash ) const override final { - return hash == HASHID; - } - - const coid::tokenhash& intergen_interface_name() const override final { - static const coid::tokenhash _name = "bt::physics"; - return _name; - } - - static const coid::token& intergen_default_creator_static( EBackend bck ) { - static const coid::token _dc("bt::physics.get@3023259009"); - static const coid::token _djs("bt::physics@wrapper.js"); - static const coid::token _dlua("bt::physics@wrapper.lua"); - static const coid::token _dnone; - - switch(bck) { - case IFC_BACKEND_CXX: return _dc; - case IFC_BACKEND_JS: return _djs; - case IFC_BACKEND_LUA: return _dlua; - default: return _dnone; - } - } - - - template - static void* intergen_wrapper_cache() { - static void* _cached_wrapper=0; - if (!_cached_wrapper) { - const coid::token& tok = intergen_default_creator_static(B); - _cached_wrapper = coid::interface_register::get_interface_creator(tok); - } - return _cached_wrapper; - } - - void* intergen_wrapper( EBackend bck ) const override final { - switch(bck) { - case IFC_BACKEND_JS: return intergen_wrapper_cache(); - case IFC_BACKEND_LUA: return intergen_wrapper_cache(); - default: return 0; - } - } - - EBackend intergen_backend() const override { return IFC_BACKEND_CXX; } - - const coid::token& intergen_default_creator( EBackend bck ) const override final { - return intergen_default_creator_static(bck); - } - - ///Client registrator - template - static int register_client() - { - static_assert(std::is_base_of::value, "not a base class"); - - typedef iref (*fn_client)(void*, intergen_interface*); - fn_client cc = [](void*, intergen_interface*) -> iref { return new C; }; - - coid::token type = typeid(C).name(); - type.consume("class "); - type.consume("struct "); - - coid::charstr tmp = "bt::physics"; - tmp << "@client" << '.' << type; - - coid::interface_register::register_interface_creator(tmp, cc); - return 0; - } - -protected: - - typedef void (*cleanup_fn)(physics*, intergen_interface*); - cleanup_fn _cleaner; - - physics() : _cleaner(0) - {} -}; - -//////////////////////////////////////////////////////////////////////////////// -template -inline iref physics::create( T* _subclass_, double r, void* context ) -{ - typedef iref (*fn_creator)(physics*, double, void*); - - static fn_creator create = 0; - static const coid::token ifckey = "bt::physics.create@3023259009"; - - if (!create) - create = reinterpret_cast( - coid::interface_register::get_interface_creator(ifckey)); - - if (!create) - throw coid::exception("interface creator inaccessible: ") << ifckey; - - return create(_subclass_, r, context); -} -//////////////////////////////////////////////////////////////////////////////// -template -inline iref physics::get( T* _subclass_ ) -{ - typedef iref (*fn_creator)(physics*); - - static fn_creator create = 0; - static const coid::token ifckey = "bt::physics.get@3023259009"; - - if (!create) - create = reinterpret_cast( - coid::interface_register::get_interface_creator(ifckey)); - - if (!create) - throw coid::exception("interface creator inaccessible: ") << ifckey; - - return create(_subclass_); -} - -#pragma warning(push) -#pragma warning(disable : 4191) - -inline void physics::step_simulation( double step ) -{ return VT_CALL(void,(double),0)(step); } - -inline void physics::ray_test( const double from[3], const double to[3], void* cb ) -{ return VT_CALL(void,(const double[3],const double[3],void*),1)(from,to,cb); } - -inline btRigidBody* physics::fixed_object() -{ return VT_CALL(btRigidBody*,(),2)(); } - -inline btRigidBody* physics::create_rigid_body( float mass, btCollisionShape* shape, void* usr1, void* usr2 ) -{ return VT_CALL(btRigidBody*,(float,btCollisionShape*,void*,void*),3)(mass,shape,usr1,usr2); } - -inline void physics::destroy_rigid_body( btRigidBody*& obj ) -{ return VT_CALL(void,(btRigidBody*&),4)(obj); } - -inline void physics::add_rigid_body( btRigidBody* obj, unsigned int group, unsigned int mask, btActionInterface* action, bt::constraint_info* constraint ) -{ return VT_CALL(void,(btRigidBody*,unsigned int,unsigned int,btActionInterface*,bt::constraint_info*),5)(obj,group,mask,action,constraint); } - -inline void physics::remove_rigid_body( btRigidBody* obj, btActionInterface* action, bt::constraint_info* constraint ) -{ return VT_CALL(void,(btRigidBody*,btActionInterface*,bt::constraint_info*),6)(obj,action,constraint); } - -inline void physics::pause_rigid_body( btRigidBody* obj, bool pause ) -{ return VT_CALL(void,(btRigidBody*,bool),7)(obj,pause); } - -inline void physics::set_rigid_body_mass( btRigidBody* obj, float mass, const float inertia[3] ) -{ return VT_CALL(void,(btRigidBody*,float,const float[3]),8)(obj,mass,inertia); } - -inline void physics::set_rigid_body_gravity( btRigidBody* obj, const double gravity[3] ) -{ return VT_CALL(void,(btRigidBody*,const double[3]),9)(obj,gravity); } - -inline void physics::set_rigid_body_transform( btRigidBody* obj, const btTransform& tr, const double gravity[3] ) -{ return VT_CALL(void,(btRigidBody*,const btTransform&,const double[3]),10)(obj,tr,gravity); } - -inline void physics::predict_rigid_body_transform( btRigidBody* obj, double dt, btTransform& tr ) -{ return VT_CALL(void,(btRigidBody*,double,btTransform&),11)(obj,dt,tr); } - -inline btCollisionObject* physics::create_collision_object( btCollisionShape* shape, void* usr1, void* usr2 ) -{ return VT_CALL(btCollisionObject*,(btCollisionShape*,void*,void*),12)(shape,usr1,usr2); } - -inline void physics::destroy_collision_object( btCollisionObject*& obj ) -{ return VT_CALL(void,(btCollisionObject*&),13)(obj); } - -inline void physics::update_collision_object( btCollisionObject* obj, const btTransform& tr, bool update_aabb ) -{ return VT_CALL(void,(btCollisionObject*,const btTransform&,bool),14)(obj,tr,update_aabb); } - -inline void physics::set_collision_info( btCollisionObject* obj, unsigned int group, unsigned int mask ) -{ return VT_CALL(void,(btCollisionObject*,unsigned int,unsigned int),15)(obj,group,mask); } - -inline void physics::add_collision_object( btCollisionObject* obj, unsigned int group, unsigned int mask, bool inactive ) -{ return VT_CALL(void,(btCollisionObject*,unsigned int,unsigned int,bool),16)(obj,group,mask,inactive); } - -inline void physics::remove_collision_object( btCollisionObject* obj ) -{ return VT_CALL(void,(btCollisionObject*),17)(obj); } - -inline btCompoundShape* physics::create_compound_shape() -{ return VT_CALL(btCompoundShape*,(),18)(); } - -inline void physics::add_child_shape( btCompoundShape* group, btCollisionShape* child, const btTransform& tr ) -{ return VT_CALL(void,(btCompoundShape*,btCollisionShape*,const btTransform&),19)(group,child,tr); } - -inline void physics::update_child( btCompoundShape* group, int index, const btTransform& tr ) -{ return VT_CALL(void,(btCompoundShape*,int,const btTransform&),20)(group,index,tr); } - -inline void physics::recalc_compound_shape( btCompoundShape* shape ) -{ return VT_CALL(void,(btCompoundShape*),21)(shape); } - -inline void physics::destroy_compound_shape( btCompoundShape*& shape ) -{ return VT_CALL(void,(btCompoundShape*&),22)(shape); } - -inline btCollisionShape* physics::create_shape( bt::EShape sh, const float hvec[3] ) -{ return VT_CALL(btCollisionShape*,(bt::EShape,const float[3]),23)(sh,hvec); } - -inline void physics::add_convex_point( btCollisionShape* shape, const float point[3] ) -{ return VT_CALL(void,(btCollisionShape*,const float[3]),24)(shape,point); } - -inline void physics::close_convex_shape( btCollisionShape* shape ) -{ return VT_CALL(void,(btCollisionShape*),25)(shape); } - -inline void physics::destroy_shape( btCollisionShape*& shape ) -{ return VT_CALL(void,(btCollisionShape*&),26)(shape); } - -inline bt::ot_world_physics_stats physics::get_stats() -{ return VT_CALL(bt::ot_world_physics_stats,(),27)(); } - -inline bt::ot_world_physics_stats* physics::get_stats_ptr() -{ return VT_CALL(bt::ot_world_physics_stats*,(),28)(); } - -inline void physics::set_debug_draw_enabled( btIDebugDraw* debug_drawer ) -{ return VT_CALL(void,(btIDebugDraw*),29)(debug_drawer); } - -inline void physics::set_debug_drawer_mode( int debug_mode ) -{ return VT_CALL(void,(int),30)(debug_mode); } - -inline void physics::debug_draw_world() -{ return VT_CALL(void,(),31)(); } - -inline void physics::query_volume_sphere( const double3& pos, float rad, coid::dynarray& result ) -{ return VT_CALL(void,(const double3&,float,coid::dynarray&),32)(pos,rad,result); } - -inline void physics::query_volume_frustum( const double3& pos, const float4* f_planes_norms, uint8 nplanes, bool include_partial, coid::dynarray& result ) -{ return VT_CALL(void,(const double3&,const float4*,uint8,bool,coid::dynarray&),33)(pos,f_planes_norms,nplanes,include_partial,result); } - -#pragma warning(pop) - -} //namespace - -#endif //__INTERGEN_GENERATED__physics_H__ + +class physics; + + +namespace bt { + +//////////////////////////////////////////////////////////////////////////////// +///Interface for the physics module +class physics + : public intergen_interface +{ +public: + + // --- interface methods --- + + void step_simulation( double step ); + + void ray_test( const double from[3], const double to[3], void* cb ); + + btRigidBody* fixed_object(); + + btRigidBody* create_rigid_body( float mass, btCollisionShape* shape, void* usr1, void* usr2 ); + + void destroy_rigid_body( btRigidBody*& obj ); + + void add_rigid_body( btRigidBody* obj, unsigned int group, unsigned int mask, btActionInterface* action, bt::constraint_info* constraint ); + + void remove_rigid_body( btRigidBody* obj, btActionInterface* action, bt::constraint_info* constraint ); + + void pause_rigid_body( btRigidBody* obj, bool pause ); + + void set_rigid_body_mass( btRigidBody* obj, float mass, const float inertia[3] ); + + void set_rigid_body_gravity( btRigidBody* obj, const double gravity[3] ); + + void set_rigid_body_transform( btRigidBody* obj, const btTransform& tr, const double gravity[3] ); + + void predict_rigid_body_transform( btRigidBody* obj, double dt, ifc_out btTransform& tr ); + + btCollisionObject* create_collision_object( btCollisionShape* shape, void* usr1, void* usr2 ); + + void destroy_collision_object( btCollisionObject*& obj ); + + void update_collision_object( btCollisionObject* obj, const btTransform& tr, bool update_aabb ); + + void set_collision_info( btCollisionObject* obj, unsigned int group, unsigned int mask ); + + void add_collision_object( btCollisionObject* obj, unsigned int group, unsigned int mask, bool inactive ); + + void remove_collision_object( btCollisionObject* obj ); + + btCompoundShape* create_compound_shape(); + + void add_child_shape( btCompoundShape* group, btCollisionShape* child, const btTransform& tr ); + + void update_child( btCompoundShape* group, int index, const btTransform& tr ); + + void recalc_compound_shape( btCompoundShape* shape ); + + void destroy_compound_shape( ifc_inout btCompoundShape*& shape ); + + btCollisionShape* create_shape( bt::EShape sh, const float hvec[3] ); + + void add_convex_point( btCollisionShape* shape, const float point[3] ); + + void close_convex_shape( btCollisionShape* shape ); + + void destroy_shape( ifc_inout btCollisionShape*& shape ); + + bt::ot_world_physics_stats get_stats(); + + bt::ot_world_physics_stats* get_stats_ptr(); + + void set_debug_draw_enabled( btIDebugDraw* debug_drawer ); + + void set_debug_drawer_mode( int debug_mode ); + + void debug_draw_world(); + + void query_volume_sphere( const double3& pos, float rad, ifc_inout coid::dynarray& result ); + + void query_volume_frustum( const double3& pos, const float4* f_planes_norms, uint8 nplanes, bool include_partial, ifc_inout coid::dynarray& result ); + + +protected: + // --- interface events (callbacks from host to client) --- + // --- overload these to handle host events --- + + friend class ::physics; + + virtual bool terrain_collisions( const void* context, const double3& center, float radius, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame ){ throw coid::exception("handler not implemented"); } + + virtual bool terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray& data, coid::dynarray& trees, coid::slotalloc& tree_batches, uint frame, bool& is_above_tm ){ throw coid::exception("handler not implemented"); } + + virtual float3 tree_collisions( btRigidBody* obj, bt::tree_collision_contex& ctx, float time_step, coid::slotalloc& tree_batches ){ throw coid::exception("handler not implemented"); } + + virtual float terrain_ray_intersect( const void* context, const double3& from, const float3& dir, const float2& minmaxlen, float3* norm, double3* pos ){ throw coid::exception("handler not implemented"); } + + virtual float elevation_above_terrain( const double3& pos, float maxlen, float3* norm, double3* hitpoint ){ throw coid::exception("handler not implemented"); } + + virtual void add_static_collider( const void* context, btCollisionObject* obj, const double3& cen, const float3x3& basis ) {} + + virtual void log( const coid::token& text ) {} + + virtual void force_bind_script_events() {} + +public: + // --- host helpers to check presence of handlers in scripts --- + + virtual bool is_bound_terrain_collisions() { return true; } + virtual bool is_bound_terrain_collisions_aabb() { return true; } + virtual bool is_bound_tree_collisions() { return true; } + virtual bool is_bound_terrain_ray_intersect() { return true; } + virtual bool is_bound_elevation_above_terrain() { return true; } + virtual bool is_bound_add_static_collider() { return true; } + virtual bool is_bound_log() { return true; } + +public: + // --- creators --- + + static iref create( double r, void* context ) { + return create(0, r, context); + } + + template + static iref create( T* _subclass_, double r, void* context ); + + static iref get() { + return get(0); + } + + template + static iref get( T* _subclass_ ); + + // --- internal helpers --- + + virtual ~physics() { + if (_cleaner) _cleaner(this,0); + } + + static const int HASHID = 3573161280; + + int intergen_hash_id() const override final { return HASHID; } + + bool iface_is_derived( int hash ) const override final { + return hash == HASHID; + } + + const coid::tokenhash& intergen_interface_name() const override final { + static const coid::tokenhash _name = "bt::physics"; + return _name; + } + + static const coid::token& intergen_default_creator_static( EBackend bck ) { + static const coid::token _dc("bt::physics.get@3573161280"); + static const coid::token _djs("bt::physics@wrapper.js"); + static const coid::token _dlua("bt::physics@wrapper.lua"); + static const coid::token _dnone; + + switch(bck) { + case IFC_BACKEND_CXX: return _dc; + case IFC_BACKEND_JS: return _djs; + case IFC_BACKEND_LUA: return _dlua; + default: return _dnone; + } + } + + + template + static void* intergen_wrapper_cache() { + static void* _cached_wrapper=0; + if (!_cached_wrapper) { + const coid::token& tok = intergen_default_creator_static(B); + _cached_wrapper = coid::interface_register::get_interface_creator(tok); + } + return _cached_wrapper; + } + + void* intergen_wrapper( EBackend bck ) const override final { + switch(bck) { + case IFC_BACKEND_JS: return intergen_wrapper_cache(); + case IFC_BACKEND_LUA: return intergen_wrapper_cache(); + default: return 0; + } + } + + EBackend intergen_backend() const override { return IFC_BACKEND_CXX; } + + const coid::token& intergen_default_creator( EBackend bck ) const override final { + return intergen_default_creator_static(bck); + } + + ///Client registrator + template + static int register_client() + { + static_assert(std::is_base_of::value, "not a base class"); + + typedef iref (*fn_client)(void*, intergen_interface*); + fn_client cc = [](void*, intergen_interface*) -> iref { return new C; }; + + coid::token type = typeid(C).name(); + type.consume("class "); + type.consume("struct "); + + coid::charstr tmp = "bt::physics"; + tmp << "@client" << '.' << type; + + coid::interface_register::register_interface_creator(tmp, cc); + return 0; + } + +protected: + + typedef void (*cleanup_fn)(physics*, intergen_interface*); + cleanup_fn _cleaner; + + physics() : _cleaner(0) + {} +}; + +//////////////////////////////////////////////////////////////////////////////// +template +inline iref physics::create( T* _subclass_, double r, void* context ) +{ + typedef iref (*fn_creator)(physics*, double, void*); + + static fn_creator create = 0; + static const coid::token ifckey = "bt::physics.create@3573161280"; + + if (!create) + create = reinterpret_cast( + coid::interface_register::get_interface_creator(ifckey)); + + if (!create) + throw coid::exception("interface creator inaccessible: ") << ifckey; + + return create(_subclass_, r, context); +} +//////////////////////////////////////////////////////////////////////////////// +template +inline iref physics::get( T* _subclass_ ) +{ + typedef iref (*fn_creator)(physics*); + + static fn_creator create = 0; + static const coid::token ifckey = "bt::physics.get@3573161280"; + + if (!create) + create = reinterpret_cast( + coid::interface_register::get_interface_creator(ifckey)); + + if (!create) + throw coid::exception("interface creator inaccessible: ") << ifckey; + + return create(_subclass_); +} + +#pragma warning(push) +#pragma warning(disable : 4191) + +inline void physics::step_simulation( double step ) +{ return VT_CALL(void,(double),0)(step); } + +inline void physics::ray_test( const double from[3], const double to[3], void* cb ) +{ return VT_CALL(void,(const double[3],const double[3],void*),1)(from,to,cb); } + +inline btRigidBody* physics::fixed_object() +{ return VT_CALL(btRigidBody*,(),2)(); } + +inline btRigidBody* physics::create_rigid_body( float mass, btCollisionShape* shape, void* usr1, void* usr2 ) +{ return VT_CALL(btRigidBody*,(float,btCollisionShape*,void*,void*),3)(mass,shape,usr1,usr2); } + +inline void physics::destroy_rigid_body( btRigidBody*& obj ) +{ return VT_CALL(void,(btRigidBody*&),4)(obj); } + +inline void physics::add_rigid_body( btRigidBody* obj, unsigned int group, unsigned int mask, btActionInterface* action, bt::constraint_info* constraint ) +{ return VT_CALL(void,(btRigidBody*,unsigned int,unsigned int,btActionInterface*,bt::constraint_info*),5)(obj,group,mask,action,constraint); } + +inline void physics::remove_rigid_body( btRigidBody* obj, btActionInterface* action, bt::constraint_info* constraint ) +{ return VT_CALL(void,(btRigidBody*,btActionInterface*,bt::constraint_info*),6)(obj,action,constraint); } + +inline void physics::pause_rigid_body( btRigidBody* obj, bool pause ) +{ return VT_CALL(void,(btRigidBody*,bool),7)(obj,pause); } + +inline void physics::set_rigid_body_mass( btRigidBody* obj, float mass, const float inertia[3] ) +{ return VT_CALL(void,(btRigidBody*,float,const float[3]),8)(obj,mass,inertia); } + +inline void physics::set_rigid_body_gravity( btRigidBody* obj, const double gravity[3] ) +{ return VT_CALL(void,(btRigidBody*,const double[3]),9)(obj,gravity); } + +inline void physics::set_rigid_body_transform( btRigidBody* obj, const btTransform& tr, const double gravity[3] ) +{ return VT_CALL(void,(btRigidBody*,const btTransform&,const double[3]),10)(obj,tr,gravity); } + +inline void physics::predict_rigid_body_transform( btRigidBody* obj, double dt, btTransform& tr ) +{ return VT_CALL(void,(btRigidBody*,double,btTransform&),11)(obj,dt,tr); } + +inline btCollisionObject* physics::create_collision_object( btCollisionShape* shape, void* usr1, void* usr2 ) +{ return VT_CALL(btCollisionObject*,(btCollisionShape*,void*,void*),12)(shape,usr1,usr2); } + +inline void physics::destroy_collision_object( btCollisionObject*& obj ) +{ return VT_CALL(void,(btCollisionObject*&),13)(obj); } + +inline void physics::update_collision_object( btCollisionObject* obj, const btTransform& tr, bool update_aabb ) +{ return VT_CALL(void,(btCollisionObject*,const btTransform&,bool),14)(obj,tr,update_aabb); } + +inline void physics::set_collision_info( btCollisionObject* obj, unsigned int group, unsigned int mask ) +{ return VT_CALL(void,(btCollisionObject*,unsigned int,unsigned int),15)(obj,group,mask); } + +inline void physics::add_collision_object( btCollisionObject* obj, unsigned int group, unsigned int mask, bool inactive ) +{ return VT_CALL(void,(btCollisionObject*,unsigned int,unsigned int,bool),16)(obj,group,mask,inactive); } + +inline void physics::remove_collision_object( btCollisionObject* obj ) +{ return VT_CALL(void,(btCollisionObject*),17)(obj); } + +inline btCompoundShape* physics::create_compound_shape() +{ return VT_CALL(btCompoundShape*,(),18)(); } + +inline void physics::add_child_shape( btCompoundShape* group, btCollisionShape* child, const btTransform& tr ) +{ return VT_CALL(void,(btCompoundShape*,btCollisionShape*,const btTransform&),19)(group,child,tr); } + +inline void physics::update_child( btCompoundShape* group, int index, const btTransform& tr ) +{ return VT_CALL(void,(btCompoundShape*,int,const btTransform&),20)(group,index,tr); } + +inline void physics::recalc_compound_shape( btCompoundShape* shape ) +{ return VT_CALL(void,(btCompoundShape*),21)(shape); } + +inline void physics::destroy_compound_shape( btCompoundShape*& shape ) +{ return VT_CALL(void,(btCompoundShape*&),22)(shape); } + +inline btCollisionShape* physics::create_shape( bt::EShape sh, const float hvec[3] ) +{ return VT_CALL(btCollisionShape*,(bt::EShape,const float[3]),23)(sh,hvec); } + +inline void physics::add_convex_point( btCollisionShape* shape, const float point[3] ) +{ return VT_CALL(void,(btCollisionShape*,const float[3]),24)(shape,point); } + +inline void physics::close_convex_shape( btCollisionShape* shape ) +{ return VT_CALL(void,(btCollisionShape*),25)(shape); } + +inline void physics::destroy_shape( btCollisionShape*& shape ) +{ return VT_CALL(void,(btCollisionShape*&),26)(shape); } + +inline bt::ot_world_physics_stats physics::get_stats() +{ return VT_CALL(bt::ot_world_physics_stats,(),27)(); } + +inline bt::ot_world_physics_stats* physics::get_stats_ptr() +{ return VT_CALL(bt::ot_world_physics_stats*,(),28)(); } + +inline void physics::set_debug_draw_enabled( btIDebugDraw* debug_drawer ) +{ return VT_CALL(void,(btIDebugDraw*),29)(debug_drawer); } + +inline void physics::set_debug_drawer_mode( int debug_mode ) +{ return VT_CALL(void,(int),30)(debug_mode); } + +inline void physics::debug_draw_world() +{ return VT_CALL(void,(),31)(); } + +inline void physics::query_volume_sphere( const double3& pos, float rad, coid::dynarray& result ) +{ return VT_CALL(void,(const double3&,float,coid::dynarray&),32)(pos,rad,result); } + +inline void physics::query_volume_frustum( const double3& pos, const float4* f_planes_norms, uint8 nplanes, bool include_partial, coid::dynarray& result ) +{ return VT_CALL(void,(const double3&,const float4*,uint8,bool,coid::dynarray&),33)(pos,f_planes_norms,nplanes,include_partial,result); } + +#pragma warning(pop) + +} //namespace + +#endif //__INTERGEN_GENERATED__physics_H__ diff --git a/src/otbullet/physics.js.h b/src/otbullet/physics.js.h index 6167825265..d6464f7327 100644 --- a/src/otbullet/physics.js.h +++ b/src/otbullet/physics.js.h @@ -1,60 +1,60 @@ -#pragma once - -#ifndef __INTERGEN_GENERATED__physics_JS_H__ -#define __INTERGEN_GENERATED__physics_JS_H__ - -//@file Javascript interface file for physics interface generated by intergen -//See LICENSE file for copyright and license information - -#include "physics.h" - -#include -#include - -namespace bt { -namespace js { - -class physics -{ -public: - - //@param scriptpath path to js script to bind to - static iref create( const script_handle& script, double r, void* context, const coid::token& bindvar = coid::token(), v8::Handle* ctx=0 ) - { - typedef iref (*fn_bind)(const script_handle&, double, void*, const coid::token&, v8::Handle*); - static fn_bind binder = 0; - static const coid::token ifckey = "bt::physics.create@creator.js"; - - if (!binder) - binder = reinterpret_cast( - coid::interface_register::get_interface_creator(ifckey)); - - if (!binder) - throw coid::exception("interface binder inaccessible: ") << ifckey; - - return binder(script, r, context, bindvar, ctx); - } - - //@param scriptpath path to js script to bind to - static iref get( const script_handle& script, const coid::token& bindvar = coid::token(), v8::Handle* ctx=0 ) - { - typedef iref (*fn_bind)(const script_handle&, const coid::token&, v8::Handle*); - static fn_bind binder = 0; - static const coid::token ifckey = "bt::physics.get@creator.js"; - - if (!binder) - binder = reinterpret_cast( - coid::interface_register::get_interface_creator(ifckey)); - - if (!binder) - throw coid::exception("interface binder inaccessible: ") << ifckey; - - return binder(script, bindvar, ctx); - } -}; - -} //namespace js -} //namespace - - -#endif //__INTERGEN_GENERATED__physics_JS_H__ +#pragma once + +#ifndef __INTERGEN_GENERATED__physics_JS_H__ +#define __INTERGEN_GENERATED__physics_JS_H__ + +//@file Javascript interface file for physics interface generated by intergen +//See LICENSE file for copyright and license information + +#include "physics.h" + +#include +#include + +namespace bt { +namespace js { + +class physics +{ +public: + + //@param scriptpath path to js script to bind to + static iref create( const script_handle& script, double r, void* context, const coid::token& bindvar = coid::token(), v8::Handle* ctx=0 ) + { + typedef iref (*fn_bind)(const script_handle&, double, void*, const coid::token&, v8::Handle*); + static fn_bind binder = 0; + static const coid::token ifckey = "bt::physics.create@creator.js"; + + if (!binder) + binder = reinterpret_cast( + coid::interface_register::get_interface_creator(ifckey)); + + if (!binder) + throw coid::exception("interface binder inaccessible: ") << ifckey; + + return binder(script, r, context, bindvar, ctx); + } + + //@param scriptpath path to js script to bind to + static iref get( const script_handle& script, const coid::token& bindvar = coid::token(), v8::Handle* ctx=0 ) + { + typedef iref (*fn_bind)(const script_handle&, const coid::token&, v8::Handle*); + static fn_bind binder = 0; + static const coid::token ifckey = "bt::physics.get@creator.js"; + + if (!binder) + binder = reinterpret_cast( + coid::interface_register::get_interface_creator(ifckey)); + + if (!binder) + throw coid::exception("interface binder inaccessible: ") << ifckey; + + return binder(script, bindvar, ctx); + } +}; + +} //namespace js +} //namespace + + +#endif //__INTERGEN_GENERATED__physics_JS_H__ diff --git a/src/otbullet/rigid_body.cpp b/src/otbullet/rigid_body.cpp index ef7fb4bfdb..82279dc3f4 100644 --- a/src/otbullet/rigid_body.cpp +++ b/src/otbullet/rigid_body.cpp @@ -86,8 +86,8 @@ void physics::destroy_rigid_body( btRigidBody*& obj ) void physics::add_rigid_body( btRigidBody* obj, unsigned int group, unsigned int mask, btActionInterface* action, bt::constraint_info* constraint ) { - if(action) - obj->setActivationState(DISABLE_DEACTIVATION); +// if(action) +// obj->setActivationState(DISABLE_DEACTIVATION); _world->addRigidBody(obj, group, mask); @@ -120,7 +120,7 @@ void physics::remove_rigid_body( btRigidBody* obj, btActionInterface* action, bt //////////////////////////////////////////////////////////////////////////////// void physics::pause_rigid_body( btRigidBody* obj, bool pause ) { - obj->forceActivationState(pause ? DISABLE_SIMULATION : DISABLE_DEACTIVATION); + obj->forceActivationState(pause ? DISABLE_SIMULATION : ACTIVE_TAG); if(pause) { btVector3 v(0,0,0); diff --git a/src/otbullet/wrapper.cpp b/src/otbullet/wrapper.cpp index 7a284b0489..ff3d219111 100644 --- a/src/otbullet/wrapper.cpp +++ b/src/otbullet/wrapper.cpp @@ -136,7 +136,10 @@ static float3 _ext_tree_col(btRigidBody * obj, coid::slotalloc& tree_batches) { return _physics->tree_collisions(obj, ctx, time_step,tree_batches); +} +static void _ext_add_static_collider(const void * context,btCollisionObject * obj, const double3& cen, const float3x3& basis) { + _physics->add_static_collider(context,obj,cen,basis); } #endif @@ -336,7 +339,20 @@ void physics::add_collision_object( btCollisionObject* obj, unsigned int group, if(inactive) obj->setActivationState(DISABLE_SIMULATION); + /* if (obj->isStaticObject()) { + float3x3 basis; + double3 cen; + + _world->get_obb(obj->getCollisionShape(),obj->getWorldTransform(),cen,basis); + add_static_collider(_world->get_context(),obj,cen,basis); + } + else { + _world->addCollisionObject(obj, group, mask); + }*/ + _world->addCollisionObject(obj, group, mask); + + } ////////////////////////////////////////////////////////////////////////////////