Skip to content

Commit

Permalink
re enabled vehicle selector simple system
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJerez committed Jan 5, 2025
1 parent 554d2d3 commit ef60d33
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 47 deletions.
92 changes: 56 additions & 36 deletions newton-4.00/applications/ndSandbox/toolbox/ndVehicleCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ ndVehicleEntityNotify::~ndVehicleEntityNotify()
{
}

//***************************************************************************************************
//
//
//***************************************************************************************************
ndVehicleDectriptor::ndEngineTorqueCurve::ndEngineTorqueCurve()
{
// take from the data sheet of a 2005 dodge viper,
Expand Down Expand Up @@ -209,57 +213,73 @@ ndVehicleDectriptor::ndVehicleDectriptor(const char* const fileName)
m_useHardSolverMode = true;
}

//***************************************************************************************************
//
//
//***************************************************************************************************
ndVehicleSelector::ndVehicleSelector()
:ndModel()
,m_changeVehicle()
{
}

void ndVehicleSelector::SelectNext(ndWorld* const world)
{
ndDemoEntityManager* const scene = ((ndPhysicsWorld*)world)->GetManager();
const ndModelList& modelList = world->GetModelList();

//ndInt32 vehiclesCount = 0;
ndFixSizeArray<ndMultiBodyVehicle*, 1024> vehicleArray;
for (ndModelList::ndNode* node = modelList.GetFirst(); node; node = node->GetNext())
class ndVehicleSelectorNotify : public ndModelNotify
{
ndModel* const model = *node->GetInfo();
if (model->GetAsMultiBodyVehicle())
public:
ndVehicleSelectorNotify(ndVehicleSelector* const model)
:ndModelNotify()
,m_changeVehicle()
{
vehicleArray.PushBack((ndMultiBodyVehicle*)model->GetAsMultiBodyVehicle());
SetModel(model);
}
}

if (vehicleArray.GetCount() > 1)
{
for (ndInt32 i = 0; i < vehicleArray.GetCount(); ++i)
void SelectNext(ndWorld* const world)
{
ndVehicleCommonNotify* const notify = (ndVehicleCommonNotify*)*vehicleArray[i]->GetNotifyCallback();
if (notify->m_isPlayer)
ndDemoEntityManager* const scene = ((ndPhysicsWorld*)world)->GetManager();
const ndModelList& modelList = world->GetModelList();

ndFixSizeArray<ndMultiBodyVehicle*, 1024> vehicleArray;
for (ndModelList::ndNode* node = modelList.GetFirst(); node; node = node->GetNext())
{
ndVehicleCommonNotify* const nextNotify = (ndVehicleCommonNotify*)*vehicleArray[(i + 1) % vehicleArray.GetCount()]->GetNotifyCallback();
notify->SetAsPlayer(scene, false);
nextNotify->SetAsPlayer(scene, true);
break;
ndModel* const model = *node->GetInfo();
if (model->GetAsMultiBodyVehicle())
{
vehicleArray.PushBack((ndMultiBodyVehicle*)model->GetAsMultiBodyVehicle());
}
}

for (ndInt32 i = 0; i < vehicleArray.GetCount(); ++i)
{
ndVehicleCommonNotify* const notify = (ndVehicleCommonNotify*)*vehicleArray[i]->GetNotifyCallback();
if (notify->m_isPlayer)
{
ndVehicleCommonNotify* const nextNotify = (ndVehicleCommonNotify*)*vehicleArray[(i + 1) % vehicleArray.GetCount()]->GetNotifyCallback();
notify->SetAsPlayer(scene, false);
nextNotify->SetAsPlayer(scene, true);
break;
}
}
}
}
}

void ndVehicleSelector::PostUpdate(ndWorld* const world, ndFloat32)
{
ndDemoEntityManager* const scene = ((ndPhysicsWorld*)world)->GetManager();
void PostUpdate(ndWorld* const world, ndFloat32) override
{
ndDemoEntityManager* const scene = ((ndPhysicsWorld*)world)->GetManager();

ndGameControllerInputs inputs;
inputs.Update(scene);

if (m_changeVehicle.Update(inputs.m_buttons[ndVehicleCommonNotify::m_playerButton] ? true : false))
{
SelectNext(world);
}
ndGameControllerInputs inputs;
inputs.Update(scene);
if (m_changeVehicle.Update(inputs.m_buttons[ndVehicleCommonNotify::m_playerButton] ? true : false))
{
SelectNext(world);
}
}

ndDemoEntityManager::ndKeyTrigger m_changeVehicle;
};

SetNotifyCallback(ndSharedPtr<ndModelNotify>(new ndVehicleSelectorNotify(this)));
}

//***************************************************************************************************
//
//
//***************************************************************************************************
ndVehicleMaterial::ndVehicleMaterial()
:ndApplicationMaterial()
{
Expand Down
12 changes: 1 addition & 11 deletions newton-4.00/applications/ndSandbox/toolbox/ndVehicleCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,7 @@ class ndVehicleSelector : public ndModel
{
public:
D_CLASS_REFLECTION(ndVehicleSelector, ndModel)
ndVehicleSelector();

virtual void OnAddToWorld() {}
virtual void OnRemoveFromToWorld() {}

void Update(ndWorld* const, ndFloat32) {}
void PostUpdate(ndWorld* const world, ndFloat32);

void SelectNext(ndWorld* const world);

ndDemoEntityManager::ndKeyTrigger m_changeVehicle;
ndVehicleSelector();
};

class ndVehicleEntityNotify : public ndDemoEntityNotify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ const ndList<ndMultiBodyVehicleTireJoint*>& ndMultiBodyVehicle::GetTireList() co
return m_tireList;
}

ndMultiBodyVehicle* ndMultiBodyVehicle::GetAsMultiBodyVehicle()
{
return this;
}

ndFloat32 ndMultiBodyVehicle::GetSpeed() const
{
const ndVector dir(m_chassis->GetMatrix().RotateVector(m_localFrame.m_front));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ndMultiBodyVehicle : public ndModelArticulation
D_NEWTON_API ndBodyDynamic* GetChassis() const;
D_NEWTON_API ndMultiBodyVehicleMotor* GetMotor() const;
D_NEWTON_API ndMultiBodyVehicleGearBox* GetGearBox() const;
D_NEWTON_API ndMultiBodyVehicle* GetAsMultiBodyVehicle();
D_NEWTON_API const ndList<ndMultiBodyVehicleTireJoint*>& GetTireList() const;

D_NEWTON_API bool IsSleeping() const;
Expand Down

0 comments on commit ef60d33

Please sign in to comment.