RayCast problem

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

RayCast problem

Postby Bird » Sun Oct 05, 2014 7:46 pm

Hi Julio,

I'm hitting a problem using NewtonWorldRayCast in the latest build.

Here's a video. http://hurleyworks.com/media/flash/RayCastProblem/RayCastProblem.html

I'm using the mouse to RayCast into the scene and drawing the hit point and normal. As you can see in the video in some cases the ground mesh is not detected by the ray and the hit point appears on the underside of the ball instead.

I'm using Ball and Box collision shapes in the video but I tried using Static Mesh and Convex Hulls for both meshes too and got the same result.

The ball has a 6m dia and the ground box is 30m x 30m x ,25n. I tried different thickness for the box and those failed too.

I tried an older version of Newton ( sorry I don't know the version number) and everything works fine.

-Bird
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: RayCast problem

Postby Julio Jerez » Sun Oct 05, 2014 8:27 pm

can you serialize the scene and load in the sandbox, and see if it also fail there?
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast problem

Postby Bird » Sun Oct 05, 2014 9:18 pm

Julio Jerez wrote:can you serialize the scene and load in the sandbox, and see if it also fail there?


I serialized the scene but the latest version of the sandbox app crashes immediately on startup here. I compiled the sandbox demos using vs2013 express( i converted from the vs2012 solution ) It compiles ok(debug64) but immediately crashes in pthread/semp_post.c ( line 77 ). I tried several different DEFAULT_SCENE settings and they all crashed.

Here's the call stack leading up to the crash
> demosSandbox_d.exe!sem_post(sem_t_ * * sem) Line 77 C
demosSandbox_d.exe!dgThread::dgSemaphore::Release() Line 160 C++
demosSandbox_d.exe!dgThreadHive::SynchronizationBarrier() Line 236 C++
demosSandbox_d.exe!dgAmpInstance::BuildJacobianMatrixParallel(dgParallelSolverSyncData * const syncData) Line 1199 C++
demosSandbox_d.exe!dgAmpInstance::ConstraintSolver(int islandCount, const dgIsland * const islandArray, float timestep) Line 741 C++
demosSandbox_d.exe!dgWorldDynamicUpdate::UpdateDynamics(float timestep) Line 195 C++
demosSandbox_d.exe!dgWorld::StepDynamics(float timestep) Line 991 C++
demosSandbox_d.exe!dgWorld::TickCallback(int threadID) Line 1031 C++
demosSandbox_d.exe!dgMutexThread::Execute(int threadID) Line 64 C++
demosSandbox_d.exe!dgThread::dgThreadSystemCallback(void * threadData) Line 246 C++
demosSandbox_d.exe!ptw32_threadStart(void * vthreadParms) Line 225 C

-Bird
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: RayCast problem

Postby Julio Jerez » Sun Oct 05, 2014 9:56 pm

Oh sorry I check in the demo set to use the AMP stuff, it is still a work in progress.

Please and try again sync again.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast problem

Postby Bird » Mon Oct 06, 2014 12:52 am

Julio Jerez wrote:Oh sorry I check in the demo set to use the AMP stuff, it is still a work in progress.

Please and try again sync again.


Ok thanks, the sandbox is working now, I can load the serialized scene but didn't see any way to test it easily so a made a little demo scene from parts of the Kinematic demo. Unfortunately for me, though this demo seems to work perfectly. Do you have any idea what might be going wrong in my scene? If you look in the video you'll see that it works ok if the ray is pointed directly at the sphere but fails when it's at glancing angles to it.

-Bird

Code: Select all
#include <toolbox_stdafx.h>
#include "SkyBox.h"
#include "TargaToOpenGl.h"
#include "DemoMesh.h"
#include "DemoEntityManager.h"
#include "DemoCamera.h"
#include "PhysicsUtils.h"
#include "NewtonDemos.h"

const float BOX_HEIGHT = 1.0f;
const float DIAMETER = 8.0f;

class Placement: public CustomControllerBase
{
   public:
   void PreUpdate(dFloat timestep, int threadIndex)
   {
   }

   void PostUpdate(dFloat timestep, int threadIndex)
   {
   }
};


class PlacementManager : public CustomControllerManager<Placement>
{

 public:

   PlacementManager(DemoEntityManager* const scene)
      :CustomControllerManager<Placement>(scene->GetNewton(), "PlacementManger"),
      m_hitParam(0.0f)
   {
   }

   static dFloat RayCastFilter (const NewtonBody* const body, const NewtonCollision* const collisionHit, const dFloat* const contact, const dFloat* const normal, dLong collisionID, void* const userData, dFloat intersetParam)
    {
      PlacementManager* const me = (PlacementManager*) userData;
      me->m_hitParam = intersetParam;
      
      return intersetParam;
    }

   virtual void PreUpdate(dFloat timestep)
   {
      NewtonWorld* const world = GetWorld();
      DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(world);
      NewtonDemos* const mainWindow = scene->GetRootWindow();
      DemoCamera* const camera = scene->GetCamera();

      bool buttonState = mainWindow->GetMouseKeyState(1);
      if (buttonState)
      {
         int mouseX;
         int mouseY;
         mainWindow->GetMousePosition(mouseX, mouseY);

         float x = dFloat(mouseX);
         float y = dFloat(mouseY);
         dVector p0(camera->ScreenToWorld(dVector(x, y, 0.0f, 0.0f)));
         dVector p1(camera->ScreenToWorld(dVector(x, y, 1.0f, 0.0f)));

         NewtonWorldRayCast(world, &p0[0], &p1[0], RayCastFilter, this, nullptr, 0);
         if (m_hitParam > 0)
         {
            dVector spot = p0 + (p1 - p0).Scale(m_hitParam);
            float y = spot[1];
            float tol = 1e-03f;
            float boxTop = BOX_HEIGHT * .5f;
            if ( y > boxTop + tol || y < boxTop - tol)
            {
               dAssert(0);
            }
         }
      }
   }

  private:      
   dFloat m_hitParam;
};

void RayCastTest(DemoEntityManager* const scene)
{
   // create a system for object placement
   new PlacementManager (scene);

   NewtonWorld* const world = scene->GetNewton();
   int materialID = NewtonMaterialGetDefaultGroupID (world);
   dMatrix matrix (dGetIdentityMatrix());
   dFloat mass = 0.0f;

   // box
   dVector boxSize (30.0f, BOX_HEIGHT, 30.0f, 0.0f);
   NewtonCollision* const boxCollision = CreateConvexCollision (world, matrix, boxSize, _BOX_PRIMITIVE, materialID);
   DemoMesh* const boxGeometry = new DemoMesh("primitive", boxCollision, "smilli.tga", "smilli.tga", "smilli.tga");
   
   CreateSimpleSolid (scene, boxGeometry, mass, matrix, boxCollision, materialID);
   boxGeometry->Release();
   NewtonDestroyCollision (boxCollision);

   // sphere
   dVector sphereSize (DIAMETER, DIAMETER, DIAMETER, 0.0f);
   NewtonCollision* const sphereCollision = CreateConvexCollision (world, matrix, sphereSize, _SPHERE_PRIMITIVE, materialID);
   DemoMesh* const sphereGeometry = new DemoMesh("primitive", sphereCollision, "smilli.tga", "smilli.tga", "smilli.tga");
   
   CreateSimpleSolid (scene, sphereGeometry, mass, matrix, sphereCollision, materialID);
   sphereGeometry->Release();
   NewtonDestroyCollision (sphereCollision);

   // camera
   dQuaternion rot;
   dVector origin (-12.0, 6.5f, 4.0f, 0.0f);
   scene->SetCameraMatrix(rot, origin);
}
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: RayCast problem

Postby Julio Jerez » Mon Oct 06, 2014 6:52 am

I think I know what that is.
a while back I fixed a crash bug that bug that if a ray became of zero length, the broadPhase will continue train to cast a ray of zero length.
is was on file: ../coreLibrary_300\source\physics\dgBroadPhase.cpp
line 1600
I added this
Code: Select all
                        maxParam = param;
                        if (maxParam < dgFloat32 (1.0e-3f)) {
                           break;
                        }


but one part I 1000 may be too course granularity for very long rays.
if the ray hit the ground at parameter lower 1.0e-3, the code will accept that as a hit and terminate
I changed to one part in 100 million
Code: Select all
                        maxParam = param;
                        if (maxParam < dgFloat32 (1.0e-8f)) {
                           break;
                        }
 


please sync and try again
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast problem

Postby Bird » Mon Oct 06, 2014 7:56 am

I change to one part in 100 million


That fixed it. Thanks very much for the quick fix!

-Bird
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: RayCast problem

Postby manny » Mon Oct 06, 2014 10:21 am

Awesome. Locking this thread.
http://www.instaLOD.io - InstaLOD - State of the art 3D optimization
manny
Site Admin
Site Admin
 
Posts: 131
Joined: Tue Feb 11, 2014 6:49 pm


Return to Bugs and Fixes

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

cron