A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Alessan » Fri Aug 01, 2014 1:28 pm
Hi,
I'm having some problems with player controller when is over a scaled DynamicBody. If the floor(Dynamic Body of mass 0) is not scaled all works fine but if the floor is scaled then player controller ground plane detection not work correctly, m_isJumping in CustomPlayerControler is always true and position is not stable.
I'm using last svn (2014/07/14)
I put an example:
- Code: Select all
/*
* File: main.cpp
* Author: main
*
* Created on 24 de julio de 2014, 21:17
*/
//-----------------------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include "newton/dNewton/dNewton.h"
#include "newton/dNewton/dNewtonDynamicBody.h"
#include "newton/dNewton/dNewtonCollision.h"
#include "newton/dNewton/dNewtonPlayerManager.h"
//-----------------------------------------------------------------------------
using namespace std;
//-----------------------------------------------------------------------------
class MyDynamicBody: public dNewtonDynamicBody
{
public:
MyDynamicBody(dNewton* const world, dFloat mass,
const dNewtonCollision* const collision, void* const userData,
const dMatrix& matrix)
:dNewtonDynamicBody (world, mass, collision, userData, &matrix[0][0], NULL)
{
}
// the end application need to overload this function from dNetwonBody
void OnBodyTransform (const dFloat* const matrix, int threadIndex)
{
Update (matrix);
}
// the end application need to overload this function from dNetwonDynamicBody
void OnForceAndTorque (dFloat timestep, int threadIndex)
{
// apply gravity force to the body
dFloat mass;
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
GetMassAndInertia (mass, Ixx, Iyy, Izz);
dVector gravityForce (0.0f, -9.8f * mass, 0.0f);
SetForce (&gravityForce[0]);
}
};
//-----------------------------------------------------------------------------
class MyPlayer : public dNewtonPlayerManager::dNewtonPlayer
{
public:
MyPlayer(dNewtonPlayerManager* const manager, void* const userData, dFloat mass,
dFloat outerRadius, dFloat innerRadius, dFloat height, dFloat stairStep,
const dFloat* const upDir, const dFloat* const frontDir, dLong collisionMask)
: dNewtonPlayer(manager, userData, mass, outerRadius, innerRadius,
height, stairStep, upDir, frontDir, collisionMask)
{
}
~MyPlayer()
{
}
void OnPlayerMove (dFloat timestep)
{
dVector gravity(0, -9.81, 0);
SetPlayerVelocity (0.0f, 0.0f, 0.0f, 0.0f, &gravity[0], timestep);
}
};
//-----------------------------------------------------------------------------
int main(int argc, char** argv)
{
dNewton* world = new dNewton();
// create floor
dNewtonCollisionBox floor_collision (world, 100, 1, 100, 1);
//floor_collision.SetScale(1, 2, 1); // If I uncomment this line dNewtonPlayer->CustomPlayerController->m_isJumping never change.
MyDynamicBody* floor = new MyDynamicBody (world, 0, &floor_collision, NULL, GetIdentityMatrix());
// create player
dFloat mass = 100.0f;
dFloat outerRadius = 1;
dFloat innerRadius = 0.25;
dFloat height = 2.0f;
dFloat stairStep = 0.5;
dVector upDir(0, 1, 0);
dVector frontDir(0, 0, 1);
dNewtonPlayerManager* manager = new dNewtonPlayerManager(world);
MyPlayer* player = new MyPlayer(manager, NULL,
mass, outerRadius, innerRadius, height, stairStep, &upDir[0], &frontDir[0], 1);
dMatrix matrix;
player->GetMatrix(&matrix[0][0]);
matrix.m_posit.m_y = 5.0f;
player->SetMatrix(&matrix[0][0]);
std::cout << "height: " << std::endl;
while(true)
{
world->UpdateOffLine(1.0f/60.f);
dMatrix matrix;
player->InterplateMatrix(1.0f, &matrix[0][0]);
std::cout << matrix.m_posit.m_y << " ";
}
return 0;
}
Result: (stable at 0.5 height, work as expected)
- Code: Select all
height:
5 4.99727 4.99183 4.98365 4.97275 4.95913 4.94278 4.9237 4.9019 4.87738 4.85013 4.82015 4.78745 4.75203 4.71388 4.673 4.6294 4.58308 4.53403 4.48225 4.42775 4.37052 4.31058 4.2479 4.1825 4.11437 4.04352 3.96995 3.89365 3.81462 3.73287 3.6484 3.5612 3.47127 3.37862 3.28325 3.18515 3.08432 2.98077 2.8745 2.7655 2.65377 2.53932 2.42215 2.30225 2.17963 2.05428 1.9262 1.7954 1.66188 1.52562 1.38665 1.24495 1.10053 0.953375 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 .............
Result of uncomment <floor_collision.SetScale(1, 2, 1);> (2x Axis-Y = Player must collide at height 1 but collide lower than expected, height is not stable and m_isJumping in CustomPlayerController.cpp is always true)
height:
- Code: Select all
5 4.99727 4.99183 4.98365 4.97275 4.95913 4.94278 4.9237 4.9019 4.87738 4.85013 4.82015 4.78745 4.75203 4.71388 4.673 4.6294 4.58308 4.53403 4.48225 4.42775 4.37052 4.31058 4.2479 4.1825 4.11437 4.04352 3.96995 3.89365 3.81462 3.73287 3.6484 3.5612 3.47127 3.37862 3.28325 3.18515 3.08432 2.98077 2.8745 2.7655 2.65377 2.53932 2.42215 2.30225 2.17963 2.05428 1.9262 1.7954 1.66188 1.52562 1.38665 1.24495 1.10053 0.953375 0.8035 0.6509 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521094 0.518369 0.512919 0.504744 0.521 ............
I'm doing something wrong or is a bug?
Thanks.
Last edited by
Alessan on Tue Aug 05, 2014 2:37 am, edited 1 time in total.
-
Alessan
-
- Posts: 4
- Joined: Fri Jul 25, 2014 9:43 pm
by Julio Jerez » Fri Aug 01, 2014 3:04 pm
can you get the gibhub version, before doing anything?
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JoeJ » Fri Aug 01, 2014 3:36 pm
-
JoeJ
-
- Posts: 1453
- Joined: Tue Dec 21, 2010 6:18 pm
by Julio Jerez » Fri Aug 01, 2014 4:26 pm
yes we move to GibHub, but I believe that that but was fixed even on the last committed version to Google source.
Last version was 07/28/2014 you have a version that is several commits older
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Alessan » Fri Aug 01, 2014 4:29 pm
Hi,
Thanks for response,
with the gitbub version position is stable, but height at collision (if i'm not wrong) must be 1 not 0.5, and in
CustomPlayerController::UpdateGroundPlane the castray never hit any body and then m_isJumping is always false.
height:
- Code: Select all
5 4.99727 4.99183 4.98365 4.97275 4.95913 4.94278 4.9237 4.9019 4.87738 4.85013 4.82015 4.78745 4.75203 4.71388 4.673 4.6294 4.58308 4.53403 4.48225 4.42775 4.37052 4.31058 4.2479 4.1825 4.11437 4.04352 3.96995 3.89365 3.81462 3.73287 3.6484 3.5612 3.47127 3.37862 3.28325 3.18515 3.08432 2.98077 2.8745 2.7655 2.65377 2.53932 2.42215 2.30225 2.17963 2.05428 1.9262 1.7954 1.66188 1.52562 1.38665 1.24495 1.10053 0.953375 0.8035 0.6509 0.525 0.522275 0.516825 0.50865 0.49775 0.49775 0.49775 0.49775 0.49775 0.49775 0.49775 0.49775 ........
-
Alessan
-
- Posts: 4
- Joined: Fri Jul 25, 2014 9:43 pm
by Julio Jerez » Fri Aug 01, 2014 4:34 pm
Ok you are on gibhub, now how are you doing this test, are you doing it on the demos sandbox?
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Alessan » Fri Aug 01, 2014 4:52 pm
No, for test I'm not using sandbox demos, only one file with the source of the first post. Not using graphic interface, only console output and breakpoints.
I put a breakpoint in /home/main/Descargas/newton-dynamics.git/trunk/packages/dCustomJoints/CustomPlayerControllerManager.cpp
in function: CustomPlayerController::UpdateGroundPlane line 318, if i not use scaled collision the debug breaks at this line, if i scale the collision the player body collide but never breaks at this line.
-
Alessan
-
- Posts: 4
- Joined: Fri Jul 25, 2014 9:43 pm
by Julio Jerez » Fri Aug 01, 2014 5:47 pm
Oh I see the code you posted has every thing. I will debug it tonigh
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Sat Aug 02, 2014 1:40 pm
ok I pasted the demo in the newton project tutorial
C:\Development\newton-dynamics\applications\tutorialsSDK300\CNewtonTutorials\newtonTutorials.sln
and when I run it I get these numbers
0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
right there I see that the values are different than what you get,
I check that demo, maybe you can just open it with visual studio and see if you get the same results? before we move on
when I uncomement the line that scale the collision I see the bug, it is on this function
- Code: Select all
dgFloat32 dgCollisionInstance::ConvexRayCast (const dgCollisionInstance* const convexShape, const dgMatrix& convexShapeMatrix, const dgVector& localVeloc, dgFloat32 minT, dgContactPoint& contactOut, OnRayPrecastAction preFilter, const dgBody* const referenceBody, void* const userData, dgInt32 threadId) const
{
if ((GetCollisionPrimityType() != m_nullCollision) && (!preFilter || preFilter(referenceBody, this, userData))) {
switch(m_scaleType)
{
case m_unit:
{
dgFloat32 t = m_childShape->ConvexRayCast (convexShape, convexShapeMatrix, localVeloc, minT, contactOut, referenceBody, this, userData, threadId);
if (t <= minT) {
if (!(m_childShape->IsType(dgCollision::dgCollisionMesh_RTTI) || m_childShape->IsType(dgCollision::dgCollisionCompound_RTTI))) {
contactOut.m_shapeId0 = GetUserDataID();
//contactOut.m_shapeId1 = GetUserDataID();
contactOut.m_shapeId1 = convexShape->GetUserDataID();
}
contactOut.m_collision0 = this;
//contactOut.m_collision1 = this;
contactOut.m_collision1 = convexShape;
}
return t;
}
default:
dgAssert(0);
}
}
return dgFloat32 (1.2f);
}
as you can see the branch of the switch case that does the cast for scale shape is no implemented, I see if I added this afternoon.
Mean time do you have to scale your world?
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Sun Aug 03, 2014 12:39 am
all right, I fix the scale bug and now the floor value is 1.0 with the non uniform scale as It should be.
sync to github and you will find the demo the demo there.
Later I will make the secund tutorial demo, if you do not mind.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Alessan » Tue Aug 05, 2014 2:37 am
Hi,
Thanks Julio, now all works fine. Now I can continue on my custom player controller.
Tanks again.
-
Alessan
-
- Posts: 4
- Joined: Fri Jul 25, 2014 9:43 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 34 guests