【发布时间】:2015-12-08 09:33:43
【问题描述】:
我正在尝试在 3D 世界中创建广告牌纹理,其中广告牌以中心为旋转点旋转。
Matrix.CreateBillboard 函数出于某种原因仅围绕球体旋转对象。所以当使用这个函数时,旋转是围绕一个球体的边缘,但我希望旋转是围绕对象中心的一个点。
这是我现在设置的代码:
effect.World *= Matrix.CreateBillboard(position, position - Camera.Position, Vector3.Up, null);
int topLeftIndex = 0;
int topRightIndex = 1;
int bottomRightIndex = 2;
int bottomLeftIndex = 3;
VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[4];
vertices[topLeftIndex] = new VertexPositionColorTexture(new Vector3(position.X - size.X / 2, position.Y + size.Y / 2, position.Z), Color.White, new Vector2(0, 0));
vertices[topRightIndex] = new VertexPositionColorTexture(new Vector3(position.X + size.X / 2, position.Y + size.Y / 2, position.Z), Color.White, new Vector2(1, 0));
vertices[bottomLeftIndex] = new VertexPositionColorTexture(new Vector3(position.X - size.X / 2, position.Y - size.Y / 2, position.Z), Color.White, new Vector2(0, 1));
vertices[bottomRightIndex] = new VertexPositionColorTexture(new Vector3(position.X + size.X / 2, position.Y - size.Y / 2, position.Z), Color.White, new Vector2(1, 1));
int[] indices = new int[6];
indices[0] = topLeftIndex;
indices[1] = bottomRightIndex;
indices[2] = bottomLeftIndex;
indices[3] = topLeftIndex;
indices[4] = topRightIndex;
indices[5] = bottomRightIndex;
graphicsDeviceManager.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 4, indices, 0, 2);
position 变量包含对象中心的位置,Camera.Position 是相机位置(显然)。
我可能将错误的坐标传递给函数,但我已经尝试了所有方法(包括将位置转换为对象空间),但到目前为止没有任何效果。
【问题讨论】:
-
XNA不是停产了吗?
-
@Raptor 是的。我只是用它来学习。