Simplistic Source Example?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Simplistic Source Example?

Postby 3TATUK » Wed Sep 11, 2013 5:33 pm

Can anyone link/pastebin some example code which is minimalistic in style... Not using the tutorial SDK or another framework, but just "direct" Newton functionality... Something that would make it easily portable to C.

Anything will do, but i'm specifically looking for being able to load a world geometry from triangle arrays into Newton and adding a character to collide with the world.
3TATUK
 
Posts: 22
Joined: Thu Sep 05, 2013 11:55 pm

Re: Simplistic Source Example?

Postby JoeJ » Thu Sep 12, 2013 3:32 am

I assume what you want is not really possible with a few lines of code.
As far as i know applications\tutorials is also outdated, and demo sandbox might be a better reference.
It might be worth it to install Visual Studio just to look at how things should be done.

Also mesh and character is not the easiest thing to start with -
i'd suggest to use a static floor box and a dynamic box falling down and collide.
To do this, there are still a lot steps necessary:

Setup:
* Build your own BodyData struct to store your non physics information.
* Create a static (mass = 0) floor body, Collision shape, calculate mass properties with Newton, link it to your BodyData (most complex step)
* Do the same for the dynamic (mass > 0) body
* Setup ForceTorqueCallback for the dynamic body to apply gravity
Runtime:
* For now advance simulation each frame by 1/60 sec. (later sync to realtime, but keep a fixed timestep for newton)
* To render, get the bodies matrices (or use transform feedback) to render the box shapes - be sure physics and visuals match up

I can say Newton is easy to use, but the initial complexity to use any physics engine is unavoidable.
Try and ask again when there is a problem...
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Simplistic Source Example?

Postby Julio Jerez » Thu Sep 12, 2013 6:54 am

like joe said, you nee to start with a simpler example than a player.

can you compile these tutorial: ..\newton-dynamics\applications\tutorials

They were write for core 200, but if you can compile those I can go and update the to work with core 300.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Simplistic Source Example?

Postby 3TATUK » Mon Sep 16, 2013 6:06 pm

But it uses all these instead of just Newton.h

#include "StdAfx.h"
#include "Entity.h"
#include "FindFloor.h"
#include "TutorialCode.h"
#include "SoundManager.h"
#include "SceneManager.h"
#include "RigidBodyUtil.h"
#include "CollisionShapeUtil.h"
#include "CollectInputAndUpdateCamera.h"

which i'm sure some need C++ and i'm looking to use C.. So i need *simplistic* stuff? Are there any? You think it's basically impossible to use Newton in C?
3TATUK
 
Posts: 22
Joined: Thu Sep 05, 2013 11:55 pm

Re: Simplistic Source Example?

Postby Sweenie » Tue Sep 17, 2013 2:45 am

What about the piece of code you mentioned in the other thread?
http://newtondynamics.com/wiki/index.ph ... _C_example
That code should work, just change the NewtonCreateBody to NewtonCreateDynamicBody
The other functions in that example are valid and it seemed more that you had some missing reference or linker error.
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Simplistic Source Example?

Postby 3TATUK » Thu Sep 19, 2013 10:21 am

Those references are still missing. I'm linking only libNewton.a which is all that I assume I need - but it's built with Julio's new mingw32 project files and I'm guessing it outputs a broken/corrupt lib :/
3TATUK
 
Posts: 22
Joined: Thu Sep 05, 2013 11:55 pm

Re: Simplistic Source Example?

Postby JoeJ » Thu Sep 19, 2013 2:04 pm

That simple c example should work indeed and is much simpler than what i suggested, and libNewton.a should contain all functions from newton.h.
3TATUK wrote:Those references are still missing

Any newton function? Can you post compiler messages and your code?
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Simplistic Source Example?

Postby 3TATUK » Thu Sep 19, 2013 7:58 pm

Again, I think the libNewton.a created by the new mingw32 files is broken... Hopefully Julio can help test/fix them? :P

Code:

Code: Select all
#include <stdio.h>
#include <stdbool.h>
#include "Newton.h"

void   applyForceAndTorque (const NewtonBody* const body, dFloat timestep, int threadIndex)
{
   float   gravity      =   -9.8f;
   float   mass, ix, iy, iz;
   NewtonBodyGetMassMatrix(body, &mass, &ix, &iy, &iz);
   
   float   force[4]   =   { 0.0f, gravity * mass, 0.0f, 1.0f };
   NewtonBodySetForce(body, force);
}

int main (int argc, const char * argv[])
{
   float            const   initialTM[16]   =   { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
   
   NewtonWorld*      const   world      =   NewtonCreate();
   NewtonCollision*   const   collision   =   NewtonCreateBox(world, 10, 10, 10, 0, NULL);
   NewtonBody*         const   body      =   NewtonCreateDynamicBody(world, collision, initialTM);
   NewtonBodySetForceAndTorqueCallback(body, applyForceAndTorque);
   NewtonBodySetMassMatrix(body, 10, 1, 1, 1);
   
   for   (int i=0; i<100; i++)
   {
      NewtonUpdate(world, 1/60);
      float   newTM[16];
      NewtonBodyGetMatrix(body, newTM);
      printf("iteration = %d, position = %f, %f, %f\n", i, newTM[12], newTM[13], newTM[14]);
   }
   
   NewtonDestroyAllBodies(world);
   NewtonDestroy(world);

   printf("Hello, World!\n");
   return 0;
}


Compile line:

Code: Select all
gcc -std=c99 -l:libs/newton/coreLibrary_300/projects/mingw32/libNewton.a -Ilibs/newton/coreLibrary_300/source/newton/ test.c


Output:

Code: Select all
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x5a): undefined reference to `_imp__NewtonBodyGetMassMatrix'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x97): undefined reference to `_imp__NewtonBodySetForce'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x159): undefined reference to `_imp__NewtonCreate'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x19c): undefined reference to `_imp__NewtonCreateBox'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x1c7): undefined reference to `_imp__NewtonCreateDynamicBody'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x1e7): undefined reference to `_imp__NewtonBodySetForceAndTorqueCallback'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x21c): undefined reference to `_imp__NewtonBodySetMassMatrix'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x243): undefined reference to `_imp__NewtonUpdate'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x25c): undefined reference to `_imp__NewtonBodyGetMatrix'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x2b0): undefined reference to `_imp__NewtonDestroyAllBodies'
C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o:test.c:(.text+0x2c1): undefined reference to `_imp__NewtonDestroy'
d:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\DOCUME~1\ZTATIK~1\LOCALS~1\Temp\cc2PyurB.o: bad reloc address 0x20 in section `.eh_frame'
d:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
3TATUK
 
Posts: 22
Joined: Thu Sep 05, 2013 11:55 pm

Re: Simplistic Source Example?

Postby Sweenie » Fri Sep 20, 2013 2:26 am

Maybe it's linking the lib as a dll instead of a static lib.
Make sure NEWTON_API isn't declared as __declspec (dllimport)
Not sure how gcc works but adding -D_NEWTON_STATIC_LIB to your compile line might work.
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Simplistic Source Example?

Postby 3TATUK » Fri Sep 20, 2013 5:43 am

Cool, maybe a little better... But:

Code: Select all
libs/newton/coreLibrary_300/projects/mingw32/libNewton.a(Newton.o): In function `NewtonMeshSimplify':
c:\Documents and Settings\Ztatik Oh Light\Desktop\Hexer\libs\newton\coreLibrary_
300\projects\mingw32/../../source/newton/Newton.cpp:7907: undefined reference to `dgMeshEffect::CreateSimplification(int, bool (*)(float)) const'
libs/newton/coreLibrary_300/projects/mingw32/libNewton.a(dgCollisionConvexHull.o): In function `ZN21dgCollisionConvexHull6CreateEiiPKff':
c:\Documents and Settings\Ztatik Oh Light\Desktop\Hexer\libs\newton\coreLibrary_300\projects\mingw32/../../source/physics/dgCollisionConvexHull.cpp:345: undefined reference to `dgObb::SetDimensions(float const*, int, int, dgMatrix const*)'
libs/newton/coreLibrary_300/projects/mingw32/libNewton.a(dgPolyhedra.o): In function `ZNK11dgPolyhedra15CalculateSphereEPKdiPK8dgMatrix':
c:\Documents and Settings\Ztatik Oh Light\Desktop\Hexer\libs\newton\coreLibrary_300\projects\mingw32/../../source/core/dgPolyhedra.cpp:1911: undefined reference to `dgObb::SetDimensions(float const*, int, int const*, int, dgMatrix const*)'
c:\Documents and Settings\Ztatik Oh Light\Desktop\Hexer\libs\newton\coreLibrary_300\projects\mingw32/../../source/core/dgPolyhedra.cpp:1940: undefined reference to `dgObb::SetDimensions(float const*, int, int const*, int, dgMatrix const*)'
collect2.exe: error: ld returned 1 exit status
3TATUK
 
Posts: 22
Joined: Thu Sep 05, 2013 11:55 pm

Re: Simplistic Source Example?

Postby Julio Jerez » Fri Sep 20, 2013 6:41 am

On these errors

c:\Documents and Settings\Ztatik Oh Light\Desktop\Hexer\libs\newton\coreLibrary_300\projects\mingw32/../../source/core/dgPolyhedra.cpp:1911: undefined reference to `dgObb::SetDimensions

the file dgObb was added recently and is missing on the make file, I added it now, please sync again
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Simplistic Source Example?

Postby 3TATUK » Fri Sep 20, 2013 8:40 am

Code: Select all
Newton.cpp:7907: undefined reference to `dgMeshEffect::CreateSimplification(int, bool (*)(float)) const'
3TATUK
 
Posts: 22
Joined: Thu Sep 05, 2013 11:55 pm

Re: Simplistic Source Example?

Postby Julio Jerez » Fri Sep 20, 2013 9:05 am

that function is there.
..\coreLibrary_300\source\meshUtil\dgMeshEffect.h
dgMeshEffect* CreateSimplification (dgInt32 maxVertexCount, dgReportProgress reportProgressCallback) const;
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Simplistic Source Example?

Postby 3TATUK » Fri Sep 20, 2013 9:42 am

Okay, i fixed it by making a couple changes, first in Newton.cpp...

At the top, add:
Code: Select all
#include "../meshUtil/dgMeshEffect.h"


and then change line 7908 from:

Code: Select all
   return (NewtonMesh*) ((dgMeshEffect*) mesh)->CreateSimplification (dgInt32 (maxVertexCount), (dgReportProgress) progressReportCallback);


to:

Code: Select all
   return (NewtonMesh*) ((dgMeshEffect*) mesh)->CreateSimplification ((dgInt32) maxVertexCount, (dgReportProgress) progressReportCallback);


now works... So... how to create character-triangleMesh collisions? ^_^

this I guess: http://newtondynamics.com/wiki/index.ph ... _Collision
3TATUK
 
Posts: 22
Joined: Thu Sep 05, 2013 11:55 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron