protected override void DrawBox(FogOfWarShapeBox shape) { // convert size to fog space float fogradius = shape.radius * _map.pixelSize; DrawInfo info = new DrawInfo(_map, shape, shape.radius * _map.pixelSize, shape.radius * _map.pixelSize); 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, fogradius)) { continue; } if (!LineOfSightCanSeeCell(shape, offset)) { continue; } _values[y * _map.resolution.x + x] = 0; } } }
FogOfWarShape CreateShape() { if (shapeType == FogOfWarShapeType.Circle) { FogOfWarShapeCircle shape = new FogOfWarShapeCircle(); FillShape(shape); shape.innerRadius = innerRadius; shape.angle = angle; return(shape); } else if (shapeType == FogOfWarShapeType.Box) { FogOfWarShapeBox shape = new FogOfWarShapeBox(); FillShape(shape); return(shape); } else if (shapeType == FogOfWarShapeType.Texture) { if (texture == null) { return(null); } FogOfWarShapeTexture shape = new FogOfWarShapeTexture(); FillShape(shape); shape.texture = texture; shape.rotateToForward = rotateToForward; return(shape); } return(null); }
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); } } } }
protected override void DrawBox(FogOfWarShapeBox shape) { if (shape.rotateToForward) { DrawRotatedBox(shape); } else { DrawAxisAlignedBox(shape); } }
FogOfWarShape CreateShape(FogOfWar fow) { if (shapeType == FogOfWarShapeType.Circle) { FogOfWarShapeCircle shape = new FogOfWarShapeCircle(); FillShape(fow, shape); shape.innerRadius = innerRadius; shape.angle = angle; return(shape); } else if (shapeType == FogOfWarShapeType.Box) { FogOfWarShapeBox shape = new FogOfWarShapeBox(); shape.texture = texture; shape.hasTexture = texture != null; shape.rotateToForward = rotateToForward; FillShape(fow, shape); return(shape); } return(null); }
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); } } } }
protected abstract void DrawBox(FogOfWarShapeBox shape);