public void DrawReticleHighlight(Camera camera) { if (camera.Eye.HasValue && m_highlightRaycastResult is TerrainRaycastResult) { TerrainRaycastResult terrainRaycastResult = (TerrainRaycastResult)m_highlightRaycastResult; Vector3 vector = terrainRaycastResult.HitPoint(); Vector3 vector2 = (!(BlocksManager.Blocks[Terrain.ExtractContents(terrainRaycastResult.Value)] is CrossBlock)) ? CellFace.FaceToVector3(terrainRaycastResult.CellFace.Face) : (-terrainRaycastResult.Ray.Direction); float num = Vector3.Distance(camera.ViewPosition, vector); float s = 0.03f + MathUtils.Min(0.008f * num, 0.04f); float s2 = 0.01f * num; Vector3 v = (MathUtils.Abs(Vector3.Dot(vector2, Vector3.UnitY)) < 0.5f) ? Vector3.UnitY : Vector3.UnitX; Vector3 vector3 = Vector3.Normalize(Vector3.Cross(vector2, v)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector2, vector3)); Subtexture subtexture = ContentManager.Get <Subtexture>("Textures/Atlas/Reticle"); TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(subtexture.Texture, useAlphaTest: false, 0, DepthStencilState.DepthRead, null, null, SamplerState.LinearClamp); Vector3 p = vector + s * (-vector3 + v2) + s2 * vector2; Vector3 p2 = vector + s * (vector3 + v2) + s2 * vector2; Vector3 p3 = vector + s * (vector3 - v2) + s2 * vector2; Vector3 p4 = vector + s * (-vector3 - v2) + s2 * vector2; Vector2 texCoord = new Vector2(subtexture.TopLeft.X, subtexture.TopLeft.Y); Vector2 texCoord2 = new Vector2(subtexture.BottomRight.X, subtexture.TopLeft.Y); Vector2 texCoord3 = new Vector2(subtexture.BottomRight.X, subtexture.BottomRight.Y); Vector2 texCoord4 = new Vector2(subtexture.TopLeft.X, subtexture.BottomRight.Y); texturedBatch3D.QueueQuad(p, p2, p3, p4, texCoord, texCoord2, texCoord3, texCoord4, Color.White); texturedBatch3D.Flush(camera.ViewProjectionMatrix); } }
public static Subtexture GetSubtexture(string name) { if (!m_subtextures.TryGetValue(name, out Subtexture value)) { try { value = new Subtexture(ContentManager.Get <Texture2D>(name), Vector2.Zero, Vector2.One); m_subtextures.Add(name, value); return(value); } catch (Exception innerException) { throw new InvalidOperationException($"Required subtexture {name} not found in TextureAtlasManager.", innerException); } } return(value); }
public void Draw(Camera camera, int drawOrder) { if (camera.GameWidget != m_componentPlayer.GameWidget) { return; } if (m_componentPlayer.ComponentHealth.Health > 0f && m_componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible) { if (IsSightsVisible) { Texture2D texture = ContentManager.Get <Texture2D>("Textures/Gui/Sights"); float s = (!camera.Eye.HasValue) ? 8f : 2.5f; Vector3 v = m_sightsPosition + m_sightsDirection * 50f; Vector3 vector = Vector3.Normalize(Vector3.Cross(m_sightsDirection, Vector3.UnitY)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(m_sightsDirection, vector)); Vector3 p = v + s * (-vector - v2); Vector3 p2 = v + s * (vector - v2); Vector3 p3 = v + s * (vector + v2); Vector3 p4 = v + s * (-vector + v2); TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None); int count = texturedBatch3D.TriangleVertices.Count; texturedBatch3D.QueueQuad(p, p2, p3, p4, new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f), Color.White); texturedBatch3D.TransformTriangles(camera.ViewMatrix, count); } if (!camera.Eye.HasValue && !camera.UsesMovementControls && !IsSightsVisible && (SettingsManager.LookControlMode == LookControlMode.SplitTouch || !m_componentPlayer.ComponentInput.IsControlledByTouch)) { Subtexture subtexture = ContentManager.Get <Subtexture>("Textures/Atlas/Crosshair"); float s2 = 1.25f; Vector3 v3 = camera.ViewPosition + camera.ViewDirection * 50f; Vector3 vector2 = Vector3.Normalize(Vector3.Cross(camera.ViewDirection, Vector3.UnitY)); Vector3 v4 = Vector3.Normalize(Vector3.Cross(camera.ViewDirection, vector2)); Vector3 p5 = v3 + s2 * (-vector2 - v4); Vector3 p6 = v3 + s2 * (vector2 - v4); Vector3 p7 = v3 + s2 * (vector2 + v4); Vector3 p8 = v3 + s2 * (-vector2 + v4); TexturedBatch3D texturedBatch3D2 = m_primitivesRenderer3D.TexturedBatch(subtexture.Texture, useAlphaTest: false, 0, DepthStencilState.None); int count2 = texturedBatch3D2.TriangleVertices.Count; texturedBatch3D2.QueueQuad(p5, p6, p7, p8, new Vector2(subtexture.TopLeft.X, subtexture.TopLeft.Y), new Vector2(subtexture.BottomRight.X, subtexture.TopLeft.Y), new Vector2(subtexture.BottomRight.X, subtexture.BottomRight.Y), new Vector2(subtexture.TopLeft.X, subtexture.BottomRight.Y), Color.White); texturedBatch3D2.TransformTriangles(camera.ViewMatrix, count2); } } m_primitivesRenderer2D.Flush(); m_primitivesRenderer3D.Flush(camera.ProjectionMatrix); }
public static void LoadTextureAtlas(Texture2D texture, string atlasDefinition, string prefix) { string[] array = atlasDefinition.Split(new char[2] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); int num = 0; while (true) { if (num < array.Length) { string[] array2 = array[num].Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length < 5) { break; } string key = prefix + array2[0]; int num2 = int.Parse(array2[1], CultureInfo.InvariantCulture); int num3 = int.Parse(array2[2], CultureInfo.InvariantCulture); int num4 = int.Parse(array2[3], CultureInfo.InvariantCulture); int num5 = int.Parse(array2[4], CultureInfo.InvariantCulture); Vector2 topLeft = new Vector2((float)num2 / (float)texture.Width, (float)num3 / (float)texture.Height); Vector2 bottomRight = new Vector2((float)(num2 + num4) / (float)texture.Width, (float)(num3 + num5) / (float)texture.Height); Subtexture value = new Subtexture(texture, topLeft, bottomRight); m_subtextures.Add(key, value); num++; continue; } return; } throw new InvalidOperationException("Invalid texture atlas definition."); }
public override void Draw(DrawContext dc) { Subtexture subtexture = ContentManager.Get <Subtexture>("Textures/Atlas/MoveRose"); Subtexture subtexture2 = ContentManager.Get <Subtexture>("Textures/Atlas/MoveRose_Pressed"); TexturedBatch2D texturedBatch2D = dc.PrimitivesRenderer2D.TexturedBatch(subtexture.Texture); TexturedBatch2D texturedBatch2D2 = dc.PrimitivesRenderer2D.TexturedBatch(subtexture2.Texture); int count = texturedBatch2D.TriangleVertices.Count; int count2 = texturedBatch2D2.TriangleVertices.Count; Vector2 p = base.ActualSize / 2f; Vector2 vector = new Vector2(0f, 0f); Vector2 vector2 = new Vector2(base.ActualSize.X, 0f); Vector2 vector3 = new Vector2(base.ActualSize.X, base.ActualSize.Y); Vector2 vector4 = new Vector2(0f, base.ActualSize.Y); if (m_direction.Z > 0f) { Vector2 subtextureCoords = GetSubtextureCoords(subtexture2, new Vector2(0f, 0f)); Vector2 subtextureCoords2 = GetSubtextureCoords(subtexture2, new Vector2(1f, 0f)); Vector2 subtextureCoords3 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f)); texturedBatch2D2.QueueTriangle(vector, vector2, p, 0f, subtextureCoords, subtextureCoords2, subtextureCoords3, base.GlobalColorTransform); } else { Vector2 subtextureCoords4 = GetSubtextureCoords(subtexture, new Vector2(0f, 0f)); Vector2 subtextureCoords5 = GetSubtextureCoords(subtexture, new Vector2(1f, 0f)); Vector2 subtextureCoords6 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f)); texturedBatch2D.QueueTriangle(vector, vector2, p, 0f, subtextureCoords4, subtextureCoords5, subtextureCoords6, base.GlobalColorTransform); } if (m_direction.X > 0f) { Vector2 subtextureCoords7 = GetSubtextureCoords(subtexture2, new Vector2(1f, 0f)); Vector2 subtextureCoords8 = GetSubtextureCoords(subtexture2, new Vector2(1f, 1f)); Vector2 subtextureCoords9 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f)); texturedBatch2D2.QueueTriangle(vector2, vector3, p, 0f, subtextureCoords7, subtextureCoords8, subtextureCoords9, base.GlobalColorTransform); } else { Vector2 subtextureCoords10 = GetSubtextureCoords(subtexture, new Vector2(1f, 0f)); Vector2 subtextureCoords11 = GetSubtextureCoords(subtexture, new Vector2(1f, 1f)); Vector2 subtextureCoords12 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f)); texturedBatch2D.QueueTriangle(vector2, vector3, p, 0f, subtextureCoords10, subtextureCoords11, subtextureCoords12, base.GlobalColorTransform); } if (m_direction.Z < 0f) { Vector2 subtextureCoords13 = GetSubtextureCoords(subtexture2, new Vector2(1f, 1f)); Vector2 subtextureCoords14 = GetSubtextureCoords(subtexture2, new Vector2(0f, 1f)); Vector2 subtextureCoords15 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f)); texturedBatch2D2.QueueTriangle(vector3, vector4, p, 0f, subtextureCoords13, subtextureCoords14, subtextureCoords15, base.GlobalColorTransform); } else { Vector2 subtextureCoords16 = GetSubtextureCoords(subtexture, new Vector2(1f, 1f)); Vector2 subtextureCoords17 = GetSubtextureCoords(subtexture, new Vector2(0f, 1f)); Vector2 subtextureCoords18 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f)); texturedBatch2D.QueueTriangle(vector3, vector4, p, 0f, subtextureCoords16, subtextureCoords17, subtextureCoords18, base.GlobalColorTransform); } if (m_direction.X < 0f) { Vector2 subtextureCoords19 = GetSubtextureCoords(subtexture2, new Vector2(0f, 1f)); Vector2 subtextureCoords20 = GetSubtextureCoords(subtexture2, new Vector2(0f, 0f)); Vector2 subtextureCoords21 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f)); texturedBatch2D2.QueueTriangle(vector4, vector, p, 0f, subtextureCoords19, subtextureCoords20, subtextureCoords21, base.GlobalColorTransform); } else { Vector2 subtextureCoords22 = GetSubtextureCoords(subtexture, new Vector2(0f, 1f)); Vector2 subtextureCoords23 = GetSubtextureCoords(subtexture, new Vector2(0f, 0f)); Vector2 subtextureCoords24 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f)); texturedBatch2D.QueueTriangle(vector4, vector, p, 0f, subtextureCoords22, subtextureCoords23, subtextureCoords24, base.GlobalColorTransform); } if (texturedBatch2D == texturedBatch2D2) { texturedBatch2D.TransformTriangles(base.GlobalTransform, count); return; } texturedBatch2D.TransformTriangles(base.GlobalTransform, count); texturedBatch2D2.TransformTriangles(base.GlobalTransform, count2); }
public static Vector2 GetSubtextureCoords(Subtexture subtexture, Vector2 texCoords) { return(new Vector2(MathUtils.Lerp(subtexture.TopLeft.X, subtexture.BottomRight.X, texCoords.X), MathUtils.Lerp(subtexture.TopLeft.Y, subtexture.BottomRight.Y, texCoords.Y))); }