CompoundCollision tutorial using current tutorial framework

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

CompoundCollision tutorial using current tutorial framework

Postby misho » Thu Sep 02, 2010 11:12 am

I asked for this in the general forum, and I'll give it another shot here:

Is it possible to create a CompoundCollision tutorial into the tutorial library, using the current tutorial framework (i.e. using Entity class)? Please?

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: CompoundCollision tutorial using current tutorial framework

Postby Julio Jerez » Thu Sep 02, 2010 1:30 pm

But I beleive one of the demos uses compound shape.
I thonk is the one that demostarte the sound integration,
Advance marterial.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: CompoundCollision tutorial using current tutorial framework

Postby misho » Thu Sep 02, 2010 3:08 pm

Hi Julio,

Yes, you are correct - that tutorial utilizes NewtonCreateCompoundCollision by adding sub-meshes inside DAT file into the compound collision. The example of DAT file with sub-meshes is "dumb.dat" (I presume, dumbell) that has 3 sub meshes: Two spherical weighs and one handle. That indeed creates a correct compound collision object for that particular object with sub-meshes, through a utility function CreateNewtonCompoundFromEntitySubmesh

What I would like to see is a tutorial oh now to create Compound Collision from separate entities, something like

CreateNewtonCompoundFromEntityList(NewtonWorld* world, Entity* const entArray[], ...)

I know you said that the Entity class is for illustration purposes and it shouldn't be used for anything except understanding tutorials, but I think Compound Collisions are a wonderful and essential feature of NGD, and a tutorial that would illustrate creating compound collisions from separate entities would go a long way in demomnstrating this particular feature.

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: CompoundCollision tutorial using current tutorial framework

Postby Stucuk » Thu Sep 02, 2010 4:08 pm

NGD is a physics library not a General Purpose Engine. People should be learn how to use newton rather than someones entity system, so they can then make any modifications they want. If you rely on someone elses then you will be relying on them telling you how to modify it to do what you want. Personally i think it would be better if the tutorials didn't rely on "complex" systems, but showed people the raw basics so they can easily see how to do what they want themselves without someone elses vision of a system.

To create a compound all you do is first create the collisions you want with NewtonCreateBox\NewtonCreateSphere\NewtonCreateTreeCollision\NewtonCreateCone\Etc and then pass them in an array to NewtonCreateCompoundCollision . Then you just create the body from the compound you get.

Basic Example:
Code: Select all
function CreateCompoundCollision : PNewtonBody;
var
X : Integer;
Collisions : Array [0..5] of PNewtonCollision;
Compound : PNewtonCollision;
begin
  //Setup 6 Collisions
  for X := 0 to 5 do
  Collisions[X] := NewtonCreateBox(World,1,1,1,0,Nil);

  //Create Compound
  Compound := NewtonCreateCompoundCollision(World,6,@Collisions[0],0);

  //Create Body
  Result := NewtonCreateBody(World,Compound);

  //Release Collisions
  for X := 0 to 5 do
  NewtonReleaseCollision(World,Collisions[X]);
  NewtonReleaseCollision(World,Compound);
end;
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: CompoundCollision tutorial using current tutorial framework

Postby misho » Thu Sep 02, 2010 5:00 pm

Thanks Stucuk - first of all, the only reason I am asking for this is because I'm lazy :mrgreen: and I don't want to re-invent the wheel if someone already covered this. I am perfectly clear on putting a compound collision together, however, compound collision as such is only a collection of collision primitives clumped together. A Newton body that is created from such a collection can have a pointer to only one visual Entity. What I am asking for is the mechanism of tying those collision primitives back to their separate entities, so that they all display properly. For example:

Let's say I want to use tutorial framework and tie two boxes, Frowny and Smilly, into a Compound Collision. The boxes would be visually next to each other, at some small distance (much like the dumb.dat object, but withouth the middle handle)

Creating Compound Collision from two box primitives is fairly easy, but tying each one of those primitives to the separate Entity class (visual cubes), so that they "follow" their collision boxes is what I was asking for. Obviously, I will have to write some functionality that will poll the collision primitives in the Compound collision and adjust the position and orientation of the entities associated with them. I am perfectly happy to do this myself, I was just wondering if anyone else had a solution already, or if Julio was thinking of adding it to the tutorial collection!

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: CompoundCollision tutorial using current tutorial framework

Postby Stucuk » Thu Sep 02, 2010 6:13 pm

If you want a Generic solution you just need to have one Main Class which holds sub classes.

I.E
Code: Select all
TSubObject = Class(TObject)
public
 function BuildCollision : PNewtonCollision; Virtual;
 procedure Draw; Virtual;
end;

TCube = Class(TSubObject)
public
 constructor Create(X,Y,Z : Single; SizeX,SizeY,SizeZ : Single);
 function BuildCollision : PNewtonCollision; override;
 procedure Draw; override;
end;

TSphere = ...


Code: Select all
TEntity = Class(TObject)
private
 FBody         : PNewtonCollision;
 FSubObject : Array of TSubObject;
public
 procedure AddSubObject(SubObject : TSubObject);
 procedure Draw; //Calls all sub classes Draw
 procedure BuildCollisions; //Calls all sub classes BuildCollision and creates a compound collision if there is more than one
end;


Thats the basic class outline. You would create the TCube and then pass it to the TEntity's AddSubObject, which would add it to the FSubObject List. As the TCube uses virtuals you can treat it like a TSubObject and it will use the TCube's stuff. The BuildCollisions would get the collisions from the subobjects and would create the body (Thus its only ever got the userdata of the TEntity). When TEntity is drawn it calls all the subobjects and thus you have the object rendered correctly.

You can expand the TEntity by making Children classes which inherit its stuff, so you can then have a TWaterTower and a TMouseMat with different properties but which still have the basic functionality of the Entity.

P.S Before you ask i can't provide C++ code as its not my main language.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: CompoundCollision tutorial using current tutorial framework

Postby Julio Jerez » Thu Sep 02, 2010 6:25 pm

misho what Stucuk is talking about in CPP is supported in the SDK,
there is a data structure in the newton SDK called dHierarchy the can help with that, with very litle effort.
basically all you have to do is subclass the entity and the dHierarchy together, somethimg like

Code: Select all
#include "Entity.h"
#include "dBaseHierarchy.h"

class MyModel: public dHierarchy <Entity>
{
   // add whate vet you wnat here.
   NewtonBody* my physic
      ...
}

by doing that you can have hierarchies of entire that are all children of the same parent, for example a Table can be the top, and four children ass the legs.

Then all you have to do i to figure out what kind of collision the body of that model will have,
a Table must likely will has a compound collision made of the table top, and all the child legs,
a rag doll will be each child it own body, a single body will be just a root node, with convex shape, a mesh level one or more entities all grouped by a collision tree at the root, and so on.

Check out the class dHierarchy in the dContatiner library of the SDK, the dBone class in and example of how it can be used to make hierachical structures.

The entity class is no bad, it is just that I made liek that to avoid the complexity of chlidern, and parent that confuse some people.
but if you make it part of a scene node hiearchy like the dHierarchy,
then it is a full blown game engine Scene Graph Node Entity, with support for meshes, sub meshes, material, children and parents.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: CompoundCollision tutorial using current tutorial framework

Postby misho » Sat Sep 04, 2010 1:32 am

Stucuk, Julio - Thanks again! I didn't look into SDK much but now I see it has everything I need.

Incidentally, once again, I have no luck loading the NewtonDemos_2009.sln (SDK Demos) projects into Visual Studio 2010 Express. The solution wizard is giving me errors on each project. Julio, is it possible to fix these so that 2010 can load them? I had the problem with tutorials which you fixed since, but these errors are different.

Thanks,
Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: CompoundCollision tutorial using current tutorial framework

Postby misho » Tue Sep 07, 2010 11:08 am

Hi julio - not sure if my last question was missed, but I was wondering if SDK examples (the ones in C:\Newton\NewtonWin-2.24\samples\sdkDemos) are meant to be compilable. I have had no luck in converting the solution through Microsoft Visual C++ 2010 Express. Any hints or ideas?

thankns,
Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: CompoundCollision tutorial using current tutorial framework

Postby Stucuk » Tue Sep 07, 2010 11:11 am

As there in 2009 not 2010, they weren't designed to be compiled with 2010. Don't quote me, but i think 2010 changes some stuff (Compiler wise) so not everything created with previous versions will compile without changes made to them.

I don't think the 2.24 demos(Or at least all of them) can compile, AFAIK Julio still hasn't fully converted them to use a new file format.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: CompoundCollision tutorial using current tutorial framework

Postby Julio Jerez » Tue Sep 07, 2010 11:53 am

Stucuk wrote:As there in 2009 not 2010, they weren't designed to be compiled with 2010. Don't quote me, but i think 2010 changes some stuff (Compiler wise) so not everything created with previous versions will compile without changes made to them.

is that true?
I tryed the SDK demos with VS2010 beta, but since then I have not tryed.
anyway I will convert the VS2003 projects to VS 2008, and remove all version prior to 2008
This is because I updated to Window 7, and finally VS2003 does no works noce with win7.
Every time I compiled a project with VS2003 the next time I have to quick and restart VS because it says the file .pdb is read only.
It appears is a bug related to Vista and Window 7 and Vs 2003 that Microsft will not fix, thefore I have to let go of VS2003.

I am hoping the VS2010 can Import VS2003 projects, because it will be a Bone headed move from Microsof to cut support to the previus ide
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: CompoundCollision tutorial using current tutorial framework

Postby Stucuk » Tue Sep 07, 2010 1:13 pm

I could be thinking of an older version of VS. In any case, you generally get some differences in different versions of compilers which can break some things. So there is never any garentee that loading and older VS Solution will compile perfectly in a newer version.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: CompoundCollision tutorial using current tutorial framework

Postby misho » Tue Sep 07, 2010 2:53 pm

Ok - thanks guys. I am running Win 7 and VS 2010. I can send you the errors resulting from the attempt to use a Solution Wizard and load a VS2008 Solution in VS2010.

I would love to be able to load (and compile :mrgreen: ) these - Julio, please let me know if you'll be attempting a fix and provide a 2010 version of a SDK project, or if I should keep trying myself.

Thanks again
Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: CompoundCollision tutorial using current tutorial framework

Postby Julio Jerez » Wed Sep 08, 2010 10:01 am

Ok the wiki tutorial are converted to to Vs 2008, I do not remember if it was you who asked, but for they they are.

for now on the lowest version of Visual studio is VS 2008,
it should be very simple to import the project into VS 2010, I will not not that because I do not have time to spend now.

Note:
The Raycast is not working when I did the coneversion, this may be because of the stuff I am working now, but I cannot debug at this time.
or it could also be beacuse of what was said about sleeping bodies no weaking up after they go to sleep. I have to find out what it is as soon as I have the demos running.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: CompoundCollision tutorial using current tutorial framework

Postby misho » Wed Sep 08, 2010 11:22 pm

Julio Jerez wrote:Ok the wiki tutorial are converted to to Vs 2008, I do not remember if it was you who asked, but for they they are.

for now on the lowest version of Visual studio is VS 2008,
it should be very simple to import the project into VS 2010, I will not not that because I do not have time to spend now.

Note:
The Raycast is not working when I did the coneversion, this may be because of the stuff I am working now, but I cannot debug at this time.
or it could also be beacuse of what was said about sleeping bodies no weaking up after they go to sleep. I have to find out what it is as soon as I have the demos running.


Hi Julio - it was indeed me who pointed out errors in the tutorial package ("d" in front of "JointLibrary.dll" and a few other small things) and I subsequently fixed that myself and got the whole TUTORIAL package to compile OK in 2010.

However, here I am talking about SDK examples/demos, NOT tutorials. SDK examples come with the Newton Package, NewtonDemos_2009.sln. I'd like to be able to compile these in VS2010 Express. Is that what you've fixed for 2008, and it should be easily converted to 2010?

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 143 guests