A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Ripiz » Fri Jul 23, 2010 6:52 am
I built JointLibrary as .lib and link it in my project (.dll not needed), included CustomPlayerController.cpp, CustomPlayerController.h, MyPlayerController.h (MyPlayerController class from CharacterController.cpp in SDK) and CustomNewtonJoint.h .
I create MyPlayerController:
- Code: Select all
extern MyPlayerController *controller;
dMatrix mx(
dVector(matWorld._11, matWorld._21, matWorld._31, matWorld._41),
dVector(matWorld._12, matWorld._22, matWorld._32, matWorld._42),
dVector(matWorld._13, matWorld._23, matWorld._33, matWorld._43),
dVector(matWorld._14, matWorld._24, matWorld._34, matWorld._44));
controller = new MyPlayerController(mx, playerBody, 1.0f, 1.0f);
And it crashes at this line in CustomPlayerController.cpp:
- Code: Select all
contactCount = NewtonWorldConvexCast (m_world, &bodyMatrix[0][0], &destination[0], m_bodySensorShape, &hitParam, &castFilterData, ConvexStaticCastPrefilter, info, sizeof (info) / sizeof (info[0]), threadIndex);
I found out that m_bodySensorShape is null pointer, for some reason this line fails to create collision:
- Code: Select all
m_bodySensorShape = NewtonCreateConvexHull (m_world, SENSOR_SHAPE_SEGMENTS * 2, &bodySensorPoints[0].m_x, sizeof (dVector), 0.0f, 0, 0);
Anyone have idea how can I fix this?
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Fri Jul 23, 2010 10:09 am
it mean it coudl no build m_sensor shape form teh dimnation that were passed in.
when you call teh constructor make sure the data can build a meaninful collision shape.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Fri Jul 23, 2010 1:45 pm
I'm sure that's not a problem, it's only NewtonBox
- Code: Select all
D3DXMATRIX matRotX, matRotY, matRotZ, matTrans, matWorld;
D3DXMatrixRotationX( &matRotX, 0);
D3DXMatrixRotationY( &matRotY, 0);
D3DXMatrixRotationZ( &matRotZ, 0);
D3DXMatrixTranslation(&matTrans, loc.x, loc.y, loc.z + 14);
matWorld=(matRotX*matRotY*matRotZ)*matTrans;
newtonData *data = new newtonData;
data->id = eMyPlayer;
data->data = 0;
float mass = 70;
Vector3 origin, inertia;
extern NewtonWorld *world;
NewtonCollision *collision = NewtonCreateBox(world, 6, 3, 28, 0, matWorld);
playerBody = NewtonCreateBody (world, collision);
NewtonConstraintCreateUpVector(world, Vector3(0, 0, 1), playerBody);
NewtonBodySetDestructorCallback (playerBody, DestroyBodyCallback);
NewtonBodySetUserData (playerBody, data);
NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
D3DXMatrixIdentity(&matWorld);
NewtonBodySetMatrix (playerBody, matWorld);
NewtonBodySetMassMatrix (playerBody, mass, mass * inertia.x, mass * inertia.y, mass * inertia.z);
NewtonBodySetCentreOfMass (playerBody, &origin[0]);
NewtonBodySetForceAndTorqueCallback (playerBody, ApplyForceAndTorqueCallback);
NewtonBodySetTransformCallback (playerBody, SetTransformCallback);
NewtonReleaseCollision (world, collision);
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Fri Jul 23, 2010 2:03 pm
can you put a break poin in the constructor and see if the parameters passed to m_bodySensorShape are right.
the function should return a valid pointer
in here
m_bodySensorShape = NewtonCreateConvexHull (m_world, SENSOR_SHAPE_SEGMENTS * 2, &bodySensorPoints[0].m_x, sizeof (dVector), 0.0f, 0, 0);
in the points in bodySensorPointsdo no form a convex volume then NewtonCreateConvexHull return NULL,
and tha usually happens whne the dimention of the player size are incorrect.
BTW cool that you are using jointLibrary in static linking

-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Sat Jul 24, 2010 2:14 am
- Code: Select all
m_bodySensorShape = NewtonCreateConvexHull (m_world, SENSOR_SHAPE_SEGMENTS * 2, &bodySensorPoints[0].m_x, sizeof (dVector), 0.0f, 0, 0);
I put breakpoint there and..
m_world is not null
bodySensorPoints contains 64 vertexes:
52, 37, 0;
52, 36, 7;
52, 34, 14;
//etc
Strange... x value doesn't change through all 64 vertex
Maybe I don't convert DirectX matrix to Newton Matrix correctly?
- Code: Select all
dMatrix mx(
dVector(matWorld._11, matWorld._21, matWorld._31, matWorld._41),
dVector(matWorld._12, matWorld._22, matWorld._32, matWorld._42),
dVector(matWorld._13, matWorld._23, matWorld._33, matWorld._43),
dVector(matWorld._14, matWorld._24, matWorld._34, matWorld._44));
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Sat Jul 24, 2010 10:45 am
Ripiz wrote:bodySensorPoints contains 64 vertexes:
52, 37, 0;
52, 36, 7;
52, 34, 14;
//etc
Strange... x value doesn't change through all 64 vertex
[/code]
that would be why, some how it is genedation a flat disk, which has not volume and convehull return NULL.
I think that you can convert d3d matrix to newton like this
- Code: Select all
dMatrix mx(
dVector(matWorld._11, matWorld._12, matWorld._13, matWorld._14),
dVector(matWorld._21, matWorld._22, matWorld._23, matWorld._24),
dVector(matWorld._31, matWorld._32, matWorld._33, matWorld._34),
dVector(matWorld._41, matWorld._42, matWorld._43, matWorld._44));
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Sun Jul 25, 2010 2:06 pm
Nothing changed at all...

-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Ripiz » Sun Aug 01, 2010 8:58 am
I figured it had no volume because my step_size was 1.0f
- Code: Select all
controller = new MyPlayerController(mx, playerBody, 1.0f, 1.0f);
I lowered it and it doesn't crash anymore
- Code: Select all
controller = new MyPlayerController(mx, playerBody, 0.1f, 1.0f);
However there's new problem.
Instead of turning, collision moves up and down when my character turns. Here's the code for input:
- Code: Select all
int x = 0, y = 0;
if(chr_KeybState[DIK_W])
x++;
if(chr_KeybState[DIK_S])
x--;
if(chr_KeybState[DIK_D])
y++;
if(chr_KeybState[DIK_A])
y--;
controller->SetVelocity(x, y, xrot);
'xrot' is character's rotation around Z axis. Value is in radians.
Anyone have idea how to fix this?
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Sun Aug 01, 2010 10:34 am
it means that the collisin shape of teh body is aligned to the wrong axis.
the demo use y up,
- Code: Select all
dMatrix globalFrame (GetIdentityMatrix());
globalFrame.m_front = dVector (0.0f, 1.0f, 0.0f, 0.0f); // up direction in global Space
globalFrame.m_up = dVector (1.0f, 0.0f, 0.0f, 0.0f); // front direction in global Space
globalFrame.m_right = globalFrame.m_front * globalFrame.m_up; // strafing direction in global Space
dFloat maxStairStepFactor = 0.7f / size.m_x;
player = new MyPlayerController (globalFrame, playerBody, maxStairStepFactor, kinematicCushion);
if you use z up you have to pass and aligmen matrix to the shape.
something like this
- Code: Select all
globalFrame.m_front = dVector (0.0f, 0.0f, 1.0f, 0.0f); // up direction in global Space
globalFrame.m_up = dVector (1.0f, 0.0f, 0.0f, 0.0f); // front direction in global Space
globalFrame.m_right = globalFrame.m_front * globalFrame.m_up; // strafing direction in global Space
also make sure the collision shape of the body is aligned properlly, I mean if is is a cylinder and teh teh offset matrix sodul be correct, debug display can help with that.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Mon Aug 02, 2010 1:52 am
Heh... I didn't even have that code
- Code: Select all
dMatrix globalFrame (GetIdentityMatrix());
globalFrame.m_front = dVector (0.0f, 0.0f, 1.0f, 0.0f);
globalFrame.m_up = dVector (1.0f, 0.0f, 0.0f, 0.0f);
globalFrame.m_right = globalFrame.m_front * globalFrame.m_up;
controller = new MyPlayerController(globalFrame, playerBody, 0.1f, 1.0f);
With this code it turning around right axis, but in opposite direction, so inside CustomPlayerController.cpp I changed
- Code: Select all
dVector heading (0.0f, dCos (m_heading), dSin (m_heading), 0.0f);
//into
dVector heading (0.0f, dSin (m_heading), dCos (m_heading), 0.0f);
But it didn't fix other problem. Collision doesn't move in correct direction. Here's my movement code again:
- Code: Select all
int x = 0, y = 0;
if(chr_KeybState[DIK_W])
x++;
if(chr_KeybState[DIK_S])
x--;
if(chr_KeybState[DIK_D])
y++;
if(chr_KeybState[DIK_A])
y--;
controller->SetVelocity(x * speed, y * speed, xrot); //speed is 500
Any idea what's wrong this time?

-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Mon Aug 02, 2010 9:13 am
Ripiz wrote:With this code it turning around right axis, but in opposite direction, so inside CustomPlayerController.cpp I changed
- Code: Select all
dVector heading (0.0f, dCos (m_heading), dSin (m_heading), 0.0f);
//into
dVector heading (0.0f, dSin (m_heading), dCos (m_heading), 0.0f);
where did you do that? that's must certainlly wrong.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Mon Aug 02, 2010 10:20 am
Ripiz wrote:With this code it turning around right axis, but in opposite direction, so inside CustomPlayerController.cpp I changed
It's inside Custom Joint code, inside
- Code: Select all
void CustomPlayerController::KinematicMotion (dFloat timestep, int threadIndex)
function
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Mon Aug 02, 2010 1:54 pm
no, leave that like it was, you are offseting the angle by 90 degress, that makes no sence
if it turnning the wrong direction all you need to do is mutiply headin by -1.0
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Tue Aug 03, 2010 1:08 am
I've been told I'll have problems if I use box for character controller, so I changed to capsule, I'd say direction doesn't matter now >.> Shape doesn't change even if it rotates.
Well I changed heading to -1.0f and changed that line back. But my character doesn't move in correct direction for some reason. Instead of going forward or sidestep it goes.. Kind of diagonally.
Don't know what code to show...
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 214 guests