3
며칠 동안 저는 지금 XNA 프로젝트를 진행하고 있습니다. 응용 프로그램의 주요 아이디어는 개별적으로 뒤집을 수있는 평면 컬러 타일 격자를 갖는 것입니다. 내가 가지고있는 문제는 타일 주변의 플립 회전을 수행하는 방법을 실제로 파악할 수 없다는 것입니다.3D 축을 중심 축을 중심으로 회전
지금 일어나는 일은 타일이 자체 축 대신 세계 축을 중심으로 회전한다는 것입니다.
각 타일은 3D 세계에서 2 차원 정사각형을 만드는 정점 배열로 구성됩니다.
저는 문제가 저와 행렬이 어수선하게 어울린다고 확신합니다. 그것이 내가 당신에게 전체 소스를 보낼 수 있습니다 도움이된다면
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
RasterizerState rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = rasterizerState;
viewMatrix = Matrix.CreateLookAt(cameraPos, new Vector3(0, 0, 0), Vector3.Up);
effect.CurrentTechnique = effect.Techniques["ColoredNoShading"];
effect.Parameters["xView"].SetValue(viewMatrix);
effect.Parameters["xProjection"].SetValue(projectionMatrix);
Vector3 rotAxis = new Vector3(0, 0, 1);
rotAxis.Normalize();
worldMatrix = Matrix.Identity;
effect.Parameters["xWorld"].SetValue(worldMatrix);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
foreach(Tile tile in tiles)
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, tile.Vertices, 0, 2, VertexPositionColor.VertexDeclaration);
}
base.Draw(gameTime);
}
: 여기
public Tile(Vector3 position, int size, Matrix world)
{
this.position = position;
this.size = size;
this.world = world;
vertices = new VertexPositionColor[6];
for (int i = 0; i < vertices.Length; i++)
vertices[i].Position = position;
vertices[0].Position += new Vector3(0, 0, 0);
vertices[0].Color = Color.Pink;
vertices[1].Position += new Vector3(0, size, 0);
vertices[1].Color = Color.Yellow;
vertices[2].Position += new Vector3(0, size, size);
vertices[2].Color = Color.Green;
vertices[3].Position += new Vector3(0, size, size);
vertices[3].Color = Color.Green;
vertices[4].Position += new Vector3(0, 0f, size);
vertices[4].Color = Color.Blue;
vertices[5].Position += new Vector3(0, 0, 0);
vertices[5].Color = Color.Blue;
}
public VertexPositionColor[] Vertices
{
get{ return Functions.TransformVertices((VertexPositionColor[])vertices.Clone(), GetMatrix()); }
}
private Matrix GetMatrix()
{
return Matrix.CreateRotationZ(rot);
}
private void TransformVertices(Matrix matrix)
{
for (int i = 0; i < vertices.Length; i++)
vertices[i].Position = Vector3.Transform(vertices[i].Position, matrix);
}
그리고
그리기 방법 : 여기 는 각 타일에 대한 코드입니다. 어떤 도움이라도 귀중한 것입니다!
감사합니다! 누군가가 이것을 실제로 어떻게 수행 할 수 있는지 보여줄 수 있습니까? – Pijm0
Matrix.CreateTranslation (-tilePosition) * Matrix.CreateTranslation (0, -size/2, -size/2) * Matrix.CreateRotationX (angle) * Matrix.CreateTranslation (tilePosition) – Blau
downvoter가 왜 부정적으로 찬성했는지 설명하려고합니다. ? – Paddyd