A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Ripiz » Mon Jun 28, 2010 5:59 am
- Code: Select all
float dist = 0;
float _cdecl Hit(const NewtonBody* body, const float* hitNormal, int collisionID, void* userData, float intersetParam){
if(intersetParam < dist)
dist = intersetParam;
return intersetParam;
}
//camera code
m_TargetPos = loc;
m_TargetPos.z += 50;
m_EyePos.x = loc.x + 500 * sin(yrot) * sin(xrot);
m_EyePos.y = loc.y + 500 * sin(yrot) * cos(xrot);
m_EyePos.z = loc.z + 25 - 500 * cos(yrot);
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);
Basically, sometimes RayCast works, sometimes it doesn't.
My CollisionTree (or Trimesh):
http://dl.dropbox.com/u/2637453/nwtn/CollisionTree.PNGIf I stand on that "canyon" and move camera into it, ray works perfectly:
http://dl.dropbox.com/u/2637453/nwtn/Canyon.PNGBut it doesn't detect anything with those huge triangles:
http://dl.dropbox.com/u/2637453/nwtn/Bug.PNG (that's view from underground)
Anyone know how to fix this?
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Mon Jun 28, 2010 6:59 am
check carefully, it is unlikelly the ray cast will work in one triangel an dfail other consitntly. you most have a bug.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Mon Jun 28, 2010 7:11 am
Visual debug mesh and original terrain matches, I don't know what else to check. Any tips?
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Carli » Mon Jun 28, 2010 7:34 am
maybe you could debug my raycast case, too:
viewtopic.php?f=12&t=5914Basically, sometimes RayCast works, sometimes it doesn't.
both crashes could be caused by the same problem
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Ripiz » Mon Jun 28, 2010 8:35 am
It doesn't crash, just Ray doesn't work.
Heres demo source for demo in which bug is reproducible:
http://dl.dropbox.com/u/2637453/nwtn/demo.rarBut you'll need DirectX SDK.
I hope this helps.
P.S. I hope there's not too much mess
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Mon Jun 28, 2010 1:25 pm
Ok I will check tonight.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Carli » Tue Jun 29, 2010 5:26 am
Ripiz wrote:It doesn't crash, just Ray doesn't work.
in my linux64 mashine, it does not work, on linux32 it crashes. (i did not test win32 (or maybe it does not work, too))
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Ripiz » Tue Jun 29, 2010 6:28 am
I have win64, but it's compiled as 32bit code.
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Tue Jun 29, 2010 11:13 am
I do not have VS 2010 can you make the project with VS2008
Getting and setting 2010 spress that three tor four hours
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Tue Jun 29, 2010 12:34 pm
I don't have VS2008.
Just include all .cpp and .h files, I think I have #pragma's for all libraries, you might need to specify directory for DirectX Includes/Libs, but that's all.
Edit:
Not sure about newton library, might need vs7 one, I think I use vs9, but it's 2.22 so I'm sure you have either of them, header is same anyways.
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Tue Jun 29, 2010 1:53 pm
Can you make a exe that links to the newton dll? that is better and quiker for me to debug.
Making project file I usually have to spend a lot of time figure out path, and extenrla dependecies, d3d, and so on.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Wed Jun 30, 2010 1:47 am
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Wed Jun 30, 2010 8:37 am
In you code if this is you ray cast, I believe it will never work because you are setting the parameter to 2.0 and I believe it should be 0.0
- Code: Select all
float dist = 0;
float _cdecl Hit(const NewtonBody* body, const float* hitNormal, int collisionID, void* userData, float intersetParam){
if(intersetParam < dist)
dist = intersetParam;
return intersetParam;
}
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);
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);
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);
}
If you change you to this
- Code: Select all
//float dist = 0;
float _cdecl Hit(const NewtonBody* body, const float* hitNormal, int collisionID, void* userData, float intersetParam)
{
float& dist = *((float*) usetData);
if(intersetParam < dist)
dist = intersetParam;
return intersetParam;
}
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 = 0.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);
}
It should work
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ripiz » Wed Jun 30, 2010 1:38 pm
Not only my camera + movement broke, but it still goes through terrain.
Setting it to 0.0f makes my code + Hit() think that RayCast hit something 0.0f away from Ray start
Edit:
Also it can't be it, as in Canyon this works fine.
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Wed Jun 30, 2010 1:46 pm
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.
-
Julio Jerez
- 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 3 guests