如何在XNA上移动3D模型?

发布于 2024-12-05 01:59:55 字数 52 浏览 1 评论 0原文

我想控制我的 3D 模型,将其向各个方向移动,但我不知道如何做到这一点。有人有什么想法吗?

I want to control my 3D model, move it every direction but I don't know way to do this. Anybody have any idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-12-12 01:59:55

您只需提供模型的世界变换效果即可。

 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;
}

您还可以将您的移动基于向前向量,或者平滑角度变化,将最终向前插值到当前,...

You only have to provide to the effect the model's world transform.

 Matrix World = Matrix.CreateWorld(position, forward, up);

In your update method you can modify the position:

  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;
}

You also can base your movement in forward vector, or smooth the angle change interpolating the final forward with the current,...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文