A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Bird » Sat May 26, 2012 10:00 am
in my temp folder, and click check out from svn.
then and when to folder
C:\tmp\newton-dynamics\coreLibrary_300\projets\windows\project_vs2010
Hmm, that works here too with a fresh svn install. It's only when using my normal svn install that I hit those linking problems in DLL Release mode. So I don't understand the problem but it's easy to fix with a completely fresh SVN install. Thanks for the help!
For others who need an idiot proof guide (maybe it's just me?):
1. Download the newton 300 release software from the wiki and extract the "coreLibrary_300" to your C: drive
If you do that you're getting an older version of the library(Feb 4). The library has grown quite a bit since then so you'd be better off getting the latest version via SVN.
-Bird
-
Bird
-
- Posts: 636
- Joined: Tue Nov 22, 2011 1:27 am
by Julio Jerez » Sat May 26, 2012 10:14 am
I beleive it is the project setting,
verify that in your project the runtime libraries match, if they do not change the newton settings.
My sugestion is that you also use /MT for runtime
It is much safer, because it prevent hacker from installing mallisios system DLL that ruin all apps that use that DLL.
it is not like a user is making upgraded version of the OS Runtime libraries, it is only microsoft that does that once every 4 or 5 years.
the other people who do that are Hackers who make malision viruses.
there is not reason to use shared DLLs anymore, any machine has several gbytes of ram, and DLL do not get upgraded legitimally that often.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Bird » Sat May 26, 2012 10:29 am
I beleive it is the project setting,
verify that in your project the runtime libraries match, if they do not change the newton settings.
The linking problems were while trying to compile the DLL Release version of Newton 300, not while trying to link to Newton from my own project, so I don't think it's a runtime lib mismatch in this case.
there is not reason to use shared DLLs anymore, any machine has several gbytes of ram, and DLL do not get upgraded legitimally that often.
Yeah, I always use Newton static libs in my own projects. I was just curious why the DLL verson was failing for someone else

-Bird
-
Bird
-
- Posts: 636
- Joined: Tue Nov 22, 2011 1:27 am
by en51nm » Sat May 26, 2012 12:42 pm
Bird wrote:If you do that you're getting an older version of the library(Feb 4). The library has grown quite a bit since then so you'd be better off getting the latest version via SVN.
I was under the impression it wasn't a good idea to use the SVN as it could be unstable and it's better to use the most recent release? I'd be more than happy to use the SVN if this isn't the case though...
-
en51nm
-
- Posts: 27
- Joined: Thu May 17, 2012 3:20 pm
by Bird » Sat May 26, 2012 1:01 pm
en51nm wrote:Bird wrote:If you do that you're getting an older version of the library(Feb 4). The library has grown quite a bit since then so you'd be better off getting the latest version via SVN.
I was under the impression it wasn't a good idea to use the SVN as it could be unstable and it's better to use the most recent release? I'd be more than happy to use the SVN if this isn't the case though...
Julio tends to fix bugs as soon as he's aware of them, if possible. So in my experience the latest SVN versions are usually more stable and have more features than previous versions.
-Bird
-
Bird
-
- Posts: 636
- Joined: Tue Nov 22, 2011 1:27 am
by en51nm » Sat May 26, 2012 1:29 pm
Okay, I'm checking out the SVN now. I'll keep this thread updated with my progress in case something goes wrong.
-
en51nm
-
- Posts: 27
- Joined: Thu May 17, 2012 3:20 pm
by en51nm » Sat May 26, 2012 3:27 pm
Good news: I've checked out the SVN and compiled it successfully and got it working

Bad news: the collision detection is quite inaccurate.
No collision:

Collision:

I've got the newton world setup for the most accurate collisions:
- Code: Select all
NewtonSetSolverModel(nWorld,0);
This is my function for calculating the collision:
- Code: Select all
bool CheckForCollision(NewtonWorld *nWorld, SObject *obj_A, SObject *obj_B)
{
//Matrix to store irr_node position
matrix4 mat_A,mat_B;
//Copy position
mat_A.makeIdentity();
mat_B.makeIdentity();
mat_A.setTranslation(obj_A->irr_node->getPosition());
mat_B.setTranslation(obj_B->irr_node->getPosition());
const int nContacts = 2;
float contacts[3 * nContacts];
float normals[3 * nContacts];
float penetration[ nContacts ];
int attribute[nContacts];
int threadIndex = 0;
//Check for collision between collision meshes,
// returns number of contact points
int nHits = NewtonCollisionCollide(nWorld,nContacts,
obj_A->nwtn_collision, (float*)&mat_A[0],
obj_B->nwtn_collision, (float*)&mat_B[0],
contacts,
normals,
penetration,
attribute,
threadIndex);
//Collision detected if nHits > 0
if( nHits > 0)
return true;
return false;
}
Any ideas?
-
en51nm
-
- Posts: 27
- Joined: Thu May 17, 2012 3:20 pm
by Sweenie » Sat May 26, 2012 3:45 pm
Did you pass an identity matrix as the last parameter for NewtonCreateConvexHull?
Or maybe you just passed NULL which would be the same thing.
Anyway I recommend that you implement debug rendering to visualise the collision to make sure that the collision hull isn't offset.
Use NewtonCollisionForEachPolygonDo to retrieve the collision mesh.
-
Sweenie
-
- Posts: 503
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Julio Jerez » Sat May 26, 2012 5:31 pm
I think Sweeny is right, you need to implement the debug display to see where your collision shapes are.
if I am correct I believe the shapes will be offset by half the height.
I say this because the Irrlicth engine, last time I checked, was still using the ther trick of placing the origin of a mesh at the lowest y.
if that is a sphere the visual mesh will be offset from the collsion mesk.
bascially for Irrlicth you cannot use and identity matrix for shape offset, you need to make a matrix with a local y set and (meshMxayY - meshMinY) / 2
the debug display will expose all that.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by en51nm » Sat May 26, 2012 7:15 pm
Hi, thanks for the help. Is it easy to render the debug display for Newton using irrlicht? I wouldn't even know when to start with doing that!
-
en51nm
-
- Posts: 27
- Joined: Thu May 17, 2012 3:20 pm
by en51nm » Sun May 27, 2012 5:18 am
I've had a look at NewtonCollisionForEachPolygonDo in the wiki and I'm getting stuck with what to put in the following parameters:
- const dFloat* matrix : should I leave this as NULL (I don't want any transformation of the mesh vertices)
- NewtonCollisionIterator callback : still trying to get my head around callback functions, I have no idea where to start with this, I guess for each pollygon I should just call driver->draw3DTriangle? But I don't know what data type NewtonCollisionForEachPolygonDo will pass?
Sorry, I'm still quite new to all this...
-
en51nm
-
- Posts: 27
- Joined: Thu May 17, 2012 3:20 pm
by Sweenie » Sun May 27, 2012 6:02 am
-
Sweenie
-
- Posts: 503
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Julio Jerez » Sun May 27, 2012 6:03 am
here is an example how to use that function, from file: ..\applications\demosSandbox\sdkDemos\toolBox\DebugDisplay.cpp
- Code: Select all
void DebugShowGeometryCollision (void* userData, int vertexCount, const dFloat* faceVertec, int id)
{
//DEBUG_DRAW_MODE mode = (DEBUG_DRAW_MODE) ((int)userData); //NOTE error: cast from ‘void*’ to ‘int’ loses precision
DEBUG_DRAW_MODE mode = (DEBUG_DRAW_MODE) ((intptr_t)userData);
if (mode == m_lines) {
int i = vertexCount - 1;
dVector p0 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
for (int i = 0; i < vertexCount; i ++) {
dVector p1 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
glVertex3f (p0.m_x, p0.m_y, p0.m_z);
glVertex3f (p1.m_x, p1.m_y, p1.m_z);
p0 = p1;
}
} else {
dVector p0 (faceVertec[0 * 3 + 0], faceVertec[0 * 3 + 1], faceVertec[0 * 3 + 2]);
dVector p1 (faceVertec[1 * 3 + 0], faceVertec[1 * 3 + 1], faceVertec[1 * 3 + 2]);
for (int i = 2; i < vertexCount; i ++) {
dVector p2 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
glVertex3f (p0.m_x, p0.m_y, p0.m_z);
glVertex3f (p1.m_x, p1.m_y, p1.m_z);
glVertex3f (p2.m_x, p2.m_y, p2.m_z);
p1 = p2;
}
}
}
static void DebugShowBodyCollision (const NewtonBody* const body, DEBUG_DRAW_MODE mode)
{
dFloat mass;
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
if (mode == m_lines) {
glBegin(GL_LINES);
} else {
glBegin(GL_TRIANGLES);
}
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
if (mass > 0.0f) {
int sleepState = NewtonBodyGetSleepState(body);
if (sleepState == 1) {
// indicate when body is sleeping
glColor3f(0.42f, 0.73f, 0.98f);
} else {
// body is active
glColor3f(1.0f, 1.0f, 1.0f);
}
dMatrix matrix;
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, (void*) mode);
} else {
NewtonCollisionInfoRecord info;
glColor3f(1.0f, 1.0f, 0.0f);
NewtonCollision* const collision = NewtonBodyGetCollision (body);
NewtonCollisionGetInfo (collision, &info);
switch (info.m_collisionType)
{
//case SERIALIZE_ID_TREE:
//case SERIALIZE_ID_SCENE:
case SERIALIZE_ID_USERMESH:
case SERIALIZE_ID_HEIGHTFIELD:
{
break;
}
default:
{
dMatrix matrix;
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, (void*) mode);
break;
}
}
}
glColor3f(1.0f, 1.0f, 0.0f);
for (int i = 0; i < debugDisplayCount; i += 2) {
glVertex3f (debugDisplayCallback[i].m_x, debugDisplayCallback[i].m_y, debugDisplayCallback[i].m_z);
glVertex3f (debugDisplayCallback[i+1].m_x, debugDisplayCallback[i+1].m_y, debugDisplayCallback[i+1].m_z);
}
glEnd();
}
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by en51nm » Sun May 27, 2012 6:57 am
Okay, I've taken a look at those functions and I think I've got something that should be correct...
Here is my call back function definition:
- Code: Select all
//Callback function for debugging newton collision
void DebugShowGeometryCollision (void* userData, int vertexCount, const dFloat* faceVertec, int id)
{
// get a pointer to the device
IrrlichtDevice* dev = (IrrlichtDevice*)userData;
core::vector3df line;
float NewtonToIrr = 1.0f;
int i = vertexCount - 1;
core::vector3df p0 (
faceVertec[i * 3 + 0] * NewtonToIrr,
faceVertec[i * 3 + 1] * NewtonToIrr,
faceVertec[i * 3 + 2] * NewtonToIrr);
for (i = 0; i < vertexCount; i ++)
{
core::vector3df p1 (
faceVertec[i * 3 + 0] * NewtonToIrr,
faceVertec[i * 3 + 1] * NewtonToIrr,
faceVertec[i * 3 + 2] * NewtonToIrr);
dev->getVideoDriver()->draw3DLine(p0, p1, SColor(255,0,0,255));
p0 = p1;
}
}
Now I call NewtonCollisionForEachPolygonDo for my two objects inside my draw loop:
- Code: Select all
//Draw the newton collision mesh polygon by polygon
dgMatrix matrix1, matrix2;
NewtonCollisionGetMatrix(Sobj1.nwtn_collision,&matrix1[0][0]);
NewtonCollisionGetMatrix(Sobj2.nwtn_collision,&matrix2[0][0]);
NewtonCollisionForEachPolygonDo(Sobj1.nwtn_collision,&matrix1[0][0],DebugShowGeometryCollision,device);
NewtonCollisionForEachPolygonDo(Sobj2.nwtn_collision,&matrix1[0][0],DebugShowGeometryCollision,device);
code compiles and runs as before, but nothing extra is drawn...
-
en51nm
-
- Posts: 27
- Joined: Thu May 17, 2012 3:20 pm
by Sweenie » Sun May 27, 2012 7:12 am
Think you should replace NewtonCollisionGetMatrix with NewtonBodyGetMatrix .
-
Sweenie
-
- Posts: 503
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest