Problem with the playerController

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Problem with the playerController

Postby FSA » Wed Nov 07, 2012 2:29 pm

Hi. I use the player controller from Newton 2.33(CustomPlayerController). When I walk into an object, the playershape walk's upwards on the Object(take a look at the video). How can I solve this? Is this alreadey solved in the actual Playercontroller from SVN?
Video: https://www.dropbox.com/s/0evgjdre7kd9we5/Record.avi
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby Julio Jerez » Wed Nov 07, 2012 4:09 pm

you need to move to newton core 300. The player controller is much improved.
Download the SDKL and run the test see if it is what you look for.

migration from core 200 to core 300 is eassy, and worth doing it.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby FSA » Wed Nov 07, 2012 4:27 pm

I only must change from core200 to core300? I thougt the player controller is in joint libary.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby Julio Jerez » Wed Nov 07, 2012 5:00 pm

The controller is in the Joint library, but it uses features that are new for core 300
like Kinematic body and Pre and post listeners.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby FSA » Thu Nov 08, 2012 6:01 am

OK I'll give it a try. What is the most important i must looking for?
And another qusteion: Whats the diffrent between Kinematic and dynamic bodys?
Yeah I know I'm not the best for understanding newton :P
Thank alot.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby FSA » Thu Nov 08, 2012 6:25 am

Is NewtonDestroyCollision the same as NewtonReleaseCollision?
And wich function has overwrite NewtonSetWorldSize?
Tank alot ;)
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby Julio Jerez » Thu Nov 08, 2012 8:35 am

"Is NewtonDestroyCollision the same as NewtonReleaseCollision?"
NewtonDestroyCollision yes, but now collsion are instance objects, not refrenced counted objects, this mean that each newton body meaks it own copy of teh collsion that is use to make the body.
you tthe collision yo uuse to crate teh body if you crtaed just to make that body. an dthen use NewtonGetCollission fi yo uwna to get a refrence to teh collsion of a body .

"And wich function has overwrite NewtonSetWorldSize?" In core 300 worlds are open size. no limit

Kinematic body are bodies that do not interat with dynamics bodies, but they do everything else. They are good for triggers and Gameplay objects
the new the Play Controller is a kinamatic body, and later the soft body Soft bodies and cloth are also going to be be kinematic bodies.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby FSA » Thu Nov 08, 2012 8:53 am

Thank you for the explanation! Now I will make a working program with the new PlayerController(manager now named?). I use the BasicPlayerController.cpp file from the demosSandbox.exe. Right one?
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby Julio Jerez » Thu Nov 08, 2012 10:24 am

yes you cna use that sample class BasicPlayerController.cpp and your start up point.

then you can added or removed the functionality you want to your manager, and you your controller.
that one is very basic.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby FSA » Thu Nov 08, 2012 12:47 pm

Sorry Julio i dont understand your code :lol:
Where I must call Pre/Post-Update? Can you wirte a very simple example right here, how tu use the controller/manager on the basis from BasicPlayerController.cpp without any entitys?
Like:
Code: Select all
CreateController(...)

// In Update
PreUpdate(...)
// ...
PostUpdate(...)


Sorry but I really dont get that ;)
If you can make that, I will be *very* happy :)
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby Julio Jerez » Thu Nov 08, 2012 1:16 pm

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.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby FSA » Thu Nov 08, 2012 1:56 pm

WOW Thank you!
Also a big change is that i must not create a NewotnBody by my self? If so then I get it! :D
What would I do without you... :P
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby Julio Jerez » Thu Nov 08, 2012 2:49 pm

No you do not have to create a NetwonBody you simple call

Code: Select all
      dMatrix playerAxis;
      playerAxis[0] = dVector (0.0f, 1.0f, 0.0f, 0.0f); // the y axis is the character up vector
      playerAxis[1] = dVector (1.0f, 0.0f, 0.0f, 0.0f); // the x axis is the character front direction
      playerAxis[2] = playerAxis[0] * playerAxis[1];
      playerAxis[3] = dVector (0.0f, 0.0f, 0.0f, 1.0f);
CustomPlayerControllerManager::CustomController* controller = manager->CreatePlayer(radius, radius * 0.5f, height, height * 0.33f, playerAxis);

      // get body from player, and set some parameter
      NewtonBody* const body = m_controller->GetBody();

      // set the user data
      NewtonBodySetUserData(body, this);

      // set the transform callback
      NewtonBodySetTransformCallback (body, DemoEntity::TransformCallback);

      // set the player matrix
      NewtonBodySetMatrix(body, &location[0][0]);


And the you get the body that the manger create for you.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby FSA » Fri Nov 09, 2012 2:07 pm

OK. I have made it like you said. It compiles good, but it doesn't link...
I get 2 Errors:

unresolved external symbol ""private: static class dRtti CustomControllerBase::m_rtti" (?m_rtti@CustomControllerBase@@0VdRtti@@A)".

reference at unresolved external symbol ""public: void __thiscall CustomPlayerController::SetPlayerVelocity(float,float,float,float,class dVector const &,float)" (?SetPlayerVelocity@CustomPlayerController@@QAEXMMMMABVdVector@@M@Z)" in function ""public: virtual void __thiscall BasicPlayerControllerManager::ApplyPlayerMove(class CustomPlayerController * const,float)" (?ApplyPlayerMove@BasicPlayerControllerManager@@UAEXQAVCustomPlayerController@@M@Z)".

I've build newton core 300, dJointLibary well and link newton_d.lib and dJointLibary_d.lib.

Whats wrong?
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Problem with the playerController

Postby Julio Jerez » Fri Nov 09, 2012 3:08 pm

m_rtti is declared in the DContainer library, did you link to that library?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest