a95ec67a31
-active/finished Players Lists -distanceAttenuation Properties -setBuffers Method for assigning buffers to Actor
124 lines
2.4 KiB
C#
124 lines
2.4 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
|
|
{
|
|
private static List<Actor> activeActors = new List<Actor>();
|
|
private 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(("Actor" + id), Position);
|
|
activePlayers.Add(_player);
|
|
|
|
}
|
|
|
|
public void destroy(){
|
|
finishedActors.Add(this);
|
|
finishedPlayers.Add(_player);
|
|
}
|
|
|
|
public Vector3 Heading { get; set; }
|
|
public Vector3 Velocity { get; set; }
|
|
public float Weight { get; set; }
|
|
|
|
protected virtual void update(float timespan){
|
|
}
|
|
|
|
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 List<nhPlayer> finishedPlayers = new List<nhPlayer>();
|
|
|
|
private static List<int> aBuffers = new List<int>();
|
|
|
|
private nhPlayer _player;
|
|
|
|
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)
|
|
{
|
|
this.rollOf = rollOf;
|
|
this.refDistance = refDistance;
|
|
this.maxDistance = maxDistance;
|
|
}
|
|
|
|
public void setBuffers(params string[] buffers)
|
|
{
|
|
for (int i = 0; i < buffers.Length; i++)
|
|
{
|
|
aBuffers.Add(nhBuffers.buffers[buffers[i]]);
|
|
}
|
|
}
|
|
|
|
|
|
public void playSound(string sound, float gain, bool loop)
|
|
{
|
|
_player.play(sound, gain, loop);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|