Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

[C#] JigLibX - Can't return position of collision correctly.

This topic is 3166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there, I have JigLibX setup in C# and all was going great until I tried to get any information about the collision that occur. I have the engine and collision detector setup as follows:
        private void InitializePhysicsEngine()
        {
            // PhysicsSystem controls anything physics related in any simulation
            physics_Engine = new PhysicsSystem();

            // Collision detection for PhysicsSystem
            physics_Engine.CollisionSystem = new CollisionSystemSAP();

            // CollisionFunctor checks for collision-pairs (collision detection info)
            collision_Functor = new BasicCollisionFunctor(collision_Info);
        }


Then I catch all collisions in the Update() method:
            //=============================================
            //----- [Collision Detection Information] -----
            //=============================================
            // bodies               - Bodies which should get tested
            // collisionFunctor     - Derive your own class from CollisionFunctor or use BasicCollisionFunctor. The function passes all collisions back to them
            // collisionPredicate   - Derive a class from CollisionSkinPredicate2 or use "null" to let JigLibX know which bodies should not be considered
            // collTolerance        - The tollerance of detection
            physics_Engine.CollisionSystem.DetectAllCollisions(body_List, collision_Functor, null, 0.05f);

            // Check if there is new collision information
            if (collision_Info.Count > 0) 
            {
                foreach (CollisionInfo info in collision_Info)
                {
                    for (int i = 0; i < info.NumCollPts; i++)
                    {
                        Console.WriteLine(info.PointInfo.Position);    
                    }            
                }

                // Clear the list to get only new collision information next frame
                collision_Info.Clear();
            }


However, the value "Position" always returns (0,0,0) for each PointInfo. All the bodies were added during the load() method to the body_List which the collision detection relies on.
            // Add all actor's bodies to list for collision detection information
            body_List.Add(box_Falling.Body);
            body_List.Add(box_Immovable.Body);
Why am I getting incorrect results? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Solved it using this:


collision_Number_Of = collision_Info.Count;

// Check if there is new collision information
if (collision_Number_Of > 0)
{
foreach (CollisionInfo info in collision_Info)
{
//Console.WriteLine(info.PointInfo[0].Info.R1);

Vector3 point_Collision = Vector3.Zero;
for (int i = 0; i < info.NumCollPts; i++)
{
point_Collision += info.PointInfo[0].Info.R1;
}

point_Collision /= info.NumCollPts;
Console.WriteLine(point_Collision);
}

// Clear the list to get only new collision information next frame
collision_Info.Clear();
}



but it is returning multiple collisions for once bounce of a ball. The tolerance can't go any lower without collisions being missed though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!