public CollisionComponent(Actor owner) : base(owner) { mTransformComponent = null; Owner.ComponentsCreated += ComponentsCreatedHandler; Owner.ActorInitialized += ActorInitializedHandler; mClipsCamera = false; }
private void ComponentsCreatedHandler(object sender, EventArgs e) { mParticleSystem = Owner.GetComponent<ParticleSystemRenderComponent>(ActorComponent.ComponentType.Render); if (mParticleSystem == null) throw new LevelManifestException("Expected ActorComponent missing."); mTransform = Owner.GetComponent<TransformComponent>(ActorComponent.ComponentType.Transform); if (mTransform == null) throw new LevelManifestException("Expected ActorComponent missing."); }
private void ComponentsCreatedHandler(object sender, EventArgs e) { // Holding on to this reference should be okay since the scene graph nodes which own this object should // be released when the Actor is despawned. mTransform = Subject.GetComponent<TransformComponent>(ActorComponent.ComponentType.Transform); }
private void ComponentsCreatedHandler(object sender, EventArgs e) { mTransformComponent = Owner.GetComponent<TransformComponent>(ComponentType.Transform); if (mTransformComponent == null) throw new LevelManifestException("ControllerComponents expect to be accompanied by TransformComponents."); mController.Reset(mTransformComponent.Transform); }
public Rotation(Actor owner) : base(owner) { mAngularVelocity = 1.0d; mTransform = null; }
public ParticleSpray(Actor owner) : base(owner) { mParticleSystem = null; mTransform = null; }
public void ImpactHandler(object sender, UpdateStepEventArgs e) { GameResources.ActorManager.PostPhysicsUpdateStep -= ImpactHandler; // TODO: P2: Some boooom sound effects... TransformComponent myXForm = Owner.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); // Do a sphere cast to get actors in the blast radius List <RayCastResult> inRangeActors = new List <RayCastResult>(); SphereShape blastZone = new SphereShape(mBlastRadius); RigidTransform blastPosition = new RigidTransform(BepuConverter.Convert(myXForm.Translation)); BEPUutilities.Vector3 bepuZero = BEPUutilities.Vector3.Zero; GameResources.ActorManager.SimSpace.ConvexCast(blastZone, ref blastPosition, ref bepuZero, inRangeActors); RayCastDistanceComparer rcdc = new RayCastDistanceComparer(); for (int a = 0; a < inRangeActors.Count; ++a) { EntityCollidable inRangeEntityCollidable = inRangeActors[a].HitObject as EntityCollidable; if (inRangeEntityCollidable != null && inRangeEntityCollidable.Entity != null && inRangeEntityCollidable.Entity.Tag != null) { Actor blastedActor = GameResources.ActorManager.GetActorById((int)(inRangeEntityCollidable.Entity.Tag)); IDamagable actorDamage = blastedActor.GetBehaviorThatImplementsType <IDamagable>(); DynamicCollisionComponent actorCollidable = blastedActor.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics); BepuVec3 blastToActorCenter = actorCollidable.Entity.Position - blastPosition.Position; BepuRay loeRay = new BepuRay(blastPosition.Position, blastToActorCenter); bool hasCover = false; float distance = mBlastRadius; if (actorDamage != null || (actorCollidable != null && actorCollidable.IsDynamic && !(actorCollidable.Entity.CollisionInformation.CollisionRules.Personal.HasFlag(BEPUphysics.CollisionRuleManagement.CollisionRule.NoSolver)))) { List <RayCastResult> loeResults = new List <RayCastResult>(); GameResources.ActorManager.SimSpace.RayCast(loeRay, mBlastRadius, loeResults); loeResults.Sort(rcdc); for (int c = 0; c < loeResults.Count; ++c) { EntityCollidable possibleCover = loeResults[c].HitObject as EntityCollidable; if (possibleCover != null && possibleCover.Entity == inRangeEntityCollidable.Entity) { // Hit distance = loeResults[c].HitData.T; break; } Terrain possibleCoverTerrain = loeResults[c].HitObject as Terrain; if (possibleCoverTerrain != null) { hasCover = true; break; } if (possibleCover != null && possibleCover.Entity != null && !possibleCover.Entity.IsDynamic) { hasCover = true; break; } } } if (!hasCover && actorDamage != null) { actorDamage.TakeDamage((int)(MathHelper.Lerp(1.0f, 0.25f, distance / mBlastRadius) * mDamage)); } if (!hasCover && actorCollidable != null && actorCollidable.IsDynamic && !(actorCollidable.Entity.CollisionInformation.CollisionRules.Personal.HasFlag(BEPUphysics.CollisionRuleManagement.CollisionRule.NoSolver))) { blastToActorCenter.Normalize(); blastToActorCenter = blastToActorCenter * 1200; // Math.Min(5000.0f / (distance + 1.0f)); actorCollidable.Entity.ApplyLinearImpulse(ref blastToActorCenter); if (!actorCollidable.Entity.ActivityInformation.IsActive) { actorCollidable.Entity.ActivityInformation.Activate(); } } } } DynamicCollisionComponent dcc = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics); Vector3 myVelocity = BepuConverter.Convert(dcc.Entity.LinearVelocity); Actor fireball = GameResources.ActorManager.SpawnTemplate("ExplosionFire"); TransformComponent fireXForm = fireball.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); fireXForm.Translation = myXForm.Translation; ExplosionFire fireBehavior = fireball.GetBehavior <ExplosionFire>(); fireBehavior.Emit(myVelocity); Actor smoke = GameResources.ActorManager.SpawnTemplate("ExplosionSmoke"); TransformComponent smokeXForm = smoke.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); smokeXForm.Translation = myXForm.Translation; ExplosionSmoke smokeBehavior = smoke.GetBehavior <ExplosionSmoke>(); smokeBehavior.Emit(myVelocity); Owner.Despawn(); }
protected virtual void ComponentsCreatedHandler(object sender, EventArgs e) { mTransformComponent = Owner.GetComponent<TransformComponent>(ComponentType.Transform); if (mTransformComponent == null) throw new LevelManifestException("CollisionComponents expect to be accompanied by TransformComponents."); }
public override void Release() { mTransformComponent = null; }
private void DrawShadowMap(ICamera camera, Actor castingActor) { TransformComponent shadowCasterTransform = castingActor.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); Matrix casterView = Matrix.Invert(shadowCasterTransform.Transform); // Find the front half of the frustum corners in world space. Matrix invCamFrustum = Matrix.Invert(camera.Frustum.Matrix); Vector3[] halfCamCorners = new Vector3[] { new Vector3(-1.0f, -1.0f, 0.0f), new Vector3(1.0f, -1.0f, 0.0f), new Vector3(1.0f, 1.0f, 0.0f), new Vector3(-1.0f, 1.0f, 0.0f), new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(1.0f, -1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(-1.0f, 1.0f, 1.0f), }; for (int c = 0; c < 8; ++c) { Vector4 transformedCorner = Vector4.Transform(halfCamCorners[c], invCamFrustum); transformedCorner /= transformedCorner.W; halfCamCorners[c].X = transformedCorner.X; halfCamCorners[c].Y = transformedCorner.Y; halfCamCorners[c].Z = transformedCorner.Z; } for (int c = 0; c < 4; ++c) { halfCamCorners[c + 4] = halfCamCorners[c] + 0.05f * (halfCamCorners[c + 4] - halfCamCorners[c]); } Vector3[] camCorners = camera.Frustum.GetCorners(); // Transform those corners into to caster space, and form a bounding box around them, which will become our caster projection. Vector3 shadowMapFrustumMinHalfCorner = Vector3.Transform(halfCamCorners[0], casterView); Vector3 shadowMapFrustumMaxHalfCorner = shadowMapFrustumMinHalfCorner; Vector3 shadowMapFrustumMinCorner = Vector3.Transform(camCorners[0], casterView); Vector3 shadowMapFrustumMaxCorner = shadowMapFrustumMinHalfCorner; for (int fc = 1; fc < 8; ++fc) { Vector3 currTranslatedCorner = Vector3.Transform(halfCamCorners[fc], casterView); shadowMapFrustumMinHalfCorner = Vector3.Min(currTranslatedCorner, shadowMapFrustumMinHalfCorner); shadowMapFrustumMaxHalfCorner = Vector3.Max(currTranslatedCorner, shadowMapFrustumMaxHalfCorner); currTranslatedCorner = Vector3.Transform(camCorners[fc], casterView); shadowMapFrustumMinCorner = Vector3.Min(currTranslatedCorner, shadowMapFrustumMinCorner); shadowMapFrustumMaxCorner = Vector3.Max(currTranslatedCorner, shadowMapFrustumMaxCorner); } Matrix shadowMapProj = SpaceUtils.CreateOrthographicOffCenter( shadowMapFrustumMinHalfCorner.X, shadowMapFrustumMaxHalfCorner.X, shadowMapFrustumMinHalfCorner.Y, shadowMapFrustumMaxHalfCorner.Y, shadowMapFrustumMaxHalfCorner.Z + 1000.0f, // Extra room to include shadow casting objects. shadowMapFrustumMinHalfCorner.Z); SceneGraph.ResetTraversal(); SceneGraph.VisibilityFrustum = new BoundingFrustum(casterView * shadowMapProj); Resources.ShadowTransform = SceneGraph.VisibilityFrustum.Matrix * sShadowTextureShift; SceneGraph.ExternalMaterialFlags = TraversalContext.MaterialFlags.ShadowMap; SharedResources.Game.GraphicsDevice.SetRenderTarget(Resources.ShadowMap); SharedResources.Game.GraphicsDevice.Clear(Color.White); SceneGraph.Draw(); }
private void ComponentsCreatedHandler(object sender, EventArgs e) { // Holding on to this reference should be okay since the scene graph nodes which own this object should // be released when the Actor is despawned. mTransform = Subject.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); }