示例#1
0
        public void OnFire(Vector3 muzzlePosition, Vector3 muzzleDir)
        {
            if (coolDownTimeRemaining <= 0)
            {
                //fpsModel.SetAnimationLayer("Pistol_Idle", 0.0f);
                fpsModel.GetAnimationLayer().AddAnimation("Pistol_Fire", true);
                //fpsModel.SetAnimationLayer("Pistol_Fire", 1.0f);
                coolDownTimeRemaining = ResourceManager.Inst.GetAnimation("Pistol_Fire").EndTime;
                float dist;
                CollisionSkin skin;
                Vector3 pos, normal;

                Segment seg = new Segment(muzzlePosition, muzzleDir * 50);

                scene.GetPhysicsEngine().CollisionSystem.SegmentIntersect(out dist, out skin, out pos, out normal, seg, ignorePred);
                if (skin != null)
                {
                    Decal decal = new Decal();
                    decal.SetMaterial("BulletMetal1");
                    decal.Normal = normal;
                    decal.Scale = new Vector2(0.25f, 0.25f);
                    Vector3 posNew = seg.Origin + seg.Delta * dist;
                    decal.Transformation.SetPosition(posNew);
                    decal.IsPersistent = false;
                    scene.AddEntity("bullet", decal);
                    ParticleEffect bulletEffect = ResourceManager.Inst.GetParticleEffect("BulletEffect");
                    ParticleEmitter collideEmitter = new ParticleEmitter(bulletEffect, 16);
                    collideEmitter.EmitOnce = true;
                    NormalTransform newTransform = new NormalTransform();
                    newTransform.ConformToNormal(normal);
                    newTransform.SetPosition(pos);
                    collideEmitter.Transformation = newTransform;
                    scene.AddEntity("bulletEmitter", collideEmitter);
                }
            }
        }
示例#2
0
        public override void OnAdd(Scene scene)
        {
            Vector3 randPosition = Vector3.Zero;
            Vector3 randNormal = Vector3.Zero;
            randomHelper.NextDouble();
            scene.MainTerrain.GenerateRandomTransform(randomHelper, out randPosition, out randNormal);

            physicsState.position = randPosition;

            tracerEmitter = new ParticleEmitter(tracerEffect, 8);
            scene.Entities.Add(tracerEmitter);
            tracerEmitter.OnAdd(scene);

            boundingBox = new BoundingBox();
            float size = tracerEmitter.GetTextureSize();
            boundingBox.Min = randPosition - Vector3.One * Vector3.Up * size;
            boundingBox.Min.X -= (size);// / 2.0f);
            boundingBox.Min.Z -= (size); // 2.0f);
            boundingBox.Max = randPosition + Vector3.One * Vector3.Up * size;
            boundingBox.Max.X += (size); // 2.0f);
            boundingBox.Max.Z += (size); // 2.0f);

            base.OnAdd(scene);
        }
 public void AddElement(Material material, ParticleEmitter element)
 {
     if (!Elements.ContainsKey(material))
         Elements.Add(material, new CustomList<ParticleEmitter>());
     Elements[material].Add(element);
 }
示例#4
0
        public void OnUpdate()
        {
            fpsModel.OnUpdate();

            if (coolDownTimeRemaining > 0)
            {
                coolDownTimeRemaining -= Time.GameTime.ElapsedTime;
            }
            if (timeTilFire > 0)
                timeTilFire -= Time.GameTime.ElapsedTime;
            if (timeTilFire <= 0 && !hasFired)
            {
                hasFired = true;
                if(!datablock.IsMelee)
                    new Sound3D(datablock.GetSoundEffect((ammo > 0)?WeaponAnimations.Fire:WeaponAnimations.Empty), muzzlePos);
                if (ammo > 0 || datablock.IsMelee)
                {
                    ammo--;
                    float dist;
                    CollisionSkin skin;
                    Vector3 pos, normal;

                    Segment seg = new Segment(muzzlePos, muzzleDir * datablock.FireDistance);
                    Microsoft.Xna.Framework.Ray shootRay = new Microsoft.Xna.Framework.Ray(muzzlePos, muzzleDir);
                    bool anyActorHit = false;
                    scene.GetPhysicsEngine().CollisionSystem.SegmentIntersect(out dist, out skin, out pos, out normal, seg, ignorePred);
                    float segDist = (skin != null) ? Vector3.Distance(seg.Delta * dist, Vector3.Zero): float.PositiveInfinity;
                    for (int i = 0; i < scene.Actors.Count; i++)
                    {
                        Actor currActor = scene.Actors[i];
                        if (currActor != scene.MainPlayer)
                        {
                            float shootDist;
                            HitType hit = currActor.GetHit(shootRay, datablock.FireDistance, out shootDist);
                            if (hit != HitType.None)
                            {
                                if (skin == null || (shootDist <= segDist))
                                {
                                    currActor.ApplyDamage(datablock.Damage);
                                    ParticleEffect bloodEffect = ResourceManager.Inst.GetParticleEffect("BloodEffect");
                                    ParticleEmitter collideEmitter = new ParticleEmitter(bloodEffect, 16);
                                    collideEmitter.EmitOnce = true;
                                    NormalTransform newTransform = new NormalTransform();
                                    newTransform.ConformToNormal(-muzzleDir);
                                    newTransform.SetPosition(muzzlePos + muzzleDir*shootDist);
                                    collideEmitter.Transformation = newTransform;
                                    scene.AddEntity("bloodEmitter", collideEmitter);
                                    anyActorHit = true;
                                }
                            }
                        }
                    }
                    if (skin != null)
                    {
                        ParticleEffect bulletEffect = ResourceManager.Inst.GetParticleEffect("BulletEffect");
                        ParticleEmitter collideEmitter = new ParticleEmitter(bulletEffect, 16);
                        collideEmitter.EmitOnce = true;
                        NormalTransform newTransform = new NormalTransform();
                        newTransform.ConformToNormal(normal);
                        newTransform.SetPosition(pos);
                        collideEmitter.Transformation = newTransform;
                        scene.AddEntity("bulletEmitter", collideEmitter);
                    }
                    if(datablock.IsMelee)
                        new Sound3D(datablock.GetSoundEffect((anyActorHit) ? WeaponAnimations.SuccessHit : WeaponAnimations.Fire), muzzlePos);
                }
            }
        }
 public void AddEmitter(ParticleEmitter emitter)
 {
     emitters.Add(emitter);
     InitializeEmitter(emitter);
 }
        void InitializeEmitter(ParticleEmitter emitter)
        {
            emitter.positionData = new Texture2D(GFX.Device, emitter.GetTextureSize(), emitter.GetTextureSize(), 1, TextureUsage.None, SurfaceFormat.Vector4);
            emitter.velocityData = new Texture2D(GFX.Device, emitter.GetTextureSize(), emitter.GetTextureSize(), 1, TextureUsage.None, SurfaceFormat.Vector4);

            ParticleEffect effect = emitter.GetParticleEffect();

            int sizeSquared = emitter.GetTextureSize() * emitter.GetTextureSize();

            Vector3 emitPos = emitter.Transformation.GetPosition();

            Vector4[] initPosition = new Vector4[sizeSquared];
            for (int i = 0; i < initPosition.Length; i++)
            {
                Vector3 offset = new Vector3(effect.offsetParameters.X, effect.offsetParameters.Y, effect.offsetParameters.Z) * new Vector3((float)(rand.NextDouble() * 2.0 - 1.0), (float)(rand.NextDouble() * 2.0 - 1.0), (float)(rand.NextDouble() * 2.0 - 1.0));
                offset *= effect.offsetParameters.W;
                offset = Vector3.TransformNormal(offset, emitter.Transformation.GetTransform());
                initPosition[i] = new Vector4(emitPos + offset, effect.lifetime * (float)rand.NextDouble());

            }

            Vector4[] initVelocity = new Vector4[sizeSquared];
            for (int i = 0; i < initVelocity.Length; i++)
            {
                Vector3 randVel = effect.initialDirection * effect.initialSpeed + Vector3.One * effect.initialSpeedVariance * (float)(rand.NextDouble() * 2.0 - 1.0);
                randVel = Vector3.TransformNormal(randVel, emitter.Transformation.GetTransform());
                float randMass = effect.mass + effect.massVariance * (float)(rand.NextDouble() * 2.0 - 1.0);
                initVelocity[i] = new Vector4(randVel, randMass);
            }

            emitter.positionData.SetData<Vector4>(initPosition);
            emitter.velocityData.SetData<Vector4>(initVelocity);
        }
 public void RemoveEmitter(ParticleEmitter emitter)
 {
     emitters.Remove(emitter);
 }
 public void AddElement(Material material, ParticleEmitter element)
 {
     if (!Elements.ContainsKey(material))
         Elements.Add(material, new Queue<ParticleEmitter>());
     Elements[material].Enqueue(element);
 }
示例#9
0
        public override void OnAdd(Scene scene)
        {
            emitter = new ParticleEmitter(Resources.ResourceManager.Inst.GetParticleEffect("PlayerParticles"), 60);
            emitter.SetColor(GetTeamColor());
            emitterLight = new Light(LightType.Point, GetTeamColor(), this.Transformation.GetPosition(), false);
            emitterLight.Parameters = new Vector4(55, 50, 0, 0);
            scene.Entities.Add(emitter);
            scene.Entities.Add(emitterLight);
            scene.Actors.Add(this);

            base.OnAdd(scene);
        }