136 lines
2.6 KiB
C#
136 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using OpenTK;
|
|
using org.niclasundharald.engine.graphics;
|
|
|
|
using nhengine.Audio;
|
|
|
|
|
|
namespace org.niclasundharald.engine
|
|
{
|
|
public class Actor : WorldObject
|
|
{
|
|
public static List<Actor> activeActors = new List<Actor>();
|
|
public static List<Actor> finishedActors = new List<Actor>();
|
|
|
|
|
|
public static void updateAll(float timespan)
|
|
{
|
|
foreach (Actor a in activeActors)
|
|
{
|
|
a.update(timespan);
|
|
}
|
|
|
|
foreach (Actor a in finishedActors)
|
|
{
|
|
activeActors.Remove(a);
|
|
|
|
|
|
}
|
|
finishedActors.Clear();
|
|
|
|
}
|
|
|
|
private int id;
|
|
|
|
public Actor(int id)
|
|
{
|
|
Console.WriteLine("New Actor: {0} / {1}",id,this);
|
|
this.id = id;
|
|
activeActors.Add(this);
|
|
|
|
_player = new nhPlayer();
|
|
activePlayers.Add(_player);
|
|
|
|
}
|
|
|
|
public void destroy(){
|
|
finishedActors.Add(this);
|
|
_player.deletePlayer();
|
|
|
|
}
|
|
|
|
public Vector3 Heading { get; set; }
|
|
public Vector3 Velocity { get; set; }
|
|
public float Weight { get; set; }
|
|
|
|
public virtual void update(float timespan){
|
|
if (soundPlaying()){
|
|
syncSoundPosition();
|
|
}
|
|
}
|
|
|
|
public void setHeading(Vector3 heading,Vector3 top){
|
|
Vector3 x,y,z;
|
|
|
|
z = heading.Normalized();
|
|
x = Vector3.Cross( top.Normalized(), z ).Normalized();
|
|
y = Vector3.Cross( x, z );
|
|
|
|
Matrix4 mRotation = new Matrix4(
|
|
new Vector4(x,0),
|
|
new Vector4(y,0),
|
|
new Vector4(z,0),
|
|
new Vector4(0,0,0,1)
|
|
);
|
|
|
|
Rotation = Matrix4.CreateRotationX(MathHelper.PiOver2) * mRotation;
|
|
}
|
|
|
|
public Model3D Model3D { get; set; }
|
|
|
|
public override Model3D getModel3D()
|
|
{
|
|
return Model3D;
|
|
}
|
|
|
|
|
|
//>>>>>>>>AUDIO
|
|
|
|
private static List<nhPlayer> activePlayers = new List<nhPlayer>();
|
|
private static Dictionary<string,int> aBuffers = new Dictionary<string,int>();
|
|
|
|
private nhPlayer _player;
|
|
|
|
public bool isPlaying = false;
|
|
|
|
|
|
|
|
|
|
public void setDistanceAttenuation(float rollOf = 2.0f, float refDistance = 1.0f, float maxDistance = 100.0f)
|
|
{
|
|
_player.setDistanceAttenuation(rollOf, refDistance, maxDistance);
|
|
|
|
}
|
|
|
|
public void setBuffers(params string[] buffers)
|
|
{
|
|
foreach (string i in buffers)
|
|
{
|
|
if(!aBuffers.ContainsKey(i))
|
|
aBuffers.Add(i, nhBuffers.buffers[i]);
|
|
}
|
|
}
|
|
|
|
public void playSound(string sound, float gain = 1.0f, bool loop = false)
|
|
{
|
|
|
|
_player.position = this.Position;
|
|
_player.velocity = this.Velocity;
|
|
_player.play(aBuffers[sound], gain, loop);
|
|
}
|
|
|
|
private void syncSoundPosition()
|
|
{
|
|
_player.setPosition(this.Position);
|
|
_player.setVelocity(this.Velocity);
|
|
}
|
|
|
|
public Boolean soundPlaying(){
|
|
return _player.state();
|
|
}
|
|
|
|
}
|
|
}
|