さて、私はマインクラフトのようなビルダーに取り組んできました。アイデアは、マイニングなどをせずに巨大な構造物をすばやく構築できるようにすることです.それは学習体験のためです.
だから今、私は厄介な点で立ち往生しています...
片側からブロックを破壊した場合。正しく動作します。
しかし、カメラを反対側に移動すると、すべてがうまくいきません。
したがって、基本的に私はこの時点で立ち往生しており、修正方法がわかりません。
私は光線を計算します:
Ray getRay(MouseState mouseState)
{
Viewport vp = mainController.engine.graphics.GraphicsDevice.Viewport;
Vector3 nearPoint = new Vector3(mouseState.X, mouseState.Y, 0);
Vector3 farPoint = new Vector3(mouseState.X, mouseState.Y, 1);
nearPoint = vp.Unproject(nearPoint, camera.getProjectionMatrix(), camera.getViewMatrix(), Matrix.Identity);
farPoint = vp.Unproject(farPoint, camera.getProjectionMatrix(), camera.getViewMatrix(), Matrix.Identity);
Vector3 direction = Vector3.Normalize(farPoint - nearPoint);
return new Ray(nearPoint, direction);
}
そして、すべてのモデルのバウンディング ボックスでブルート チェックを実行します。
for (int y = world.settings.regionHeight - 1; y >= 0; y--)
{
gotblock = false;
for (int x = 0; x < world.settings.regionWidth; x++)
for (int z = 0; z < world.settings.regionLenght; z++)
{
f = ray.Intersects(block[x, y, z].boundingBox);
if (f != null)
{
if (f < lowestDistance && world.block[(int)position.X * world.settings.regionWidth + x, y, (int)position.Y * world.settings.regionLenght + z] != BlockTypes.none)
{
result = new intVector3((int)position.X * world.settings.regionWidth + x, y, (int)position.Y * world.settings.regionLenght + z);
gotblock = true;
}
}
}
if (gotblock)
break;
}
さらに情報が必要な場合は、教えてください。前もって感謝します。