public override void Initialize(ContentArchive content, Camera camera) { camera.Position = new Vector3(-30, 8, -60); camera.Yaw = MathHelper.Pi * 3f / 4; camera.Pitch = 0; _bodyProperties = new BodyProperty <BodyProperty>(BufferPool); _events = new CollisionEvents <CollisionEventHandler>(new CollisionEventHandler(), BufferPool, ThreadDispatcher); _events.EventHandler.Pairs = new QuickList <CollidablePair>(128, BufferPool); _events.EventHandler.Simulation = Simulation; _collisionGroups = new FeeSimNarrowPhaseCallbacks <CollisionEventHandler> { Events = _events, CollisionGroups = _bodyProperties }; Simulation = Simulation.Create(BufferPool, _collisionGroups, new DefaultPoseIntegratorCallbacks(BufferPool), timestepper: new CustomPositionLastTimestepper()); var boxShape = new Box(1, 1, 1); boxShape.ComputeInertia(1, out _boxInertia); _boxIndex = Simulation.Shapes.Add(boxShape); CreateFloors(); }
protected new void Start() { base.Start(); var args = new CollisionEvents.DynamicColliderCreationEventArgs(this); CollisionEvents.FireEvent(CollisionEvents.EventType.DynamicColliderCreation, gameObject, args); }
private void keepInBounds() { px = transform.localPosition.x; py = transform.localPosition.y; pz = transform.localPosition.z; hurt = false; if (px > boundDistance - bodyRadius) { px = boundDistance - bodyRadius; hurt = true; } else if (px < -boundDistance + bodyRadius) { px = -boundDistance + bodyRadius; hurt = true; } if (pz > boundDistance - bodyRadius) { pz = boundDistance - bodyRadius; hurt = true; } else if (pz < -boundDistance + bodyRadius) { pz = -boundDistance + bodyRadius; hurt = true; } for (int i = 0; i < colliders.Length; i++) { collisionTest(i); // 1 = \ blue // 2 = / green // 3 = [Center]->[Player] yellow //Debug.DrawLine(new Vector3(colliders[i].y, 1f, colliders[i].z), new Vector3(squareCenter[i].x, 1f, squareCenter[i].y), Color.blue); //Debug.DrawLine(new Vector3(colliders[i].x, 1f, colliders[i].z), new Vector3(squareCenter[i].x, 1f, squareCenter[i].y), Color.green); //Debug.DrawLine(new Vector3(diagonal1[i].x + squareCenter[i].x, 1f, diagonal1[i].y + squareCenter[i].y), new Vector3(squareCenter[i].x, 1f, squareCenter[i].y), Color.blue); //Debug.DrawLine(new Vector3(diagonal2[i].x + squareCenter[i].x, 1f, diagonal2[i].y + squareCenter[i].y), new Vector3(squareCenter[i].x, 1f, squareCenter[i].y), Color.green); //Debug.DrawLine(new Vector3(px, 1f, pz), new Vector3(squareCenter[i].x, 1f, squareCenter[i].y), Color.yellow); } transform.localPosition = new Vector3(px, py, pz); if (hurt && !isColliding) { CollisionEvents.TriggerHurt(); isColliding = true; } else if (!hurt) { CollisionEvents.TriggerHurtLeave(); isColliding = false; } }
protected virtual void Start() { this.BeginStart(ref _started); Assert.IsNotNull(_impactAudioEvents.SoftCollisionSound, "AudioPhysics component has no audio soft collision audio trigger assigned"); Assert.IsNotNull(_impactAudioEvents.HardCollisionSound, "AudioPhysics component has no audio hard collision audio trigger assigned"); Assert.IsNotNull(_rigidbody, "AudioPhysics component has no rigidbody assigned"); _collisionEvents = _rigidbody.gameObject.AddComponent <CollisionEvents>(); this.EndStart(ref _started); }
protected new void Start() { base.Start(); mShape = new CylinderShape(radius, halfHeight); var args = new CollisionEvents.DynamicColliderCreationEventArgs(this); CollisionEvents.FireEvent(CollisionEvents.EventType.DynamicColliderCreation, gameObject, args); }
public void ReadCollisionEvents() { // Allocate a block stream for up to 10 parallel writes BlockStream collisionEventStream = new BlockStream(10, 0xabbaabba); // Do a couple of writes to different forEach indices int writeCount = 0; { BlockStream.Writer collisionEventWriter = collisionEventStream; collisionEventWriter.BeginForEachIndex(1); collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.EndForEachIndex(); collisionEventWriter.BeginForEachIndex(3); collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.EndForEachIndex(); collisionEventWriter.BeginForEachIndex(5); collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.EndForEachIndex(); collisionEventWriter.BeginForEachIndex(7); collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.EndForEachIndex(); collisionEventWriter.BeginForEachIndex(9); collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.Write(new CollisionEvent()); writeCount++; collisionEventWriter.EndForEachIndex(); } // Iterate over written events and make sure they are all read CollisionEvents collisionEvents = new CollisionEvents(collisionEventStream); int readCount = 0; foreach (var collisionEvent in collisionEvents) { readCount++; } Assert.IsTrue(readCount == writeCount); // Cleanup var disposeJob = collisionEventStream.ScheduleDispose(default);
/// <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); }
/// <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; } } }