Question about Collision Handling

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Question about Collision Handling

Postby Corgi » Fri Feb 17, 2012 9:01 pm

Hi all,
I've just recently discovered Newton and I'm still figuring out how to do what. So far this seems to be a most excellent piece of software!

I'm trying to make a simple demo application where a user can place blocks of various shapes. (like this)
This works pretty well without much effort. The problem I have is this: I don't want the user to be able to spawn a block inside another block or the ground.
I figured, for a selected position I need to check if the collision primitive of the new block would collide with any of the collision primitives already in the world.

I looked around the forum and wiki and came up with a sollution using the functions NewtonCollisionCollide and NewtonCollisionCalculateAABB. That sollution is a little limited because I need a list of all blocks already added to the world. And even then I cannot detect spawning a block inside the ground...
Of course I could pass a reference to all static collision primitives (and their offset matrices) to my block class, but is there a better way?

Another thing I want to do is to select blocks. I would use NewtonCollisionRayCast again with all collision primitives I want to be selectable right?
Im going to try that tomorrow I think.

Any hints are very much appreciated!
Corgi
 
Posts: 3
Joined: Fri Feb 17, 2012 8:14 pm

Re: Question about Collision Handling

Postby Julio Jerez » Fri Feb 17, 2012 9:36 pm

you can get the AABB of the new shape you wnat to place in teh world, then you can call function NewtonWorldForEachBodyInAABBDo,
and in the call back you can call NewtonCollisionCollide
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Question about Collision Handling

Postby Corgi » Mon Feb 20, 2012 8:15 am

That was exactly what I was looking for, works very well.

I've got a second question: What would be the best way to represent this shape as collision primitive:
Image

It should be possible to approximate the shape with several Convex Hull Primitives in a Compound. Thats pretty much the only way right?
Last edited by Corgi on Mon Feb 20, 2012 8:44 am, edited 1 time in total.
Corgi
 
Posts: 3
Joined: Fri Feb 17, 2012 8:14 pm

Re: Question about Collision Handling

Postby Julio Jerez » Mon Feb 20, 2012 8:24 am

is that a 2d shape or is that a cross section of a 3d shape?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Question about Collision Handling

Postby Corgi » Mon Feb 20, 2012 8:45 am

Its a cross section of a 3d shape, I have edited the post for clarity.
Corgi
 
Posts: 3
Joined: Fri Feb 17, 2012 8:14 pm

Re: Question about Collision Handling

Postby Julio Jerez » Mon Feb 20, 2012 9:19 am

if you are using Newtopn 300, it is ver eassy.
you can make a newtopnMesh, and then call create compound, and it will make a near perfect conve decomposition
these are the funtions.

Code: Select all
   // create a convex approximation form the original mesh, 32 convex max and no more than 100 vertex convex hulls
   NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (newtonMesh, 0.01f, 0.2f, 32, 100, NULL);

   // create a compound collision by creation a convex hull of each segment of the source mesh
   NewtonCollision* const compound = NewtonCreateCompoundCollisionFromMesh (world, convexApproximation, 0.001f, 0, 0);


see demo ..\applications\newtonDemos\sdkDemos\demos\ConvexApproximation.cpp


if the object is static then you can simple make it a collision tree.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
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 1 guest