Ypo do not call then they are all callbacks, you just overload then and the engine call then for you
This would be a minimal Controll manager class (copy for the sand box demo
- Code: Select all
class BasicPlayerControllerManager: public CustomPlayerControllerManager
{
public:
BasicPlayerControllerManager (NewtonWorld* const world)
~BasicPlayerControllerManager ();
void PlayerInputs (const CustomPlayerController* const controller, dFloat timestep);
// apply gravity
virtual void ApplyPlayerMove (CustomPlayerController* const controller, dFloat timestep);
virtual int ProcessContacts (const CustomPlayerController* const controller, NewtonWorldConvexCastReturnInfo* const contacts, int count) const;
void PostUpdate (dFloat timestep);
}
In your code when you call this BasicPlayerControllerManager* const manager = new BasicPlayerControllerManager (world);
this will create and register the controller with the engine.
and you call CeatePlayer as many time as you want.
you can overload the function void PostUpdate (dFloat timestep) for example for doing Camera update or
- Code: Select all
BasicPlayerControllerManager::PostUpdate (dFloat timestep)
{
CustomPlayerControllerManager::PostUpdate(timestep);
// do special code here. usaully I keep track o fteh camera here, by you can do anything
// for example yopu can do you path finding for all player before you call Past Update
}
the call to CustomPlayerControllerManager::PostUpdate(timestep);
will call ApplyPlayerMove for each player that you was Created.
you must overload that function if you want to move your player around
In te hoverloaded funtion after you determine the speed, the heading, the gravity for that player, you most call SetPlayerVelocity
your function soudl look like this:
- Code: Select all
virtual void ApplyPlayerMove (CustomPlayerController* const controller, dFloat timestep)
{
NewtonBody* const body = controller->GetBody();
// calculate desired linear and angular velocity form the input
dVector gravity (0.0f, DEMO_GRAVITY, 0.0f, 0.0f);
float speed = GameEntineGetSpeed (body);
float stafeSpeed = GameEntineGetStafeSpeed (body);
float jumpSpeed = GameEntineGetStafeSpeed (body);
float headingAngle = GameEntineGetHeading (body);
// set player linear and angular velocity
controller->SetPlayerVelocity (speed, strafeSpeed, jumpSpeed, headinAngle, gravity, timestep);
}
and that should do it. The engine pipe line is like this
-Apply Force and torque
-Call PreUpdate Callbackj for all Prelistener in order
-Update Bradphase
-Calculate Contact for each collidng Pairs
-Generates new ConatactJoints
-Delete old Contac Joints
-Determine Jonts Conectivity Sapwn Trees
-Calculate Joint Reaction forces.
-Apply all external and internal Joint reaction Forces and Integrate each free body to get new velocites
-Integrate velocityes to calculate new Position and orientation for each dynamics body
-Call PostUpdate Callback for all Postlistener in order
the Player controller is updated after all dynamic bodies are updated, therfore it can resulve all penetrations and object movemenet, because basicailly works on a static world
This is what makes it very different that the other controller in core 200 where it was resulve at Joint Resulution force calculations, so the player location was never accurate, because integration happen after that step.