gpt4 book ai didi

graphics - 变换 Direct3D 网格

转载 作者:行者123 更新时间:2023-12-04 07:11:04 28 4
gpt4 key购买 nike

我试着写一个 TransformMesh功能。该函数接受一个 Mesh对象和 Matrix目的。这个想法是使用矩阵来转换网格。为此,我锁定了顶点缓冲区,并在每个顶点上调用了 Vector3::TransformCoordinate。它没有产生预期的结果。生成的网格无法识别。

我究竟做错了什么?

// C++/CLI code. My apologies.
int n = verts->Length;
for(int i = 0; i < n; i++){
verts[i].Position = DX::Vector3::TransformCoordinate(verts[i].Position, matrix);
}

最佳答案

我完全同意 Coincoin,上下文代码会有所帮助。
如果您只想将变换后的网格绘制到屏幕上,则不需要以这种方式变换网格。您可以只更改世界、 View 和投影矩阵之一。这产生了预期的结果。就像在下面的示例代码中一样。

      // Clear the backbuffer to a Blue color.
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue,
1.0f, 0);

// Begin the scene.
device.BeginScene();

device.Lights[0].Enabled = true;

// Setup the world, view, and projection matrices.
Matrix m = new Matrix();

if( destination.Y != 0 )
y += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.Y
* 25);

if( destination.X != 0 )
x += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.X
* 25);

m = Matrix.RotationY(y);
m *= Matrix.RotationX(x);

device.Transform.World = m;
device.Transform.View = Matrix.LookAtLH(
new Vector3( 0.0f, 3.0f,-5.0f ),
new Vector3( 0.0f, 0.0f, 0.0f ),
new Vector3( 0.0f, 1.0f, 0.0f ) );
device.Transform.Projection = Matrix.PerspectiveFovLH(
(float)Math.PI / 4, 1.0f, 1.0f, 100.0f );

// Render the teapot.
teapot.DrawSubset(0);

// End the scene.
device.EndScene();

此样本取自 here .

关于graphics - 变换 Direct3D 网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/330757/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com