Distance Attenuation working -> high values bc 1 Tile = 5 V3 values
(-> future method for converting tiles -> V3 values)audio-streams
parent
928d7c0da4
commit
76c2f5a9de
|
@ -60,7 +60,7 @@ namespace nhengine
|
|||
|
||||
|
||||
AudioDelegate.init();
|
||||
AudioDelegate.DistanceModel("exponential");
|
||||
AudioDelegate.DistanceModel("exponential", true);
|
||||
nhBuffers.addSearchPath("./sounds");
|
||||
nhBuffers.loadSound("HowFire", "HowHit", "st1");
|
||||
//AudioDelegate.test();
|
||||
|
|
|
@ -92,16 +92,13 @@ namespace org.niclasundharald.engine
|
|||
|
||||
public bool isPlaying = false;
|
||||
|
||||
public float rollOf { get; set; }
|
||||
public float refDistance { get; set; }
|
||||
public float maxDistance { get; set; }
|
||||
|
||||
|
||||
public void setDistanceAttenuation(float rollOf = 2.0f, float refDistance = 0.0f, float maxDistance = 100.0f)
|
||||
|
||||
public void setDistanceAttenuation(float rollOf = 2.0f, float refDistance = 1.0f, float maxDistance = 100.0f)
|
||||
{
|
||||
this.rollOf = rollOf;
|
||||
this.refDistance = refDistance;
|
||||
this.maxDistance = maxDistance;
|
||||
_player.setDistanceAttenuation(rollOf, refDistance, maxDistance);
|
||||
|
||||
}
|
||||
|
||||
public void setBuffers(params string[] buffers)
|
||||
|
@ -117,11 +114,15 @@ namespace org.niclasundharald.engine
|
|||
{
|
||||
|
||||
_player.position = this.Position;
|
||||
_player.velocity = Velocity;
|
||||
_player.velocity = this.Velocity;
|
||||
_player.play(aBuffers[sound], gain, loop);
|
||||
|
||||
}
|
||||
|
||||
public void setPlayerPosition(Vector3 positon, Vector3 velocity)
|
||||
{
|
||||
_player.setPosition(positon);
|
||||
_player.setVelocity(velocity);
|
||||
}
|
||||
|
||||
public void updateSoundState()
|
||||
{
|
||||
|
|
|
@ -14,15 +14,18 @@ namespace org.niclasundharald.engine
|
|||
:base(id)
|
||||
{
|
||||
this.Model3D = ModelManager.instance.findModel("ballistisch");
|
||||
setBuffers("HowFire", "HowHit", "st1");
|
||||
setBuffers("HowFire", "HowHit");
|
||||
setDistanceAttenuation(2, 200, 800);
|
||||
}
|
||||
|
||||
int hit = 0;
|
||||
byte hit = 0;
|
||||
|
||||
|
||||
public override void update(float timespan)
|
||||
{
|
||||
base.update(timespan);
|
||||
|
||||
|
||||
Velocity += (Physics.Gravitation * timespan);
|
||||
Position += Velocity * timespan;
|
||||
Scale = Matrix4.CreateScale(3.0f);
|
||||
|
@ -46,8 +49,6 @@ namespace org.niclasundharald.engine
|
|||
hit = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!isPlaying)
|
||||
{
|
||||
destroy();
|
||||
|
@ -66,7 +67,7 @@ namespace org.niclasundharald.engine
|
|||
public void fire()
|
||||
{
|
||||
playSound("HowFire");
|
||||
setDistanceAttenuation(2, 0, 50);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,24 +23,13 @@ namespace nhengine.Audio
|
|||
public static AudioContext context = new AudioContext();
|
||||
//public static EffectsExtension efx = new EffectsExtension();
|
||||
|
||||
//PLAYERS
|
||||
public static readonly List<nhPlayer> players = new List<nhPlayer>();
|
||||
public static readonly List<string> playerNames = new List<string>();
|
||||
public static readonly List<int> playerNumbers = new List<int>();
|
||||
|
||||
|
||||
/* <<<<<<<<<<<INITIALIZE>>>>>>>>>>> */
|
||||
public static void init()
|
||||
{
|
||||
|
||||
nhBuffers.init();
|
||||
nhListener.init();
|
||||
DistanceModel();
|
||||
|
||||
|
||||
//nhAux reverb = new nhAux();
|
||||
Console.WriteLine("nhengine.Audio initialized.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,29 +39,6 @@ namespace nhengine.Audio
|
|||
testPlayer.play(nhBuffers.buffers["st1"]);
|
||||
}
|
||||
|
||||
/* <<<<<<<<<<<MAIN>>>>>>>>>>> */
|
||||
/*
|
||||
public static void Main()
|
||||
{
|
||||
|
||||
using (context)
|
||||
{
|
||||
|
||||
init();
|
||||
play(4, "st1.wav");
|
||||
|
||||
|
||||
while (debug)
|
||||
{
|
||||
Thread.Sleep(40);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public static void DistanceModel(string distanceModel = "exponential", bool clamped = false)
|
||||
{
|
||||
if (!clamped)
|
||||
|
@ -112,108 +78,5 @@ namespace nhengine.Audio
|
|||
}
|
||||
|
||||
|
||||
private static int getPlayerIndex(string playerName)
|
||||
{
|
||||
int _index = playerNames.IndexOf(playerName);
|
||||
return _index;
|
||||
}
|
||||
|
||||
private static int getPlayerIndex(int playerNumber)
|
||||
{
|
||||
int _index = playerNumbers.IndexOf(playerNumber);
|
||||
return _index;
|
||||
}
|
||||
|
||||
/*
|
||||
public static void play(string playerName, string buffer, float gain = 1.0f, bool loop = false)
|
||||
{
|
||||
|
||||
|
||||
if(playerName != null)
|
||||
players[getPlayerIndex(playerName)].play(buffer, gain, loop);
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Not an existing Player.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void play(int playerNumber, string buffer, float gain = 1.0f, bool loop = false)
|
||||
{
|
||||
if (playerNumber != 0)
|
||||
players[getPlayerIndex(playerNumber)].play(buffer, gain, loop);
|
||||
//Console.WriteLine("play player:" + )
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Not an existing Player.");
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public static void setPlayerPosition(string playerName, Vector3 position)
|
||||
{
|
||||
if(playerName != null)
|
||||
players[getPlayerIndex(playerName)].position = position;
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Not an existing Player.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPlayerPosition(int playerNumber, Vector3 position)
|
||||
{
|
||||
if (playerNumber != 0)
|
||||
players[getPlayerIndex(playerNumber)].position = position;
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Not an existing Player.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void setPlayerVelocity(string playerName, Vector3 velocity)
|
||||
{
|
||||
if (playerName != null)
|
||||
players[getPlayerIndex(playerName)].velocity = velocity;
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Not an existing Player.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPlayerVelocity(int playerNumber, Vector3 velocity)
|
||||
{
|
||||
if (playerNumber != 0)
|
||||
players[getPlayerIndex(playerNumber)].velocity = velocity;
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Not an existing Player.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public static void addPlayer(string name, Vector3 position, float rollOf = 2.0f, float refDist = 0.0f, float maxDist = 100.0f)
|
||||
{
|
||||
nhPlayer _player = new nhPlayer(name, position);
|
||||
players.Add(_player);
|
||||
playerNames.Add(_player.name);
|
||||
playerNumbers.Add(_player.number);
|
||||
|
||||
}
|
||||
|
||||
public static void deletePlayer(string name)
|
||||
{
|
||||
int _index = getPlayerIndex(name);
|
||||
players[_index].deletePlayer();
|
||||
players.RemoveAt(_index);
|
||||
playerNames.RemoveAt(_index);
|
||||
playerNumbers.RemoveAt(_index);
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
|
@ -13,29 +13,21 @@ namespace nhengine.Audio
|
|||
private static Vector3 _pos = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
private static Vector3 _vel = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
private static Vector3 _oUp = new Vector3(0.0f, 0.0f, -1.0f);
|
||||
private static Vector3 _oAt = new Vector3(0.0f, 1.0f, 0.0f);
|
||||
private static Vector3 _top = new Vector3(0.0f, 0.0f, -1.0f);
|
||||
private static Vector3 _view = new Vector3(0.0f, 1.0f, 0.0f);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void init()
|
||||
{
|
||||
AL.Listener(ALListener3f.Position, _pos.X, _pos.Y, _pos.Z);
|
||||
AL.Listener(ALListener3f.Velocity, _vel.X, _vel.Y, _vel.Z);
|
||||
AL.Listener(ALListenerfv.Orientation, ref _oAt, ref _oUp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void _setValues()
|
||||
{
|
||||
AL.Listener(ALListener3f.Position, _pos.X, _pos.Y, _pos.Z);
|
||||
AL.Listener(ALListener3f.Velocity, _vel.X, _vel.Y, _vel.Z);
|
||||
AL.Listener(ALListenerfv.Orientation, ref _oAt, ref _oUp);
|
||||
|
||||
AL.Listener(ALListenerfv.Orientation, ref _view, ref _top);
|
||||
Console.WriteLine("listener:" + _pos);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,8 +37,8 @@ namespace nhengine.Audio
|
|||
|
||||
_pos = position;
|
||||
_vel = velocity;
|
||||
_oUp = orientationUp;
|
||||
_oAt = orientationAt;
|
||||
_top = orientationUp;
|
||||
_view = orientationAt;
|
||||
|
||||
_setValues();
|
||||
|
||||
|
@ -66,14 +58,17 @@ namespace nhengine.Audio
|
|||
_setValues();
|
||||
}
|
||||
|
||||
public static void setOrientation(Vector3 Up, Vector3 At)
|
||||
public static void setTop(Vector3 Top)
|
||||
{
|
||||
_oUp = Up;
|
||||
_oAt = At;
|
||||
|
||||
_top = Top;
|
||||
_setValues();
|
||||
}
|
||||
|
||||
public static void setView(Vector3 View)
|
||||
{
|
||||
_view = View;
|
||||
_setValues();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,6 +112,9 @@ namespace nhengine.Audio
|
|||
{
|
||||
|
||||
_gain = gain;
|
||||
AL.Source(_source, ALSourcef.RolloffFactor, _rollOf);
|
||||
AL.Source(_source, ALSourcef.ReferenceDistance, _refDist);
|
||||
AL.Source(_source, ALSourcef.MaxDistance, _maxDist);
|
||||
|
||||
if (buffer != 0)
|
||||
{
|
||||
|
@ -121,11 +124,7 @@ namespace nhengine.Audio
|
|||
}
|
||||
|
||||
AL.Source(_source, ALSourceb.Looping, loop);
|
||||
|
||||
|
||||
AL.SourcePlay(_source);
|
||||
|
||||
|
||||
AL.Source(_source, ALSourcef.Gain, _gain);
|
||||
AL.Source(_source, ALSource3f.Position, position.X, position.Y, position.Z);
|
||||
AL.Source(_source, ALSource3f.Velocity, velocity.X, velocity.Y, velocity.Z);
|
||||
|
@ -138,7 +137,7 @@ namespace nhengine.Audio
|
|||
AL.SourceStop(_source);
|
||||
}
|
||||
|
||||
public void setDistanceAttenuation(float rollOf = 2.0f, float refDistance = 0.0f, float maxDistance = 100.0f)
|
||||
public void setDistanceAttenuation(float rollOf = 2.0f, float refDistance = 1.0f, float maxDistance = 100.0f)
|
||||
{
|
||||
_rollOf = rollOf;
|
||||
_refDist = refDistance;
|
||||
|
|
|
@ -50,24 +50,24 @@ namespace org.niclasundharald.engine.graphics
|
|||
width / height,
|
||||
1.0f,
|
||||
100000.0f
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
get { return new Vector3(vPosition); }
|
||||
set { this.vPosition = new Vector3(value); buildMatrices(); setListener();}
|
||||
set { this.vPosition = new Vector3(value); buildMatrices(); nhListener.setPosition(this.vPosition);}
|
||||
}
|
||||
public Vector3 View
|
||||
{
|
||||
get { return new Vector3(vView); }
|
||||
set { this.vView = new Vector3(value).Normalized(); buildMatrices(); setListener(); }
|
||||
set { this.vView = new Vector3(value).Normalized(); buildMatrices(); nhListener.setView(this.vView); }
|
||||
}
|
||||
|
||||
public Vector3 Top
|
||||
{
|
||||
get { return new Vector3(vTop); }
|
||||
set { this.vTop = new Vector3(value).Normalized(); buildMatrices(); setListener();}
|
||||
set { this.vTop = new Vector3(value).Normalized(); buildMatrices(); nhListener.setTop(this.vTop);}
|
||||
}
|
||||
|
||||
private void buildMatrices(){
|
||||
|
@ -90,12 +90,7 @@ namespace org.niclasundharald.engine.graphics
|
|||
_mCamera = mTranslation * mRotation;
|
||||
}
|
||||
|
||||
private void setListener()
|
||||
{
|
||||
nhListener.setPosition(vPosition);
|
||||
nhListener.setOrientation(vTop, vView);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue