From 88b9c425c094eb3eb9660a684bc1bccde320ea26 Mon Sep 17 00:00:00 2001 From: jaynus Date: Fri, 15 May 2015 09:10:08 -0700 Subject: [PATCH] Impact positions. --- .../functions/fnc_dispatchDamage.sqf | 1 - addons/vehicledamage/functions/fnc_doHit.sqf | 30 +++++++++++++++---- addons/vehicledamage/script_component.hpp | 1 - extensions/tests/longrod_dxtk_test.txt | 17 +++++++---- extensions/vd/base_vehicle.cpp | 6 +--- extensions/vd/controller.cpp | 6 ++++ extensions/vd/controller.hpp | 1 + extensions/vd/debug/penetration_display.cpp | 25 +++++++++++----- extensions/vd/debug/penetration_display.hpp | 2 ++ 9 files changed, 63 insertions(+), 26 deletions(-) diff --git a/addons/vehicledamage/functions/fnc_dispatchDamage.sqf b/addons/vehicledamage/functions/fnc_dispatchDamage.sqf index 007b95f316..651df9fc41 100644 --- a/addons/vehicledamage/functions/fnc_dispatchDamage.sqf +++ b/addons/vehicledamage/functions/fnc_dispatchDamage.sqf @@ -4,7 +4,6 @@ PARAMS_5(_unit,_selectionName,_damage,_source,_projectile); private["_currentDmgCount", "_hitpointCount", "_dmgId", "_dmgVarName", "_dmgArray"]; // Disable handledamage for now -if(true) exitWith { 0 }; _hitpointCount = _unit getVariable[QGVAR(hitpointCount), -1]; _currentDmgCount = _unit getVariable[QGVAR(currentDmgCount), -1]; diff --git a/addons/vehicledamage/functions/fnc_doHit.sqf b/addons/vehicledamage/functions/fnc_doHit.sqf index 646f67394c..704aa3de7e 100644 --- a/addons/vehicledamage/functions/fnc_doHit.sqf +++ b/addons/vehicledamage/functions/fnc_doHit.sqf @@ -6,8 +6,9 @@ #define __PROJECTILE_CLASS configFile >> "CfgAmmo" >> (_ammo select 4) private["_impactSurfaceType", "_isDirectHit", "_command", "_model", "_projectileType"]; +private["_relProjectilePos", "_relProjectileVelocity", "_projectilePosition", "_relImpactVelPos", "_relImpactVelocity", "_relSurfDirectionPos", "_relSurfaceDirection"]; private["_penetrationOrthogonalDepth", "_penetrationAngleDepth", "_penetrationCosAngle", "_projectileCaliber", "_projectileDensity", "_projectileLength", "_armorDensity"]; -EXPLODE_9_PVT((_this select 0),_vehicle,_shooter,_projectile,_impactPosition,_projectileVelocity,_selection,_ammo,_surfaceDirection,_radius); +EXPLODE_9_PVT((_this select 0),_vehicle,_shooter,_projectile,_impactPosition,_impactVelocity,_selection,_ammo,_surfaceDirection,_radius); _impactSurfaceType = (_this select 0) select 9; _isDirectHit = (_this select 0) select 10; TRACE_2("",_impactSurfaceType,_isDirectHit); @@ -33,6 +34,23 @@ if(_projectileLength == 0) then { _vehicleId = _vehicle getVariable[QGVAR(id), -1]; + +// The below didn't work +//#define RELATIVE_VECTOR_TEXT(o,x) ([(o worldToModelVisual ((x) call EFUNC(common,ASLToPosition)))] call FUNC(_textVector)) + +// Get a relative velocity!?!? +_relImpactPosition = _vehicle worldToModelVisual _impactPosition; +_projectilePosition = _vehicle worldToModelVisual (position _projectile); + +_relProjectilePos = (position _projectile) vectorAdd (velocity _projectile); +_relProjectileVelocity = _projectilePosition vectorFromTo (_vehicle modelToWorldVisual _relProjectilePos); + +_relImpactVelPos = _impactPosition vectorAdd _impactVelocity; +_relImpactVelocity = _relImpactPosition vectorFromTo (_vehicle modelToWorldVisual _relImpactVelPos); + +_relSurfDirectionPos = _impactPosition vectorAdd _surfaceDirection; +_relSurfaceDirection = _relImpactPosition vectorFromTo (_vehicle modelToWorldVisual _relSurfDirectionPos); + _command = format["hit:%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14,%15,%16,%17,%18", _vehicleId, // vehicle id registered // _model, _selection, @@ -42,12 +60,12 @@ _command = format["hit:%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14,%15,%16,%1 _projectileType, //projectile type id (_ammo select 4), _projectileLength, _projectileDiameter, _projectileDensity, _frastumLength, _frastumDiameter, - VECTOR_TEXT(_projectileVelocity), - RELATIVE_VECTOR_TEXT(_vehicle,getPosASL _projectile), + VECTOR_TEXT(_relProjectileVelocity), + VECTOR_TEXT(_projectilePosition), VECTOR_TEXT(vectorDir _projectile), - VECTOR_TEXT(_surfaceDirection), - RELATIVE_VECTOR_TEXT(_vehicle,_impactPosition), - VECTOR_TEXT(_projectileVelocity) + VECTOR_TEXT(_relSurfaceDirection), + VECTOR_TEXT(_relImpactPosition), + VECTOR_TEXT(_relImpactVelocity) ]; TRACE_1("", _command); _result = _command call FUNC(callExtension); diff --git a/addons/vehicledamage/script_component.hpp b/addons/vehicledamage/script_component.hpp index 1f81f8bd09..644f7f614f 100644 --- a/addons/vehicledamage/script_component.hpp +++ b/addons/vehicledamage/script_component.hpp @@ -13,7 +13,6 @@ #define CALL_EXT(x) "ace_vd" callExtension x #define VECTOR_TEXT(x) ([(x)] call FUNC(_textVector)) -#define RELATIVE_VECTOR_TEXT(o,x) ([(o worldToModelVisual ((x) call EFUNC(common,ASLToPosition)))] call FUNC(_textVector)) #define DEBUG_EXTENSION_DYNLOAD #define DEBUG_LOG_EXTENSION diff --git a/extensions/tests/longrod_dxtk_test.txt b/extensions/tests/longrod_dxtk_test.txt index 77b7bce50f..1a9aca0311 100644 --- a/extensions/tests/longrod_dxtk_test.txt +++ b/extensions/tests/longrod_dxtk_test.txt @@ -1,11 +1,18 @@ #c:\arma\arma3\addons\armor_f_epb.pbo C:\dev\ace3\extensions\tests\longrod_dxtk_test.txt init: debug_render: -register_vehicle:\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, 0, 4050.18;3802.55;5.075 register_vehicle:\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, 1, 4046.21;3902.56;5.075 #set_animation_state:1,damageHide, 0, Wheel_kolL1, 0, Wheel_koloL1, 0, Wheel_podkoloL1, 1, Wheel_kolP1, 0, Wheel_koloP1, 0, Wheel_podkoloP1, 1, Wheel_kolL2, 0, Wheel_kolP2, 0, Wheel_koloL2, 0, Wheel_koloL3, 0, Wheel_koloL4, 0, Wheel_koloL5, 0, Wheel_koloL6, 0, Wheel_koloL7, 0, Wheel_koloP2, 0, Wheel_koloP3, 0, Wheel_koloP4, 0, Wheel_koloP5, 0, Wheel_koloP6, 0, Wheel_koloP7, 0, Wheel_podkoloL2, 1, Wheel_podkoloL3, 1, Wheel_podkoloL4, 1, Wheel_podkoloL5, 0, Wheel_podkoloL6, 0, Wheel_podkoloP2, 1, Wheel_podkoloP3, 1, Wheel_podkoloP4, 1, Wheel_podkoloP5, 0, Wheel_podkoloP6, 1, podkoloL1_hide_damage, 0, podkoloL2_hide_damage, 0, podkoloL3_hide_damage, 0, podkoloL4_hide_damage, 0, podkoloL5_hide_damage, 0, podkoloL6_hide_damage, 0, podkoloL7_hide_damage, 0, podkoloL8_hide_damage, 0, podkoloP1_hide_damage, 0, podkoloP2_hide_damage, 0, podkoloP3_hide_damage, 0, podkoloP4_hide_damage, 0, podkoloP5_hide_damage, 0, podkoloP6_hide_damage, 0, podkoloP7_hide_damage, 0, podkoloP8_hide_damage, 0, damageVez, 0, MainTurret, -3, MainGun, 0, Recoil, 0, ObsTurret, -0, ObsGun, 0, MainGunOptics, 0, Wheel_podkoloP7, 0, Wheel_podkoloL7, 0, HatchDriver, 0, HatchCommander, 0, HatchGunner, 0, damageVezVelitele, 0, poklop_commander_damage, 0, poklop_gunner_damage, 0, poklop_driver_damage, 0, zaslehROT_HMG, 101, zaslehROT_coax, 16, cannon_muzzle_flash, 0, zaslehROT_cannon, 956, HideHull, 1, HideTurret, 1, LockMuzzle, 0 #set_vehicle_state:1,0;-20;0,0;0;0,0;0;0 -hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -113.705;1739.65;-16.2768, -4.0415;-2.1792;-1.48682, -0.0652189;0.99783;-0.0090309, 0.173648;-0.984808;-0.000745866, 2.17163;-2.84473;-1.37076, -113.705;1739.65;-16.2768 -hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -116.629;1649.67;-22.7955, -4.0415;-2.1792;-1.48682, -0.0652189;0.99783;-0.0090309, 0.173648;-0.984808;-0.000745866, 1.20923;-2.74414;-1.38434, -116.629;1649.67;-22.7955 -hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -111.44;1515.54;-18.5295, -4.0415;-2.1792;-1.48682, -0.0652189;0.99783;-0.0090309, 0.173648;-0.984808;-0.000746472, -1.08325;-2.51172;-1.41356, -111.44;1515.54;-18.5295 -hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -90.7305;1382.51;-21.8112, -4.0415;-2.1792;-1.48682, -0.0652189;0.99783;-0.0090309, 0.173648;-0.984808;-0.000745866, -2.08447;-2.40234;-1.42964, -90.7305;1382.51;-21.8112 \ No newline at end of file +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984808;0.173648;-0.000321539, 0.000336425;-5.62874e-005;1, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 0.000173648;-0.000984808;-1.13852e-007, 1.90674;-2.97705;-1.01589, 9.3088e-005;0.999998;0.00182291, 0.997565;0.0697389;0.00040539, 2.1709;-3.00732;3.9504, 0.996985;0.0775994;0.000355178 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984808;0.173648;-0.000321539, 0.000336425;-5.62874e-005;1, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 0.000173648;-0.000984808;-1.13852e-007, 1.90674;-2.97705;-1.01589, 9.3088e-005;0.999998;0.00182291, 0.997565;0.0697387;0.000405358, 1.90527;-2.97852;3.94798, 0.997251;0.0740926;0.000152842 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00285841, 0.00294448;-0.000238045;0.999996, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 7.61759e-005;-0.000997094;-4.61654e-007, 1.77954;-2.83154;-0.219069, -0.0380967;0.999228;0.00961505, 0.997566;0.069721;-0.00105282, 1.7749;-2.8457;4.74479, 0.996762;0.0804012;-0.000602539 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284932, 0.00294109;-0.000271166;0.999995, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 0.000173647;-0.000984808;-7.73569e-007, 1.82178;-1.9292;-0.268372, -0.0288651;0.999542;0.00905338, 0.997581;0.0695041;-0.00106295, 1.81689;-1.94336;4.69548, 0.996832;0.079526;-0.000653841 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284391, 0.00293735;-0.000281132;0.999996, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 0.000173647;-0.000984808;-7.85849e-007, 1.84595;-2.57471;-2.50434, -0.0354257;0.999277;-0.0138109, 0.997571;0.0696509;-0.00106625, 1.84106;-2.58887;2.45951, 0.99678;0.0801495;-0.00236906 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284275, 0.00293741;-0.000288139;0.999996, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 0.000173647;-0.000984808;-7.92519e-007, 1.90674;-2.85693;-0.816221, -0.0381079;0.999267;0.00357182, 0.997566;0.069714;-0.00106831, 2.16724;-2.90381;4.15556, 0.996761;0.08041;-0.00106769 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284275, 0.00293741;-0.000288139;0.999996, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 0.000173647;-0.000984808;-7.92519e-007, 1.90674;-2.85693;-0.816221, -0.0381079;0.999267;0.00357182, 0.997566;0.0697129;-0.00106831, 1.90186;-2.87109;4.14763, 0.997275;0.0737539;-0.00188146 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.002843, 0.00293819;-0.000291138;0.999996, 0, B_65x39_Caseless, 32893, 6706, 11300, 0, 0, 0.000173647;-0.000984808;-7.95372e-007, 1.67578;-2.15332;-2.30106, -0.0313568;0.99944;-0.0117081, 0.997577;0.0695593;-0.00107051, 1.6709;-2.16797;2.6628, 0.996812;0.0797612;-0.00221558 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284299, 0.00293839;-0.0002923;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -94.1198;1574.74;-13.4215, -3.81567;-2.31543;-0.841839, -0.0666772;0.997769;-0.00347184, 0.997565;0.0697371;-0.00107085, 2.16748;-3.00537;4.17418, 0.995139;0.0984623;-0.00199962 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284299, 0.00293839;-0.0002923;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -94.1198;1574.74;-13.4215, -3.81567;-2.31543;-0.841839, -0.0666772;0.997769;-0.00347184, 0.997565;0.069737;-0.00107086, 1.90186;-2.97705;4.17292, 0.995158;0.0982686;-0.00206677 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284299, 0.00293839;-0.0002923;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -94.1198;1574.74;-13.4215, -3.81567;-2.31543;-0.841839, -0.0666772;0.997769;-0.00347184, 0.997565;0.0697312;-0.00107094, -1.75977;-2.56689;4.15401, 0.995311;0.0967058;-0.00210695 +hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, BALLS, 0.984803;0.173649;-0.00284299, 0.00293839;-0.0002923;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -94.1198;1574.74;-13.4215, -3.81567;-2.31543;-0.841839, -0.0666772;0.997769;-0.00347184, 0.997565;0.0697306;-0.00107095, -2.08813;-2.5293;4.15127, 0.995439;0.0953656;-0.00261482 \ No newline at end of file diff --git a/extensions/vd/base_vehicle.cpp b/extensions/vd/base_vehicle.cpp index a2ca820caa..ff145e0486 100644 --- a/extensions/vd/base_vehicle.cpp +++ b/extensions/vd/base_vehicle.cpp @@ -46,11 +46,7 @@ namespace ace { // @TODO: This is moving it in the bullet world for handling multiple collisions, instead our raytests need to ignore ALL but this type. How do we do that? // For now this only works for single-object collisions then // Set 3d world bullet position based on game position - - btTransform transform = bt_object->getWorldTransform(); - transform.setOrigin(btVector3(position_.x(), position_.y(), position_.z())); - bt_object->setWorldTransform(transform); - + controller::get().bt_world->addCollisionObject(bt_object.get()); } base_vehicle::~base_vehicle() { diff --git a/extensions/vd/controller.cpp b/extensions/vd/controller.cpp index 0c42c8cd91..dc12eec4c3 100644 --- a/extensions/vd/controller.cpp +++ b/extensions/vd/controller.cpp @@ -45,6 +45,7 @@ namespace ace { add("selection_position", std::bind(&ace::vehicledamage::controller::selection_position, this, std::placeholders::_1, std::placeholders::_2)); #ifdef _DEBUG + add("bullet_debug", std::bind(&ace::vehicledamage::controller::_debug_render_bullet, this, std::placeholders::_1, std::placeholders::_2)); add("debug_render", std::bind(&ace::vehicledamage::controller::_debug_render, this, std::placeholders::_1, std::placeholders::_2)); add("test_raycast", std::bind(&ace::vehicledamage::controller::_test_raycast, this, std::placeholders::_1, std::placeholders::_2)); add("test_selection", std::bind(&ace::vehicledamage::controller::_test_selection, this, std::placeholders::_1, std::placeholders::_2)); @@ -252,6 +253,11 @@ namespace ace { bool controller::_debug_render(const arguments &_args, std::string & result) { _debug_display->render_thread(1024, 768, false); + return true; + } + bool controller::_debug_render_bullet(const arguments &_args, std::string & result) { + _debug_display->_enable_bullet_debug = true; + return true; } #endif diff --git a/extensions/vd/controller.hpp b/extensions/vd/controller.hpp index 780f784819..4e99c4dcb1 100644 --- a/extensions/vd/controller.hpp +++ b/extensions/vd/controller.hpp @@ -43,6 +43,7 @@ namespace ace { #if defined(DEVEL) && defined(USE_DIRECTX) bool _debug_render(const arguments &, std::string &); + bool _debug_render_bullet(const arguments &, std::string &); std::unique_ptr _debug_display; #endif diff --git a/extensions/vd/debug/penetration_display.cpp b/extensions/vd/debug/penetration_display.cpp index 8bdb94380b..41f4b87d68 100644 --- a/extensions/vd/debug/penetration_display.cpp +++ b/extensions/vd/debug/penetration_display.cpp @@ -7,7 +7,7 @@ namespace ace { namespace vehicledamage { namespace debug { - penetration_display::penetration_display() : + penetration_display::penetration_display() : _enable_bullet_debug(false), dispatcher() { _active_vehicle = nullptr; @@ -32,7 +32,7 @@ namespace ace { XMVECTORF32 eyeDir = { direction.x(), direction.y(), direction.z() }; XMVECTORF32 up = { 0.f, 1.f, 0.f }; - XMStoreFloat4x4(&_View, XMMatrixLookAtLH(eyePos, eyeDir, up)); + XMStoreFloat4x4(&_View, XMMatrixLookAtLH(eyePos, XMVectorZero(), up)); return true; } @@ -111,12 +111,13 @@ namespace ace { _Batch->End(); - // Draw the bullet world // The BT debug drawing is a single batch - _Batch->Begin(); - ace::vehicledamage::controller::get().bt_world->debugDrawWorld(); - _Batch->End(); + if (_enable_bullet_debug) { + _Batch->Begin(); + ace::vehicledamage::controller::get().bt_world->debugDrawWorld(); + _Batch->End(); + } if (_active_vehicle) { @@ -166,10 +167,11 @@ namespace ace { batch.Begin(); for (gamehit_p & hit : _active_hits) { - ace::vector3 hit_from, hit_to; + ace::vector3 hit_from, hit_to, hit_surface; hit_from = hit->impactposition; - hit_to = hit_from + (hit->impactvelocity * 0.01f); + hit_to = hit_from + hit->impactvelocity; + hit_surface = hit_from + hit->surface; XMVECTORF32 from = { hit_from.x(), hit_from.y(), hit_from.z() }; XMVECTORF32 to = { hit_to.x(), hit_to.y(), hit_to.z() }; @@ -178,6 +180,13 @@ namespace ace { VertexPositionColor v2(to, color); batch.DrawLine(v1, v2); + + XMVECTORF32 surface_direction = { hit_surface.x(), hit_surface.y(), hit_surface.z() }; + + VertexPositionColor v1_surf(from, Colors::LightGreen); + VertexPositionColor v2_surf(surface_direction, Colors::LightGreen); + + batch.DrawLine(v1_surf, v2_surf); } diff --git a/extensions/vd/debug/penetration_display.hpp b/extensions/vd/debug/penetration_display.hpp index 00e6e3cac9..b199a8dda5 100644 --- a/extensions/vd/debug/penetration_display.hpp +++ b/extensions/vd/debug/penetration_display.hpp @@ -65,6 +65,8 @@ namespace ace { vehicle_p _active_vehicle; std::vector _active_hits; + bool _enable_bullet_debug; + void DrawHits(uint32_t lod, PrimitiveBatch& batch, GXMVECTOR color); void DrawCollisions(const std::vector> & collisions, PrimitiveBatch& batch, GXMVECTOR color); void DrawObject(uint32_t lod, PrimitiveBatch& batch, ace::simulation::object & obj, GXMVECTOR color);