Newton 3 to Newton 4 migration questions

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Newton 3 to Newton 4 migration questions

Postby JoshKlint » Tue Nov 01, 2022 5:25 am

Questions about migrating to Newton 4:

  • How does scaling work in Newton 4? Are scaled matrices or shapes supported?
  • What is the Newton 4 equivalent to NewtonBodySetContinuousCollisionMode()?
  • Is there an equivalent to NewtonCollisionPointDistance and NewtonCollisionCollide?

More to come...
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Tue Nov 01, 2022 12:23 pm

I added the .lib file into my VIsual Studio project and included "ndNewton.h". The DLL seems out of sync with my program. When I run this code and walk through it in the debugger:
Code: Select all
ndShape* box = new ndShapeBox(1, 1, 1);
ndShapeNull* test = box->GetAsShapeNull();

When I step into GetAsShapeNull(), the debugger takes me to ndShapeBox::GetAsShapeBox(). :shock:

I tried changing the Newton library to use C++20 for language generation, but it made no difference.
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby Julio Jerez » Tue Nov 01, 2022 2:48 pm

That is correct, if you make a box, it will go the box function and returns null, because a box is not a null.
Only box and classes derived from boxes will return a vud pointer.

The scale you just set as is was in 3.xx
But you do not apply change to shapes.
Shape are constant objects, you apply properties to
ShapeInstances.
On ccd. With the focus on multithreaded code, I have not gotten around to ccd.
Over the years, I found that ccd is a check box feature that almost not one really uses.

It is possible to added, but I put it way low on the priority list.
Probably sometime next year after I ether fail or succeeded with the machine leaning based balance controller.
And after I five another try to Gpu heterogenous compute
This time using
Intel SYCL, and the intell gpu.

What attract my this time, us that SYCL is a cpp single source code.
And even tger is not support much support not intel GPU, in windows, there is on Linux, OS10, Android,

So maybe at some point MS also adopted it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 3 to Newton 4 migration questions

Postby Julio Jerez » Tue Nov 01, 2022 2:55 pm

On the collision.
There is a class ndContact solver.

You make on of those objects, and there you get the functionality you need.
There are few demos using it.
Player capsule is one example.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Tue Nov 01, 2022 4:06 pm

Julio Jerez wrote:That is correct, if you make a box, it will go the box function and returns null, because a box is not a null. Only box and classes derived from boxes will return a vud pointer.

I call GetAsShapeNull() but the debugger shows this line is being executed instead:
Code: Select all
D_COLLISION_API virtual ndShapeBox* GetAsShapeBox() { return this; }

It returns a valid pointer that the main program thinks is an ndShapeNull, even though it is not.

The reason I noticed this is because every object is triggering this assert in ndScene::UpdateBodyList():
Code: Select all
ndAssert(!body->GetCollisionShape().GetShape()->GetAsShapeNull());

The only thing I can think of is that maybe the class definitions are out of sync between the DLL and my project. I haven't made any changes to Newton, using Visual Studio 2022 with C++20 standard.

I guess I can try to build a new empty VS project and import the lib into that, and see if it works.
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby Julio Jerez » Tue Nov 01, 2022 11:48 pm

I didn't even want to test because I know that it is impossible, but nevertheless,
I just opened demo ../newton-4.00\tests\rigidBody_test.cpp
and pasted this:
Code: Select all
  ndShapeBox xxx(1.0f, 1.0f, 1.0f);
  ndShapeNull* xxxxx = xxx.GetAsShapeNull();


and I get this call stack
Code: Select all
>   newton_tests.exe!ndShape::GetAsShapeNull() Line 219   C++
    newton_tests.exe!RigidBody_MoveWithUnitForce_Test::TestBody() Line 76   C++
    newton_tests.exe!testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test,void>(testing::Test * object, void(testing::Test::*)() method, const char * location) Line 2584   C++
    newton_tests.exe!testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,void>(testing::Test * object, void(testing::Test::*)() method, const char * location) Line 2635   C++
    newton_tests.exe!testing::Test::Run() Line 2681   C++


which is this class

Code: Select all
class ndShape: public ndContainersFreeListAlloc<ndShape>
{
   public:
...
...
   virtual ndShapeBox* GetAsShapeBox() { return nullptr; }
   virtual ndShapeNull* GetAsShapeNull() { return nullptr; }
   virtual ndShapeCone* GetAsShapeCone() { return nullptr; }
   virtual ndShapePoint* GetAsShapePoint() { return nullptr; }
   virtual ndShapeConvex* GetAsShapeConvex() { return nullptr; }
   virtual ndShapeSphere* GetAsShapeSphere() { return nullptr; }
   virtual ndShapeCapsule* GetAsShapeCapsule() { return nullptr; }


you have some wrong is you get assert on a null body,
that mean you added a boy to the world with a null shape.

when bodies are created the get a null shape. but the null shapes,
is just a dummy collision shape so that the process of creation the body can be completed.
you must assign and collision shape to a body before you added to a world.

when you build the code in cmake, you can check off select option BUILD_SHARED_LIBRARIES.
this will let to test the UNIT test demos in subproject newton_tests

there you can find the simplest way for how to make a body, and shape, and notify callback, and few other things.
These demos are compiled and run by github each time something is committed to make sure they engine compile and run in windows and Unit systems.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Wed Nov 02, 2022 3:41 am

When I created a new VS project it worked as expected. Here are the steps I took to import the Newton library:

In preprocessor macros, define _CRT_SECURE_NO_WARNINGS

Add the following header search paths:
newton-4.00\sdk\dCore
newton-4.00\sdk\dCollision
newton-4.00\sdk\dNewton\dParticles
newton-4.00\sdk\dNewton\dJoints
newton-4.00\sdk\dNewton\dModels\dVehicle
newton-4.00\sdk\dNewton\dModels\dCharacter
newton-4.00\sdk\dNewton\dModels
newton-4.00\sdk\dNewton
newton-4.00\sdk\dNewton\dIkSolver
newton-4.00\sdk\dTinyxml
newton-4.00\sdk

Project is attached, maybe it will be useful for someone.
Attachments
NewtonTest.zip
(3.53 KiB) Downloaded 456 times
Last edited by JoshKlint on Wed Nov 02, 2022 5:11 am, edited 1 time in total.
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Wed Nov 02, 2022 4:05 am

Okay, the problem was that I had an old copy of Newton 4 in another folder, with search paths pointing there, so the method pointers were getting all mixed up. :oops:
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Wed Nov 02, 2022 5:50 am

Whenever I use ndVector::m_zero, an unresolved external symbol is detected:
Code: Select all
#include <windows.h>
#include <iostream>
#include "newton-4.00/sdk/dNewton/ndNewton.h"

int main()
{
   auto v = ndVector::m_zero;
}
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Wed Nov 02, 2022 7:05 am

What is the correct way to get rid of a ndBody object? Just call delete?:
Code: Select all
PhysicsNode::Free()
{
    if (newtonbody)
    {
        if (world && world->newtonworld) world->newtonworld->RemoveBody(newtonbody);
        delete newtonbody;
    }
}
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Wed Nov 02, 2022 7:41 am

I've got collision and forces now :D :
Untitled.jpg
Untitled.jpg (59.49 KiB) Viewed 10706 times
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Wed Nov 02, 2022 4:43 pm

What is the difference between ndShape::SetLocalMatrix and ndShape::SetGlobalMatrix? :?
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby Julio Jerez » Wed Nov 02, 2022 5:24 pm

it is the same as if was in older version.
a collision instance has a local matrix, that position the shape relative to whatever the shape is attached too.
it also has a global transform which is the product of that local matrix and the matrix that the shape is attached to. A shape could be attached to a body, but also to another shapes.
the global matrix positions the shape in the world, regardless of the parent location.

for most primitive, local matrix is identity. but the you can offset the shape by tweaking the local matrix.

you can look at demos function ndShapeInstance* ndDemoEntity::CreateCollisionFromChildren() const

and see how local shapes are calculates from a hierarchical mesh.
basically, you can place collision mesh in a graphics editor, and them some code like that can position the shape to match what is in the editors.
you can load some of the fbx files in your editor, and see the placement of a mesh.
that helps the user to have an easier time setting up a rig visually.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 3 to Newton 4 migration questions

Postby JoshKlint » Thu Nov 03, 2022 5:26 am

In Newton 3 the create hinge joint function takes a single pin and pivot matrix, in global space.

In Newton 4, the ndJointHinge constructor takes a pin and pivot matrix for the parent and another for the child. Are these in local space for each?
JoshKlint
 
Posts: 163
Joined: Sun Dec 10, 2017 8:03 pm

Re: Newton 3 to Newton 4 migration questions

Postby Julio Jerez » Thu Nov 03, 2022 1:48 pm

both constructors are there, and in all case the parameters are in global space.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 38 guests