This project is read-only.

Collision detection

Aug 14, 2011 at 11:32 PM

Hi, I am using the tutorial 8 sample, and the collision between the box and the sphere it's working fine. Now, I need to add some other objects to the scene that are not related to a marker. I am able to add some spheres to the scene, but I am not able to detect the collision between this spheres and the objects on the markers (for example, collision between the box on the toolbar and one of these spheres marker independent).

How can I do this?


Thanks in advance!!

Aug 16, 2011 at 2:17 AM

Please read this post ( first to understand the configuration.


Aug 16, 2011 at 2:59 AM

Ohan, thanks for the reply. I already red the post you mention, but I couldn't get it. It talks about two markers, and in my case, one is on a marker and the other one isn't on a marker (it's an object hanging on the scene.RootNode). Maybe the case is the same, but I still don't get it.

Here I got:

sphereNode_st.Model = new Sphere(3, 60, 60);
sphereNode_st.AddToPhysicsEngine = true;
sphereNode_st.Physics.Shape = ShapeType.Sphere;

TransformNode sphereTransNode_st = new TransformNode();
sphereTransNode_st.Scale = new Vector3(0.9f, 0.9f, 0.9f);
sphereTransNode_st.Translation = new Vector3(-10, -10, -120);

Material sphereMaterial_st = new Material();
sphereMaterial_st.Diffuse = new Vector4(0.5f, 0, 0, 1);
sphereMaterial_st.Specular = Color.White.ToVector4();
sphereMaterial_st.SpecularPower = 10;
sphereNode_st.Material = sphereMaterial_st;


And then I call the collision like you do:

NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(sphereNode_st.Physics, boxNode.Physics);
            ((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(pair, BoxSphereCollision); 


Obviously, I am missing someting, because I can see the collision, but the event is not firing, but when I collide the sphere and the box from the tutorial, it works Ok.

Can you give me a little explanation so I can understand what the problem is and how to solve it?


Thanks a lot.

Aug 17, 2011 at 1:27 AM
Edited Aug 17, 2011 at 1:28 AM

The idea is the same in the post. The basic concept is that there is only one physics world and if you want to make the collision work properly, you need to associate the coordinate into one single space. Anything attached to a marker has its own coordinate system that does not affect movements in the physics space (by design). So even if you move around a box attached on a marker, it stays at a fixed location in the physics space.

Now, to make both the visualization and physics simulation correct, the best way I would suggest is to NOT attach your virtual object on the marker, but instead, attach it directly to the root node of the scene and updates its transform through NewtonPhysics.SetTransform method in the Draw(...) call with the MarkerNode.WorldTransformation (make sure that you add this marker node to the root node of the scene so that it's updated properly) just like the tutorial. Then it should provide you with proper collision event.


Aug 21, 2011 at 5:14 PM

Excellent!! Thank you very much Ohan, that was it.