public override void LoadContent(ContentManager content, GraphicsDevice g) { base.LoadContent(content, g); //Set up our camera and primitive renderer cam = new ThirdPersonCamera(targetPos, 5.0f, 0.2f); primBatch = new PrimitiveBatch(g); //Initialize our PrimitiveBatch MeshBuilder mb = new MeshBuilder(g); Mesh triangle;// = mb.CreateSphere(0.3f, 15, 15); mb.Begin(); // mb.AddTriangle(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(1, 0, 0), true); // mb.AddTriangle(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(1, 0, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(0, 1), true); mb.AddQuad(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(2, 1, 0), new Vector3(1, 0, 0), true, new Vector2(0, 0), new Vector2(1, 1), new Vector2(2, 1), new Vector2(1, 0)); triangle = mb.End(); triangle.Texture = content.Load<Texture2D>("Cube"); target = new MeshNode(triangle); target.SetPos(targetPos); }
/// <summary> /// Draws each block, makes blocks between camera and player translucent /// </summary> /// <param name="g"></param> /// <param name="batch"></param> /// <param name="cam"></param> public void DebugDraw(GameTime g, PrimitiveBatch batch, Effect customEffect, ThirdPersonCamera cam) { //find out if block is between camera and player Vector3 camPos = cam.Pos; Vector3 playerPos = cam.TargetPos; playerPos += (camPos - playerPos) * 0.1f; AABB3D bounds = AABB3D.CreateFromPoints(new Vector3[] { camPos, playerPos }); Vector3 min = bounds.GetMin(); Vector3 max = bounds.GetMax(); int startRow = (int)min.X; startRow = (int)Math.Max(startRow, 0); int startCol = (int)min.Y; startCol = (int)Math.Max(startCol, 0); int startStack = (int)min.Z; startStack = (int)Math.Max(startStack, 0); int endRow = (int)max.X; endRow = (int)Math.Min(endRow, width - 1); int endCol = (int)max.Y; endCol = (int)Math.Min(endCol, height - 1); int endStack = (int)max.Z; endStack = (int)Math.Min(endStack, depth - 1); List<int[]> translucentBlocks = new List<int[]>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { byte type = blocks[x, y, z].Type; if (type == 0) { continue; } if ((x >= startRow) && (x <= endRow)) { if ((y >= startCol) && (y <= endCol)) { if ((z >= startStack) && (z <= endStack)) { //block is between camera and player, so store it for drawing later translucentBlocks.Add(new int[3]{x, y, z}); //batch.DrawMesh(BlockData.GetMeshFromID(blocks[x, y, z].Type), BlockData.GetRotationMatrix(blocks[x, y, z]) * Matrix.CreateTranslation(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f)), cam, 0.5f); continue; } } } //block isn't between camera and player, so draw block normally batch.DrawMesh(BlockData.GetMeshFromID(blocks[x, y, z].Type), BlockData.GetRotationMatrix(blocks[x, y, z]) * Matrix.CreateTranslation(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f)), cam, customEffect); } } } foreach (int[] coords in translucentBlocks)//draw translucent blocks that are between player and camera { batch.DrawMesh(BlockData.GetMeshFromID(blocks[coords[0], coords[1], coords[2]].Type), BlockData.GetRotationMatrix(blocks[coords[0], coords[1], coords[2]]) * Matrix.CreateTranslation(new Vector3(coords[0] + 0.5f, coords[1] + 0.5f, coords[2] + 0.5f)), cam, 0.6f); } }
public Player(Vector3 initialPlayerPosition) { cam = new ThirdPersonCamera(initialPlayerPosition, 1.4f, 1f); sphereBody = new SphereBody(initialPlayerPosition, Vector3.Zero, 1f, 0.18f); }