本文整理汇总了C#中VRageMath.Vector2类的典型用法代码示例。如果您正苦于以下问题:C# Vector2类的具体用法?C# Vector2怎么用?C# Vector2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector2类属于VRageMath命名空间,在下文中一共展示了Vector2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Draw
internal void Draw(Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
{
Rectangle dst = rect;
Rectangle src = new Rectangle(0, 0, VideoWidth, VideoHeight);
var videoSize = new Vector2(VideoWidth, VideoHeight);
float videoAspect = videoSize.X / videoSize.Y;
float rectAspect = (float)rect.Width / (float)rect.Height;
// Automatic decision based on ratios.
if (fitMode == MyVideoRectangleFitMode.AutoFit)
fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;
float scaleRatio = 0.0f;
switch (fitMode)
{
case MyVideoRectangleFitMode.None:
break;
case MyVideoRectangleFitMode.FitWidth:
scaleRatio = (float)dst.Width / videoSize.X;
dst.Height = (int)(scaleRatio * videoSize.Y);
if (dst.Height > rect.Height)
{
var diff = dst.Height - rect.Height;
dst.Height = rect.Height;
diff = (int)(diff / scaleRatio);
src.Y += (int)(diff * 0.5f);
src.Height -= diff;
}
break;
case MyVideoRectangleFitMode.FitHeight:
scaleRatio = (float)dst.Height / videoSize.Y;
dst.Width = (int)(scaleRatio * videoSize.X);
if (dst.Width > rect.Width)
{
var diff = dst.Width - rect.Width;
dst.Width = rect.Width;
diff = (int)(diff / scaleRatio);
src.X += (int)(diff * 0.5f);
src.Width -= diff;
}
break;
}
dst.X = rect.Left + (rect.Width - dst.Width) / 2;
dst.Y = rect.Top + (rect.Height - dst.Height) / 2;
VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
VRageMath.Rectangle? source = src;
Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);
MySpritesRenderer.AddSingleSprite(m_texture.ShaderView, videoSize, Color.White, origin, Vector2.UnitX, source, destination);
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:54,代码来源:MyVideoPlayer.cs
示例2: ConvertHudToNormalizedGuiPosition
public static Vector2 ConvertHudToNormalizedGuiPosition(ref Vector2 hudPos)
{
var safeFullscreenRectangle = MyGuiManager.GetSafeFullscreenRectangle();
var safeFullscreenSize = new Vector2(safeFullscreenRectangle.Width, safeFullscreenRectangle.Height);
var safeFullscreenOffset = new Vector2(safeFullscreenRectangle.X, safeFullscreenRectangle.Y);
var safeGuiRectangle = MyGuiManager.GetSafeGuiRectangle();
var safeGuiSize = new Vector2(safeGuiRectangle.Width, safeGuiRectangle.Height);
var safeGuiOffset = new Vector2(safeGuiRectangle.X, safeGuiRectangle.Y);
return ((hudPos * safeFullscreenSize + safeFullscreenOffset) - safeGuiOffset) / safeGuiSize;
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:12,代码来源:MyGuiScreenHudBase.cs
示例3: CreateBillboard
public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material,
ref Color color, ref Vector3D origin, Vector2 uvOffset, bool colorize = false, bool near = false, bool lowres = false)
{
Debug.Assert(material != null);
CreateBillboard(billboard, ref quad, material, null, 0, ref color, ref origin, uvOffset, colorize, near, lowres);
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:6,代码来源:MyTransparentGeometry.cs
示例4: TakeCustomSizedScreenshot
private static void TakeCustomSizedScreenshot(Vector2 rescale)
{
var resCpy = m_resolution;
m_resolution = new Vector2I(resCpy * rescale);
CreateScreenResources();
DrawGameScene(false);
m_resetEyeAdaptation = true;
// uav3 stores final colors
var surface = new MyRenderTarget(m_finalImage.GetSize().X, m_finalImage.GetSize().Y, SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, 1, 0);
MyCopyToRT.Run(surface, m_finalImage);
MyCopyToRT.ClearAlpha(surface);
SaveScreenshotFromResource(surface.m_resource);
surface.Release();
m_resolution = resCpy;
CreateScreenResources();
}
开发者ID:notten,项目名称:SpaceEngineers,代码行数:20,代码来源:MyRender-DrawScene.cs
示例5: MyVertexFormatPosition2Texcoord
internal MyVertexFormatPosition2Texcoord(Vector2 position, Vector2 texcoord)
{
Position = position;
Texcoord = texcoord;
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:5,代码来源:MyVertexFormats.cs
示例6: MyVertexFormatTexcoordNormalTangentTexindices
internal MyVertexFormatTexcoordNormalTangentTexindices(Vector2 texcoord, Vector3 normal, Vector3 tangent, Byte4 texIndices)
{
Texcoord = new HalfVector2(texcoord.X, texcoord.Y);
Normal = VF_Packer.PackNormalB4(ref normal);
Vector4 T = new Vector4(tangent, 1);
Tangent = VF_Packer.PackTangentSignB4(ref T);
TexIndices = texIndices;
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:8,代码来源:MyVertexFormats.cs
示例7: DrawSelectionCorner
public static void DrawSelectionCorner(string atlasTexture, MyHudSelectedObject selection, MyAtlasTextureCoordinate textureCoord, Vector2 scale, Vector2 pos, Vector2 rightVector, float textureScale)
{
if (MyVideoSettingsManager.IsTripleHead())
pos.X = pos.X * 3;
VRageRender.MyRenderProxy.DrawSpriteAtlas(
atlasTexture,
pos,
textureCoord.Offset,
textureCoord.Size,
rightVector,
scale,
selection.Color,
selection.HalfSize / MyGuiManager.GetHudSize() * textureScale);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:15,代码来源:MyGuiScreenHudBase.cs
示例8: DrawCrosshair
public static void DrawCrosshair(string atlas, MyAtlasTextureCoordinate textureCoord, MyHudCrosshair crosshair)
{
Vector2 rightVector = new Vector2(crosshair.UpVector.Y, crosshair.UpVector.X);
float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
var pos = crosshair.Position;
if (MyVideoSettingsManager.IsTripleHead())
pos.X += 1.0f;
VRageRender.MyRenderProxy.DrawSpriteAtlas(
atlas,
pos,
textureCoord.Offset,
textureCoord.Size,
rightVector,
new Vector2(hudSizeX, hudSizeY),
crosshair.Color,
crosshair.HalfSize);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:20,代码来源:MyGuiScreenHudBase.cs
示例9: DrawVoiceChat
private void DrawVoiceChat(MyHudVoiceChat voiceChat)
{
MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
var bg = MyGuiConstants.TEXTURE_VOICE_CHAT;
var basePos = new Vector2(0.01f, 0.99f);
var bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
MyGuiManager.DrawSpriteBatch(
bg.Texture,
bgPos,
bg.SizeGui,
Color.White,
align);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:13,代码来源:MyGuiScreenHudSpace.cs
示例10: DrawShipInfo
private void DrawShipInfo(MyHudShipInfo info)
{
MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
Color color = Color.White;
Vector2 bgScale = new Vector2(1.2f, 1.05f);
var bgPos = new Vector2(0.99f, 0.99f);
bgPos = ConvertHudToNormalizedGuiPosition(ref bgPos);
var bg = MyGuiConstants.TEXTURE_HUD_BG_LARGE_DEFAULT;
MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, bg.SizeGui * bgScale, color, align);
//float scale = MyGuiConstants.HUD_TEXT_SCALE;
var valuePos = bgPos - bg.PaddingSizeGui * bgScale;
var namePos = bgPos - bgScale * new Vector2(bg.SizeGui.X - bg.PaddingSizeGui.X, bg.PaddingSizeGui.Y);
info.Data.DrawBottomUp(namePos, valuePos, m_textScale);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:17,代码来源:MyGuiScreenHudSpace.cs
示例11: DrawGravityIndicator
private void DrawGravityIndicator(MyHudGravityIndicator indicator, MyHudCharacterInfo characterInfo)
{
if (indicator.Entity == null)
return;
Vector3D worldPosition = MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator ? indicator.Entity.PositionComp.WorldAABB.Center : MySpectatorCameraController.Static.Position;
Vector3 totalGravity = MyGravityProviderSystem.CalculateTotalGravityInPoint(worldPosition);
Vector3 naturalGravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(worldPosition);
Vector3 artificialGravity = totalGravity - naturalGravity;
//gravity += MyPhysics.HavokWorld.Gravity;
bool anyGravity = !Vector3.IsZero(totalGravity);
bool anyNaturalGravity = anyGravity && !Vector3.IsZero(naturalGravity);
// Background and text drawing
string totalGravityFont, artificialGravityFont = MyFontEnum.Blue, naturalGravityFont = MyFontEnum.Blue;
StringBuilder totalGravityText, artificialGravityText = null, naturalGravityText = null;
MyGuiPaddedTexture backgroundTexture;
if (anyGravity)
{
totalGravityFont = MyFontEnum.Blue;
totalGravityText = MyTexts.Get(MySpaceTexts.HudInfoGravity);
if (!anyNaturalGravity)
artificialGravityFont = MyFontEnum.White;
artificialGravityText = MyTexts.Get(MySpaceTexts.HudInfoGravityArtificial);
backgroundTexture = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
}
else
{
totalGravityFont = MyFontEnum.Red;
totalGravityText = MyTexts.Get(MySpaceTexts.HudInfoNoGravity);
backgroundTexture = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_RED;
}
if (anyNaturalGravity)
{
naturalGravityText = MyTexts.Get(MySpaceTexts.HudInfoGravityNatural);
if (naturalGravity.Length() > artificialGravity.Length())
{
artificialGravityFont = MyFontEnum.Blue;
naturalGravityFont = MyFontEnum.White;
}
else
{
artificialGravityFont = MyFontEnum.White;
naturalGravityFont = MyFontEnum.Blue;
}
}
bool drawOxygen = MySession.Static.Settings.EnableOxygen;
Vector2 bgSizeDelta = new Vector2(0.015f + 0.02f, 0.05f);
float oxygenLevel = 0f;
Vector2 oxygenCompensation = Vector2.Zero;
if (drawOxygen && anyNaturalGravity) oxygenCompensation = new Vector2(0f, 0.025f);
Vector2 backgroundSize = backgroundTexture.SizeGui + bgSizeDelta + oxygenCompensation;
Vector2 backgroundPosition, vectorPosition;
Vector2 totalGravityTextPos, artificialGravityTextPos, naturalGravityTextPos;
Vector2 totalGravityNumberPos, artificialGravityNumberPos, naturalGravityNumberPos;
Vector2 dividerLinePosition, dividerLineSize;
MyGuiDrawAlignEnum backgroundAlignment, gravityTextAlignment = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP, gravityNumberAlignment = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
dividerLineSize = new Vector2(backgroundSize.X - backgroundTexture.PaddingSizeGui.X * 1f, backgroundSize.Y / 60f);
if (indicator.Entity is MyCharacter)
{
backgroundAlignment = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
backgroundPosition = new Vector2(0.99f, 0.99f);
backgroundPosition = ConvertHudToNormalizedGuiPosition(ref backgroundPosition);
totalGravityTextPos = backgroundPosition - backgroundSize * new Vector2(0.35f, 1.075f);
totalGravityNumberPos = totalGravityTextPos + new Vector2(0.0075f, 0.002f);
dividerLinePosition = new Vector2(backgroundPosition.X - backgroundSize.X + backgroundTexture.PaddingSizeGui.X / 2.0f, totalGravityTextPos.Y) + new Vector2(0.0f, 0.026f);
{
artificialGravityTextPos = new Vector2(totalGravityTextPos.X, dividerLinePosition.Y) + new Vector2(0.0f, 0.005f);
artificialGravityNumberPos = new Vector2(totalGravityNumberPos.X, artificialGravityTextPos.Y);
naturalGravityTextPos = artificialGravityTextPos + new Vector2(0.0f, 0.025f);
naturalGravityNumberPos = artificialGravityNumberPos + new Vector2(0.0f, 0.025f);
}
vectorPosition = backgroundPosition - backgroundSize * new Vector2(0.5f, 0.5f - 0.05f) + backgroundTexture.PaddingSizeGui * Vector2.UnitY * 0.5f;
oxygenLevel = (indicator.Entity as MyCharacter).OxygenComponent != null ? (indicator.Entity as MyCharacter).OxygenComponent.EnvironmentOxygenLevel : 0f;
}
else
{
backgroundAlignment = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
backgroundPosition = new Vector2(0.01f, 1f - (characterInfo.Data.GetGuiHeight() + 0.02f));
backgroundPosition = ConvertHudToNormalizedGuiPosition(ref backgroundPosition);
gravityTextAlignment = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
gravityNumberAlignment = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
totalGravityTextPos = backgroundPosition + backgroundSize * new Vector2(1 - 0.35f, -0.99f) + backgroundTexture.PaddingSizeGui * Vector2.UnitY * 0.2f;
totalGravityNumberPos = totalGravityNumberPos = totalGravityTextPos + new Vector2(0.0075f, 0.0025f);
dividerLinePosition = new Vector2(backgroundPosition.X + backgroundTexture.PaddingSizeGui.X / 2.0f, totalGravityTextPos.Y - 0.022f) + new Vector2(0.0f, 0.026f);
{
artificialGravityTextPos = new Vector2(totalGravityTextPos.X, dividerLinePosition.Y + 0.023f) + new Vector2(0.0f, 0.005f);
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGuiScreenHudSpace.cs
示例12: GetRealPositionOnCenterScreen
/// <summary>
/// Return position on middle screen based on real desired position on gamescreen.
/// "Middle" make sense only for tripple monitors. For every else is middle screen all screen.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private static Vector2 GetRealPositionOnCenterScreen(Vector2 value)
{
Vector2 position;
if (MyGuiManager.FullscreenHudEnabled)
position = MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate_FULLSCREEN(value);
else
position = MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate(value);
if (MyVideoSettingsManager.IsTripleHead())
position.X += 1.0f;
return position;
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:19,代码来源:MyGuiScreenHudSpace.cs
示例13: Draw
public override bool Draw()
{
if (m_transitionAlpha < 1.0f)
return false;
if (MyInput.Static.IsNewKeyPressed(MyKeys.J) && MyFakes.ENABLE_OBJECTIVE_LINE)
{
MyHud.ObjectiveLine.AdvanceObjective();
}
if (!MyHud.MinimalHud)
{
ProfilerShort.Begin("Marker rendering");
ProfilerShort.Begin("m_markerRender.Draw");
m_markerRender.Draw();
ProfilerShort.BeginNextBlock("DrawTexts");
DrawTexts();
ProfilerShort.End();
ProfilerShort.End();
}
m_toolbarControl.Visible = !(m_hiddenToolbar || MyHud.MinimalHud);
Vector2 position = new Vector2(0.99f, 0.75f);
if (MySession.Static.ControlledEntity is MyShipController) position.Y = 0.65f;
position = ConvertHudToNormalizedGuiPosition(ref position);
if (MyVideoSettingsManager.IsTripleHead())
position.X += 1.0f;
// TODO: refactor this
m_blockInfo.Visible = MyHud.BlockInfo.Visible && !MyHud.MinimalHud;
m_blockInfo.BlockInfo = m_blockInfo.Visible ? MyHud.BlockInfo : null;
m_blockInfo.Position = position;
m_blockInfo.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
m_questlogControl.Visible = MyHud.Questlog.Visible && !MyHud.MinimalHud;
//m_questlogControl.QuestInfo = MyHud.Questlog;
//m_questlogControl.RecreateControls();
//m_questlogControl.Position = GetRealPositionOnCenterScreen(Vector2.Zero);
//m_questlogControl.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
m_rotatingWheelControl.Visible = MyHud.RotatingWheelVisible && !MyHud.MinimalHud;
m_chatControl.Visible = !(MyScreenManager.GetScreenWithFocus() is MyGuiScreenScenarioMpBase) && (!MyHud.MinimalHud || m_chatControl.HasFocus);
if (!base.Draw())
return false;
var bgPos = new Vector2(0.01f, 0.85f);
bgPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref bgPos);
m_chatControl.Position = bgPos + new Vector2(0.17f, 0);
m_chatControl.TextScale = 0.9f;
bgPos = new Vector2(0.03f, 0.1f);
bgPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref bgPos);
m_cameraInfoMultilineControl.Position = bgPos;
m_cameraInfoMultilineControl.TextScale = 0.9f;
if (!MyHud.MinimalHud)
{
bool inNaturalGravity = false;
var cockpit = MySession.Static.ControlledEntity as MyCockpit;
if (cockpit != null)
{
var characterPosition = cockpit.PositionComp.GetPosition();
inNaturalGravity = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(characterPosition) != 0;
}
if (inNaturalGravity)
DrawArtificialHorizonAndAltitude();
}
MyHud.Notifications.Draw();
if (!MyHud.MinimalHud)
{
m_buildModeLabel.Visible = MyHud.IsBuildMode;
m_blocksLeft.Text = MyHud.BlocksLeft.GetStringBuilder().ToString();
m_blocksLeft.Visible = MyHud.BlocksLeft.Visible;
if (MyHud.ShipInfo.Visible)
DrawShipInfo(MyHud.ShipInfo);
if (MyHud.CharacterInfo.Visible)
DrawSuitInfo(MyHud.CharacterInfo);
if (MyHud.ObjectiveLine.Visible && MyFakes.ENABLE_OBJECTIVE_LINE)
DrawObjectiveLine(MyHud.ObjectiveLine);
if (MySandboxGame.Config.EnablePerformanceWarnings)
{
foreach (var warning in MySimpleProfiler.CurrentWarnings)
{
if (warning.Value.Time < 120)
{
DrawPerformanceWarning();
break;
}
}
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGuiScreenHudSpace.cs
示例14: DrawNetgraphStringValue
private void DrawNetgraphStringValue(Vector2 position, StringBuilder sb, float scale = 0.6f)
{
MyGuiManager.DrawString(MyFontEnum.White, sb, position, scale, null, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:4,代码来源:MyGuiScreenHudSpace.cs
示例15: DrawNetgraphBasicStrings
private void DrawNetgraphBasicStrings(MyHudNetgraph netgraph, Vector2 initialPosition, Vector2 normalizedOffset)
{
StringBuilder sb = new StringBuilder();
// Draw last received packet
sb.Append("In: ").Append(netgraph.LastPacketBytesReceived);
DrawNetgraphStringValue(initialPosition, sb);
// Draw average in
sb.Clear();
sb.Append("Avg In: ").Append(netgraph.AverageIncomingKBytes.ToString("0.##")).Append(" kB/s");
initialPosition.X += normalizedOffset.X;
DrawNetgraphStringValue(initialPosition, sb);
// Draw last sent packet
sb.Clear();
sb.Append("Out: ").Append(netgraph.LastPacketBytesSent);
initialPosition.X -= normalizedOffset.X;
initialPosition.Y += normalizedOffset.Y;
DrawNetgraphStringValue(initialPosition, sb);
// Draw average out
sb.Clear();
sb.Append("Avg Out: ").Append(netgraph.AverageOutgoingKBytes.ToString("0.##")).Append(" kB/s");
initialPosition.X += normalizedOffset.X;
DrawNetgraphStringValue(initialPosition, sb);
// Draw updates per second
sb.Clear();
sb.Append("UPS: ").Append(netgraph.UpdatesPerSecond);
initialPosition.X -= normalizedOffset.X;
initialPosition.Y += normalizedOffset.Y;
DrawNetgraphStringValue(initialPosition, sb);
// Draw frames per second
sb.Clear();
sb.Append("FPS: ").Append(netgraph.FramesPerSecond);
initialPosition.X += normalizedOffset.X;
DrawNetgraphStringValue(initialPosition, sb);
// Draw latency
sb.Clear();
sb.Append("Ping: ").Append(netgraph.Ping);
initialPosition.X -= normalizedOffset.X;
initialPosition.Y += normalizedOffset.Y;
DrawNetgraphStringValue(initialPosition, sb);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:47,代码来源:MyGuiScreenHudSpace.cs
示例16: DrawVideo
static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
{
MyVideoPlayerDx9 video;
if (m_videos.TryGetValue(id, out video))
{
Rectangle dst = rect;
Rectangle src = new Rectangle(0, 0, video.VideoWidth, video.VideoHeight);
var videoSize = new Vector2(video.VideoWidth, video.VideoHeight);
float videoAspect = videoSize.X / videoSize.Y;
float rectAspect = (float)rect.Width / (float)rect.Height;
// Automatic decision based on ratios.
if (fitMode == MyVideoRectangleFitMode.AutoFit)
fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;
float scaleRatio = 0.0f;
switch (fitMode)
{
case MyVideoRectangleFitMode.None:
break;
case MyVideoRectangleFitMode.FitWidth:
scaleRatio = (float)dst.Width / videoSize.X;
dst.Height = (int)(scaleRatio * videoSize.Y);
if (dst.Height > rect.Height)
{
var diff = dst.Height - rect.Height;
dst.Height = rect.Height;
diff = (int)(diff / scaleRatio);
src.Y += (int)(diff * 0.5f);
src.Height -= diff;
}
break;
case MyVideoRectangleFitMode.FitHeight:
scaleRatio = (float)dst.Height / videoSize.Y;
dst.Width = (int)(scaleRatio * videoSize.X);
if (dst.Width > rect.Width)
{
var diff = dst.Width - rect.Width;
dst.Width = rect.Width;
diff = (int)(diff / scaleRatio);
src.X += (int)(diff * 0.5f);
src.Width -= diff;
}
break;
}
dst.X = rect.Left + (rect.Width - dst.Width) / 2;
dst.Y = rect.Top + (rect.Height - dst.Height) / 2;
Texture texture = video.OutputFrame;
// Draw upside down
VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
VRageMath.Rectangle? source = src;
Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);
MyRender.DrawSprite(texture, null, ref destination, false, ref source, color, Vector2.UnitX, ref origin, VRageRender.Graphics.SpriteEffects.None, 0f);
}
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:59,代码来源:MyRender-Video.cs
示例17: ConvertNormalizedGuiToHud
protected static Vector2 ConvertNormalizedGuiToHud(ref Vector2 normGuiPos)
{
var safeFullscreenRectangle = MyGuiManager.GetSafeFullscreenRectangle();
var safeFullscreenSize = new Vector2(safeFullscreenRectangle.Width, safeFullscreenRectangle.Height);
var safeFullscreenOffset = new Vector2(safeFullscreenRectangle.X, safeFullscreenRectangle.Y);
var safeGuiRectangle = MyGuiManager.GetSafeGuiRectangle();
var safeGuiSize = new Vector2(safeGuiRectangle.Width, safeGuiRectangle.Height);
var safeGuiOffset = new Vector2(safeGuiRectangle.X, safeGuiRectangle.Y);
return ((normGuiPos * safeGuiSize + safeGuiOffset) - safeFullscreenOffset) / safeFullscreenSize;
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:12,代码来源:MyGuiScreenHudBase.cs
示例18: DrawPowerGroupInfo
private void DrawPowerGroupInfo(MyHudSinkGroupInfo info)
{
var fsRect = MyGuiManager.GetSafeFullscreenRectangle();
float namesOffset = -0.25f / (fsRect.Width / (float)fsRect.Height);
var posValuesBase = new Vector2(0.985f, 0.65f); // coordinates in SafeFullscreenRectangle, but DrawString works with SafeGuiRectangle.
var posNamesBase = new Vector2(posValuesBase.X + namesOffset, posValuesBase.Y);
var posValues = ConvertHudToNormalizedGuiPosition(ref posValuesBase);
var posNames = ConvertHudToNormalizedGuiPosition(ref posNamesBase);
info.Data.DrawBottomUp(posNames, posValues, m_textScale);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:10,代码来源:MyGuiScreenHudSpace.cs
示例19: DrawSelectedObjectHighlight
public static void DrawSelectedObjectHighlight(string atlasTexture, MyAtlasTextureCoordinate textureCoord, MyHudSelectedObject selection)
{
var rect = MyGuiManager.GetSafeFullscreenRectangle();
Vector2 hudSize = new Vector2(rect.Width, rect.Height);
var worldViewProj = selection.InteractiveObject.ActivationMatrix * MySector.MainCamera.ViewMatrix * (MatrixD)MySector.MainCamera.ProjectionMatrix;
BoundingBoxD screenSpaceAabb = new BoundingBoxD(-Vector3D.One / 2, Vector3D.One / 2).Transform(worldViewProj);
var min = new Vector2((float)screenSpaceAabb.Min.X, (float)screenSpaceAabb.Min.Y);
var max = new Vector2((float)screenSpaceAabb.Max.X, (float)screenSpaceAabb.Max.Y);
var minToMax = min - max;
min = min * 0.5f + 0.5f * Vector2.One;
max = max * 0.5f + 0.5f * Vector2.One;
min.Y = 1 - min.Y;
max.Y = 1 - max.Y;
float textureScale = (float)Math.Pow(Math.Abs(minToMax.X), 0.35f) * 2.5f;
if (selection.InteractiveObject.ShowOverlay)
{
BoundingBoxD one = new BoundingBoxD(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f));
Color color = Color.Gold;
color *= 0.4f;
var m = selection.InteractiveObject.ActivationMatrix;
var localToWorld = MatrixD.Invert(selection.InteractiveObject.WorldMatrix);
//MySimpleObjectDraw.DrawTransparentBox(ref m, ref one, ref color, MySimpleObjectRasterizer.Solid, 0, 0.05f, "Square", null, true);
MySimpleObjectDraw.DrawAttachedTransparentBox(ref m, ref one, ref color, selection.InteractiveObject.RenderObjectID,
ref localToWorld, MySimpleObjectRasterizer.Solid, 0, 0.05f, "Square", null, true);
}
if (MyFakes.ENABLE_USE_OBJECT_CORNERS)
{
DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, min, -Vector2.UnitY, textureScale);
DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, new Vector2(min.X, max.Y), Vector2.UnitX, textureScale);
DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, new Vector2(max.X, min.Y), -Vector2.UnitX, textureScale);
DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, max, Vector2.UnitY, textureScale);
}
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:42,代码来源:MyGuiScreenHudBase.cs
示例20: DrawSuitInfo
private void DrawSuitInfo(MyHudCharacterInfo suitInfo)
{
MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
Color color = Color.White;
var basePos = new Vector2(0.01f, 0.99f);
var bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
Vector2 namePos, valuePos, bgScale;
MyGuiPaddedTexture bg;
bg = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
bgScale = new Vector2(1.1f, 1f);
var bgWidth = (!MyHud.ShipInfo.Visible || MyUtils.IsZero(m_gravityHudWidth)) ? bg.SizeGui.X * bgScale.X : m_gravityHudWidth;
MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, new Vector2(bgWidth, suitInfo.Data.GetGuiHeight()), Color.White, align);
namePos = bgPos + new Vector2(1f, -1f) * bg.PaddingSizeGui * bgScale;
valuePos = bgPos + (new Vector2(bgWidth, 0f) - bg.PaddingSizeGui);
suitInfo.Data.DrawBottomUp(namePos, valuePos, m_textScale);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:19,代码来源:MyGuiScreenHudSpace.cs
注:本文中的VRageMath.Vector2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论