budnhead/org.budnhead/core/Actor.cs

133 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using OpenTK;
using org.budnhead.audio;
using org.budnhead.graphics;
namespace org.budnhead.core
{
public class Actor : WorldObject
{
internal static List<Actor> activeActors = new List<Actor>();
private static List<Actor> finishedActors = new List<Actor>();
internal static void updateActors(float elapsed){
// Update all active Actors...
foreach (Actor a in activeActors.ToArray()){
a.update(elapsed);
}
// Remove finished Actors
foreach (Actor a in finishedActors.ToArray()){
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 readonly BufferedValueInstance<Vector3> Heading = new BufferedValueInstance<Vector3>(new Vector3(0,0,1));
public readonly BufferedValueInstance<Vector3> Velocity = new BufferedValueInstance<Vector3>(new Vector3());
public readonly BufferedValueInstance<float> Weight = new BufferedValueInstance<float>(0);
public bool IsActive {
get { return activeActors.Contains(this); }
}
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.Value = 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.Value;
// _player.velocity = this.Velocity.Value;
// _player.play(aBuffers[sound], gain, loop);
}
private void syncSoundPosition()
{
// _player.setPosition(this.Position.Value);
// _player.setVelocity(this.Velocity.Value);
}
public Boolean soundPlaying(){
return false; //_player.state();
}
}
}