NewtonWorldConvexCast

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonWorldConvexCast

Postby dezzie64 » Mon Sep 29, 2008 10:27 pm

I've been looking at the NewtonWorldConvexCast because it'll be really useful for some of the stuff I want to build into a game, the problem is that we're not entirely sure about what each of the function parameters is used for and what values to put in... I can't find anything online, could someone please give me an idea of how it works?
dezzie64
 
Posts: 3
Joined: Mon Sep 29, 2008 10:19 pm

Re: NewtonWorldConvexCast

Postby Julio Jerez » Mon Sep 29, 2008 10:58 pm

take a look at the function in file Physics utils

Code: Select all
void ConvexCastPlacement (NewtonBody* body)
{
   dFloat param;
   dMatrix matrix;
   NewtonWorld* world;
   NewtonCollision* collision;
   NewtonWorldConvexCastReturnInfo info[16];

   NewtonBodyGetMatrix (body, &matrix[0][0]);

   matrix.m_posit.m_y += 20.0f;
   dVector p (matrix.m_posit);
   p.m_y -= 40.0f;

   world = NewtonBodyGetWorld(body);
   collision = NewtonBodyGetCollision(body);
   NewtonWorldConvexCast (world, &matrix[0][0], &p[0], collision, &param, body, ConvexCastCallback, info, 16);
   _ASSERTE (param < 1.0f);

   matrix.m_posit.m_y += (p.m_y - matrix.m_posit.m_y) * param;

   NewtonBodySetMatrix(body, &matrix[0][0]);
}



int NewtonWorldConvexCast (const NewtonWorld* newtonWorld, const dFloat* matrix, const dFloat* target, const NewtonCollision* shape, dFloat* hitParam, void* userData,
NewtonWorldRayPrefilterCallback prefilter, NewtonWorldConvexCastReturnInfo* info, int maxContactsCount);

Matrix is the intiail position of the shape,
target is the final destination
shape is the collision shape, it must be a convex shape
hitParam, is a poinet to a float that will hold parametyer o fteh line for matrix.posit ot dest posit at wid teh hiot happens
userdata is a poinet to use data you will get in eth call back.
prefilter is a function call baklc teh you can sue to reject object the you wna to be invisible to the collision.
maxcount is the total maximun number of contact to be calculated.

the funtion return the contac count.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWorldConvexCast

Postby dezzie64 » Mon Sep 29, 2008 11:47 pm

What we have is a player model drawn inside a bounding Cylinder which is being used as a collision box for the player. What we're trying to do is cast a cylinder shape down under the player to use as a findfloor function. We got a raycastfilter working perfectly except it was only launching a ray down in the middle of the players bounding cylinder, meaning if you were on a slope, or out over the edge of a platform slightly, it wouldn't work.

Do you think using a convexcast is the best way to do a findfloor function in this case? The problem we're having at the moment is that this convex cast is finding no contacts at all even when running along the ground. Appreciate your help.
dezzie64
 
Posts: 3
Joined: Mon Sep 29, 2008 10:19 pm

Re: NewtonWorldConvexCast

Postby dezzie64 » Tue Sep 30, 2008 1:13 am

Nevermind, got it working. Our precast filter was the problem, thanks for your help
dezzie64
 
Posts: 3
Joined: Mon Sep 29, 2008 10:19 pm

Re: NewtonWorldConvexCast

Postby KiwiCoder » Thu Jun 18, 2009 4:39 am

Hi there,

I'd like to use NewtonWorldConvexCast() to check if there's something in front of my object.
What I'm doing is:

const int MAX_CONTACTS = 16;
dFloat matrix[16];
NewtonWorldConvexCastReturnInfo info[MAX_CONTACTS];

NewtonBodyGetMatrix(body, &matrix[0]);
NewtonCollision *sensorShape = NewtonCreateCone(world, 4*kFixRad, 20*kFixRad, NULL);
contacts = NewtonWorldConvexCast(world, &matrix[0], &matrix[0], sensorShape, &param, NULL, NULL, info, MAX_CONTACTS, 0);


However, it fails to return the objects I would expect it to return..
Is there something fundamentally wrong with my code?

thanks,
KC
KiwiCoder
 
Posts: 15
Joined: Thu Jun 11, 2009 4:39 pm

Re: NewtonWorldConvexCast

Postby Julio Jerez » Thu Jun 18, 2009 9:00 am

KiwiCoder wrote:contacts = NewtonWorldConvexCast(world, &matrix[0], &matrix[0], sensorShape, &param, NULL, NULL, info, MAX_CONTACTS, 0);


int NewtonWorldConvexCast (const NewtonWorld* newtonWorld, const dFloat* matrix, const dFloat* target, const NewtonCollision* shape, dFloat* hitParam, void* userData,
NewtonWorldRayPrefilterCallback prefilter, NewtonWorldConvexCastReturnInfo* info, int maxContactsCount, int threadIndex);


matrix is the starting position and orinetation of the shape,
target is a vector, and it is the destination of the cast.

the position past of matrix, and target detrmine the ray alone the shape casting.
I would use a thin cylinder and no a cone as teh casting shape.
Maybe a convex hull like it is use in ray cast car.
you are pasing matrix and target wich mean it will use the first row as a vector, and I am sure the is wrong.

why don't you use a simpler function, like for all object in AABB?
I would use sometion like this:
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWorldConvexCast

Postby JernejL » Thu Jun 18, 2009 12:51 pm

Julio thanks for the good description for convex cast function, i created a wiki page for it, can you give me any corrections for any errors i might have made? link: NewtonWorldConvexCast
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWorldConvexCast

Postby KiwiCoder » Thu Jun 18, 2009 8:47 pm

why don't you use a simpler function, like for all object in AABB?
I would use sometion like this:


Hmm.. something was snipped off.

Well, I'm trying to simulate objects hit by something like an ultrasonic sensor, so I'd need some sort of code.
Altough, thinking about it, I could optionally approximate the cone using a series of AABB boxes growing in diameter..

Cheers,
KC
KiwiCoder
 
Posts: 15
Joined: Thu Jun 11, 2009 4:39 pm

Re: NewtonWorldConvexCast

Postby Julio Jerez » Thu Jun 18, 2009 10:16 pm

No, no

what I say is teh to use convex cast you need to knwo the direstion of castiong.
if you know it, teh yo ucna cast a shape.

But you need to kwon how the shape must be oriented, if you want or need a cone that is fine, but you need to calculate and matrix so the cone in properly oriented alone the cast ray,
if you cast a sphere teh you do not need to worry about the orientions.

The SDK comes with convex cast demo that show different shape being casted. had you test that?
It will give you and idea how it works.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWorldConvexCast

Postby KiwiCoder » Fri Jun 19, 2009 11:58 pm

After some fooling around with the matrices everything now works like a breeze!
I'm using the cone collision shape and matrix == target, i.e. just detecting the objects within the cone shape at the current position w/o moving it around.

BTW, what does the threadIndex parameter do..?

NewtonWorldConvexCast (const NewtonWorld* newtonWorld, const dFloat* matrix, const dFloat* target, const NewtonCollision* shape, dFloat* hitParam, void* userData, NewtonWorldRayPrefilterCallback prefilter, NewtonWorldConvexCastReturnInfo* info, int maxContactsCount, int threadIndex);


Thanks for the help!

Cheers,
KC
KiwiCoder
 
Posts: 15
Joined: Thu Jun 11, 2009 4:39 pm

Re: NewtonWorldConvexCast

Postby Julio Jerez » Sat Jun 20, 2009 1:53 am

KiwiCoder wrote:BTW, what does the threadIndex parameter do..?


if you are calling a funtion outside a newton update, the thread index is not important, you can pass zero.
but let use say you are calling a funtion from a callback (a collsion callback for example), since newton can be set to work in muttreaded more, it is possible that one callback is action on one body, and another in anothe body at the same time.
in that case if you are saving data into some gloval array, the you can use teh index to adress an array entry, rather tha adding teh data to the body.

You can see an example of that in the raycast car, when the car is working with multitreaded mode upto 4 car can be solved at the same time with out having to complicate the code with extrat local data in each car for collectiong the convex cast information.

in your case you can just pass zero if you are not using threads.
you can also call any those functions from your own thread system, there are pure re-entant.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWorldConvexCast

Postby KiwiCoder » Sat Jun 20, 2009 6:12 pm

I see!

Thanks,
KC
KiwiCoder
 
Posts: 15
Joined: Thu Jun 11, 2009 4:39 pm

Re: NewtonWorldConvexCast

Postby JernejL » Sat Jun 20, 2009 7:24 pm

Julio: the more i look at this function.. the more suitable it seems to be for me for shadow geometry projection, would it be hard to add target scaling to this function? if the function can use a compound collision, this could literally be used to create complex projected shapes that touch the ground, getting a sillhuette out of resulting vertex cloud and triangulating it shouldnt be hard, and by caching the resulting geometry, this would be great to use with complex projected shadows!

Convex casting with target scaling would be also also useful for detecting AI field of view, as this is usually a frustum like shape.

EDIT: i wrote a wiki page about the threadindex, i hope the information there is easier to find, i will add links to it to all callbacks and functions that use it.
http://newtondynamics.com/wiki/index.ph ... hreadIndex
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWorldConvexCast

Postby Marc » Thu Oct 22, 2009 10:23 am

Hi !

Im trying to use this function - but somehow the returned ReturnInfos are wrong for me. I created a small test that recreates the issue - but I'm not entirely sure the function is supposed to do what I think it's doing.

Well. Here is my example: It creates a NewtonWorld, adds a sphere (collision and body) of radius 5 at (10,10,15). Then it creates a collision of another sphere of radius 2 and it does a NewtonWorldConvexCast() of that sphere through the scene from (10,10,10) to (10,10,10). (I'm not sure if this is supposed to work, but the result is similar strange if I try (10,10,10.01) as the target). This should place the center of the 2nd sphere at the border of the first sphere and therefore, I thought, return a collision. But it returns 0 collisions for me. I tried it with newton 2.08 as well as 2.10 -same result.

Here is the code doing the above:
Code: Select all
   float worldbb[6];
   NewtonWorld * nWorld;

   worldbb[0] = -100;
   worldbb[1] = -100;
   worldbb[2] = -100;
   worldbb[3] = 100;
   worldbb[4] = 100;
   worldbb[5] = 100;


   // create world
   nWorld = NewtonCreate(0, 0);
   
   NewtonSetThreadsCount(nWorld, 1);
   NewtonSetPlatformArchitecture(nWorld, 0);
   NewtonSetMultiThreadSolverOnSingleIsland(nWorld, 0);
   NewtonSetSolverModel(nWorld, 1);
   NewtonSetFrictionModel(nWorld, 1);
   
   NewtonSetWorldSize(nWorld, worldbb, worldbb + 3);


   // create sphere
   NewtonCollision * col = NewtonCreateSphere(nWorld, 5, 5, 5, 0, 0);

   float p[16];
   int i;
   for (i = 0; i < 16; ++i)
   {
      p[i] = 0;
   }
   p[0] = 1;
   p[5] = 1;
   p[10] = 1;
   p[15] = 1;
   p[12] = 10;
   p[13] = 10;
   p[14] = 15;

   NewtonBody * body = NewtonCreateBody(nWorld, col);
   
   NewtonReleaseCollision(nWorld, col);

   NewtonBodySetMatrix(body, p);


   // collision
   col = NewtonCreateSphere(nWorld, 2, 2, 2, 0, 0);

   for (i = 0; i < 16; ++i)
   {
      p[i] = 0;
   }
   p[0] = 1;
   p[5] = 1;
   p[10] = 1;
   p[15] = 1;
   p[12] = 10;
   p[13] = 10;
   p[14] = 10;


   float hitparam;
   NewtonWorldConvexCastReturnInfo returninfo[128];
   int returninfon = NewtonWorldConvexCast(nWorld, p, p, col, &hitparam, 0, 0, returninfo, 128, 0);
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: NewtonWorldConvexCast

Postby Julio Jerez » Thu Oct 22, 2009 7:46 pm

int returninfon = NewtonWorldConvexCast(nWorld, p, p, col, &hitparam, 0, 0, returninfo, 128, 0);

It looks to me the origin and destination are teh same vector, but they must be diffrent object, one is a matrix and teh secudn is a target position (a vector).
the position in teh matrixis the last row (10, 10, 10)
for the seucund argument the vector will be the values 1, 0, 0 wich are the in matrix p
so it is casting from (10, 10, 10) to (1, 0, 0)
and I am sure tha is not what you want.
Basically it is moving in the opposite direction and down to want you want.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
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 0 guests

cron