v0.12.0.2
This commit is contained in:
@@ -99,6 +99,94 @@ namespace Barotrauma
|
||||
if (hue < 240) return q1 + (q2 - q1) * (240 - hue) / 60;
|
||||
return q1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a HSV value into a RGB value.
|
||||
/// </summary>
|
||||
/// <param name="hue">Value between 0 and 360</param>
|
||||
/// <param name="saturation">Value between 0 and 1</param>
|
||||
/// <param name="value">Value between 0 and 1</param>
|
||||
/// <see href="https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB">Reference</see>
|
||||
/// <returns></returns>
|
||||
public static Color HSVToRGB(float hue, float saturation, float value)
|
||||
{
|
||||
float c = value * saturation;
|
||||
|
||||
float h = Math.Clamp(hue, 0, 360) / 60f;
|
||||
|
||||
float x = c * (1 - Math.Abs(h % 2 - 1));
|
||||
|
||||
float r = 0,
|
||||
g = 0,
|
||||
b = 0;
|
||||
|
||||
if (0 <= h && h <= 1) { r = c; g = x; b = 0; }
|
||||
else if (1 < h && h <= 2) { r = x; g = c; b = 0; }
|
||||
else if (2 < h && h <= 3) { r = 0; g = c; b = x; }
|
||||
else if (3 < h && h <= 4) { r = 0; g = x; b = c; }
|
||||
else if (4 < h && h <= 5) { r = x; g = 0; b = c; }
|
||||
else if (5 < h && h <= 6) { r = c; g = 0; b = x; }
|
||||
|
||||
float m = value - c;
|
||||
|
||||
return new Color(r + m, g + m, b + m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a RGB value into a HSV value.
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <see href="https://www.cs.rit.edu/~ncs/color/t_convert.html">Reference</see>
|
||||
/// <returns>
|
||||
/// Vector3 where X is the hue (0-360 or NaN)
|
||||
/// Y is the saturation (0-1)
|
||||
/// Z is the value (0-1)
|
||||
/// </returns>
|
||||
public static Vector3 RGBToHSV(Color color)
|
||||
{
|
||||
float r = color.R / 255f,
|
||||
g = color.G / 255f,
|
||||
b = color.B / 255f;
|
||||
|
||||
float h, s;
|
||||
|
||||
float min = Math.Min(r, Math.Min(g, b));
|
||||
float max = Math.Max(r, Math.Max(g, b));
|
||||
|
||||
float v = max;
|
||||
|
||||
float delta = max - min;
|
||||
|
||||
if (max != 0)
|
||||
{
|
||||
s = delta / max;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = 0;
|
||||
h = -1;
|
||||
return new Vector3(h, s, v);
|
||||
}
|
||||
|
||||
if (MathUtils.NearlyEqual(r, max))
|
||||
{
|
||||
h = (g - b) / delta;
|
||||
}
|
||||
else if (MathUtils.NearlyEqual(g, max))
|
||||
{
|
||||
h = 2 + (b - r) / delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
h = 4 + (r - g) / delta;
|
||||
}
|
||||
|
||||
h *= 60;
|
||||
if (h < 0) { h += 360; }
|
||||
|
||||
return new Vector3(h, s, v);
|
||||
}
|
||||
|
||||
|
||||
public static Color Add(this Color sourceColor, Color color)
|
||||
{
|
||||
@@ -235,6 +323,7 @@ namespace Barotrauma
|
||||
{
|
||||
linePos = splitSize = 0.0f;
|
||||
splitWord[k] = splitWord[k].Remove(splitWord[k].Length - 1) + "\n";
|
||||
if (splitWord[k].Length <= 1) { break; }
|
||||
j--;
|
||||
splitWord.Add(string.Empty);
|
||||
k++;
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
using Barotrauma.IO;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
static class WikiImage
|
||||
{
|
||||
public static Rectangle CalculateBoundingBox(Character character)
|
||||
{
|
||||
Rectangle boundingBox = new Rectangle(character.WorldPosition.ToPoint(), Point.Zero);
|
||||
|
||||
void addPointsToBBox(float extentX, float extentY, Vector2 worldPos, Vector2 origin, float rotation)
|
||||
{
|
||||
float sinRotation = (float)Math.Sin((double)rotation);
|
||||
float cosRotation = (float)Math.Cos((double)rotation);
|
||||
|
||||
origin = new Vector2(
|
||||
origin.X * cosRotation + origin.Y * sinRotation,
|
||||
origin.X * sinRotation - origin.Y * cosRotation);
|
||||
var limbPos = worldPos.ToPoint();
|
||||
boundingBox.AddPoint(limbPos);
|
||||
Vector2 xExtend = new Vector2((extentX * cosRotation), (extentX * sinRotation));
|
||||
Vector2 yExtend = new Vector2((extentY * sinRotation), (-extentY * cosRotation));
|
||||
boundingBox.AddPoint(limbPos + (xExtend + yExtend - origin).ToPoint());
|
||||
boundingBox.AddPoint(limbPos + (xExtend - yExtend - origin).ToPoint());
|
||||
boundingBox.AddPoint(limbPos + (-xExtend - yExtend - origin).ToPoint());
|
||||
boundingBox.AddPoint(limbPos + (-xExtend + yExtend - origin).ToPoint());
|
||||
}
|
||||
|
||||
foreach (Limb limb in character.AnimController.Limbs)
|
||||
{
|
||||
if (limb.ActiveSprite == null) { continue; }
|
||||
float extentX = (float)limb.ActiveSprite.size.X * limb.Scale * limb.TextureScale * 0.5f;
|
||||
//extentX = ConvertUnits.ToDisplayUnits(extentX);
|
||||
float extentY = (float)limb.ActiveSprite.size.Y * limb.Scale * limb.TextureScale * 0.5f;
|
||||
//extentY = ConvertUnits.ToDisplayUnits(extentY);
|
||||
|
||||
Vector2 origin = (limb.ActiveSprite.Origin - (limb.ActiveSprite.SourceRect.Size.ToVector2() * 0.5f)) * limb.Scale * limb.TextureScale;
|
||||
addPointsToBBox(extentX, extentY, limb.WorldPosition, origin, limb.body.Rotation);
|
||||
}
|
||||
|
||||
|
||||
if (character.Inventory != null)
|
||||
{
|
||||
foreach (var item in character.Inventory.AllItems)
|
||||
{
|
||||
if (item?.Sprite != null && item?.body != null)
|
||||
{
|
||||
float extentX = (float)item.Sprite.size.X * item.Scale * 0.5f;
|
||||
//extentX = ConvertUnits.ToDisplayUnits(extentX);
|
||||
float extentY = (float)item.Sprite.size.Y * item.Scale * 0.5f;
|
||||
//extentY = ConvertUnits.ToDisplayUnits(extentY);
|
||||
|
||||
Vector2 origin = (item.Sprite.Origin - (item.Sprite.SourceRect.Size.ToVector2() * 0.5f)) * item.Scale;
|
||||
addPointsToBBox(extentX, extentY, item.WorldPosition, origin, item.body.Rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boundingBox.X -= 25; boundingBox.Y -= 25;
|
||||
boundingBox.Width += 50; boundingBox.Height += 50;
|
||||
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
public static void Create(Character character)
|
||||
{
|
||||
Rectangle boundingBox = CalculateBoundingBox(character);
|
||||
|
||||
int texWidth = Math.Clamp((int)(boundingBox.Width * 2.5f), 512, 4096);
|
||||
float zoom = (float)texWidth / (float)boundingBox.Width;
|
||||
int texHeight = (int)(zoom * boundingBox.Height);
|
||||
|
||||
Camera cam = new Camera();
|
||||
cam.SetResolution(new Point(texWidth, texHeight));
|
||||
cam.MaxZoom = zoom;
|
||||
cam.MinZoom = zoom * 0.5f;
|
||||
cam.Zoom = zoom;
|
||||
cam.Position = boundingBox.Center.ToVector2();
|
||||
cam.UpdateTransform(false);
|
||||
|
||||
using (RenderTarget2D rt = new RenderTarget2D(
|
||||
GameMain.Instance.GraphicsDevice,
|
||||
texWidth, texHeight, false, SurfaceFormat.Color, DepthFormat.None))
|
||||
{
|
||||
using (SpriteBatch spriteBatch = new SpriteBatch(GameMain.Instance.GraphicsDevice))
|
||||
{
|
||||
Viewport prevViewport = GameMain.Instance.GraphicsDevice.Viewport;
|
||||
GameMain.Instance.GraphicsDevice.Viewport = new Viewport(0, 0, texWidth, texHeight);
|
||||
GameMain.Instance.GraphicsDevice.SetRenderTarget(rt);
|
||||
GameMain.Instance.GraphicsDevice.Clear(Color.Transparent);
|
||||
spriteBatch.Begin(SpriteSortMode.BackToFront, transformMatrix: cam.Transform);
|
||||
character.Draw(spriteBatch, cam);
|
||||
if (character.Inventory != null)
|
||||
{
|
||||
foreach (var item in character.Inventory.AllItems)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
item.Draw(spriteBatch, false, false);
|
||||
item.Draw(spriteBatch, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
spriteBatch.End();
|
||||
GameMain.Instance.GraphicsDevice.SetRenderTarget(null);
|
||||
GameMain.Instance.GraphicsDevice.Viewport = prevViewport;
|
||||
using (FileStream fs = File.Open("wikiimage.png", System.IO.FileMode.Create))
|
||||
{
|
||||
rt.SaveAsPng(fs, boundingBox.Width, boundingBox.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Create(Submarine sub)
|
||||
{
|
||||
int width = 4096; int height = 4096;
|
||||
|
||||
Rectangle subDimensions = sub.CalculateDimensions(false);
|
||||
Vector2 viewPos = subDimensions.Center.ToVector2();
|
||||
float scale = Math.Min(width / (float)subDimensions.Width, height / (float)subDimensions.Height);
|
||||
|
||||
var viewMatrix = Matrix.CreateTranslation(new Vector3(width / 2.0f, height / 2.0f, 0));
|
||||
var transform = Matrix.CreateTranslation(
|
||||
new Vector3(-viewPos.X, viewPos.Y, 0)) *
|
||||
Matrix.CreateScale(new Vector3(scale, scale, 1)) *
|
||||
viewMatrix;
|
||||
|
||||
using (RenderTarget2D rt = new RenderTarget2D(
|
||||
GameMain.Instance.GraphicsDevice,
|
||||
width, height, false, SurfaceFormat.Color, DepthFormat.None))
|
||||
using (SpriteBatch spriteBatch = new SpriteBatch(GameMain.Instance.GraphicsDevice))
|
||||
{
|
||||
Viewport prevViewport = GameMain.Instance.GraphicsDevice.Viewport;
|
||||
GameMain.Instance.GraphicsDevice.Viewport = new Viewport(0, 0, width, height);
|
||||
GameMain.Instance.GraphicsDevice.SetRenderTarget(rt);
|
||||
GameMain.Instance.GraphicsDevice.Clear(Color.Transparent);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, null, null, null, null, transform);
|
||||
Submarine.Draw(spriteBatch);
|
||||
Submarine.DrawFront(spriteBatch);
|
||||
Submarine.DrawDamageable(spriteBatch, null);
|
||||
spriteBatch.End();
|
||||
|
||||
GameMain.Instance.GraphicsDevice.SetRenderTarget(null);
|
||||
GameMain.Instance.GraphicsDevice.Viewport = prevViewport;
|
||||
using (FileStream fs = File.Open("wikiimage.png", System.IO.FileMode.Create))
|
||||
{
|
||||
rt.SaveAsPng(fs, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user