diff --git a/newton-4.00/applications/ndSandbox/demos/ndHeavyVehicle.cpp b/newton-4.00/applications/ndSandbox/demos/ndHeavyVehicle.cpp index 7b20f21c0..2af719270 100644 --- a/newton-4.00/applications/ndSandbox/demos/ndHeavyVehicle.cpp +++ b/newton-4.00/applications/ndSandbox/demos/ndHeavyVehicle.cpp @@ -219,7 +219,6 @@ class ndHeavyMultiBodyVehicle : public ndVehicleCommon vehicleEntity->ResetMatrix(vehicleEntity->CalculateGlobalMatrix() * matrix); // create the vehicle chassis as a normal rigid body - //ndBodyKinematic* const chassis = CreateChassis(scene, vehicleEntity, m_configuration.m_chassisMass); ndSharedPtr chassisBody (CreateChassis(scene, vehicleEntity, m_configuration.m_chassisMass)); AddChassis(chassisBody); m_chassis->SetAngularDamping(ndVector(m_configuration.m_chassisAngularDrag)); @@ -323,26 +322,24 @@ class ndLav25Vehicle : public ndHeavyMultiBodyVehicle ,m_cannonHigh(0.0f) ,m_turretAngle(0.0f) { - ndAssert(0); - //VehicleAssembly(scene); + VehicleAssembly(scene); } -#if 0 + void VehicleAssembly(ndDemoEntityManager* const scene) { // 2- each tire to the model, // this function will create the tire as a normal rigid body // and attach them to the chassis with the tire joints - ndWorld* const world = scene->GetWorld(); ndBodyKinematic* const chassis = m_chassis; ndVehicleDectriptor::ndTireDefinition r0_tireConfiguration(m_configuration.m_rearTire); ndVehicleDectriptor::ndTireDefinition r1_tireConfiguration(m_configuration.m_rearTire); ndVehicleDectriptor::ndTireDefinition r2_tireConfiguration(m_configuration.m_rearTire); ndVehicleDectriptor::ndTireDefinition r3_tireConfiguration(m_configuration.m_rearTire); - ndBodyKinematic* const rr_tire0_body = CreateTireBody(scene, chassis, r0_tireConfiguration, "rtire_3"); - ndBodyKinematic* const rl_tire0_body = CreateTireBody(scene, chassis, r1_tireConfiguration, "ltire_3"); - ndBodyKinematic* const rr_tire1_body = CreateTireBody(scene, chassis, r2_tireConfiguration, "rtire_2"); - ndBodyKinematic* const rl_tire1_body = CreateTireBody(scene, chassis, r3_tireConfiguration, "ltire_2"); + ndSharedPtr rr_tire0_body = CreateTireBody(scene, chassis, r0_tireConfiguration, "rtire_3"); + ndSharedPtr rl_tire0_body = CreateTireBody(scene, chassis, r1_tireConfiguration, "ltire_3"); + ndSharedPtr rr_tire1_body = CreateTireBody(scene, chassis, r2_tireConfiguration, "rtire_2"); + ndSharedPtr rl_tire1_body = CreateTireBody(scene, chassis, r3_tireConfiguration, "ltire_2"); ndMultiBodyVehicleTireJoint* const rr_tire0 = AddTire(r0_tireConfiguration, rr_tire0_body); ndMultiBodyVehicleTireJoint* const rl_tire0 = AddTire(r1_tireConfiguration, rl_tire0_body); ndMultiBodyVehicleTireJoint* const rr_tire1 = AddTire(r2_tireConfiguration, rr_tire1_body); @@ -352,33 +349,15 @@ class ndLav25Vehicle : public ndHeavyMultiBodyVehicle ndVehicleDectriptor::ndTireDefinition f1_tireConfiguration(m_configuration.m_frontTire); ndVehicleDectriptor::ndTireDefinition f2_tireConfiguration(m_configuration.m_frontTire); ndVehicleDectriptor::ndTireDefinition f3_tireConfiguration(m_configuration.m_frontTire); - ndBodyKinematic* const fr_tire0_body = CreateTireBody(scene, chassis, f0_tireConfiguration, "rtire_0"); - ndBodyKinematic* const fl_tire0_body = CreateTireBody(scene, chassis, f1_tireConfiguration, "ltire_0"); - ndBodyKinematic* const fr_tire1_body = CreateTireBody(scene, chassis, f2_tireConfiguration, "rtire_1"); - ndBodyKinematic* const fl_tire1_body = CreateTireBody(scene, chassis, f3_tireConfiguration, "ltire_1"); + ndSharedPtr fr_tire0_body = CreateTireBody(scene, chassis, f0_tireConfiguration, "rtire_0"); + ndSharedPtr fl_tire0_body = CreateTireBody(scene, chassis, f1_tireConfiguration, "ltire_0"); + ndSharedPtr fr_tire1_body = CreateTireBody(scene, chassis, f2_tireConfiguration, "rtire_1"); + ndSharedPtr fl_tire1_body = CreateTireBody(scene, chassis, f3_tireConfiguration, "ltire_1"); ndMultiBodyVehicleTireJoint* const fr_tire0 = AddTire(f0_tireConfiguration, fr_tire0_body); ndMultiBodyVehicleTireJoint* const fl_tire0 = AddTire(f1_tireConfiguration, fl_tire0_body); ndMultiBodyVehicleTireJoint* const fr_tire1 = AddTire(f2_tireConfiguration, fr_tire1_body); ndMultiBodyVehicleTireJoint* const fl_tire1 = AddTire(f3_tireConfiguration, fl_tire1_body); - ndSharedPtr rr_tire0_body_Ptr(rr_tire0_body); - ndSharedPtr rl_tire0_body_Ptr(rl_tire0_body); - ndSharedPtr rr_tire1_body_Ptr(rr_tire1_body); - ndSharedPtr rl_tire1_body_Ptr(rl_tire1_body); - ndSharedPtr fr_tire0_body_Ptr(fr_tire0_body); - ndSharedPtr fl_tire0_body_Ptr(fl_tire0_body); - ndSharedPtr fr_tire1_body_Ptr(fr_tire1_body); - ndSharedPtr fl_tire1_body_Ptr(fl_tire1_body); - - world->AddBody(rr_tire0_body_Ptr); - world->AddBody(rl_tire0_body_Ptr); - world->AddBody(rr_tire1_body_Ptr); - world->AddBody(rl_tire1_body_Ptr); - world->AddBody(fr_tire0_body_Ptr); - world->AddBody(fl_tire0_body_Ptr); - world->AddBody(fr_tire1_body_Ptr); - world->AddBody(fl_tire1_body_Ptr); - m_currentGear = sizeof(m_configuration.m_transmission.m_forwardRatios) / sizeof(m_configuration.m_transmission.m_forwardRatios[0]) + 1; // add the slip differential @@ -415,10 +394,10 @@ class ndLav25Vehicle : public ndHeavyMultiBodyVehicle gearBox->SetIdleOmega(m_configuration.m_engine.GetIdleRadPerSec() * dRadPerSecToRpm); // add torsion bar - ndMultiBodyVehicleTorsionBar* const torsionBar = AddTorsionBar(world->GetSentinelBody()); - torsionBar->AddAxel(rl_tire0->GetBody0(), rr_tire0->GetBody0()); - torsionBar->AddAxel(fl_tire0->GetBody0(), fr_tire0->GetBody0()); - torsionBar->SetTorsionTorque(m_configuration.m_torsionBarSpringK, m_configuration.m_torsionBarDamperC, m_configuration.m_torsionBarRegularizer); + //ndMultiBodyVehicleTorsionBar* const torsionBar = AddTorsionBar(world->GetSentinelBody()); + //torsionBar->AddAxel(rl_tire0->GetBody0(), rr_tire0->GetBody0()); + //torsionBar->AddAxel(fl_tire0->GetBody0(), fr_tire0->GetBody0()); + //torsionBar->SetTorsionTorque(m_configuration.m_torsionBarSpringK, m_configuration.m_torsionBarDamperC, m_configuration.m_torsionBarRegularizer); // add vehicle turret CreateEightWheelTurret(scene); @@ -430,19 +409,16 @@ class ndLav25Vehicle : public ndHeavyMultiBodyVehicle void CreateEightWheelTurret(ndDemoEntityManager* const scene) { //turret body - ndWorld* const world = scene->GetWorld(); ndSharedPtrturretBody (MakeChildPart(scene, m_chassis, "turret", m_configuration.m_chassisMass * 0.05f)); const ndMatrix turretMatrix(m_localFrame * turretBody->GetMatrix()); ndSharedPtr turretHinge (new ndJointHinge(turretMatrix, turretBody->GetAsBodyKinematic(), m_chassis)); - world->AddBody(turretBody); - world->AddJoint(turretHinge); + ndNode* const turretNode = AddLimb(GetRoot(), turretBody, turretHinge); //cannon body ndSharedPtrcanonBody (MakeChildPart(scene, turretBody->GetAsBodyKinematic(), "canon", m_configuration.m_chassisMass * 0.025f)); ndMatrix cannonMatrix(m_localFrame * canonBody->GetMatrix()); ndSharedPtr cannonHinge (new ndJointHinge(cannonMatrix, canonBody->GetAsBodyKinematic(), turretBody->GetAsBodyKinematic())); - world->AddBody(canonBody); - world->AddJoint(cannonHinge); + AddLimb(turretNode, canonBody, cannonHinge); // link the effector for controlling the turret ndDemoEntity* const turretEntity = (ndDemoEntity*)turretBody->GetNotifyCallback()->GetUserData(); @@ -456,25 +432,25 @@ class ndLav25Vehicle : public ndHeavyMultiBodyVehicle m_effector->EnableAxisZ(false); m_effector->EnableRotationAxis(ndIk6DofEffector::m_fixAxis); ndSharedPtr effectorPtr(m_effector); - world->AddJoint(effectorPtr); + AddCloseLoop(effectorPtr); } - void LinkTires(ndDemoEntityManager* const scene, const ndMultiBodyVehicleTireJoint* const tire0, const ndMultiBodyVehicleTireJoint* const tire1) - { - ndBodyKinematic* const body0 = tire0->GetBody0(); - ndBodyKinematic* const body1 = tire1->GetBody0(); - - ndShapeInfo rearInfo(body0->GetCollisionShape().GetShapeInfo()); - ndShapeInfo frontInfo(body1->GetCollisionShape().GetShapeInfo()); - ndFloat32 tireRatio = rearInfo.m_scale.m_y / frontInfo.m_scale.m_y; - - ndMatrix pin0(tire0->GetLocalMatrix0() * body0->GetMatrix()); - ndMatrix pin1(tire1->GetLocalMatrix0() * body1->GetMatrix()); - - ndWorld* const world = scene->GetWorld(); - ndSharedPtr link(new ndJointGear(tireRatio, pin0.m_front.Scale(-1.0f), body0, pin1.m_front, body1)); - world->AddJoint(link); - } + //void LinkTires(ndDemoEntityManager* const scene, const ndMultiBodyVehicleTireJoint* const tire0, const ndMultiBodyVehicleTireJoint* const tire1) + //{ + // ndBodyKinematic* const body0 = tire0->GetBody0(); + // ndBodyKinematic* const body1 = tire1->GetBody0(); + // + // ndShapeInfo rearInfo(body0->GetCollisionShape().GetShapeInfo()); + // ndShapeInfo frontInfo(body1->GetCollisionShape().GetShapeInfo()); + // ndFloat32 tireRatio = rearInfo.m_scale.m_y / frontInfo.m_scale.m_y; + // + // ndMatrix pin0(tire0->GetLocalMatrix0() * body0->GetMatrix()); + // ndMatrix pin1(tire1->GetLocalMatrix0() * body1->GetMatrix()); + // + // ndWorld* const world = scene->GetWorld(); + // ndSharedPtr link(new ndJointGear(tireRatio, pin0.m_front.Scale(-1.0f), body0, pin1.m_front, body1)); + // world->AddJoint(link); + //} void ApplyInputs(ndWorld* const world, ndFloat32 timestep) { @@ -522,7 +498,7 @@ class ndLav25Vehicle : public ndHeavyMultiBodyVehicle } } } -#endif + ndIk6DofEffector* m_effector; ndFloat32 m_cannonHigh; ndFloat32 m_turretAngle; @@ -538,44 +514,31 @@ class ndTractorVehicle : public ndHeavyMultiBodyVehicle ,m_armAngle(0.0f) ,m_bucketAngle(0.0f) { - ndAssert(0); - //VehicleAssembly(scene); + VehicleAssembly(scene); } -#if 0 void VehicleAssembly(ndDemoEntityManager* const scene) { // 2- each tire to the model, // this function will create the tire as a normal rigid body // and attach them to the chassis with the tire joints - ndWorld* const world = scene->GetWorld(); ndBodyKinematic* const chassis = m_chassis; ndVehicleDectriptor::ndTireDefinition r0_tireConfiguration(m_configuration.m_rearTire); ndVehicleDectriptor::ndTireDefinition r1_tireConfiguration(m_configuration.m_rearTire); - ndBodyKinematic* const rr_tire0_body = CreateTireBody(scene, chassis, r0_tireConfiguration, "rr_tire"); - ndBodyKinematic* const rl_tire0_body = CreateTireBody(scene, chassis, r1_tireConfiguration, "rl_tire"); + ndSharedPtr rr_tire0_body (CreateTireBody(scene, chassis, r0_tireConfiguration, "rr_tire")); + ndSharedPtr rl_tire0_body (CreateTireBody(scene, chassis, r1_tireConfiguration, "rl_tire")); ndMultiBodyVehicleTireJoint* const rr_tire0 = AddTire(r0_tireConfiguration, rr_tire0_body); ndMultiBodyVehicleTireJoint* const rl_tire0 = AddTire(r1_tireConfiguration, rl_tire0_body); ndVehicleDectriptor::ndTireDefinition f0_tireConfiguration(m_configuration.m_frontTire); ndVehicleDectriptor::ndTireDefinition f1_tireConfiguration(m_configuration.m_frontTire); - ndBodyKinematic* const frontAxel_body = MakeFronAxel(scene, chassis); - ndBodyKinematic* const fr_tire0_body = CreateTireBody(scene, frontAxel_body, f0_tireConfiguration, "fr_tire"); - ndBodyKinematic* const fl_tire0_body = CreateTireBody(scene, frontAxel_body, f1_tireConfiguration, "fl_tire"); + ndSharedPtr frontAxel_body (MakeFronAxel(scene, chassis)); + ndSharedPtr fr_tire0_body (CreateTireBody(scene, frontAxel_body->GetAsBodyDynamic(), f0_tireConfiguration, "fr_tire")); + ndSharedPtr fl_tire0_body (CreateTireBody(scene, frontAxel_body->GetAsBodyDynamic(), f1_tireConfiguration, "fl_tire")); ndMultiBodyVehicleTireJoint* const fr_tire0 = AddAxleTire(f0_tireConfiguration, fr_tire0_body, frontAxel_body); ndMultiBodyVehicleTireJoint* const fl_tire0 = AddAxleTire(f1_tireConfiguration, fl_tire0_body, frontAxel_body); - - ndSharedPtr rr_tire0_body_Ptr(rr_tire0_body); - ndSharedPtr rl_tire0_body_Ptr(rl_tire0_body); - ndSharedPtr fr_tire0_body_Ptr(fr_tire0_body); - ndSharedPtr fl_tire0_body_Ptr(fl_tire0_body); - - world->AddBody(rr_tire0_body_Ptr); - world->AddBody(rl_tire0_body_Ptr); - world->AddBody(fr_tire0_body_Ptr); - world->AddBody(fl_tire0_body_Ptr); m_currentGear = sizeof(m_configuration.m_transmission.m_forwardRatios) / sizeof(m_configuration.m_transmission.m_forwardRatios[0]) + 1; @@ -595,28 +558,25 @@ class ndTractorVehicle : public ndHeavyMultiBodyVehicle ndMultiBodyVehicleGearBox* const gearBox = AddGearBox(differential); gearBox->SetIdleOmega(m_configuration.m_engine.GetIdleRadPerSec() * dRadPerSecToRpm); - // add the bucket joints - CreateTractorBucket(scene); + //// add the bucket joints + //CreateTractorBucket(scene); // set a soft of hard mode SetVehicleSolverModel(m_configuration.m_useHardSolverMode ? true : false); } - ndBodyKinematic* MakeFronAxel(ndDemoEntityManager* const scene, ndBodyKinematic* const chassis) + ndSharedPtr MakeFronAxel(ndDemoEntityManager* const scene, ndBodyKinematic* const chassis) { ndSharedPtr axleBody(MakeChildPart(scene, m_chassis, "front_axel", m_configuration.m_chassisMass * 0.2f)); // connect the part to the main body with a hinge - ndWorld* const world = scene->GetWorld(); - ndMatrix hingeFrame(m_localFrame * axleBody->GetMatrix()); + const ndMatrix hingeFrame(m_localFrame * axleBody->GetMatrix()); ndJointHinge* const hinge = new ndJointHinge(hingeFrame, axleBody->GetAsBodyKinematic(), chassis); hinge->SetLimitState(true); hinge->SetLimits(-15.0f * ndDegreeToRad, 15.0f * ndDegreeToRad); ndSharedPtr hingePtr(hinge); - - world->AddBody(axleBody); - world->AddJoint(hingePtr); - return axleBody->GetAsBodyKinematic(); + AddLimb(GetRoot(), axleBody, hingePtr); + return axleBody; } void AddHydraulic(ndDemoEntityManager* const scene, ndBodyKinematic* const parentBody, const char* const name0, const char* const name1, ndBodyKinematic* const attachmentBody, const char* const attachement) @@ -718,7 +678,6 @@ class ndTractorVehicle : public ndHeavyMultiBodyVehicle } } } -#endif ndJointHinge* m_armHinge; ndJointHinge* m_bucketHinge; @@ -845,20 +804,20 @@ void ndHeavyVehicle (ndDemoEntityManager* const scene) ndSharedPtr vehicleUIPtr(vehicleUI); scene->Set2DDisplayRenderFunction(vehicleUIPtr); - ndSharedPtr vehicle0(new ndBigRigVehicle(scene, bigRigDesc, matrix, vehicleUI)); + //ndSharedPtr vehicle0(new ndBigRigVehicle(scene, bigRigDesc, matrix, vehicleUI)); matrix.m_posit.m_x += 6.0f; matrix.m_posit.m_z += 6.0f; //ndSharedPtr vehicle1(new ndLav25Vehicle(scene, lav25Desc, matrix, vehicleUI)); matrix.m_posit.m_z -= 12.0f; - //ndSharedPtr vehicle2(new ndTractorVehicle(scene, tractorDesc, matrix, vehicleUI)); + ndSharedPtr vehicle2(new ndTractorVehicle(scene, tractorDesc, matrix, vehicleUI)); - world->AddModel(vehicle0); + //world->AddModel(vehicle0); //world->AddModel(vehicle1); - //world->AddModel(vehicle2); + world->AddModel(vehicle2); - ndHeavyMultiBodyVehicle* const vehicle = (ndHeavyMultiBodyVehicle*)*vehicle0; + ndHeavyMultiBodyVehicle* const vehicle = (ndHeavyMultiBodyVehicle*)*vehicle2; vehicle->SetAsPlayer(scene); matrix.m_posit.m_x += 25.0f; diff --git a/newton-4.00/applications/ndSandbox/toolbox/ndPngToOpenGl.cpp b/newton-4.00/applications/ndSandbox/toolbox/ndPngToOpenGl.cpp index f1cc605bd..295370277 100644 --- a/newton-4.00/applications/ndSandbox/toolbox/ndPngToOpenGl.cpp +++ b/newton-4.00/applications/ndSandbox/toolbox/ndPngToOpenGl.cpp @@ -181,6 +181,11 @@ GLuint LoadTexture(const char* const filename) char pngName[1024]; char fullPathName[2048]; + if (!strlen(filename)) + { + return 0; + } + snprintf(pngName, sizeof (pngName), "%s", filename); strtolwr(pngName); char* const fileNameEnd = strstr(pngName, ".tga"); diff --git a/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.cpp b/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.cpp index bf6883b66..37c31b288 100644 --- a/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.cpp +++ b/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.cpp @@ -96,32 +96,6 @@ ndMultiBodyVehicle* ndMultiBodyVehicle::GetAsMultiBodyVehicle() } -ndMultiBodyVehicleTireJoint* ndMultiBodyVehicle::AddAxleTire(const ndMultiBodyVehicleTireJointInfo&, ndBodyKinematic* const, ndBodyKinematic* const) -{ - ndAssert(0); - return nullptr; - //ndMatrix tireFrame(ndGetIdentityMatrix()); - //tireFrame.m_front = ndVector(0.0f, 0.0f, 1.0f, 0.0f); - //tireFrame.m_up = ndVector(0.0f, 1.0f, 0.0f, 0.0f); - //tireFrame.m_right = ndVector(-1.0f, 0.0f, 0.0f, 0.0f); - //ndMatrix matrix(tireFrame * m_localFrame * axleBody->GetMatrix()); - //matrix.m_posit = tire->GetMatrix().m_posit; - // - //// make tire inertia spherical - //ndVector inertia(tire->GetMassMatrix()); - //ndFloat32 maxInertia(ndMax(ndMax(inertia.m_x, inertia.m_y), inertia.m_z)); - //inertia.m_x = maxInertia; - //inertia.m_y = maxInertia; - //inertia.m_z = maxInertia; - //tire->SetMassMatrix(inertia); - // - //ndSharedPtr tireJoint (new ndMultiBodyVehicleTireJoint(matrix, tire, axleBody, desc, this)); - ////ndSharedPtr& xxxx = (ndSharedPtr&)tireJointPtr; - //m_tireList.Append(tireJoint); - // - //tire->SetDebugMaxLinearAndAngularIntegrationStep(ndFloat32(2.0f * 360.0f) * ndDegreeToRad, ndFloat32(10.0f)); - //return *tireJoint; -} //ndMultiBodyVehicleTorsionBar* ndMultiBodyVehicle::AddTorsionBar(ndBodyKinematic* const sentinel) ndMultiBodyVehicleTorsionBar* ndMultiBodyVehicle::AddTorsionBar(ndBodyKinematic* const) @@ -371,8 +345,6 @@ void ndMultiBodyVehicle::SetVehicleSolverModel(bool hardJoint) ndMultiBodyVehicleTireJoint* ndMultiBodyVehicle::AddTire(const ndMultiBodyVehicleTireJointInfo& desc, const ndSharedPtr& tire) { ndAssert(m_chassis); - //return AddAxleTire(desc, tire, m_chassis); - ndMatrix tireFrame(ndGetIdentityMatrix()); tireFrame.m_front = ndVector(0.0f, 0.0f, 1.0f, 0.0f); tireFrame.m_up = ndVector(0.0f, 1.0f, 0.0f, 0.0f); @@ -398,6 +370,38 @@ ndMultiBodyVehicleTireJoint* ndMultiBodyVehicle::AddTire(const ndMultiBodyVehicl return m_tireList.GetLast()->GetInfo(); } +ndMultiBodyVehicleTireJoint* ndMultiBodyVehicle::AddAxleTire(const ndMultiBodyVehicleTireJointInfo& desc, const ndSharedPtr& tire, const ndSharedPtr& axleBody) +{ + ndAssert(m_chassis); + + ndMatrix tireFrame(ndGetIdentityMatrix()); + tireFrame.m_front = ndVector(0.0f, 0.0f, 1.0f, 0.0f); + tireFrame.m_up = ndVector(0.0f, 1.0f, 0.0f, 0.0f); + tireFrame.m_right = ndVector(-1.0f, 0.0f, 0.0f, 0.0f); + ndMatrix matrix(tireFrame * m_localFrame * axleBody->GetMatrix()); + matrix.m_posit = tire->GetMatrix().m_posit; + + ndBodyDynamic* const tireBody = tire->GetAsBodyDynamic(); + // make tire inertia spherical + ndVector inertia(tireBody->GetMassMatrix()); + ndFloat32 maxInertia(ndMax(ndMax(inertia.m_x, inertia.m_y), inertia.m_z)); + inertia.m_x = maxInertia; + inertia.m_y = maxInertia; + inertia.m_z = maxInertia; + tireBody->SetMassMatrix(inertia); + + //ndSharedPtr tireJoint (new ndMultiBodyVehicleTireJoint(matrix, tire, axleBody, desc, this)); + ndSharedPtr tireJoint(new ndMultiBodyVehicleTireJoint(matrix, tireBody, axleBody->GetAsBodyDynamic(), desc, this)); + m_tireList.Append((ndMultiBodyVehicleTireJoint*)*tireJoint); + ndNode* const parentNode = FindByBody(*axleBody); + ndAssert(parentNode); + AddLimb(parentNode, tire, tireJoint); + + tireBody->SetDebugMaxLinearAndAngularIntegrationStep(ndFloat32(2.0f * 360.0f) * ndDegreeToRad, ndFloat32(10.0f)); + return m_tireList.GetLast()->GetInfo(); +} + + ndShapeInstance ndMultiBodyVehicle::CreateTireShape(ndFloat32 radius, ndFloat32 width) const { ndShapeInstance tireCollision(m_tireShape); diff --git a/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.h b/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.h index c55adc7d2..3f394d615 100644 --- a/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.h +++ b/newton-4.00/sdk/dNewton/dModels/dVehicle/ndMultiBodyVehicle.h @@ -87,6 +87,7 @@ class ndMultiBodyVehicle : public ndModelArticulation D_NEWTON_API ndShapeInstance CreateTireShape(ndFloat32 radius, ndFloat32 width) const; D_NEWTON_API ndMultiBodyVehicleGearBox* AddGearBox(ndMultiBodyVehicleDifferential* const differential); D_NEWTON_API ndMultiBodyVehicleTireJoint* AddTire(const ndMultiBodyVehicleTireJointInfo& desc, const ndSharedPtr& tire); + D_NEWTON_API ndMultiBodyVehicleTireJoint* AddAxleTire(const ndMultiBodyVehicleTireJointInfo& desc, const ndSharedPtr& tire, const ndSharedPtr& axleBody); D_NEWTON_API ndMultiBodyVehicleDifferential* AddDifferential(ndFloat32 mass, ndFloat32 radius, ndMultiBodyVehicleTireJoint* const leftTire, ndMultiBodyVehicleTireJoint* const rightTire, ndFloat32 slipOmegaLock); D_NEWTON_API ndMultiBodyVehicleDifferential* AddDifferential(ndFloat32 mass, ndFloat32 radius, ndMultiBodyVehicleDifferential* const leftDifferential, ndMultiBodyVehicleDifferential* const rightDifferential, ndFloat32 slipOmegaLock); @@ -95,7 +96,6 @@ class ndMultiBodyVehicle : public ndModelArticulation D_NEWTON_API virtual void PostUpdate(ndWorld* const world, ndFloat32 timestep); #if 0 - D_NEWTON_API ndMultiBodyVehicleTireJoint* AddAxleTire(const ndMultiBodyVehicleTireJointInfo& desc, ndBodyKinematic* const tire, ndBodyKinematic* const axleBody); D_NEWTON_API ndMultiBodyVehicleTorsionBar* AddTorsionBar(ndBodyKinematic* const sentinel); D_NEWTON_API ndMultiBodyVehicle* GetAsMultiBodyVehicle(); diff --git a/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.cpp b/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.cpp index a31e2e997..c1385a809 100644 --- a/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.cpp +++ b/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.cpp @@ -322,6 +322,19 @@ void ndModelArticulation::AddToWorld(ndWorld* const world) world->AddModel(this); } +ndModelArticulation::ndNode* ndModelArticulation::FindByBody(const ndBody* const body) const +{ + for (ndModelArticulation::ndNode* node = m_rootNode->GetFirstIterator(); node; node = node->GetNextIterator()) + { + if (*node->m_body == body) + { + return node; + } + } + + return nullptr; +} + ndModelArticulation::ndNode* ndModelArticulation::FindByName(const char* const name) const { for (ndModelArticulation::ndNode* node = m_rootNode->GetFirstIterator(); node; node = node->GetNextIterator()) diff --git a/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.h b/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.h index e68133923..7b79823a1 100644 --- a/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.h +++ b/newton-4.00/sdk/dNewton/dModels/ndModelArticulation.h @@ -63,6 +63,7 @@ class ndModelArticulation: public ndModel D_NEWTON_API const ndString& GetName() const; D_NEWTON_API void SetName(const ndString& name); D_NEWTON_API ndNode* FindByName(const char* const name) const; + D_NEWTON_API ndNode* FindByBody(const ndBody* const body) const; D_NEWTON_API ndNode* FindLoopByName(const char* const name) const; D_NEWTON_API void ClearMemory();