A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by lperkins2 » Sun Jul 10, 2022 11:30 pm
Seems I'm back again, looking for a dead-simple example to get newton up and running (last time was for newton 3's C API, which I did eventually figure out). I've tried to copy the concepts from *that* forward to the C++ API of newton 4, but I'm obviously doing something wrong, as I don't see any of the callbacks firing and the sphere isn't moving.
Here's what I have so far, but if someone who
has newton 4 working (in a simpler project than the demos) is willing to share, I'd appreciate it.
- Code: Select all
class TestEntityNotify: public ndBodyNotify
{
public:
TestEntityNotify(ndFloat32 gravity)
:ndBodyNotify(ndVector (ndFloat32 (0.0f), gravity, ndFloat32(0.0f), ndFloat32(0.0f))){}
void OnObjectPick() const
{
cout << "61\n";
}
void OnApplyExternalForce(ndInt32, ndFloat32)
{
cout << ("66\n");
}
void OnTransform(ndInt32, const ndMatrix& matrix)
{
cout << "85";
}
};
extern "C" {
int main() {
TestEntityNotify *_cb = new TestEntityNotify(9.8);
ndWorld world{};
ndShapeSphere sphere{1};
ndShapeInstance instance{&sphere};
ndBodyDynamic *body = new ndBodyDynamic();
ndVector gravity{0,-10,0,0};
body->SetMatrix(dGetIdentityMatrix());
body->SetMassMatrix(5, dGetIdentityMatrix());
body->SetNotifyCallback(_cb);
body->SetCollisionShape(instance);
body->SetVelocityNoSleep(gravity);
world.AddBody(body);
for (int i=0; i < 1000; i++) {
world.Update(10.0);
world.Sync();
}
ndVector p0;
ndVector p1;
body->GetAABB(p0, p1);
return p0.GetX() > 10;
}
}
I've tried various minor changes, like polling if the body is asleep and so on, but nothing's jumped out at me as a solution.
-
lperkins2
-
- Posts: 39
- Joined: Fri Jul 03, 2015 4:16 am
by Dave Gravel » Mon Jul 11, 2022 4:01 am
Hi lperkins2,
I have this quick test, I have make it for debug a old problem.
Maybe my little test can help you to find your problem.
The exemple is surely not perfect, But I think it can help for begin with newton 4.
https://www.mediafire.com/file/5l3031ay91ukhd5/quick_newton_test.zipYou just need to add the newton 4 sdk inside folder Externals\newton-dynamics-master
Use CMake for compile the newton 4 sdk.
After you can try to build the newton_debug.sln file.
Good luck with your project.
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Julio Jerez » Mon Jul 11, 2022 1:23 pm
newton 4 is more object oriented than 3.xx, the callback are now objects with data and methods.
I should be far simpler to use for CPP and object oriented languages users than previews version.
you can use those samples from Dave, there is also the equivalent of the newton hello word. that you can try by enabling NEWTON_BUILD_TEST in the cmake script.
it is a main function that put a sphere on a flat floor and even connected to a joint and joint
if you run the test, it give you the most basic start to continue going wit the engine.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by lperkins2 » Mon Jul 11, 2022 2:25 pm
Well I feel half foolish, half vindicated.
The half foolish part is, after I hand compiled my test program once, I set up a macro to recompile it, but forgot to re-link it. So all this time I spent testing the "does it find newton" version that created an empty world before exiting, rather than my actual test program.
The half vindicated part is, unlike newton 3, newton 4 appears to skip physics processing if there is only one body in the world. I tried to only add a single dynamic body (a sphere), and then let gravity move it, but that doesn't work. Likewise, if I start from the test program included in newton's source, and comment out the join and either the floor or the sphere, the external force callback ceases to be called. This is not a problem, since you generally don't need a physics enging if you only have one object, it just was a bit of a surprise. Anyway, think I'm good to keep going here.
-
lperkins2
-
- Posts: 39
- Joined: Fri Jul 03, 2015 4:16 am
by Julio Jerez » Mon Jul 11, 2022 3:42 pm
That could be a bug produced by recent commit.
I just have a report that this is happening. I am looking into it.
In general I add a define whe doing these changes, but some time ther is a point where it does not make sense because the define will add a tremendous amount of conditional code. So it is better to just take the hit and tested.
But not matter how much I test, most the time I can't cover everything.
Anyway I am testing that, it should simply work with one body.
Edit:
If you sync, it should work with a single body now.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 4 guests