KinPortal/Game/DynamicObject.cs
2020-05-15 12:18:51 +02:00

58 lines
1.6 KiB
C#
Executable File

using Microsoft.Xna.Framework;
using Jitter.Dynamics;
namespace KinPortal {
public class DynamicObject : Object {
public RigidBody PhysicModel {get; private set;}
public TargetingStrategy TargetingStrategy {get; set;}
public override Vector3 Pos {
get {
return Geometry.GetXnaVector(PhysicModel.Position);
}
set {
PhysicModel.Position = Geometry.GetJitterVector(value);
}
}
public override Quaternion Rot {
get {
return Quaternion.CreateFromRotationMatrix(Geometry.GetXnaMatrix(PhysicModel.Orientation));
}
set {
PhysicModel.Orientation = Geometry.GetJitterMatrix(Matrix.CreateFromQuaternion(value));
}
}
public bool IsStatic {
get {
return PhysicModel.IsStatic;
}
set {
PhysicModel.IsStatic = value;
}
}
public DynamicObject(string filepath, Vector3 pos, Quaternion rot, Scene scene, ShapeType shapeType, bool isStatic, TargetingStrategy strategy)
: base(filepath, scene) {
PhysicModel = new RigidBody(ShapeFactory.CreateShape(Model, shapeType));
Pos = pos;
Rot = rot;
TargetingStrategy = strategy;
IsStatic = isStatic;
}
public DynamicObject(string filepath, Scene scene, ShapeType shapeType)
: this(filepath, Vector3.Zero, Quaternion.Identity, scene, shapeType, false, new NoTargetingStrategy()) {}
public void Target(HandsProjection leftHand, HandsProjection rightHand) {
TargetingStrategy.Target(this, leftHand, rightHand);
}
public override void Update(GameTime gameTime) {
TargetingStrategy.Update(this, gameTime);
base.Update(gameTime);
}
}
}