Exemple #1
0
        private Vector3 FMODDirectionVector(Vector3 slimdxPosition, FMOD.VECTOR fmodListenerPosition, out Vector3 fmodPosition)
        {
            fmodPosition = new Vector3(slimdxPosition.X, slimdxPosition.Z, -slimdxPosition.Y);
            Vector3 fmodListenerPos = new Vector3(fmodListenerPosition.x, fmodListenerPosition.y, fmodListenerPosition.z);

            return(fmodPosition - fmodListenerPos);
        }
Exemple #2
0
        /// <summary>
        /// Gets all listener attributes at once.
        /// </summary>
        private void GetAttributes(
            out FMOD.VECTOR position,
            out FMOD.VECTOR velocity,
            out FMOD.VECTOR forward,
            out FMOD.VECTOR up
            )
        {
            if (FMODManager.UsesStudio)
            {
                StudioSystem.Native.getListenerAttributes(_index, out var attributes);

                position = attributes.position;
                velocity = attributes.velocity;
                forward  = attributes.forward;
                up       = attributes.up;
            }
            else
            {
                CoreSystem.Native.get3DListenerAttributes(
                    _index,
                    out position,
                    out velocity,
                    out forward,
                    out up
                    );
            }
        }
Exemple #3
0
        public FMOD.Reverb3D CreateReverb(FMOD.REVERB_PROPERTIES props, Vector3 location, float maxDist, float minDist)
        {
            FMOD.Reverb3D reverb;
            FMOD.RESULT   res = soundSystem.createReverb3D(out reverb);
            if (res == FMOD.RESULT.OK)
            {
                res = reverb.setProperties(ref props);
                if (res == FMOD.RESULT.OK)
                {
                    FMOD.VECTOR pos = new FMOD.VECTOR();
                    pos.x = location.X;
                    pos.y = location.Y;
                    pos.z = location.Z;

                    res = reverb.set3DAttributes(ref pos, minDist, maxDist);
                    if (res == FMOD.RESULT.OK)
                    {
                        return(reverb);
                    }
                    else
                    {
                        throw new Exceptions.LoadFailException(FMOD.Error.String(res));
                    }
                }
                else
                {
                    throw new Exceptions.LoadFailException(FMOD.Error.String(res));
                }
            }
            else
            {
                throw new Exceptions.LoadFailException(FMOD.Error.String(res));
            }
        }
 public static Vector2 ToVector2(this FMOD.VECTOR v)
 {
     return(new Vector2
     {
         X = v.x,
         Y = v.y,
     });
 }
 public void Set3DListenerAttributes(Vector3 position, Vector3 velocity, Vector3 forward, Vector3 up)
 {
     FMOD.VECTOR position_ = FMODManager.Vector3ToFMODVector(position);
     FMOD.VECTOR vel_      = FMODManager.Vector3ToFMODVector(velocity);
     FMOD.VECTOR forward_  = FMODManager.Vector3ToFMODVector(forward);
     FMOD.VECTOR up_       = FMODManager.Vector3ToFMODVector(up);
     FMODManager.ERRCHECK(system.set3DListenerAttributes(0, ref position_, ref vel_, ref forward_, ref up_));
 }
 public static Vector3 ToVector3(this FMOD.VECTOR v)
 {
     return(new Vector3
     {
         X = v.x,
         Y = v.y,
         Z = v.z
     });
 }
Exemple #7
0
        public static FMOD.VECTOR FMODVectorFromVector3(Vector3 vector)
        {
            FMOD.VECTOR res = new FMOD.VECTOR();
            res.x = vector.X;
            res.y = vector.Y;
            res.z = vector.Z;

            return(res);
        }
        public void SetPosition(Channel channel, Vector3 pos)
        {
            FMOD.RESULT result;
            FMOD.VECTOR pos2;
            FMOD.VECTOR vel2 = new FMOD.VECTOR();
            pos2.x = pos.X;
            pos2.y = pos.Y;
            pos2.z = pos.Z;
            FmodChannel c = (FmodChannel)channel;

            result = c.channel.set3DAttributes(ref pos2, ref vel2);
            ERRCHECK(result);
        }
Exemple #9
0
 /// <summary>
 /// Sets all listener attributes at once.
 /// </summary>
 private void SetAttributes(
     FMOD.VECTOR position,
     FMOD.VECTOR velocity,
     FMOD.VECTOR forward,
     FMOD.VECTOR up
     )
 {
     CoreSystem.Native.set3DListenerAttributes(
         _index,
         ref position,
         ref velocity,
         ref forward,
         ref up
         );
 }
Exemple #10
0
        public override void OnBeginContact(Actor otherActor, Shape shape, Shape otherShape)
        {
            base.OnBeginContact(otherActor, shape, otherShape);

            FMOD.VECTOR pos = new FMOD.VECTOR();
            pos.x = location.X;
            pos.y = location.Y;
            pos.z = 0;

            FMOD.VECTOR vel = new FMOD.VECTOR();

            FMOD.VECTOR alt_pane_pos = new FMOD.VECTOR();

            Game.soundPlayer.PlaySound(woodBoxImpact, null).set3DAttributes(ref pos, ref vel, ref alt_pane_pos);
        }
Exemple #11
0
 public void SetPositionAndVelocity(Vector3 position, Vector3 velocity)
 {
     if (channel == null)
     {
         return;
     }
     FMOD.VECTOR pos = new FMOD.VECTOR();
     pos.x = position.x;
     pos.y = position.y;
     pos.z = position.z;
     FMOD.VECTOR vel = new FMOD.VECTOR();
     vel.x = velocity.x;
     vel.y = velocity.y;
     vel.z = velocity.z;
     CheckRetCode(channel.set3DAttributes(ref pos, ref vel));
 }
Exemple #12
0
        public void Set3DListenerAttributes(int listenerId, Vector3 location, Vector3 velocity, Vector3 forward, Vector3 up)
        {
            //Vectors here are changed into fmod's one so that in future it will be easier to modify them
            FMOD.VECTOR FMODPos = SoundPlayer.FMODVectorFromVector3(location);

            FMOD.VECTOR FMODvel = SoundPlayer.FMODVectorFromVector3(velocity);

            FMOD.VECTOR FMODForw = SoundPlayer.FMODVectorFromVector3(forward);

            FMOD.VECTOR FMODUp = SoundPlayer.FMODVectorFromVector3(up);

            //Matrix.CreateTranslation(location).Up

            FMOD.RESULT res = soundSystem.set3DListenerAttributes(listenerId, ref FMODPos, ref FMODvel, ref FMODForw, ref FMODUp);
            if (res != FMOD.RESULT.OK)
            {
                throw new Exceptions.LoadFailException(FMOD.Error.String(res));
            }
        }
        public void SetListener(Vector3 pos, Vector3 forward, Vector3 up)
        {
            FMOD.RESULT result;
            FMOD.VECTOR pos2;
            FMOD.VECTOR forward2;
            FMOD.VECTOR up2;
            FMOD.VECTOR v = new FMOD.VECTOR();
            pos2.x     = pos.X;
            pos2.y     = pos.Y;
            pos2.z     = pos.Z;
            forward2.x = forward.X;
            forward2.y = forward.Y;
            forward2.z = forward.Z;
            up2.x      = up.X;
            up2.y      = up.Y;
            up2.z      = up.Z;

            result = system.set3DListenerAttributes(0, ref pos2, ref v, ref forward2, ref up2);
            ERRCHECK(result);
        }
        private void timer_Tick(object sender, System.EventArgs e)
        {
            FMOD.RESULT result;

            // ==========================================================================================
            // UPDATE THE LISTENER
            // ==========================================================================================

            FMOD.VECTOR forward = new FMOD.VECTOR();
            forward.x = 0.0f; forward.y = 0.0f; forward.z = 1.0f;

            FMOD.VECTOR up = new FMOD.VECTOR();
            up.x = 0.0f; up.y = 1.0f; up.z = 0.0f;

            FMOD.VECTOR vel = new FMOD.VECTOR();

            if (listenerflag)
            {
                listenerpos.x          = ((float)Math.Sin(t * 0.05f) * 33.0f * DISTANCEFACTOR); // left right pingpong
                trackBarPosition.Value = (int)listenerpos.x;
            }

            // ********* NOTE ******* READ NEXT COMMENT!!!!!
            // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
            vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
            vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
            vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);

            // store pos for next time
            lastpos = listenerpos;

            result = system.set3DListenerAttributes(0, ref listenerpos, ref vel, ref forward, ref up);
            ERRCHECK(result);

            t += (30 * (1.0f / (float)INTERFACE_UPDATETIME));    // t is just a time value .. it increments in 30m/s steps in this example

            if (system != null)
            {
                system.update();
            }
        }
Exemple #15
0
        public bool Update(float updatetime)
        {
            pos.x = m_position.x;
            pos.y = m_position.y;
            pos.z = m_position.z;

            vel.x = (pos.x - lastPos.x) * (1 / updatetime);
            vel.y = (pos.y - lastPos.y) * (1 / updatetime);
            vel.z = (pos.z - lastPos.z) * (1 / updatetime);

            //Update listener attributes
            m_system.set3DListenerAttributes(0, ref pos, ref vel, ref forward, ref up);

            m_position.x = pos.x;
            m_position.y = pos.y;
            m_position.z = pos.z;

            lastPos = pos;

            m_system.update();
            return(true);
        }
Exemple #16
0
        public static int PlaySound(string key, Vector3 position, float volume = 1f)
        {
            if (sounds.TryGetValue(key, out FMOD.Sound sound))
            {
                FMOD.RESULT r1 = RuntimeManager.CoreSystem.getMasterChannelGroup(out FMOD.ChannelGroup cg);
                if (r1 == FMOD.RESULT.OK)
                {
                    FMOD.RESULT r2 = RuntimeManager.CoreSystem.playSound(sound, cg, true, out FMOD.Channel channel);
                    if (r2 == FMOD.RESULT.OK)
                    {
                        FMOD.VECTOR pos = CameraController.Instance.GetVerticallyScaledPosition(position, false).ToFMODVector();
                        FMOD.VECTOR vel = new FMOD.VECTOR();
                        channel.set3DAttributes(ref pos, ref vel);
                        channel.setVolume(volume);

                        channel.setPaused(false);

                        channel.getIndex(out int index);
                        return(index);
                    }
                    else
                    {
                        Debug.LogError($"AutoUtil: Failed to create sound instance. (key={key}, error={r2})");
                    }
                }
                else
                {
                    Debug.LogError($"AutoUtil: Failed to get master channel group. (key={key}, error={r1})");
                }
            }
            else
            {
                Debug.LogWarning($"AudioUtil: Tried to play sound that does not exist. (key={key})");
            }

            return(-1);
        }
Exemple #17
0
        private void timer_Tick(object sender, System.EventArgs e)
        {
            FMOD.RESULT result;

            // ==========================================================================================
            // UPDATE THE LISTENER
            // ==========================================================================================

            FMOD.VECTOR forward  = new FMOD.VECTOR();
            forward.x = 0.0f; forward.y = 0.0f; forward.z = 1.0f;

            FMOD.VECTOR up = new FMOD.VECTOR();
            up.x = 0.0f; up.y = 1.0f; up.z = 0.0f;

            FMOD.VECTOR vel = new FMOD.VECTOR();

            if (listenerflag)
            {
                listenerpos.x = ((float)Math.Sin(t * 0.05f) * 33.0f * DISTANCEFACTOR); // left right pingpong
                trackBarPosition.Value = (int)listenerpos.x;
            }

            // ********* NOTE ******* READ NEXT COMMENT!!!!!
            // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
            vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
            vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
            vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);

            // store pos for next time
            lastpos = listenerpos;

            result = system.set3DListenerAttributes(0, ref listenerpos, ref vel, ref forward, ref up);
            ERRCHECK(result);

            t += (30 * (1.0f / (float)INTERFACE_UPDATETIME));    // t is just a time value .. it increments in 30m/s steps in this example

            if (system != null)
            {
                system.update();
            }
        }
Exemple #18
0
        private void threeD_Load(object sender, System.EventArgs e)
        {
            uint            version = 0;
            FMOD.RESULT     result;

            trackBarPosition.Enabled = false;

            /*
                Create a System object and initialize.
            */
            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                Application.Exit();
            }

            result = system.init(100, FMOD.INITFLAG.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            /*
                Set the distance units. (meters/feet etc).
            */
            result = system.set3DSettings(1.0f, DISTANCEFACTOR, 1.0f);
            ERRCHECK(result);

            /*
                Load some sounds
            */
            result = system.createSound("../../examples/media/drumloop.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound1);
            ERRCHECK(result);
            result = sound1.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound1.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../examples/media/jaguar.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound2);
            ERRCHECK(result);
            result = sound2.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound2.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../examples/media/swish.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._2D), ref sound3);
            ERRCHECK(result);

            /*
                Play sounds at certain positions
            */
            {
                FMOD.VECTOR pos1 = new FMOD.VECTOR();
                pos1.x = -10.0f * DISTANCEFACTOR; pos1.y = -0.0f; pos1.z = 0.0f;

                FMOD.VECTOR vel1 = new FMOD.VECTOR();
                vel1.x = 0.0f; vel1.y =  0.0f; vel1.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, true, ref channel1);
                ERRCHECK(result);
                result = channel1.set3DAttributes(ref pos1, ref vel1);
                ERRCHECK(result);
                result = channel1.setPaused(false);
                ERRCHECK(result);
            }

            {
                FMOD.VECTOR pos2 = new FMOD.VECTOR();
                pos2.x = 15.0f * DISTANCEFACTOR; pos2.y = -0.0f; pos2.z = -0.0f;

                FMOD.VECTOR vel2 = new FMOD.VECTOR();
                vel2.x = 0.0f; vel2.y = 0.0f; vel2.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound2, true, ref channel2);
                ERRCHECK(result);
                result = channel2.set3DAttributes(ref pos2, ref vel2);
                ERRCHECK(result);
                result = channel2.setPaused(false);
                ERRCHECK(result);
            }

            lastpos.x = 0.0f;
            lastpos.y = 0.0f;
            lastpos.z = 0.0f;

            listenerpos.x = 0.0f;
            listenerpos.y = 0.0f;
            listenerpos.z = -1.0f * DISTANCEFACTOR;
        }
Exemple #19
0
        public override void HandleInput(Microsoft.Xna.Framework.Input.Keys[] keys)
        {
            foreach (var comp in components)
            {
                comp.HandleInput(keys);
            }

            if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                if (!upButtonPressed)
                {
                    upButtonPressed = true;
                    physicsBody.ApplyImpulseAtCenter(new Vector2(0, -100 / Game.physicsScaleY));
                }
            }
            else if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                if (upButtonPressed)
                {
                    upButtonPressed = false;
                }
            }


            if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                downButtonPressed = true;
            }
            else if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                downButtonPressed = false;
            }

            if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                leftButtonPressed = true;
                float velChange = (-5) - physicsBody.GetVelocity().X;

                physicsBody.ApplyImpulseAtCenter(new Vector2(velChange * physicsBody.GetMass(), 0));
            }
            else if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                leftButtonPressed = false;
            }

            if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                rightButtonPressed = true;
                float velChange = (5) - physicsBody.GetVelocity().X;

                physicsBody.ApplyImpulseAtCenter(new Vector2(velChange * physicsBody.GetMass(), 0));
            }
            else if (Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                rightButtonPressed = false;
            }

            if (!rightButtonPressed && !leftButtonPressed)
            {
                float velChange = (0) - physicsBody.GetVelocity().X;

                physicsBody.ApplyImpulseAtCenter(new Vector2(velChange * physicsBody.GetMass(), 0));
            }

            if (!Game._desktop.IsMouseOverGUI)
            {
                int buildingId = 0;;
                for (int i = 0; i < (Game._desktop.GetChild(0) as Myra.Graphics2D.UI.Grid).ChildrenCount; i++)
                {
                    if ((Game._desktop.GetChild(0) as Myra.Graphics2D.UI.Grid).GetChild(i).Id == "buildingType")
                    {
                        buildingId = ((Game._desktop.GetChild(0) as Myra.Graphics2D.UI.Grid).GetChild(i) as Myra.Graphics2D.UI.ComboBox).SelectedIndex.GetValueOrDefault();
                    }
                }
                if (Microsoft.Xna.Framework.Input.Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    if (!leftMouseButtonPressed)
                    {
                        leftMouseButtonPressed = true;

                        Vector3 gridPos = new Vector3();

                        gridPos.X = (int)(Microsoft.Xna.Framework.Input.Mouse.GetState().Position.X / Game.gridSize.X) * Game.gridSize.X;
                        gridPos.Y = (int)(Microsoft.Xna.Framework.Input.Mouse.GetState().Position.Y / Game.gridSize.Y) * Game.gridSize.Y;
                        gridPos.Z = 0;

                        bool canSpawn = true;
                        if (buildingId == 0)
                        {
                            foreach (var actor in Game.actors.OfType <GroundBaseActor>())
                            {
                                if (actor.location.X == gridPos.X && actor.location.Y == gridPos.Y)
                                {
                                    if (!actor.canBeBuiltOn)
                                    {
                                        canSpawn &= false; break;
                                    }
                                }
                            }
                            foreach (var actor in Game.actors.OfType <Building>())
                            {
                                if (actor.collision.Intersects(new Rectangle((int)gridPos.X, (int)gridPos.Y, 32, 32)))
                                {
                                    canSpawn &= false; break;
                                }
                            }
                            if (canSpawn)
                            {//new Vector3(Microsoft.Xna.Framework.Input.Mouse.GetState().X, Microsoft.Xna.Framework.Input.Mouse.GetState().Y, 0)
                                Game.AddActor(new PowerConsumingBuilding(Game, "consumer", new Rectangle((int)gridPos.X, (int)gridPos.Y, 32, 32), new Rectangle((int)gridPos.X - 32, (int)gridPos.Y - 32, 64, 64), new Vector3(gridPos.X, gridPos.Y, 0), new Vector3(0, 0, 0), 6.0f));
                                Game.actors[Game.actors.Count - 1].Components.Add(new Engine.Components.ImageDisplayComponent(Game, Game.actors[Game.actors.Count - 1], "Textures/grassy_bricks"));
                                Game.actors[Game.actors.Count - 1].Components.Add(new Engine.Components.Physics.PhysicsBodyComponent(Game, new Vector2(gridPos.X, gridPos.Y), true, Game.actors[Game.actors.Count - 1]));
                                Game.actors[Game.actors.Count - 1].Components.Add(Engine.Components.Physics.ShapeComponent.CreateRectangeShape(Game, Game.actors[Game.actors.Count - 1], false, 1.0f, 0.0f, 16.0f, 16.0f));
                                Game.actors[Game.actors.Count - 1].Init();

                                FMOD.VECTOR pos = new FMOD.VECTOR();
                                pos.x = Game.actors[Game.actors.Count - 1].location.X;
                                pos.y = Game.actors[Game.actors.Count - 1].location.Y;
                                pos.z = Game.actors[Game.actors.Count - 1].location.Z;

                                FMOD.VECTOR vel = new FMOD.VECTOR();

                                FMOD.VECTOR alt_pane_pos = new FMOD.VECTOR();

                                Game.soundPlayer.PlaySound(spawnSuccess, null, false).set3DAttributes(ref pos, ref vel, ref alt_pane_pos);
                            }
                            else
                            {
                                FMOD.VECTOR pos = new FMOD.VECTOR();
                                pos.x = gridPos.X;
                                pos.y = gridPos.Y;
                                pos.z = 0;

                                FMOD.VECTOR vel = new FMOD.VECTOR();

                                FMOD.VECTOR alt_pane_pos = new FMOD.VECTOR();

                                Game.soundPlayer.PlaySound(spawnFailSound, null, false).set3DAttributes(ref pos, ref vel, ref alt_pane_pos);
                            }
                        }
                        else if (buildingId == 1)
                        {
                            foreach (var actor in Game.actors.OfType <GroundBaseActor>())
                            {
                                if (actor.location.X == gridPos.X && actor.location.Y == gridPos.Y)
                                {
                                    if (!actor.canBeBuiltOn)
                                    {
                                        canSpawn &= false; break;
                                    }
                                }
                            }
                            foreach (var actor in Game.actors.OfType <Building>())
                            {
                                if (actor.collision.Intersects(new Rectangle((int)gridPos.X, (int)gridPos.Y, 64, 64)))
                                {
                                    canSpawn &= false; break;
                                }
                            }
                            if (canSpawn)
                            {
                                Game.AddActor(BuildingSystem.Factory.CreateGeneratorBuilding(Game, new Vector3(gridPos.X, gridPos.Y, 0), new Vector3(0, 0, 0)));

                                Game.actors[Game.actors.Count - 1].Init();

                                FMOD.VECTOR pos = new FMOD.VECTOR();
                                pos.x = Game.actors[Game.actors.Count - 1].location.X;
                                pos.y = Game.actors[Game.actors.Count - 1].location.Y;
                                pos.z = Game.actors[Game.actors.Count - 1].location.Z;

                                FMOD.VECTOR vel = new FMOD.VECTOR();

                                FMOD.VECTOR alt_pane_pos = new FMOD.VECTOR();

                                Game.soundPlayer.PlaySound(spawnPowerSource, null, false).set3DAttributes(ref pos, ref vel, ref alt_pane_pos);
                            }
                            else
                            {
                                FMOD.VECTOR pos = new FMOD.VECTOR();
                                pos.x = gridPos.X;
                                pos.y = gridPos.Y;
                                pos.z = 0;

                                FMOD.VECTOR vel = new FMOD.VECTOR();

                                FMOD.VECTOR alt_pane_pos = new FMOD.VECTOR();

                                Game.soundPlayer.PlaySound(spawnFailSound, null, false).set3DAttributes(ref pos, ref vel, ref alt_pane_pos);
                            }
                        }
                        else
                        {
                            throw new System.Exception("buildingId is bigger than amount of existing types. Value is " + buildingId);
                        }
                    }
                }
                if (Microsoft.Xna.Framework.Input.Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                {
                    leftMouseButtonPressed = false;
                }

                if (Microsoft.Xna.Framework.Input.Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    if (!rightMouseButtonPressed)
                    {
                        rightMouseButtonPressed = true;

                        foreach (Building building in Game.actors.OfType <Building>())
                        {
                            if (building.collision.Contains((int)(Microsoft.Xna.Framework.Input.Mouse.GetState().Position.X / Game.gridSize.X) * Game.gridSize.X, (int)(Microsoft.Xna.Framework.Input.Mouse.GetState().Position.Y / Game.gridSize.Y) * Game.gridSize.Y))
                            {
                                building.Dispose();
                                Game.actors.Remove(building);
                                break;
                            }
                        }
                    }
                }
                if (Microsoft.Xna.Framework.Input.Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                {
                    rightMouseButtonPressed = false;
                }
            }
        }
        private void threeD_Load(object sender, System.EventArgs e)
        {
            uint version = 0;

            FMOD.RESULT result;

            trackBarPosition.Enabled = false;

            /*
             *  Create a System object and initialize.
             */
            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                Application.Exit();
            }

            FMOD.CAPS        caps        = FMOD.CAPS.NONE;
            FMOD.SPEAKERMODE speakermode = FMOD.SPEAKERMODE.STEREO;

            int           outputrate = 0;
            StringBuilder name       = new StringBuilder(128);

            result = system.getDriverCaps(0, ref caps, ref outputrate, ref speakermode);
            ERRCHECK(result);

            result = system.setSpeakerMode(speakermode);                                         /* Set the user selected speaker mode. */
            ERRCHECK(result);

            if ((caps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
            {                                                                                    /* You might want to warn the user about this. */
                result = system.setDSPBufferSize(1024, 10);                                      /* At 48khz, the latency between issuing an fmod command and hearing it will now be about 213ms. */
                ERRCHECK(result);
            }

            FMOD.GUID guid = new FMOD.GUID();

            result = system.getDriverInfo(0, name, 256, ref guid);
            ERRCHECK(result);

            if (name.ToString().IndexOf("SigmaTel") != -1)               /* Sigmatel sound devices crackle for some reason if the format is pcm 16bit.  pcm floating point output seems to solve it. */
            {
                result = system.setSoftwareFormat(48000, FMOD.SOUND_FORMAT.PCMFLOAT, 0, 0, FMOD.DSP_RESAMPLER.LINEAR);
                ERRCHECK(result);
            }

            result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)
            {
                result = system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO);                             /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
                ERRCHECK(result);

                result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);                        /* Replace with whatever channel count and flags you use! */
                ERRCHECK(result);
            }

            /*
             *  Set the distance units. (meters/feet etc).
             */
            result = system.set3DSettings(1.0f, DISTANCEFACTOR, 1.0f);
            ERRCHECK(result);

            /*
             *  Load some sounds
             */
            result = system.createSound("../../../../../examples/media/drumloop.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound1);
            ERRCHECK(result);
            result = sound1.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound1.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/jaguar.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound2);
            ERRCHECK(result);
            result = sound2.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound2.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/swish.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._2D), ref sound3);
            ERRCHECK(result);

            /*
             *  Play sounds at certain positions
             */
            {
                FMOD.VECTOR pos1 = new FMOD.VECTOR();
                pos1.x = -10.0f * DISTANCEFACTOR; pos1.y = -0.0f; pos1.z = 0.0f;

                FMOD.VECTOR vel1 = new FMOD.VECTOR();
                vel1.x = 0.0f; vel1.y = 0.0f; vel1.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, true, ref channel1);
                ERRCHECK(result);
                result = channel1.set3DAttributes(ref pos1, ref vel1);
                ERRCHECK(result);
                result = channel1.setPaused(false);
                ERRCHECK(result);
            }

            {
                FMOD.VECTOR pos2 = new FMOD.VECTOR();
                pos2.x = 15.0f * DISTANCEFACTOR; pos2.y = -0.0f; pos2.z = -0.0f;

                FMOD.VECTOR vel2 = new FMOD.VECTOR();
                vel2.x = 0.0f; vel2.y = 0.0f; vel2.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound2, true, ref channel2);
                ERRCHECK(result);
                result = channel2.set3DAttributes(ref pos2, ref vel2);
                ERRCHECK(result);
                result = channel2.setPaused(false);
                ERRCHECK(result);
            }

            lastpos.x = 0.0f;
            lastpos.y = 0.0f;
            lastpos.z = 0.0f;

            listenerpos.x = 0.0f;
            listenerpos.y = 0.0f;
            listenerpos.z = -1.0f * DISTANCEFACTOR;
        }
Exemple #21
0
        private void threeD_Load(object sender, System.EventArgs e)
        {
            uint            version = 0;
            FMOD.RESULT     result;

            trackBarPosition.Enabled = false;

            /*
                Create a System object and initialize.
            */
            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                Application.Exit();
            }

            FMOD.CAPS        caps        = FMOD.CAPS.NONE;
            FMOD.SPEAKERMODE speakermode = FMOD.SPEAKERMODE.STEREO;

            int	 minfrequency = 0, maxfrequency = 0;
            StringBuilder name = new StringBuilder(128);

            result = system.getDriverCaps(0, ref caps, ref minfrequency, ref maxfrequency, ref speakermode);
            ERRCHECK(result);

            result = system.setSpeakerMode(speakermode);                             /* Set the user selected speaker mode. */
            ERRCHECK(result);

            if ((caps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED) /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
            {                                                                        /* You might want to warn the user about this. */
                result = system.setDSPBufferSize(1024, 10);	                     /* At 48khz, the latency between issuing an fmod command and hearing it will now be about 213ms. */
                ERRCHECK(result);
            }

            FMOD.GUID guid = new FMOD.GUID();

            result = system.getDriverInfo(0, name, 256, ref guid);
            ERRCHECK(result);

            if (name.ToString().IndexOf("SigmaTel") != -1)   /* Sigmatel sound devices crackle for some reason if the format is pcm 16bit.  pcm floating point output seems to solve it. */
            {
                result = system.setSoftwareFormat(48000, FMOD.SOUND_FORMAT.PCMFLOAT, 0,0, FMOD.DSP_RESAMPLER.LINEAR);
                ERRCHECK(result);
            }

            result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)
            {
                result = system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO);             /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
                ERRCHECK(result);

                result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);        /* Replace with whatever channel count and flags you use! */
                ERRCHECK(result);
            }

            /*
                Set the distance units. (meters/feet etc).
            */
            result = system.set3DSettings(1.0f, DISTANCEFACTOR, 1.0f);
            ERRCHECK(result);

            /*
                Load some sounds
            */
            result = system.createSound("../../../../../examples/media/drumloop.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound1);
            ERRCHECK(result);
            result = sound1.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound1.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/jaguar.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound2);
            ERRCHECK(result);
            result = sound2.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound2.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/swish.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._2D), ref sound3);
            ERRCHECK(result);

            /*
                Play sounds at certain positions
            */
            {
                FMOD.VECTOR pos1 = new FMOD.VECTOR();
                pos1.x = -10.0f * DISTANCEFACTOR; pos1.y = -0.0f; pos1.z = 0.0f;

                FMOD.VECTOR vel1 = new FMOD.VECTOR();
                vel1.x = 0.0f; vel1.y =  0.0f; vel1.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, true, ref channel1);
                ERRCHECK(result);
                result = channel1.set3DAttributes(ref pos1, ref vel1);
                ERRCHECK(result);
                result = channel1.setPaused(false);
                ERRCHECK(result);
            }

            {
                FMOD.VECTOR pos2 = new FMOD.VECTOR();
                pos2.x = 15.0f * DISTANCEFACTOR; pos2.y = -0.0f; pos2.z = -0.0f;

                FMOD.VECTOR vel2 = new FMOD.VECTOR();
                vel2.x = 0.0f; vel2.y = 0.0f; vel2.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound2, true, ref channel2);
                ERRCHECK(result);
                result = channel2.set3DAttributes(ref pos2, ref vel2);
                ERRCHECK(result);
                result = channel2.setPaused(false);
                ERRCHECK(result);
            }

            lastpos.x = 0.0f;
            lastpos.y = 0.0f;
            lastpos.z = 0.0f;

            listenerpos.x = 0.0f;
            listenerpos.y = 0.0f;
            listenerpos.z = -1.0f * DISTANCEFACTOR;
        }
Exemple #22
0
        public static bool Play(string strRootPath, SoundItemProperty prop)
        {
            FMOD.RESULT result;

            if (channel != null)
            {
                channel.stop();
            }

            string name = strRootPath + prop.FileName;

            FMOD.MODE mode = FMOD.MODE.DEFAULT;
            if (prop.Type == SoundItemProperty.typeSound[0])
            {
                mode |= FMOD.MODE._2D | FMOD.MODE.CREATESAMPLE | FMOD.MODE.SOFTWARE;
            }
            else if (prop.Type == SoundItemProperty.typeSound[1])
            {
                mode |= FMOD.MODE._3D | FMOD.MODE.CREATESAMPLE | FMOD.MODE.SOFTWARE | FMOD.MODE._3D_LINEARROLLOFF | FMOD.MODE._3D_WORLDRELATIVE | FMOD.MODE._3D_IGNOREGEOMETRY;
            }
            else if (prop.Type == SoundItemProperty.typeSound[2])
            {
                mode |= FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.SOFTWARE;
            }

            if (prop.Loop == true)
            {
                mode |= FMOD.MODE.LOOP_NORMAL;
            }

            result = system.createSound(name, mode, ref sound);
            ERRCHECK(result);

            result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref channel);
            ERRCHECK(result);

            if (prop.Type == SoundItemProperty.typeSound[1])
            {
                channel.set3DMinMaxDistance(100.0f, prop.MaxDistance);

                FMOD.VECTOR pos = new FMOD.VECTOR();
                pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f;
                FMOD.VECTOR vel = new FMOD.VECTOR();
                vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f;
                channel.set3DAttributes(ref pos, ref vel);

                FMOD.DSP dsp = null;
                result = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS_SIMPLE, ref dsp);
                ERRCHECK(result);

                dsp.setParameter((int)FMOD.DSP_LOWPASS_SIMPLE.CUTOFF, 22000.0f);
                FMOD.DSPConnection dspcon = null;
                channel.addDSP(dsp, ref dspcon);
            }

            channel.setVolume((float)prop.Volume * 0.01f);
            channel.setCallback(CHANNELCALLBACK);
            channel.setPaused(false);

            return(true);
        }
        public void SetListener(Vector3 pos, Vector3 forward, Vector3 up)
        {
            FMOD.RESULT result;
            FMOD.VECTOR pos2;
            FMOD.VECTOR forward2;
            FMOD.VECTOR up2;
            FMOD.VECTOR v = new FMOD.VECTOR();
            pos2.x = pos.X;
            pos2.y = pos.Y;
            pos2.z = pos.Z;
            forward2.x = forward.X;
            forward2.y = forward.Y;
            forward2.z = forward.Z;
            up2.x = up.X;
            up2.y = up.Y;
            up2.z = up.Z;

            result = system.set3DListenerAttributes(0, ref pos2, ref v, ref forward2, ref up2);
            ERRCHECK(result);
        }
 public void SetPosition(Channel channel, Vector3 pos)
 {
     FMOD.RESULT result;
     FMOD.VECTOR pos2;
     FMOD.VECTOR vel2 = new FMOD.VECTOR();
     pos2.x = pos.X;
     pos2.y = pos.Y;
     pos2.z = pos.Z;
     FmodChannel c = (FmodChannel)channel;
     result = c.channel.set3DAttributes(ref pos2, ref vel2);
     ERRCHECK(result);
 }