Esempio n. 1
0
            protected new void Start()
            {
                base.Start();

                var args = new CollisionEvents.DynamicColliderCreationEventArgs(this);

                CollisionEvents.FireEvent(CollisionEvents.EventType.DynamicColliderCreation, gameObject, args);
            }
Esempio n. 2
0
            protected new void Start()
            {
                base.Start();

                mShape = new CylinderShape(radius, halfHeight);

                var args = new CollisionEvents.DynamicColliderCreationEventArgs(this);

                CollisionEvents.FireEvent(CollisionEvents.EventType.DynamicColliderCreation, gameObject, args);
            }
Esempio n. 3
0
            /// <summary>
            /// Initialise the data needed for collision detection of <c>CSACollider</c>s.
            /// </summary>
            /// <remarks>
            /// This function calculates the bounding sphere, and reads the slices from a json file,
            /// then fire the <c>DynamicColliderCreation</c> event.
            /// </remarks>
            new void Start()
            {
                base.Start();

                if (slicesJsonFile != null)
                {
                    InitSlicesFromJson(slicesJsonFile.ToString());
                }

                CollisionEvents.DynamicColliderCreationEventArgs args = new CollisionEvents.DynamicColliderCreationEventArgs(this);
                CollisionEvents.FireEvent(CollisionEvents.EventType.DynamicColliderCreation, gameObject, args);
            }
            protected new void Start()
            {
                base.Start();

                mTriangles = new List <Triangle>();
                for (int i = 0; i < mMesh.triangles.Length; i += 3)
                {
                    mTriangles.Add(new Triangle(
                                       mMesh.vertices[mMesh.triangles[i]],
                                       mMesh.vertices[mMesh.triangles[i + 1]],
                                       mMesh.vertices[mMesh.triangles[i + 2]]
                                       ));
                }

                CollisionEvents.DynamicColliderCreationEventArgs args = new CollisionEvents.DynamicColliderCreationEventArgs(this);
                CollisionEvents.FireEvent(CollisionEvents.EventType.DynamicColliderCreation, gameObject, args);
            }
            /// <summary>
            /// Initialise the data needed for colliding with height maps and fires the
            /// <c>HeightMapTerrainColliderCreation</c> event.
            /// </summary>
            void Start()
            {
                heightMapTerrain = GetComponent <HeightMapTerrain>();
                Width            = heightMapTerrain.sourceRect.width;
                Height           = heightMapTerrain.sourceRect.height;
                CellSize         = heightMapTerrain.cellSize;
                TriMesh          = GetComponent <MeshFilter>().sharedMesh;

                TriGrid = new TriangleGrid(
                    TriMesh.vertices,
                    TriMesh.triangles,
                    Width - 1,
                    Height - 1,
                    CellSize,
                    transform.localScale,
                    transform.position
                    );

                var args = new CollisionEvents.HeightMapColliderCreationEventArgs(this);

                CollisionEvents.FireEvent(CollisionEvents.EventType.HeightMapTerrainColliderCreation, gameObject, args);
            }
Esempio n. 6
0
            /// <summary>
            /// Iterates throught the list of <c>HeightMap</c> and <c>CSACollider</c>
            /// to find the intersected points.
            /// </summary>
            /// <remarks>
            /// This function performs the Sphere-Triangle, Plane-Triangle, Curve-Triangle
            /// intersection tests. After found any contact points it sends toward the
            /// <c>PhysicsManager</c>.
            /// </remarks>
            void FixedUpdate()
            {
                debugSegments.Clear();
                debugPoints.Clear();
                debugVectors.Clear();
                segmentColor.Clear();
                foreach (HeightMapCollider hMapCollider in heightMapColliders)
                {
                    if (!hMapCollider.enabled)
                    {
                        continue;
                    }

                    colors = new Color[hMapCollider.TriMesh.vertexCount];
                    Color origCol = new Color(200f / 255f, 200f / 255f, 200f / 255f);
                    for (int i = 0; i < colors.Length; i++)
                    {
                        colors[i] = origCol;
                    }


                    foreach (DynamicCollider dynCollider in dynamicColliderList)
                    {
                        if (!dynCollider.enabled)
                        {
                            continue;
                        }

                        // creating a list of contacts for the physics manager
                        List <Contact> contacts       = new List <Contact>();
                        List <Segment> coarseContacts = new List <Segment>();

                        // position of bounding sphere in world coordinates
                        Vector3 spherePos = dynCollider.BoundingSphere.CenterW;
                        float   radius    = dynCollider.BoundingSphere.Radius;

                        // filtering the triangle grid with the sphere projection
                        hMapCollider.TriGrid.FilterBySphereProjection(spherePos, radius);

                        if (dynCollider is CSACollider)
                        {
                            HandleCSAVsHeightMapCollision(
                                dynCollider as CSACollider,
                                hMapCollider,
                                contacts,
                                coarseContacts);
                        }
                        else if (dynCollider is BruteForceCollider)
                        {
                            HandleBruteForceVsHeightMapCollision(
                                dynCollider as BruteForceCollider,
                                hMapCollider,
                                contacts,
                                coarseContacts);
                        }
                        else if (dynCollider is VertexCollider)
                        {
                            HandleVertexVsHeightMapCollision(
                                dynCollider as VertexCollider,
                                hMapCollider,
                                contacts,
                                coarseContacts);
                        }
                        else if (dynCollider is SAGJKCollider)
                        {
                            HandleSAGJKVsHeightMapCollision(
                                dynCollider as SAGJKCollider,
                                hMapCollider,
                                contacts,
                                coarseContacts);
                        }
                        else if (dynCollider is GJKCollider)
                        {
                            HandleGJKVsHeightMapCollision(
                                dynCollider as GJKCollider,
                                hMapCollider,
                                contacts,
                                coarseContacts);
                        }
                        else if (dynCollider is XenoCollider)
                        {
                            HandleXenoVsHeighMapCollision(
                                dynCollider as XenoCollider,
                                hMapCollider,
                                contacts,
                                coarseContacts);
                        }
                        else if (dynCollider is ConvDecompCollider)
                        {
                            HandleConvDecompVsHeighMapCollision(
                                dynCollider as ConvDecompCollider,
                                hMapCollider,
                                contacts,
                                coarseContacts);
                        }

                        // reset the filtering of the triangle grid
                        hMapCollider.TriGrid.Reset();


                        if (coarseContacts.Count > 0 && dynCollider.GetComponent <Rigidbody>() != null)
                        {
                            var args = new CollisionEvents.CoarseCollisionEventArgs(
                                dynCollider.GetComponent <RigidBody>(),
                                coarseContacts
                                );

                            CollisionEvents.FireEvent(CollisionEvents.EventType.CoarseCollision, this, args);
                        }

                        // if any contacts got caught, we send them to the physics manager by the collision event
                        if (contacts.Count > 0 && dynCollider.GetComponent <RigidBody>() != null)
                        {
                            var args = new CollisionEvents.CollisionEventArgs(
                                dynCollider.GetComponent <RigidBody>(),
                                contacts
                                );

                            CollisionEvents.FireEvent(CollisionEvents.EventType.Collision, this, args);
                        }
                    }

                    if (debugColors)
                    {
                        hMapCollider.TriMesh.colors = colors;
                    }
                }
            }