Exemplo n.º 1
0
        private void updatePhysics()
        {
            if (this.Fluid != null)
            {
                this.main.Space.Remove(this.Fluid);
            }

            List <Vector3[]> tris   = new List <Vector3[]>();
            float            width  = this.Scale.Value.X;
            float            length = this.Scale.Value.Y;
            Vector3          pos    = this.Position;

            tris.Add(new[]
            {
                pos + new Vector3(width / -2, 0, length / -2),
                pos + new Vector3(width / 2, 0, length / -2),
                pos + new Vector3(width / -2, 0, length / 2)
            });
            tris.Add(new[]
            {
                pos + new Vector3(width / -2, 0, length / 2),
                pos + new Vector3(width / 2, 0, length / -2),
                pos + new Vector3(width / 2, 0, length / 2)
            });

            this.Fluid = new Util.CustomFluidVolume(Vector3.Up, this.main.Space.ForceUpdater.Gravity.Y, tris, this.Depth, 0.7f, 0.997f, 0.2f, this.main.Space.BroadPhase.QueryAccelerator, this.main.Space.ThreadManager);
            this.main.Space.Add(this.Fluid);
        }
Exemplo n.º 2
0
        public override void InitializeProperties()
        {
            this.EnabledWhenPaused.Value = true;
            this.Add(new NotifyBinding(delegate() { this.needResize = true; }, this.main.ScreenSize));
            this.Add(new Binding<bool>(this.EnableReflection, ((GameMain)this.main).Settings.EnableReflections));

            Action removeFluid = delegate()
            {
                if (this.fluid.Space != null)
                    this.main.Space.Remove(this.fluid);
            };

            Action addFluid = delegate()
            {
                if (this.fluid.Space == null && this.Enabled && !this.Suspended)
                    this.main.Space.Add(this.fluid);
            };

            this.Add(new CommandBinding(this.OnSuspended, removeFluid));
            this.Add(new CommandBinding(this.OnDisabled, removeFluid));
            this.Add(new CommandBinding(this.OnResumed, addFluid));
            this.Add(new CommandBinding(this.OnEnabled, addFluid));

            this.DrawOrder = new Property<int> { Editable = false, Value = 10 };

            this.camera = new Camera();
            this.main.AddComponent(this.camera);
            this.parameters = new RenderParameters
            {
                Camera = this.camera,
                Technique = Technique.Clip,
                ReverseCullOrder = true,
            };

            this.Color.Set = delegate(Vector3 value)
            {
                this.Color.InternalValue = value;
                this.effect.Parameters["Color"].SetValue(value);
            };

            this.UnderwaterColor.Set = delegate(Vector3 value)
            {
                this.UnderwaterColor.InternalValue = value;
                this.effect.Parameters["UnderwaterColor"].SetValue(value);
            };

            this.Fresnel.Set = delegate(float value)
            {
                this.Fresnel.InternalValue = value;
                this.effect.Parameters["Fresnel"].SetValue(value);
            };

            this.Speed.Set = delegate(float value)
            {
                this.Speed.InternalValue = value;
                this.effect.Parameters["Speed"].SetValue(value);
            };

            this.RippleDensity.Set = delegate(float value)
            {
                this.RippleDensity.InternalValue = value;
                this.effect.Parameters["RippleDensity"].SetValue(value);
            };

            this.Distortion.Set = delegate(float value)
            {
                this.Distortion.InternalValue = value;
                this.effect.Parameters["Distortion"].SetValue(value);
            };

            this.Brightness.Set = delegate(float value)
            {
                this.Brightness.InternalValue = value;
                this.effect.Parameters["Brightness"].SetValue(value);
            };

            this.Clearness.Set = delegate(float value)
            {
                this.Clearness.InternalValue = value;
                this.effect.Parameters["Clearness"].SetValue(value);
            };

            List<Vector3[]> tris = new List<Vector3[]>();
            const float basinWidth = 2500.0f;
            const float basinLength = 2500.0f;
            float waterHeight = this.Position.Value.Y;

            tris.Add(new[]
            {
                new Vector3(-basinWidth / 2, waterHeight, -basinLength / 2), new Vector3(basinWidth / 2, waterHeight, -basinLength / 2),
                new Vector3(-basinWidth / 2, waterHeight, basinLength / 2)
            });
            tris.Add(new[]
            {
                new Vector3(-basinWidth / 2, waterHeight, basinLength / 2), new Vector3(basinWidth / 2, waterHeight, -basinLength / 2),
                new Vector3(basinWidth / 2, waterHeight, basinLength / 2)
            });

            this.fluid = new Util.CustomFluidVolume(Vector3.Up, this.main.Space.ForceUpdater.Gravity.Y, tris, 1000.0f, 1.25f, 0.997f, 0.2f, this.main.Space.BroadPhase.QueryAccelerator, this.main.Space.ThreadManager);
            this.main.Space.Add(this.fluid);

            instances.Add(this);
        }