void DrawRotatedBox(FogOfWarShapeBox shape) { // convert size to fog space DrawInfo info = new DrawInfo(_map, shape); float lineofsightradius = shape.CalculateMaxLineOfSightDistance() * _map.pixelSize; // rotation stuff Vector2 sizemul = shape.size * 0.5f * _map.pixelSize; Vector2 invfogsize = new Vector2(1.0f / (shape.size.x * _map.pixelSize), 1.0f / (shape.size.y * _map.pixelSize)); float sin = Mathf.Sin(info.forwardAngle); float cos = Mathf.Cos(info.forwardAngle); byte brightness = shape.maxBrightness; bool drawtexture = shape.hasTexture && !_isMultithreaded; for (int y = info.yMin; y < info.yMax; ++y) { float yy = y - info.fogCenterPos.y; for (int x = info.xMin; x < info.xMax; ++x) { float xx = x - info.fogCenterPos.x; // get rotated uvs float u = xx * cos - yy * sin; if (u < -sizemul.x || u >= sizemul.x) { continue; } float v = yy * cos + xx * sin; if (v < -sizemul.y || v >= sizemul.y) { continue; } // can see pixel Vector2i offset = new Vector2i(x, y) - info.fogEyePos; if (!LineOfSightCanSee(shape, offset.vector2, lineofsightradius)) { continue; } if (!LineOfSightCanSeeCell(shape, offset)) { continue; } // unfog if (drawtexture) { Unfog(x, y, SampleTexture(shape.texture, 0.5f + u * invfogsize.x, 0.5f + v * invfogsize.y, shape.brightness)); } else { Unfog(x, y, brightness); } } } }
void DrawAxisAlignedBox(FogOfWarShapeBox shape) { // convert size to fog space DrawInfo info = new DrawInfo(_map, shape); float lineofsightradius = shape.CalculateMaxLineOfSightDistance() * _map.pixelSize + 0.01f; byte brightness = shape.maxBrightness; bool drawtexture = shape.hasTexture && !_isMultithreaded; for (int y = info.yMin; y <= info.yMax; ++y) { for (int x = info.xMin; x <= info.xMax; ++x) { // can see pixel Vector2i offset = new Vector2i(x, y) - info.fogEyePos; if (!LineOfSightCanSee(shape, offset.vector2, lineofsightradius)) { continue; } if (!LineOfSightCanSeeCell(shape, offset)) { continue; } // unfog if (drawtexture) { float u = Mathf.InverseLerp(info.xMin, info.xMax, x); float v = Mathf.InverseLerp(info.yMin, info.yMax, y); Unfog(x, y, SampleTexture(shape.texture, u, v, shape.brightness)); } else { Unfog(x, y, brightness); } } } }