A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by JulBaxter » Wed Mar 10, 2010 7:15 am
My program simulate a basic body with a ConstraintUpVector "walking" on a floor. When I replace the join by a CustomPlayerController the program crashes.
I use the lastest version of NewtonSDK (2.18) and I've based my work on NewtonTutorials.
I use Newton.dll and JointLibrary.dll
Execution stack:
NewtonUpdate(717) in newton.cpp
Newton::UpdatePhysics(98) in newtonclass.cpp
dgWorld::Update(694) in dgworld.cpp
dgWorldDynamicUpdate::UpdateDynamics(208) in dgworlddynamicupdate.cpp
dgSolverWorlkerThreads::ThreadExecute(328) in dgworlddynamicupdate.cpp
NewtonWorldConvexCast(1340) in newton.cpp
dgBroadPhaseCollision::ConvexCast(596) in dgbroadphasecollision.cpp
What kind of mistake I've done ?
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
by Julio Jerez » Wed Mar 10, 2010 8:05 am
I do not know what mistake you made, do you have a test?
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JulBaxter » Wed Mar 10, 2010 9:29 am
What do you mean by test ?
Here, you can see the creation code part:
- Code: Select all
if( CharacterController->Transformation )
{
dFloat OffsetMatrix[16];
NePhysicDevice::ConvertCgMatrixToNeMatrix( TMatrix44<>(), OffsetMatrix );
SPtr<CgBoxMesh> Mesh = CONSTRUCT( BoxMesh );
Mesh->Bake();
NewtonCollision* Collision = NewtonCreateConvexHull( World, Mesh->VertexBuffer->VertexCount, (FLOAT*)Mesh->VertexBuffer->GetPositions().GetData(), 3*sizeof(FLOAT), 0.1f, 0, NULL );
NewtonBody *Body = NewtonCreateBody( World, Collision );
NewtonBodySetMaterialGroupID( Body, ControllerGroupID );
NewtonBodySetUserData( Body, CharacterController );
NewtonBodySetMatrix( Body, OffsetMatrix );
FLOAT Mass = 3 * NewtonConvexCollisionCalculateVolume( Collision );
FLOAT Inertia[3], Origin[3];
NewtonConvexCollisionCalculateInertialMatrix( Collision, Inertia, Origin );
NewtonBodySetMassMatrix( Body, Mass, Mass * Inertia[0], Mass * Inertia[1], Mass * Inertia[2] );
NewtonBodySetCentreOfMass( Body, Origin );
NewtonBodySetForceAndTorqueCallback( Body, GlobalNePhysicDevice.ApplyForceAndTorqueCallback );
NewtonBodySetTransformCallback( Body, GlobalNePhysicDevice.SetTransformCallback );
NewtonBodySetAutoSleep( Body, 0 );
NewtonUserJoint *UserJoint = CreateCustomPlayerController( OffsetMatrix, Body, 1.f, 1.f / 64.f );
CustomSetUserData( UserJoint, CharacterController );
CustomSetSubmitContraintCallback( UserJoint, GlobalNePhysicDevice.SubmitContraintCallback );
ControllerMap.Add( NeControllerPair( CharacterController, Body ) );
NewtonReleaseCollision( World, Collision );
}
The body without CreateCustomPlayerController part works well.
The program crashes even if callbacks are empty
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
by Julio Jerez » Wed Mar 10, 2010 10:18 am
I cannot test that code fragment, there is stuff that will not compile.
Setting the player join is quiet ease, here is the base setup code take form the base 2.00 tutorual in the wiki.
http://www.newtondynamics.com/downloads ... torials.ra - Code: Select all
// Create a Body and attach a player controller joint
{
dFloat y0;
Entity* player;
NewtonBody* playerBody;
NewtonCollision* shape;
// find the a floor to place the player
y0 = FindFloor (world, 0.0f, 0.0f) + 1.0f;
// load the player mesh
player = sceneManager->CreateEntity();
player->LoadMesh ("gymnast.dat");
player->m_curPosition.m_y = y0;
player->m_prevPosition = player->m_curPosition;
// get the bounding Box of the player to get the collision shape dimensions
dVector minBox;
dVector maxBox;
player->GetBBox (minBox, maxBox);
// calculate player high and width
dFloat padding = 1.0f / 64.0f; // this si the default padding, for teh palye joint, we must subtract it from the shape
dFloat playerHigh = (maxBox.m_y - minBox.m_y) - padding;
dFloat playerRadius0 = (maxBox.m_z - minBox.m_z) * 0.5f;
dFloat playerRadius1 = (maxBox.m_x - minBox.m_x) * 0.5f;
dFloat playerRadius = (playerRadius0 > playerRadius1 ? playerRadius0 : playerRadius1) - padding;
// No we make and make a upright capsule for the collision mesh
dMatrix orientation;
orientation.m_front = dVector (0.0f, 1.0f, 0.0f, 0.0f); // this is the player up direction
orientation.m_up = dVector (1.0f, 0.0f, 0.0f, 0.0f); // this is the player front direction
orientation.m_right = orientation.m_front * orientation.m_up; // this is the player sideway direction
orientation.m_posit = dVector (0.0f, 0.0f, 0.0f, 1.0f);
// add a body with a box shape
//shape = CreateNewtonCapsule (world, player, playerHigh, playerRadius, m_wood, orientation);
shape = CreateNewtonCylinder (world, player, playerHigh, playerRadius, m_wood, orientation);
playerBody = CreateRigidBody (world, player, shape, 10.0f);
NewtonReleaseCollision (world, shape);
// make sure the player does not go to sleep
NewtonBodySetAutoSleep (playerBody, 0);
// now we will attach a player controller to the body
NewtonUserJoint* playerController;
// the player can take step up to 0.7 units;
dFloat maxStairStepFactor = 0.7f / playerHigh;
playerController = CreateCustomPlayerController (&orientation[0][0], playerBody, maxStairStepFactor, padding);
// set the Max Slope the player can climb to PLAYER_MAX_SLOPE degree
CustomPlayerControllerSetMaxSlope (playerController, PLAYER_MAX_SLOPE * 3.1416f / 180.0f);
// now we will append some application data for the application to control the player
PlayerController* userControl = (PlayerController*) malloc (sizeof (PlayerController));
userControl->m_isThirdView = 1;
userControl->m_point = dVector (0.0f, playerHigh, 0.0f,0.0f);
// set the user data for the application to control the player
CustomSetUserData (playerController, userControl);
// set the destruction call back so that the application can destroy local used data
CustomSetDestructorCallback (playerController, PlayerController::Destroy);
// set a call back to control the player
CustomSetSubmitContraintCallback (playerController, PlayerController::ApplyPlayerInput);
// we also need to set override the transform call back so the we can set the Camera
userControl->m_setTransformOriginal = NewtonBodyGetTransformCallback(playerBody);
NewtonBodySetTransformCallback (playerBody, PlayerController::SetTransform);
// we will need some ID to fin this joint in the transform Callback
CustomSetJointID (playerController, PLAYER_JOINT_ID);
}
You can take the code fragment, past in you code and make it work with your system of data structures.
Also you can download the tutorial and see how it works, in each toturial relevant code is in file
TutorialCode.cpp
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JulBaxter » Wed Mar 10, 2010 11:53 am
I think I've found the "mistake". Application crash when CreateCustomPlayerController is called with 1.f for maxStairStepFactor parameter.
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
by Julio Jerez » Wed Mar 10, 2010 2:15 pm
that sound right maxStairStepFactor is a factor of the player height, making it 1.0 means 100% witch has not meaning.
I also suggest you check the axis.
check the demo to to see the debug display that shows how the auxialiry shapes used for collsion are used.
do you have it working?
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JulBaxter » Wed Mar 10, 2010 2:26 pm
Okay, thank you for your reply. Yes it's working now.
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
by JulBaxter » Fri Mar 12, 2010 2:19 pm
The CharacterController have a nice behavior on plane surface or against vertical wall. But when the environment become more chaotic ( slope, crater, hole, etc ), it begin jittering. Worse, when it is in a cave, it can be teleport outside.
I know perfection doesn't exist with character controller, but is there something i can do to imrove this( settings, parameter, etc... ) without attemp to do my own controller ?
It is a known behavior which is planned to improve during this next month ?
Your answer would help me to make choices and plans for my game developpement.
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
by Julio Jerez » Fri Mar 12, 2010 2:23 pm
It should be smooth as silk, zero jitter in all terrains.
I have not test it in many terrain, just the geometries in the SDK (a small level and a simple Hightdfield Terrain).
Do you have a test sampel I can try it and see what it is?
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Mon Mar 15, 2010 9:50 am
My guess is the you have something wrong on teh set up because teh player should be totally smooth on ramps.
I would like to take a look at it and fix it if I can but it is very difficult to debug at video.
can you send me a test demo tha I can try?
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Tue Mar 16, 2010 1:16 pm
if you are still intertested. id you get read teh last post.
I'd like to see what it is that make the player jiter like that, but without a test it is very hard.
when I set it up I kknow how to do it and I do not get those errors, so for me to check this I need a test.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JulBaxter » Fri Mar 19, 2010 1:31 pm
Thank you for your assistance but now i work on MaterialContact and I have no more charactercontroller test.
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 0 guests