第三人称摄像头的轴未正确围绕玩家呈球形 - 逻辑问题?

发布于 2024-10-21 02:28:08 字数 1613 浏览 4 评论 0原文

我正在使用 Ox Engine 在 XNA 中制作 3D 游戏。文档很少,到目前为止我还活着,但现在我已经遇到了很长一段时间的逻辑障碍,我认为是时候寻求外部帮助了。

所有移动和鼠标看起来都有效,并且相机正确跟随,但是当我在 Y 轴上向上/向下移动鼠标以使相机在角色周围的循环“气泡”中移动时,它会导致其他所有内容不同步。角色应该由摄像机绕轨道运行,但也需要知道角色面向的方向。我似乎无法两者兼得。

当我有代码告诉它角色的方向并“远离”(转置)它时,它正在移动轨道本身:

        if (changeY > 0)
        {
            if (camMemory.Y > 110)
                tempMatrix *= Matrix.CreateFromAxisAngle(model.Orientation.Left, MathHelper.ToRadians(changeY));
        }
        else if (changeY < 0)
        {
            if (camMemory.Y < 400)//FAKE PLACEHOLDER VALUE... highest point in arc goes here
                tempMatrix *= Matrix.CreateFromAxisAngle(model.Orientation.Left, MathHelper.ToRadians(changeY));       
        }

        Vector3 camPos = new Vector3(0, 0, 0) ;
        camMemory = tempMatrix.Translation;

        //NOTE: this is the piece that causes the "bubble" to move
        moveAmount = tempMatrix.Forward * 200f;
        /////
        tempMatrix.Translation += moveAmount;
        camPos = tempMatrix.Translation + model.Position;

        //Pointer in front, Camera behind, make camera face pointer.



        Engine.Camera.SetTransformByLookTarget(camPos, model.Orientation.Up, trackPos);

这意味着由于没有正确地围绕角色运行,当他转动相机时,相机就错位了。

但是,当我解决这个问题时,我离角色的距离不够远,无法获得正确的视图,并且只需乘以 tempMatrix。翻译为“扩大”“泡沫”使我严重格格不入。我失去了顿悟。任何见解将不胜感激。

tl,dr:如何在不移动中心点的情况下使角色周围的轨道摄像机气泡变大(转置不起作用或者我使用错误!)

编辑:我希望我能对此给予赏金,哈哈

I'm making a 3D game in XNA using Ox Engine. There is very little documentation and I have been surviving thus far, but now I've hit a logical road block for a good while and I think it's time to ask for outside help.

All movement and mouse look x work and the camera follows properly however when I move the mouse up/down on the Y axis to make the camera move in its circling "bubble" around the character it causes everything else to go out of sync. The character should orbited by the camera, but it also needs to be told what direction the character is facing. I cannot seem to have both.

When I have the code to tell it the direction of the character and move "away"(transpose) from it, it's moving the orbit itself:

        if (changeY > 0)
        {
            if (camMemory.Y > 110)
                tempMatrix *= Matrix.CreateFromAxisAngle(model.Orientation.Left, MathHelper.ToRadians(changeY));
        }
        else if (changeY < 0)
        {
            if (camMemory.Y < 400)//FAKE PLACEHOLDER VALUE... highest point in arc goes here
                tempMatrix *= Matrix.CreateFromAxisAngle(model.Orientation.Left, MathHelper.ToRadians(changeY));       
        }

        Vector3 camPos = new Vector3(0, 0, 0) ;
        camMemory = tempMatrix.Translation;

        //NOTE: this is the piece that causes the "bubble" to move
        moveAmount = tempMatrix.Forward * 200f;
        /////
        tempMatrix.Translation += moveAmount;
        camPos = tempMatrix.Translation + model.Position;

        //Pointer in front, Camera behind, make camera face pointer.



        Engine.Camera.SetTransformByLookTarget(camPos, model.Orientation.Up, trackPos);

This means that by not properly orbiting the character, when he turns the camera is out of place.

However when I remedy this problem I am not far enough away from the character to have a proper view and simply multiplying upon tempMatrix.Translation to 'widen' the 'bubble' causes me to be severely out of place. I am bereft of epiphanies. Any insights would be greatly appreciated.

tl,dr: How do I make the orbiting camera bubble around the character bigger without moving the center point (transpose isn't working or I'm using it wrong!)

Edit: I wish I could put a bounty on this, lol

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

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

发布评论

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

评论(1

很酷不放纵 2024-10-28 02:28:08

角色应该围绕
相机,但也需要告诉
角色的方向是什么
面对。我似乎无法两者兼得。

兼具两者的方法是根据角色矩阵基向量的偏移来设置摄像机位置。这样,当角色旋转并改变基本向量时,您的相机将跟随它。同时或独立地,更改偏移值将使您的相机也绕角色运行。

您的代码似乎仅绕模型的 X 轴旋转。为了演示围绕该轴的方法,您可以执行以下操作:

Vector3 offset = Vector3.Transform(model.Orientation.Backward, Matrix.CreateFromAxisAngle(model.Orientation.Left, camMemory.Y));

camPos = model.Position + (offset * bubbleSize);

现在,如果角色自行旋转,相机将跟随,因为 model.Orientation.Backward 将发生变化。而且,如果 camMemory.Y 发生变化(我假设这是关闭输入),相机将自行运行。

请注意缩放偏移向量如何影响“气泡”大小。

The character should orbited by the
camera, but it also needs to be told
what direction the character is
facing. I cannot seem to have both.

The way to have them both is to set the camera position based on offsets to the character's matrix basis vectors. This way when the character rotates and changes a basis vector, your camera will follow it. While at the same time or independently, changing the offset value will make your camera orbit the character as well.

It appears that your code is only orbiting about the model's X axis. To demonstrate the approach about that axis, you can do something like this:

Vector3 offset = Vector3.Transform(model.Orientation.Backward, Matrix.CreateFromAxisAngle(model.Orientation.Left, camMemory.Y));

camPos = model.Position + (offset * bubbleSize);

So now, if the character rotates on his own, the camera will follow because model.Orientation.Backward will change. But also, if camMemory.Y changes (I'm assuming this is keyed off input), the camera will orbit on its own.

Note how scaling the offset vector affects 'bubble' size.

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