本文整理汇总了C#中VRageMath.Vector2类的典型用法代码示例。如果您正苦于以下问题:C# Vector2类的具体用法?C# Vector2怎么用?C# Vector2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector2类属于VRageMath命名空间,在下文中一共展示了Vector2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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);
}
示例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();
}
示例5: MyVertexFormatPosition2Texcoord
internal MyVertexFormatPosition2Texcoord(Vector2 position, Vector2 texcoord)
{
Position = position;
Texcoord = texcoord;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
//.........这里部分代码省略.........
示例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;
}
示例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;
}
}
//.........这里部分代码省略.........
示例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);
}
示例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);
}