// This returns a range of blocks in a frustum public List <VisualBlockEntry> GetFrustumRange(ProjectedFrustum2D frustum) { // Make square range from frustum circle // This will be the range in which we will test blocks Point lt = GetBlockCoordinates(frustum.Center - frustum.Radius); Point rb = GetBlockCoordinates(frustum.Center + frustum.Radius); // Constants we need float blockfrustumdistance2 = (frustum.Radius * frustum.Radius) + (BLOCK_RADIUS * BLOCK_RADIUS); // Go through the range to make a list int entriescount = (rb.X - lt.X) * (rb.Y - lt.Y); List <VisualBlockEntry> entries = new List <VisualBlockEntry>(entriescount); for (int x = lt.X; x <= rb.X; x++) { for (int y = lt.Y; y <= rb.Y; y++) { // First check if the block circle is intersecting the frustum circle Point block = new Point(x, y); Vector2D blockcenter = GetBlockCenter(block); if (Vector2D.DistanceSq(frustum.Center, blockcenter) < blockfrustumdistance2) { // Add the block if the block circle is inside the frustum if (frustum.IntersectCircle(blockcenter, BLOCK_RADIUS)) { entries.Add(GetBlock(block)); } } } } // Return list return(entries); }
// Constructor internal Renderer3D(D3DDevice graphics) : base(graphics) { // Initialize CreateProjection(); CreateMatrices2D(); SetupThingCage(); SetupTextures(); renderthingcages = true; showselection = true; showhighlight = true; // Dummy frustum frustum = new ProjectedFrustum2D(new Vector2D(), 0.0f, 0.0f, PROJ_NEAR_PLANE, General.Settings.ViewDistance, Angle2D.DegToRad(General.Settings.VisualFOV)); }
// This returns a range of blocks in a frustum public List <VisualBlockEntry> GetFrustumRange(ProjectedFrustum2D frustum2D) { var frustum = new Frustum(); frustum.planes = new Plane[4] { new Plane(frustum2D.Lines[0]), new Plane(frustum2D.Lines[1]), new Plane(frustum2D.Lines[2]), new Plane(frustum2D.Lines[3]) }; var result = new List <VisualBlockEntry>(); root.GetBlocks(frustum, ref result); return(result); }
// This creates matrices for a camera view public void PositionAndLookAt(Vector3D pos, Vector3D lookat) { // Calculate delta vector cameraposition = pos; Vector3D delta = lookat - pos; float anglexy = delta.GetAngleXY(); float anglez = delta.GetAngleZ(); // Create frustum frustum = new ProjectedFrustum2D(pos, anglexy, anglez, PROJ_NEAR_PLANE, General.Settings.ViewDistance, Angle2D.DegToRad(General.Settings.VisualFOV)); // Make the view matrix view3d = Matrix.LookAtRH(D3DDevice.V3(pos), D3DDevice.V3(lookat), new Vector3(0f, 0f, 1f)); // Make the billboard matrix billboard = Matrix.RotationZ(anglexy + Angle2D.PI); }