Minimal raycast test won't work.

Moderators: Sascha Willems, Thomas

Minimal raycast test won't work.

Postby FunkyJive » Tue Nov 02, 2010 1:47 pm

Not really sure what is going on here but I am trying to integrate newton into my current project for raycast selecting purposes (I don't need it for physics simulation). I tried to set up a minimal hello world raycast example but not getting any results. Any ideas of what I am doing wrong? Thanks in advance!

Here is the callback function. It is never printing the message and never getting to this callback.
Code: Select all
dFloat FilterRayCast(const NewtonBody* body, const dFloat* normal, int collisionid, void* userdata, dFloat intersetparam)
{
    printf("Hello world you hit me!\n");
    return intersetparam;
}


Here is the main function.
Code: Select all
NewtonWorld * world = NewtonCreate();
    float min[3];
    float max[3];
    for(int i=0; i<3; i++)
    {
        min[i] = -1000;
        max[i] = 1000;
    }

    NewtonSetWorldSize(world, min, max);
    NewtonCollision * col = NewtonCreateBox(world, 10.0, 10.0, 10.0, 1, NULL);
    NewtonBody * body = NewtonCreateBody(world, col);

    float point1[3];
    point1[0] = 50.0;
    point1[1] = 0.0;
    point1[2] = 0.0;
    float point2[3];
    point2[0] = -50.0;
    point2[1] = 0.0;
    point2[2] = 0.0;
    printf("Shooting the ray...");
    NewtonWorldRayCast(world, point1, point2, FilterRayCast, NULL, NULL);


I am using the latest windows version of newton.

Thanks again.
FunkyJive
 
Posts: 6
Joined: Wed Jun 17, 2009 1:42 pm

Re: Minimal raycast test won't work.

Postby Julio Jerez » Tue Nov 02, 2010 2:04 pm

yes I beleive there is a problem there, I have let that bug go for too long, it is time to fix it.
good you provided such simple demo, I will verify tonight
Thank you for the test.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Minimal raycast test won't work.

Postby FunkyJive » Tue Nov 02, 2010 2:17 pm

Glad I can help but this seems to be puzzling me also. I had used a previous version of Newton in a previous game and the raycasting worked perfect. So for this game, I got my old code and just did some updating on the function calls to meet the current requirements and it doesn't work now. I figured I forgot to copy something so I stripped the program down to this bare bones example and still no luck. Let me take a look back at what version I was using when the ray casting was working.

EDIT*

If it is any help here is the header of the version of newton I was using when it did work.

#ifndef NEWTON_H__736495_6495_076__INCLUDED_
#define NEWTON_H__736495_6495_076__INCLUDED_


#define NEWTON_MAJOR_VERSION 2
#define NEWTON_MINOR_VERSION 15
FunkyJive
 
Posts: 6
Joined: Wed Jun 17, 2009 1:42 pm

Re: Minimal raycast test won't work.

Postby Julio Jerez » Tue Nov 02, 2010 2:31 pm

The engine goes over optimization and new features in each new release.
for the most part I try to keep everything working bu some time a new optimization may create some side effect and break some funtionality.
Specially now that I changed the file format and many SDK demos are disabled, which prevent me from running the smoke test in each realease.

I am gessing I provably have some part commented out while working on something else and I forgot to re-enable it.
not to worry it should be very eassy to see what is wrong.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Minimal raycast test won't work.

Postby Julio Jerez » Wed Nov 03, 2010 9:26 am

Ok there was a bog in the ray cast, but it was not a raycast failure, it was that ray castion was reportion the wrong collision ID whne ray cation a shape.

This si the ray cat rotine for cation and collision Box in local space

Code: Select all
dgFloat32 dgCollisionBox::RayCast (
   const dgVector& localP0,
   const dgVector& localP1,
   dgContactPoint& contactOut,
   OnRayPrecastAction preFilter,
   const dgBody* body,   
   void* userData) const
{

   if (PREFILTER_RAYCAST (preFilter, body, this, userData)) {
      return dgFloat32 (1.2f);
   }


   dgInt32 index = 0;
   dgFloat32 signDir = dgFloat32 (0.0f);
   dgFloat32 tmin = dgFloat32 (0.0f);
   dgFloat32 tmax = dgFloat32 (1.0f);
   for (dgInt32 i = 0; i < 3; i++) {
      dgFloat32 dp = localP1[i] - localP0[i];
      if (dgAbsf (dp) < dgFloat32 (1.0e-8f)) {
         if (localP0[i] <= m_size[1][i] || localP0[i] >= m_size[0][i]) {
            return dgFloat32 (1.2f);
         }
      } else {
         dp = dgFloat32 (1.0f) / dp;
         dgFloat32 t1 = (m_size[1][i] - localP0[i]) * dp;
         dgFloat32 t2 = (m_size[0][i] - localP0[i]) * dp;

         dgFloat32 sign = dgFloat32 (-1.0f);
         if (t1 > t2) {
            sign = 1;
            Swap(t1, t2);
         }
         if (t1 > tmin) {
            signDir = sign;
            index = i;
            tmin = t1;
         }
         if (t2 < tmax) {
            tmax = t2;
         }
         if (tmin > tmax) {
            return dgFloat32 (1.2f);
         }
      }
   }

   if (tmin >= dgFloat32 (0.0f)) {
      _ASSERTE (tmin < 1.0f);
      contactOut.m_normal = dgVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
      contactOut.m_normal[index] = signDir;
      //contactOut.m_userId = SetUserData(); // Julio thsi was the Bug wrong collision ID report to callback
      contactOut.m_userId = SetUserDataID();
   } else {
      tmin = dgFloat32 (1.2f);
   }
   return tmin;
}


In the end if the function found a Hit, it was setting the contact normal to the hit normal but the sphere user data pointer.
Long time ago, there user data of a collision shape use to store the collision ID of the shape, but when I added the scene collision, there is a new object called body Proxy, which act as a pseudo body.
The object needs to store information in the collision shape, so I separate the ID and the collsionUserData.
I made the changed on all collision routine, by I forgot to change he raycast routines. So the where reportion a userdata pointer as collision id, usually zero instead for the collisionID.
It is fix now.
The callback now reports
normal,3 { 1.0000000 0.00000000 0.00000000}
intersetparam 0.44999999 float
collisionid 1 int


Get SDK 2.25 and try again please
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Minimal raycast test won't work.

Postby FunkyJive » Wed Nov 03, 2010 12:19 pm

Thank you so much for the fix! Just downloaded the new version and everything seems to be working fine now. Thanks again for the quick reply and the fix.
FunkyJive
 
Posts: 6
Joined: Wed Jun 17, 2009 1:42 pm

Re: Minimal raycast test won't work.

Postby Aphex » Wed Nov 03, 2010 5:01 pm

Smashin, cheers for fix :)
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK


Return to Solved bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron