我想控制我的3D模型,向各个方向移动,但我不知道如何做到这一点。有人有任何想法吗?
答案 0 :(得分:1)
您只需提供模型的世界变换效果。
Matrix World = Matrix.CreateWorld(position, forward, up);
在您的更新方法中,您可以修改位置:
LastPosition = Position;
if (IsKeyDonw(Left) Position -= Vector3.UnitX * Speed * ElapsedTime; ForwardDirty = true;
if (IsKeyDonw(Right) Position += Vector3.UnitX * Speed * ElapsedTime; ForwardDirty = true;
if (IsKeyDonw(Up) Position -= Vector3.UnitZ * Speed * ElapsedTime; ForwardDirty = true;
if (IsKeyDonw(Down) Position += Vector3.UnitZ * Speed * ElapsedTime; ForwardDirty = true;
// the forward is the direction where will point your model.
if (ForwardDirty) {
Forward = Position - LastPosition;
Forward.Normalize();
ForwardDirty = false;
}
你也可以将你的动作建立在前向矢量的基础上,或者平滑角度变化,用当前内插最后的前进,...