一个模型与另一个模型重叠,应该是相反的

发布于 2024-12-03 22:11:18 字数 6602 浏览 0 评论 0原文

我目前正在尝试开发一款3D乒乓球游戏。我的问题是,在绘制桌子和球拍时,桌子当前与球拍重叠,这应该是相反的。有人可以帮忙吗?

这是代码的一部分:

   Model table;
   Model racket;

   Vector3 modelPosition = new Vector3(0,100,150);
   Vector3 modelPosition_table = new Vector3(0,40,0);

   // Set the position of the camera in world space, for our view matrix.
   Vector3 cameraPosition_racket = new Vector3(0.0f, 1000.0f, 10.0f);
   Vector3 cameraPosition_table = new Vector3(0.0f, 150.0f, 250.0f);

   void Draw_Racket()
    {
        // Copy any parent transforms.
        Matrix[] transforms_racket = new Matrix[racket.Bones.Count];
        racket.CopyAbsoluteBoneTransformsTo(transforms_racket);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in racket.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_racket[mesh.ParentBone.Index] *     Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
                effect.View = Matrix.CreateLookAt(cameraPosition_racket, Vector3.Up, Vector3.Up);
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }
    }

    void Draw_Table()
    {

        // Copy any parent transforms.
        Matrix[] transforms_table = new Matrix[table.Bones.Count];
        table.CopyAbsoluteBoneTransformsTo(transforms_table);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in table.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_table[mesh.ParentBone.Index] *                                                              Matrix.CreateTranslation(modelPosition_table);
                effect.View = Matrix.CreateLookAt(cameraPosition_table, Vector3.Down, Vector3.Up);
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 1000.0f);
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }

    }

    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        Draw_Table();
        Draw_Racket();

        base.Draw(gameTime);
    }

如果您需要更多代码,请告诉我。预先感谢:)

编辑...

@Pablo Ariel ..ye我现在明白了并意识到我可以在x轴上旋转球拍,而不是尝试改变相机,并设法得到我想要的东西,但现在一个问题是球拍有点大。这是新代码。

    // Set the 3D model to draw.
    Model table;
    Model racket;

    // The aspect ratio determines how to scale 3d to 2d projection.
    float aspectRatio;

    // Set the position of the model in world space, and set the rotation.
    Vector3 modelPosition = new Vector3(0,250,-25);
    Vector3 modelPosition_table = new Vector3(0,40,500);

    float modelRotation = (MathHelper.Pi*3)/2;

    Vector3 cameraPosition;
    Vector3 cameraTarget;
    Matrix mWorld;
    Matrix mWorld1;
    Matrix mView;
    Matrix mView1;
    Matrix mProjection;

    protected override void Initialize()
    {
        // TODO: Add your initialization logic here
        graphics.PreferredBackBufferWidth = 1000;
        graphics.PreferredBackBufferHeight = 500;
        graphics.IsFullScreen = false;
        graphics.ApplyChanges();
        Window.Title = "Table Tennis 3D";

        mProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), 1.0f, 1.0f, 10000.0f);
        cameraPosition = modelPosition;
        cameraTarget = modelPosition_table;
        modelPosition_table.Z += 40;
        mView = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);

        cameraPosition.Z -= 300;
        modelPosition.Y -= 100;
        mView1 = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);



        base.Initialize();
    }

    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        mWorld = Matrix.CreateRotationY(modelRotation) * Matrix.CreateRotationX(modelRotation) * Matrix.CreateTranslation(modelPosition);
        mWorld1 = Matrix.CreateTranslation(modelPosition_table);

        Draw_Table();
        Draw_Racket();

        base.Draw(gameTime);
    }

    void Draw_Table()
    {

        // Copy any parent transforms.
        Matrix[] transforms_table = new Matrix[table.Bones.Count];
        table.CopyAbsoluteBoneTransformsTo(transforms_table);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in table.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_table[mesh.ParentBone.Index] * mWorld1;
                effect.View = mView;
                effect.Projection = mProjection;
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }

    }

    void Draw_Racket()
    {
        Matrix[] transforms_racket = new Matrix[racket.Bones.Count];
        racket.CopyAbsoluteBoneTransformsTo(transforms_racket);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in racket.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_racket[mesh.ParentBone.Index] * mWorld;
                effect.View = mView1;
                effect.Projection = mProjection;
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }
    }

我应该为球拍做一个新的投影,以便将其尺寸更改为一半吗?我尝试改变它的 z 位置,但没有运气:/..再次感谢:) ps..这里有一个屏幕截图..http://i1099.photobucket.com/albums/g395/krt_ricci/3.png

编辑.. 。 我将球拍的世界矩阵与 Matrix.CreateScale(0.5f, 0.5f, 0.5f) 相乘,以便球拍缩小一半:)

I'm currently trying to develop a 3D table tennis game. My problem is that when drawing the table and racket, the table is currently overlapping the racket, which should be the other way round. Could anyone help please?

Heres part of the code:

   Model table;
   Model racket;

   Vector3 modelPosition = new Vector3(0,100,150);
   Vector3 modelPosition_table = new Vector3(0,40,0);

   // Set the position of the camera in world space, for our view matrix.
   Vector3 cameraPosition_racket = new Vector3(0.0f, 1000.0f, 10.0f);
   Vector3 cameraPosition_table = new Vector3(0.0f, 150.0f, 250.0f);

   void Draw_Racket()
    {
        // Copy any parent transforms.
        Matrix[] transforms_racket = new Matrix[racket.Bones.Count];
        racket.CopyAbsoluteBoneTransformsTo(transforms_racket);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in racket.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_racket[mesh.ParentBone.Index] *     Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
                effect.View = Matrix.CreateLookAt(cameraPosition_racket, Vector3.Up, Vector3.Up);
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }
    }

    void Draw_Table()
    {

        // Copy any parent transforms.
        Matrix[] transforms_table = new Matrix[table.Bones.Count];
        table.CopyAbsoluteBoneTransformsTo(transforms_table);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in table.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_table[mesh.ParentBone.Index] *                                                              Matrix.CreateTranslation(modelPosition_table);
                effect.View = Matrix.CreateLookAt(cameraPosition_table, Vector3.Down, Vector3.Up);
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 1000.0f);
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }

    }

    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        Draw_Table();
        Draw_Racket();

        base.Draw(gameTime);
    }

If you would need any more of the code just let me know. Thanks in advance :)

EDIT...

@Pablo Ariel..ye I understand now and realized that instead of trying to change the camera, I could have rotated the racket at the x-axis, and managed to sort of get what i want, but now one prob is that the racket is a bit to big..heres the new code..

    // Set the 3D model to draw.
    Model table;
    Model racket;

    // The aspect ratio determines how to scale 3d to 2d projection.
    float aspectRatio;

    // Set the position of the model in world space, and set the rotation.
    Vector3 modelPosition = new Vector3(0,250,-25);
    Vector3 modelPosition_table = new Vector3(0,40,500);

    float modelRotation = (MathHelper.Pi*3)/2;

    Vector3 cameraPosition;
    Vector3 cameraTarget;
    Matrix mWorld;
    Matrix mWorld1;
    Matrix mView;
    Matrix mView1;
    Matrix mProjection;

    protected override void Initialize()
    {
        // TODO: Add your initialization logic here
        graphics.PreferredBackBufferWidth = 1000;
        graphics.PreferredBackBufferHeight = 500;
        graphics.IsFullScreen = false;
        graphics.ApplyChanges();
        Window.Title = "Table Tennis 3D";

        mProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), 1.0f, 1.0f, 10000.0f);
        cameraPosition = modelPosition;
        cameraTarget = modelPosition_table;
        modelPosition_table.Z += 40;
        mView = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);

        cameraPosition.Z -= 300;
        modelPosition.Y -= 100;
        mView1 = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);



        base.Initialize();
    }

    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        mWorld = Matrix.CreateRotationY(modelRotation) * Matrix.CreateRotationX(modelRotation) * Matrix.CreateTranslation(modelPosition);
        mWorld1 = Matrix.CreateTranslation(modelPosition_table);

        Draw_Table();
        Draw_Racket();

        base.Draw(gameTime);
    }

    void Draw_Table()
    {

        // Copy any parent transforms.
        Matrix[] transforms_table = new Matrix[table.Bones.Count];
        table.CopyAbsoluteBoneTransformsTo(transforms_table);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in table.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_table[mesh.ParentBone.Index] * mWorld1;
                effect.View = mView;
                effect.Projection = mProjection;
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }

    }

    void Draw_Racket()
    {
        Matrix[] transforms_racket = new Matrix[racket.Bones.Count];
        racket.CopyAbsoluteBoneTransformsTo(transforms_racket);

        // Draw the model. A model can have multiple meshes, so loop.
        foreach (ModelMesh mesh in racket.Meshes)
        {
            // This is where the mesh orientation is set, as well 
            // as our camera and projection.
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = transforms_racket[mesh.ParentBone.Index] * mWorld;
                effect.View = mView1;
                effect.Projection = mProjection;
            }
            // Draw the mesh, using the effects set above.
            mesh.Draw();
        }
    }

Should I make a new projection for the racket so that i change its size to half? I've tried changing its z position but no luck :/..thanks once again :) ps..heres a screenshot..http://i1099.photobucket.com/albums/g395/krt_ricci/3.png

EDIT...
I've multiplied my world matrix for the racket with Matrix.CreateScale(0.5f, 0.5f, 0.5f) so that the racket is scaled down by half :)

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

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

发布评论

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

评论(1

左岸枫 2024-12-10 22:11:18

我认为这是错误的:

Matrix.CreateLookAt(cameraPosition_racket, Vector3.Up, Vector3.Up);

应该是:

Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);

我想提出的建议是,您不应该使用如此大的数字(例如 1000.0f)作为位置,除非您的游戏架构当然需要这样做,但使用较小的比例更好因为浮动不精确。

如果您将相机放在球拍所在的位置,那么您的相机可能会位于球拍内部,而您将看不到它(由于背面剔除,您看不到球拍内部的面孔)

除此之外,我可以从这段代码中无法弄清楚可能出了什么问题,但错误的视图矩阵可能会以某种方式反转你的 z 值,从而扰乱深度缓冲区。

这很复杂,因为我不明白相机向量应该是什么,你应该为相机使用3个向量:cameraPosition,cameraTarget和cameraUp,那么你想要相机指向的地方会更清楚,如果你改变相机值您不必修改矩阵的创建,只需分配另一个向量即可。

编辑:看看有一些事情你必须改变

首先,计算每个骨骼的视图和投影矩阵(场景中的每个网格都是相同的)是非常糟糕的,因为生成矩阵非常慢特别在 C# 中,因此您应该设法执行以下操作:effect.View = mView; 并对投影矩阵执行相同的操作。

这就是你出错的原因,因为生成矩阵的次数不同,你正在构建 2 个不同的投影矩阵:你

在 DrawRacket() 中执行此操作:

effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);

在 DrawTable() 中:

effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 1000.0f);

你将表网格映射到 1 到1000 和球拍为 1 到 10k 然后,当您需要为每个对象使用相同的投影矩阵时,所有坐标都会因为单个零而变得混乱,因此您应该将其存储为全局变量或然而它是在 C# 中处理的(成员变量或类似的东西)

编辑 2:

当然你必须对两个对象使用相同的相机!如果不这样做,那么每个对象都会被绘制,就好像相机位于每个对象的不同位置一样!

这是您的固定代码:

Model table;
Model racket;

Vector3 modelPosition = new Vector3(0,100,150);
Vector3 modelPosition_table = new Vector3(0,40,0);

// Set the position of the camera in world space, for our view matrix.
Vector3 cameraPosition_racket = new Vector3(0.0f, 1000.0f, 10.0f);
Vector3 cameraPosition_table = new Vector3(0.0f, 150.0f, 250.0f);

Vector3 cameraPosition = cameraPosition_racket;
Vector3 cameraTarget  = new Vector3(0.0f, 0.0f, 0.0f);

Matrix mView = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix mProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);



void Draw_Racket()
{
    // Copy any parent transforms.
    Matrix[] transforms_racket = new Matrix[racket.Bones.Count];
    racket.CopyAbsoluteBoneTransformsTo(transforms_racket);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in racket.Meshes)
    {
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms_racket[mesh.ParentBone.Index] *     Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
            effect.View = mView;
            effect.Projection = mProjection;
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();
    }
}

void Draw_Table()
{

    // Copy any parent transforms.
    Matrix[] transforms_table = new Matrix[table.Bones.Count];
    table.CopyAbsoluteBoneTransformsTo(transforms_table);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in table.Meshes)
    {
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms_table[mesh.ParentBone.Index] * Matrix.CreateTranslation(modelPosition_table);
            effect.View = mView;
            effect.Projection = mProjection;
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();
    }

}

protected override void Draw(GameTime gameTime)
{
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

    Draw_Table();
    Draw_Racket();

    base.Draw(gameTime);
}

更新:尝试这个:

 Vector3 modelPosition_racket = new Vector3(0,100,100); // former modelPosition
 Vector3 modelPosition_table  = new Vector3(0,40,500);

 // Set the position of the camera in world space, for our view matrix.
 Vector3 cameraPosition = modelPosition_racket;
 Vector3 cameraPosition.z -= 300;
 Vector3 cameraTarget   = modelPosition_table;

更新:您必须理解的是,您要正确地显示图像,您正在使用 modelPosition 执行的操作是将每个对象从其本地坐标空间转换为全局/世界坐标空间(每个模型有自己的 modelPosition)。所有对象共享相同的坐标空间和相同的投影变换。在全局/世界坐标空间中,您还可以指定相机位置,然后根据相机的世界变换值构建矩阵。
如果你想在世界空间中移动一个对象,你必须修改 modelPosition.. 这不是我只是“相信”的方式,这就是 3d 的工作原理。如果你修改其他值来改变对象的位置,例如投影或视图矩阵,那么这不会给你带来任何好处,因为它不会那样工作,你所有的数学都会搞砸,你就赢了无法正常工作。

I believe this is wrong:

Matrix.CreateLookAt(cameraPosition_racket, Vector3.Up, Vector3.Up);

it should be:

Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);

A recommendation I would like to make is that you should not use so big numbers such as 1000.0f as positions unless of course this is required for your game architecture, but using a smaller scale is better because of float imprecision.

If you put the camera where the racket is then your camera may then be inside the racket and you won't be able to see it (because of backface culling you can't see faces from inside the racket)

Other than that, I can't figure out from this code what could be wrong, but the wrong view matrix could invert your z values in a way which messes up the depth buffer.

It's complicated because I don't understand what the camera vectors should be, you should use 3 vectors for the camera: cameraPosition, cameraTarget and cameraUp, then it will be clearer where you want the camera point to, and if you change the camera values you don't have to modify the matrix creation but just assign another vector.

EDIT: Look there are some things you have to change

First of all, calculating the view and projection matrix (which are the same for EVERY mesh in the scene) for each bone is very bad because generating the matrix is REAALLLLYYY SLOW SPECIALLY IN C# so you should manage to just do this: effect.View = mView; and the same with the projection matrix.

This is the reason of you error, because of generating the matrix so many different times, you are building 2 different projection matrices:

yo do this in DrawRacket():

effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);

and in DrawTable():

effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 1000.0f);

You're mapping the table mesh to 1 to 1000 and the racket to 1 to 10k Then all coordinates get messed up because of a single zero, when you need to use the same projection matrix for every object, so you should store it as a globabl variable or howeever it's handled in c# (a member variable or something like that)

EDIT 2:

Of course you MUST use the same camera for both objects!! if you don't then every object will be drawn as if the camera were in a different place for each!

This is your fixed code:

Model table;
Model racket;

Vector3 modelPosition = new Vector3(0,100,150);
Vector3 modelPosition_table = new Vector3(0,40,0);

// Set the position of the camera in world space, for our view matrix.
Vector3 cameraPosition_racket = new Vector3(0.0f, 1000.0f, 10.0f);
Vector3 cameraPosition_table = new Vector3(0.0f, 150.0f, 250.0f);

Vector3 cameraPosition = cameraPosition_racket;
Vector3 cameraTarget  = new Vector3(0.0f, 0.0f, 0.0f);

Matrix mView = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix mProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);



void Draw_Racket()
{
    // Copy any parent transforms.
    Matrix[] transforms_racket = new Matrix[racket.Bones.Count];
    racket.CopyAbsoluteBoneTransformsTo(transforms_racket);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in racket.Meshes)
    {
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms_racket[mesh.ParentBone.Index] *     Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
            effect.View = mView;
            effect.Projection = mProjection;
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();
    }
}

void Draw_Table()
{

    // Copy any parent transforms.
    Matrix[] transforms_table = new Matrix[table.Bones.Count];
    table.CopyAbsoluteBoneTransformsTo(transforms_table);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in table.Meshes)
    {
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms_table[mesh.ParentBone.Index] * Matrix.CreateTranslation(modelPosition_table);
            effect.View = mView;
            effect.Projection = mProjection;
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();
    }

}

protected override void Draw(GameTime gameTime)
{
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

    Draw_Table();
    Draw_Racket();

    base.Draw(gameTime);
}

UPDATE: try this:

 Vector3 modelPosition_racket = new Vector3(0,100,100); // former modelPosition
 Vector3 modelPosition_table  = new Vector3(0,40,500);

 // Set the position of the camera in world space, for our view matrix.
 Vector3 cameraPosition = modelPosition_racket;
 Vector3 cameraPosition.z -= 300;
 Vector3 cameraTarget   = modelPosition_table;

UPDATE: What you have to understand is for you to properly show the image what you are doing with modelPosition is translating every object from its local coordinate space to the global/world coordinate space (each model has its own modelPosition). There all objects share the same coordinate space and the same projection transform. In the global/world coordinate space you also specify the camera position, then build a matrix from the world transform values of the camera.
If you want to move an object in the world space, you have to modify modelPosition.. this is not something i just "believe" is that way, that's how 3d works. If you modify other values to change the position of the object, such as the projection or view matrix, then that won't do you any good, because it doesn't work that way, all your math will be messed up and you won't be able to work properly.

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