[C++, DX9] NewtonWorldRayCast() doesn't work correctly

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Stucuk » Wed Jun 30, 2010 6:52 pm

Julio Jerez wrote:you should set the last distance to 0.0 before each call to RayCast, if you do not then the next ray will fail

Do what I say and post the build the Ray cast should be perfect 100% of the time.


That won't work Julio. His code (And i think everyone elses), starts with the Distance being over 1.0 . And then checking to see if the IntersectParam is lower than the last distance.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Julio Jerez » Wed Jun 30, 2010 8:00 pm

Upps my mistake, you are right, distance should be 1.0 :D
But it still need to restart dist every time before call World Raycats.
My mistake was that my initial value should be 0.0, his mistake was that he never set it after the fiert call. If hsi change that then it should be fine,
here is the function with the fix
Code: Select all
void SetUpCamera() {
   Matrix m_View, proj;
   m_TargetPos = loc;
   m_TargetPos.z += 50;
   m_EyePos.x = loc.x + 2000 * sin(yrot) * sin(xrot);
   m_EyePos.y = loc.y + 2000 * sin(yrot) * cos(xrot);
   m_EyePos.z = loc.z + 25 - 2000 * cos(yrot);

   // this is the a bug
   //dist = 2;
   dist = 1.0f;
   // also make the ray go for begin point to end, no the other way around, make sure that in
   NewtonWorldRayCast(world, m_TargetPos, m_EyePos, Hit, 0, &dist);
   if(dist <= 1.0f)
      m_EyePos = m_TargetPos + (m_EyePos - m_TargetPos) * (dist - 0.05);
   Vector3 dir = m_EyePos - m_TargetPos;
   cameraAngle = atan2(dir.y, dir.x);
   D3DXMatrixLookAtLH(&m_View, &m_EyePos, &m_TargetPos, &m_UpVector);
   device->SetTransform(D3DTS_VIEW, &m_View);
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Stucuk » Thu Jul 01, 2010 12:36 am

Shouldn't it be at least 1.1 so that you can include any hits which lie on 1.0 ?
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Ripiz » Thu Jul 01, 2010 5:19 am

Setting it to 1.0 won't change anything at all, I filter out my dist = 2 with that if(dist <= 1.0f)
Ripiz
 
Posts: 47
Joined: Sat Oct 03, 2009 12:07 pm

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Julio Jerez » Thu Jul 01, 2010 9:01 am

your line goes from

p0 {m_x=0.00000000 m_y=0.00000000 m_z=50.000000 ...}
p1 {m_x=1476.9204 m_y=948.31964 m_z=983.85132 ...}

the means that the origin is below the destination, I doubt you map is about the origin of the ray.
It may clarify more for you if you also draw the Line in wire frame, so that you can see it is not pointing in any diretikon that will touch the mesh.

when I check in teh debugger that line is rejecter by teh fist check in teh mutigrid, becaus eno object is licated in any cell at teh distabce from the origin.

you have few bugs.
-make sur you srest teh distanc each tiem you call raycats
-make sur eteh riogin an dteh distnation of teh ray are no invertes (wihch I think they are now)
after you do that is it does not work make anoeth exe with those fixes, I can no do it because I do no won VS2010.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Ripiz » Thu Jul 01, 2010 1:08 pm

You are doing something wrong.

When I stand in canyon, and move camera into canyon I get these results:
p0 {x=306.86395 y=1466.9313 z=50.000000 }
p1 {x=588.41559 y=-508.20447 z=-114.88428 }
Newton detects that Ray hits something, and my dist becomes 0.63704562f.

When I stand on one of big triangles, and move camera below terrain surface, I get these results:
p0 {x=-149.54211 y=1549.9939 z=50.000000 }
p1 {x=-2045.9237 y=1316.7340 z=-566.03864 }
In this case Newton doesn't detect Ray hit, and dist remains 2.

I can even draw both of these lines
Code: Select all
//Vertex structure
struct D3DVERTEX {
    Vector3 p;
   DWORD color;
   D3DVERTEX(Vector3 v, DWORD c){
      p = v;
      color = c;
   }
};

//Drawing
   vector<D3DVERTEX> vec;
   device->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);

   vec.push_back(D3DVERTEX(Vector3(306.86395, 1466.9313, 50.000000), 0xFFFF0000));
   vec.push_back(D3DVERTEX(Vector3(588.41559, -508.20447, -114.88428), 0xFFFF0000));
   device->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vec[0], sizeof(D3DVERTEX));
   vec.clear();
   vec.push_back(D3DVERTEX(Vector3(-149.54211, 1549.9939, 50.000000), 0xFFFF0000));
   vec.push_back(D3DVERTEX(Vector3(-2045.9237, 1316.7340, -566.03864), 0xFFFF0000));
   device->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vec[0], sizeof(D3DVERTEX));
   vec.clear();


In screenshot it's very well visible, that both rays go through terrain: http://dl.dropbox.com/u/2637453/nwtn/Two%20Rays.PNG
But only left one gets detected as it hit something.
Ripiz
 
Posts: 47
Joined: Sat Oct 03, 2009 12:07 pm

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Julio Jerez » Thu Jul 01, 2010 1:46 pm

you must have it change your code in your side, because when I run in debug I always get this points.
p0 {m_x=0.00000000 m_y=0.00000000 m_z=50.000000 ...}
p1 {m_x=1476.9204 m_y=948.31964 m_z=983.85132 ...}

I am no doing anything I just run the demo, and I can no debug until you make so that teh distane is reset afet each call.
did you do that?
if so can you make so that is show the ray, and post the new exe so that I can see what it is.

In the ground a collision tree or a Hightfield collision.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Ripiz » Thu Jul 01, 2010 1:57 pm

It's collision tree.

Hold right mouse button to turn camera, ray will turn too. Ray gets casted from that character representation (box) into camera.
Ripiz
 
Posts: 47
Joined: Sat Oct 03, 2009 12:07 pm

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Julio Jerez » Thu Jul 01, 2010 2:01 pm

this is the last time I repeat this,
the executable i have do no work because you are no setting the distance to 2 before you call WorldReayCast, you need to fix that Bug so teh teh Ray continue woring after the first call.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Ripiz » Thu Jul 01, 2010 2:30 pm

It does work, but if I set it to 0 it stops working.
Ripiz
 
Posts: 47
Joined: Sat Oct 03, 2009 12:07 pm

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Julio Jerez » Thu Jul 01, 2010 3:37 pm

I said you have to set to a value larger than one before every call to WorldRayCast.
If you want to solve the problem you have do follow the instructions I am giving you, at least while we are wroking on the bug?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Julio Jerez » Fri Jul 02, 2010 2:02 pm

did you get it working? you did not reply.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Ripiz » Sat Jul 03, 2010 1:11 am

If I set dist to 0 it doesn't work, it must be over 1.0f, that's all I can tell.
Ripiz
 
Posts: 47
Joined: Sat Oct 03, 2009 12:07 pm

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Stucuk » Sat Jul 03, 2010 5:16 am

Ripiz wrote:If I set dist to 0 it doesn't work, it must be over 1.0f, that's all I can tell.


Julio isn't telling you to set it to 0. He's saying that you need to set the Distance BEFORE you call the raycast or the second time you use it, the distance will start lower than it should meaning that it may then ignore some objects.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: [C++, DX9] NewtonWorldRayCast() doesn't work correctly

Postby Ripiz » Sat Jul 03, 2010 9:22 am

I'm already setting it
Code: Select all
      dist = 2;
      NewtonWorldRayCast(world, m_TargetPos, m_EyePos, Hit, 0, 0);
      if(dist <= 1.0f)
         m_EyePos = m_TargetPos + (m_EyePos - m_TargetPos) * (dist - 0.05);
Ripiz
 
Posts: 47
Joined: Sat Oct 03, 2009 12:07 pm

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests