public void FillClosestLights(DwarfTime time) { List <Vector3> positions = (from light in DynamicLight.Lights select light.Position).ToList(); positions.AddRange((from light in DynamicLight.TempLights select light.Position)); positions.Sort((a, b) => { float dA = MathFunctions.L1(a, Camera.Position); float dB = MathFunctions.L1(b, Camera.Position); return(dA.CompareTo(dB)); }); int numLights = Math.Min(16, positions.Count + 1); for (int i = 1; i < numLights; i++) { if (i > positions.Count) { LightPositions[i] = new Vector3(0, 0, 0); } else { LightPositions[i] = positions[i - 1]; } } for (int j = numLights; j < 16; j++) { LightPositions[j] = new Vector3(0, 0, 0); } DefaultShader.CurrentNumLights = numLights - 1; DynamicLight.TempLights.Clear(); }
public virtual void HandleCollisions(ChunkManager chunks, float dt) { if (CollideMode == CollisionMode.None) { return; } Voxel currentVoxel = new Voxel(); bool success = chunks.ChunkData.GetVoxel(null, LocalTransform.Translation, ref currentVoxel); List <Voxel> vs = new List <Voxel> { currentVoxel }; VoxelChunk chunk = chunks.ChunkData.GetVoxelChunkAtWorldLocation(LocalTransform.Translation); if (!success || currentVoxel == null || chunk == null) { return; } Vector3 grid = chunk.WorldToGrid(LocalTransform.Translation); List <Voxel> adjacencies = chunk.GetNeighborsEuclidean((int)grid.X, (int)grid.Y, (int)grid.Z); vs.AddRange(adjacencies); Vector3 half = Vector3.One * 0.5f; vs.Sort((a, b) => (MathFunctions.L1(LocalTransform.Translation, a.Position + half).CompareTo(MathFunctions.L1(LocalTransform.Translation, b.Position + half)))); int y = (int)Position.Y; foreach (Voxel v in vs) { if (v == null || v.IsEmpty) { continue; } if (CollideMode == CollisionMode.UpDown && (int)v.GridPosition.Y == y) { continue; } if (CollideMode == CollisionMode.Sides && (int)v.GridPosition.Y != y) { continue; } BoundingBox voxAABB = v.GetBoundingBox(); if (Collide(voxAABB)) { OnTerrainCollision(v); } } }