Source Code for Newton 2.00

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Source Code for Newton 2.00

Postby Julio Jerez » Tue Oct 16, 2012 11:01 pm

michDS wrote:I'm curious, why doesn't the body go to sleep in the frictionless case, and why does it slide to the left?

a rational number is the ratio of two whole numbers.
There is something that is call round off errors when you have to express a rational number as a single floating point value.
bascially it is the fact that to represent a number exactly you need a finite number of digits, at some point you will have to truncate the value.
here is an example say you have the value x = 1 / 3
and you need to represent that value with 2 digits, your resutl is 0.33
now let us say you want to collect the original value by mutiplying by 3, the result is 0.99 not 1.0
if this was a dollar, every time you do that operation you lose one penny, if you do it tousands of millions of time, these error accumulate,
and soon your error are mush bigger than a penny,

in a numerical integration this manifesct as residual net forces acting on the body, it just happens that when the body hit the floor the forces are very close to zero, but not exactly zero because of the imposibility to calculate exact values.
these residual forces are passed to the integrator, and they add some momentum to the body,
after doing this in every step, the resul is that these residual moment get applied in a randome direction, but because there is not a not way to reduce any momentumn, the body migh gain in a lareg monetum that is not no neglegible.

when friction forces are present the error are still there, but each time that the becom large in any direction the calculated friction forces
do not let the momentum grow large enought, so there residual forces do no get amplyfied.

michDS wrote:My other question is about setting the inertia. If I pass an offset matrix when creating the cylinder collision (like you have done, and I also do this in my game), would the following inertia calculation be correct, or is this still wrong? I understand that newton 300 calculates this for you, but am wondering how I would do it correctly using newton 200:

dVector I;
float Mass = WEIGHT_MASS;
float Radius = WEIGHT_RADIUS;
float Height = WEIGHT_HEIGHT;
I.m_x = I.m_z = Mass*(3.0f*Radius*Radius+Height*Height)/12.0f;
I.m_y = Mass*Radius*Radius/2.0f;
NewtonBodySetMassMatrix(gPuckBody,Mass, I.m_x, I.m_y, I.m_z);
Thanks!


if you sit the offset matrix as a shape offset then the cylinder axis will be along the y axis, your calculation will be correct.
if you want to avoid have to determine the matrix alignment, you can use the function that compute the inertia matrix off the shape.
it should produce the exact same values you calculated, but with the corrrect order.
that is why I change the interface in core 300 to take a collision shape, many people were making that king of mistake.

with the new interface you can do things like setting a balling ball, and have it with the inertia of a cylinder inside.
in fact that is how balling ball are exactly made. they have a cylidrical shape made of a material of diffrent density than the ball outer layet

it is this feature that makes balling ball to have what the call Hook, basically after the ball rools for a while
the heavy cylidrincal act as a giro tha makes the ball change diretion because the inertia want to roll as a cylinder but the shape want to roll as a sphere.
In newton 300 you can do the same, make a spherical balling ball, then make a cylinder and set the ball inertia passing the cylidrical shape and the mass.
the by setting the friction, you should be able to make very realistic balling shot.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Source Code for Newton 2.00

Postby Julio Jerez » Wed Oct 17, 2012 11:31 am

for the thread crash, you did not tell me was system were you testing that? running on a thread is important for machine with muticore.
I beleiv many mobile now are also muticores.

basically it can give you the simulation for free if is run concurrenthr game main loop if teh simulation is less that teh game update.
you can test it in the demos by setting a complex demo and in the option menu set teh phsyics update to cuncurrent execution.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Source Code for Newton 2.00

Postby michDS » Wed Oct 17, 2012 5:30 pm

Ok, thanks for the explanation. Core 300 sounds really cool. In fact, we are also working on a bowling game right now so I'd really like to get it working for that. :)

For core 300, I'm compiling with Xcode 4.3.1 (LLVM compiler), and running on the iOS 5 simulator.

I uncommented DG_USE_THREAD_EMULATION, but now I get a crash in dgWorld::CalculateContacts. Basically contact is NULL. I have a stack trace below.
I also commented out #define DG_BUILD_SIMD_CODE in order to get it compiling.
Also, I had to provide a NewtonSetPerformanceClock to prevent it from crashing.

------------

#0 0x00083a2f in dgWorld::CalculateContacts(dgCollidingPairCollector::dgPair*, float, int) at dgNarrowPhaseCollision.cpp:1394
#1 0x00041b5d in dgBroadPhase::CalculatePairContacts(dgBroadphaseSyncDescriptor*, int) ()
#2 0x00043761 in dgBroadPhase::UpdateContactsKernel(void*, int) ()
#3 0x00032df2 in dgThreadHive::QueueJob(void (*)(void*, int), void*) ()
#4 0x00044039 in dgBroadPhase::UpdateContacts(float) ()
#5 0x000890bd in dgWorld::StepDynamics(float) ()
#6 0x000893a9 in dgWorld::Update(float) ()
#7 0x00039951 in Newton::UpdatePhysics(float) ()
#8 0x00035bca in NewtonUpdate ()
#9 0x0001d348 in WorldDynamicInterface::Update(float) ()
#10 0x00011cc0 in WorldDynamic::Update(float) ()
#11 0x00010334 in ShuffleWorld::Update(float) ()
#12 0x00013710 in MainLoop ()
#13 0x0001399d in -[ShuffleboardApp NextFrame] ()
#14 0x00defeb6 in __NSFireTimer ()
#15 0x00929936 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#16 0x009293d7 in __CFRunLoopDoTimer ()
#17 0x0088c790 in __CFRunLoopRun ()
#18 0x0088bd84 in CFRunLoopRunSpecific ()
#19 0x0088bc9b in CFRunLoopRunInMode ()
#20 0x02e817d8 in GSEventRunModal ()
#21 0x02e8188a in GSEventRun ()
#22 0x01690626 in UIApplicationMain ()
#23 0x00013066 in main ()
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Source Code for Newton 2.00

Postby Julio Jerez » Wed Oct 17, 2012 8:16 pm

do you have a mac test that you can provide, for me to try?
I have a Mac prop, but unfortunally Fox GUI does not compile in Mac os 10
But if I have a test app, it should be eassy for me to debug it.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Source Code for Newton 2.00

Postby michDS » Wed Oct 17, 2012 10:07 pm

I just sent you a PM where you can download my mac test project.

Thanks!
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Source Code for Newton 2.00

Postby michDS » Wed Oct 17, 2012 10:11 pm

FYI, here are some changes I made to get core 300 compiling for iOS:

1. dgWorld.cpp - commented out #include "dgOpenclInstance.h"
2. removed dgVehicleConstraint.cpp from project
3. dgTypes.h - commented out #define DG_BUILD_SIMD_CODE
4. dgThread.h - uncommented #define DG_USE_THREAD_EMULATION (was causing crash)
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Source Code for Newton 2.00

Postby Julio Jerez » Thu Oct 18, 2012 10:58 am

Ok I brought the Mac project uptoday.

The I dow load you demop and first I compleied and runnibng as it, to see where teh crash happen
I see tow demos,
-sandbox dem0 whic place a square on teh screen moving up and down
-the 10pinshffle which try to start and return back to teh destop righ away. is that teh bug. if if crash I am no getting any exeption


The first thing I wna to do do is to syn to svn and buiodl de demo w teh newer version, I updated the xcode project.
if it still crash, then upload the demo with this newton version of core 300 so that I debug it.
do not make any modification to that version, that way I can see what is incorrect in the engine
you can make your constomuazation after we figure out what is wrong, but teh engine must work out of the Box first.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Source Code for Newton 2.00

Postby michDS » Thu Oct 18, 2012 12:12 pm

Hi,

Please don't put the project up in svn because I don't want the code to be public.

Yes, the project is 10 Pin Shuffle.xcodeproj. It is for iOS. Are you trying to run it with the simulator? You should be getting an exception.
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Source Code for Newton 2.00

Postby michDS » Thu Oct 18, 2012 12:27 pm

Basically, you should:

1. Open 10 Pin Shuffle.xcodeproj with Xcode
2. Make sure "active scheme" on the upper left is set to iPhone 5.1 simulator"
3. Go to the menu "Product/Edit Scheme" and for the "Run 10 Pin Shuffle" action, make sure "Build Configuration" is set to Debug and debugger is GDB
4. Build and run. You should see a title screen come up on the simulator, and then a EXC_BAD_ACCESS
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Source Code for Newton 2.00

Postby Julio Jerez » Thu Oct 18, 2012 1:44 pm

not I did not put your game in SVN, I mean to update the NewtonSDN because I update the xcode project.

and yes I run the simulation, I did not see the 5.1 simulation but I will check again following those instructions.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Source Code for Newton 2.00

Postby michDS » Thu Oct 18, 2012 8:38 pm

Ah ok. Sounds good.
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Source Code for Newton 2.00

Postby michDS » Fri Oct 26, 2012 5:57 pm

Hi Julio,

Were you able to get a chance to try and get the iOS demo I sent you working with core 300?
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest