private static void AddBillboard(ref QuadBoard qb, ref MyQuadD quad)
                {
                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        quad.Point0,
                        quad.Point1,
                        quad.Point2,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        qb.texCoords.Min,
                        (qb.texCoords.Min + new Vector2(0f, qb.texCoords.Size.Y)),
                        qb.texCoords.Max,
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );

                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        quad.Point0,
                        quad.Point2,
                        quad.Point3,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        qb.texCoords.Min,
                        qb.texCoords.Max,
                        (qb.texCoords.Min + new Vector2(qb.texCoords.Size.X, 0f)),
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );
                }
                private static void AddBillboard(ref QuadBoard qb, ref CroppedQuad crop)
                {
                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        crop.quad.Point0,
                        crop.quad.Point1,
                        crop.quad.Point2,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        crop.matBounds.Min,
                        (crop.matBounds.Min + new Vector2(0f, crop.matBounds.Size.Y)),
                        crop.matBounds.Max,
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );

                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        crop.quad.Point0,
                        crop.quad.Point2,
                        crop.quad.Point3,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        crop.matBounds.Min,
                        crop.matBounds.Max,
                        (crop.matBounds.Min + new Vector2(crop.matBounds.Size.X, 0f)),
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );
                }
Ejemplo n.º 3
0
        private void DrawHudOnce()
        {
            foreach (var textureToDraw in _drawList)
            {
                if (textureToDraw.UvDraw)
                {
                    MyQuadD quad;
                    MyUtils.GetBillboardQuadOriented(out quad, ref textureToDraw.Position, textureToDraw.Width, textureToDraw.Height, ref textureToDraw.Left, ref textureToDraw.Up);

                    if (textureToDraw.Color != Color.Transparent)
                    {
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                    }
                    else
                    {
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                    }
                }
                else
                {
                    textureToDraw.Position = Vector3D.Transform(textureToDraw.Position, _cameraWorldMatrix);
                    MyTransparentGeometry.AddBillboardOriented(textureToDraw.Material, textureToDraw.Color, textureToDraw.Position, _cameraWorldMatrix.Left, _cameraWorldMatrix.Up, textureToDraw.Height, textureToDraw.Blend);
                }

                if (!textureToDraw.Persistant)
                {
                    _textureDrawPool.Enqueue(textureToDraw);
                }
            }
        }
Ejemplo n.º 4
0
            public void Draw(MyStringId?faceMaterial = null, MyStringId?lineMaterial = null,
                             float lineThickness     = -1f)
            {
                var ib = _backing._indexBuffer[_lod];

                for (int i = 0, j = 0; i < ib.Length; i += 3, j++)
                {
                    var i0 = ib[i];
                    var i1 = ib[i + 1];
                    var i2 = ib[i + 2];

                    var v0 = _vertexBuffer[i0];
                    var v1 = _vertexBuffer[i1];
                    var v2 = _vertexBuffer[i2];

                    var n0 = _normalBuffer[i0];
                    var n1 = _normalBuffer[i1];
                    var n2 = _normalBuffer[i2];

                    var color = _triColorBuffer[j];

                    if (faceMaterial.HasValue)
                    {
                        MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2, n0, n1, n2, Vector2.Zero, Vector2.Zero,
                                                                   Vector2.Zero, faceMaterial.Value, 0,
                                                                   (v0 + v1 + v2) / 3, color);
                    }
                    if (lineMaterial.HasValue && lineThickness > 0)
                    {
                        MySimpleObjectDraw.DrawLine(v0, v1, lineMaterial, ref color, lineThickness);
                        MySimpleObjectDraw.DrawLine(v1, v2, lineMaterial, ref color, lineThickness);
                        MySimpleObjectDraw.DrawLine(v2, v0, lineMaterial, ref color, lineThickness);
                    }
                }
            }
Ejemplo n.º 5
0
        public void Draw(MatrixD matrix, float radius, int lod, Vector4 color, MyStringId?faceMaterial = null,
                         MyStringId?lineMaterial = null, float lineThickness = -1f)
        {
            var ix = _indexBuffer[lod];

            for (var i = 0; i < ix.Length - 2; i += 3)
            {
                var i0 = ix[i];
                var i1 = ix[i + 1];
                var i2 = ix[i + 2];

                var v0 = Vector3D.Transform(radius * _vertexBuffer[i0], matrix);
                var v1 = Vector3D.Transform(radius * _vertexBuffer[i1], matrix);
                var v2 = Vector3D.Transform(radius * _vertexBuffer[i2], matrix);

                var n = (_vertexBuffer[i0] + _vertexBuffer[i1] + _vertexBuffer[i2]) / 3;
                if (faceMaterial.HasValue)
                {
                    MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2, _vertexBuffer[i0], _vertexBuffer[i1],
                                                               _vertexBuffer[i2], Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0,
                                                               (v0 + v1 + v2) / 3, color);
                }
                if (lineMaterial.HasValue && lineThickness > 0)
                {
                    MySimpleObjectDraw.DrawLine(v0, v1, lineMaterial, ref color, lineThickness);
                    MySimpleObjectDraw.DrawLine(v1, v2, lineMaterial, ref color, lineThickness);
                    MySimpleObjectDraw.DrawLine(v2, v0, lineMaterial, ref color, lineThickness);
                }
            }
        }
Ejemplo n.º 6
0
        private void DrawTriangle(int lod, int id, float radius, ref MatrixD matrix, ref Vector4 color,
                                  MyStringId?faceMaterial, MyStringId?lineMaterial, float lineThickness)
        {
            var i0 = _indexBuffer[lod][id];
            var i1 = _indexBuffer[lod][id + 1];
            var i2 = _indexBuffer[lod][id + 2];

            var v0 = Vector3D.Transform(radius * _vertexBuffer[i0], matrix);
            var v1 = Vector3D.Transform(radius * _vertexBuffer[i1], matrix);
            var v2 = Vector3D.Transform(radius * _vertexBuffer[i2], matrix);


            var n0 = Vector3D.TransformNormal(_vertexBuffer[i0], matrix);
            var n1 = Vector3D.TransformNormal(_vertexBuffer[i1], matrix);
            var n2 = Vector3D.TransformNormal(_vertexBuffer[i2], matrix);

            var s0 = WorldToScreen(v0);
            var s1 = WorldToScreen(v1);
            var s2 = WorldToScreen(v2);

            var sSize = Vector2.Max(s0, Vector2.Max(s1, s2)) - Vector2.Min(s0, Vector2.Min(s1, s2));
            var size  = (v0 - v1).LengthSquared() /
                        (MyAPIGateway.Session.Camera.Position - (v0 + v1 + v2) / 3).Length();

            if (size < 1 || lod == _indexBuffer.Length - 1)
            {
                // draw
                if (faceMaterial.HasValue)
                {
                    MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2, n0, n1, n2, Vector2.Zero, Vector2.Zero,
                                                               Vector2.Zero, faceMaterial.Value, 0,
                                                               (v0 + v1 + v2) / 3, color);
                }
                if (lineMaterial.HasValue && lineThickness > 0)
                {
                    MySimpleObjectDraw.DrawLine(v0, v1, lineMaterial, ref color, lineThickness);
                    MySimpleObjectDraw.DrawLine(v1, v2, lineMaterial, ref color, lineThickness);
                    MySimpleObjectDraw.DrawLine(v2, v0, lineMaterial, ref color, lineThickness);
                }
            }
            else
            {
                // subdivide
                var ni = id * 4;
                DrawTriangle(lod + 1, ni, radius, ref matrix, ref color, faceMaterial, lineMaterial, lineThickness);
                DrawTriangle(lod + 1, ni + 3, radius, ref matrix, ref color, faceMaterial, lineMaterial, lineThickness);
                DrawTriangle(lod + 1, ni + 6, radius, ref matrix, ref color, faceMaterial, lineMaterial, lineThickness);
                DrawTriangle(lod + 1, ni + 9, radius, ref matrix, ref color, faceMaterial, lineMaterial, lineThickness);
            }
        }
 public void Draw(MyStringId material)
 {
     if (MyCameraComponent.ActiveCamera != null && MyCameraComponent.ActiveCamera.GetCameraFrustum().Contains(Box) == ContainmentType.Disjoint)
     {
         return;
     }
     foreach (var t in _tris)
     {
         var p0 = t.Origin;
         var p1 = t.Origin + t.Edge1;
         var p2 = t.Origin + t.Edge2;
         var n  = Vector3.Cross(t.Edge1, t.Edge2);
         MyTransparentGeometry.AddTriangleBillboard(p0, p1, p2, n, n, n, Vector2.Zero, new Vector2(1, 0), new Vector2(0, 1), material, 0,
                                                    (p0 + p1 + p2) / 3);
     }
 }
Ejemplo n.º 8
0
            internal void Draw(uint renderId)
            {
                try
                {
                    if (ImpactsFinished && !_refresh)
                    {
                        return;
                    }
                    var     ib = _backing.IndexBuffer[_lod];
                    Vector4 color;
                    if (!ImpactsFinished)
                    {
                        color         = _waveColor;
                        _faceMaterial = _faceWave;
                    }
                    else
                    {
                        color         = _refreshColor;
                        _faceMaterial = _faceCharge;
                    }
                    for (int i = 0, j = 0; i < ib.Length; i += 3, j++)
                    {
                        var face = _triColorBuffer[j];
                        if (face != 1 && face != 2)
                        {
                            continue;
                        }

                        var i0 = ib[i];
                        var i1 = ib[i + 1];
                        var i2 = ib[i + 2];

                        var v0 = _vertexBuffer[i0];
                        var v1 = _vertexBuffer[i1];
                        var v2 = _vertexBuffer[i2];

                        var n0 = _normalBuffer[i0];
                        var n1 = _normalBuffer[i1];
                        var n2 = _normalBuffer[i2];

                        MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2, n0, n1, n2, _v20, _v21, _v22, _faceMaterial, renderId, (v0 + v1 + v2) / 3, color);
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in IcoSphere Draw - renderId {renderId.ToString()}: {ex}"); }
            }
Ejemplo n.º 9
0
        //Thanks to Equinox
        public override void DrawPie(ref Vector3D position, ref MatrixD matrix, float width, float height, double start, double end)
        {
            if (start < 0 || end > Pi2 || Math.Abs(start - end) < double.Epsilon)
            {
                return;
            }
            if (start > end)
            {
                DrawPie(ref position, ref matrix, width, height, start, Pi2);
                DrawPie(ref position, ref matrix, width, height, 0, end);
            }


            var pTheta = start;
            var pPosL  = new Vector2((float)Math.Sin(pTheta), (float)-Math.Cos(pTheta));

            pPosL /= Math.Max(Math.Abs(pPosL.X), Math.Abs(pPosL.Y));
            var      pPosLd = new Vector2(pPosL.X / 2 + 0.5f, pPosL.Y / 2 + 0.5f);
            var      cPosL  = new Vector2(0, 0);
            var      cPosLd = new Vector2(0.5f, 0.5f);
            Vector3  normal = matrix.Backward;
            float    hw     = width / 2;
            float    hh     = height / 2;
            Vector3D right  = matrix.Right * hw;
            Vector3D up     = matrix.Up * hh;

            while (pTheta + localEps < end)
            {
                var nextCorner = Math.Ceiling((pTheta - Pi_4) / Pi_2 + localEps);
                var arcNext    = Pi_4 + (Pi_2 * nextCorner);
                var nTheta     = Math.Min(arcNext, end);
                var nPosL      = new Vector2((float)Math.Sin(nTheta), (float)-Math.Cos(nTheta));
                nPosL /= Math.Max(Math.Abs(nPosL.X), Math.Abs(nPosL.Y));
                var      nPosLd = new Vector2(nPosL.X / 2 + 0.5f, nPosL.Y / 2 + 0.5f);
                Vector3D p1     = position + right * cPosL.X + up * cPosL.Y;
                Vector3D p2     = position + right * pPosL.X + up * pPosL.Y;
                Vector3D p3     = position + right * nPosL.X + up * nPosL.Y;
                MyTransparentGeometry.AddTriangleBillboard(p1, p2, p3, normal, normal, normal, cPosLd, pPosLd, nPosLd, Material, 0, position, transparent);
                pTheta = nTheta;
                pPosL  = nPosL;
                pPosLd = nPosLd;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Method is called defacto from Update, but only the last one in sequence, where
        /// creating render messages makes sense
        /// </summary>
        public override void Draw()
        {
            if (!MyRenderProxy.DebugOverrides.BillboardsStatic)
            {
                return;
            }

            ProfilerShort.Begin("MyRenderComponent::Draw");

            var objToCameraSq = Vector3.DistanceSquared(MySector.MainCamera.Position, Container.Entity.PositionComp.GetPosition());

            //Disable glass for holograms (transparency < 0)
            if (Transparency >= 0f && m_model != null && m_model.GlassData != null && objToCameraSq < Container.Entity.MaxGlassDistSq)
            {
                string mat;
                var    world = (Matrix)Container.Entity.PositionComp.WorldMatrix;

                Vector3 worldP0;
                Vector3 worldP1;
                Vector3 worldP2;

                Vector3 n0;
                Vector3 n1;
                Vector3 n2;

                for (int i = 0; i < m_model.GlassData.TriCount; i++)
                {
                    var     tri = m_model.GetTriangle(m_model.GlassData.TriStart + i);
                    Vector3 p0  = m_model.GetVertex(tri.I0);
                    Vector3 p1  = m_model.GetVertex(tri.I1);
                    Vector3 p2  = m_model.GetVertex(tri.I2);

                    Vector3.Transform(ref p0, ref world, out worldP0);
                    Vector3.Transform(ref p1, ref world, out worldP1);
                    Vector3.Transform(ref p2, ref world, out worldP2);

                    var uv0 = m_model.GlassTexCoords[i * 3 + 0];
                    var uv1 = m_model.GlassTexCoords[i * 3 + 2];
                    var uv2 = m_model.GlassTexCoords[i * 3 + 1];

                    var normal = Vector3.Cross(worldP0 - worldP1, worldP0 - worldP2);

                    float dot = Vector3.Dot(normal, worldP0 - MySector.MainCamera.Position);
                    if (dot > 0)
                    {
                        mat = string.IsNullOrEmpty(m_model.GlassData.Material.GlassCW) ? "GlassCW" : m_model.GlassData.Material.GlassCW;
                    }
                    else
                    {
                        mat = string.IsNullOrEmpty(m_model.GlassData.Material.GlassCCW) ? "GlassCCW" : m_model.GlassData.Material.GlassCCW;
                    }

                    // this does not make sense, as the shader takes only the one normal from the first point; better to use calculated triangle normal

                    /*bool smooth = m_model.GlassData.Material.GlassSmooth;
                     *
                     * if (smooth)
                     * {
                     *  n0 = m_model.GetVertexNormal(tri.I0);
                     *  n1 = m_model.GetVertexNormal(tri.I1);
                     *  n2 = m_model.GetVertexNormal(tri.I2);
                     * }
                     * else
                     * {*/
                    n0 = n1 = n2 = normal;
                    //}
                    if (dot > 0)
                    {
                        n0 = -n0;
                        n1 = -n1;
                        n2 = -n2;
                    }

                    var renderID = m_renderObjectIDs[0];

                    Vector3 center; // Old way: (p0 + p1 + p2) / 3
                    //Vector3 center = (p0 + p1 + p2) / 3;

                    float worldP0P1 = (worldP1 - worldP0).LengthSquared();
                    float worldP1P2 = (worldP2 - worldP1).LengthSquared();
                    float worldP2P0 = (worldP0 - worldP2).LengthSquared();

                    if (worldP0P1 > worldP1P2 && worldP0P1 > worldP2P0)
                    {
                        center = (worldP0 + worldP1) * 0.5f;
                    }
                    else if (worldP1P2 > worldP2P0 && worldP1P2 > worldP0P1)
                    {
                        center = (worldP1 + worldP2) * 0.5f;
                    }
                    else
                    {
                        center = (worldP2 + worldP0) * 0.5f;
                    }

                    MyTransparentGeometry.AddTriangleBillboard(
                        p0, p1, p2,
                        n0, n1, n2,
                        uv0.ToVector2(), uv1.ToVector2(), uv2.ToVector2(),
                        mat, (int)renderID, center);
                }
            }

            ProfilerShort.End();
        }
Ejemplo n.º 11
0
        public static void DrawTransparentCylinder(ref MatrixD worldMatrix, float radius1, float radius2, float length,
                                                   Vector4 lineColor, Vector4 faceColor, int wireDivideRatio, float thickness,
                                                   MyStringId?lineMaterial = null, MyStringId?faceMaterial = null)
        {
            Vector3D centerTop    = Vector3D.Transform(new Vector3D(0, length / 2f, 0), ref worldMatrix);
            Vector3D centerBottom = Vector3D.Transform(new Vector3D(0, -length / 2f, 0), ref worldMatrix);

            Vector3D upDir = Vector3D.TransformNormal(new Vector3D(0, 1, 0), ref worldMatrix);

            upDir.Normalize();

            Vector3D currTop    = Vector3D.Zero;
            Vector3D currBottom = Vector3D.Zero;
            Vector3D prevTop    = Vector3D.Zero;
            Vector3D prevBottom = Vector3D.Zero;
            float    num        = 360f / wireDivideRatio;

            for (int i = 0; i <= wireDivideRatio; i++)
            {
                float degrees = i * num;
                currTop.X    = (float)(radius1 * Math.Cos(MathHelper.ToRadians(degrees)));
                currTop.Y    = length / 2f;
                currTop.Z    = (float)(radius1 * Math.Sin(MathHelper.ToRadians(degrees)));
                currBottom.X = (float)(radius2 * Math.Cos(MathHelper.ToRadians(degrees)));
                currBottom.Y = -length / 2f;
                currBottom.Z = (float)(radius2 * Math.Sin(MathHelper.ToRadians(degrees)));
                currTop      = Vector3D.Transform(currTop, worldMatrix);
                currBottom   = Vector3D.Transform(currBottom, worldMatrix);

                if (lineMaterial.HasValue)
                {
                    MySimpleObjectDraw.DrawLine(currBottom, currTop, lineMaterial, ref lineColor, thickness);
                }

                if (i > 0)
                {
                    if (lineMaterial.HasValue)
                    {
                        MySimpleObjectDraw.DrawLine(prevBottom, currBottom, lineMaterial, ref lineColor, thickness);
                        MySimpleObjectDraw.DrawLine(prevTop, currTop, lineMaterial, ref lineColor, thickness);
                    }

                    if (faceMaterial.HasValue)
                    {
                        var quad = new MyQuadD()
                        {
                            Point0 = prevTop,
                            Point1 = currTop,
                            Point2 = currBottom,
                            Point3 = prevBottom
                        };
                        MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, faceColor, ref currTop);

                        MyTransparentGeometry.AddTriangleBillboard(centerTop, currTop, prevTop, upDir, upDir, upDir,
                                                                   Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currTop, faceColor);
                        MyTransparentGeometry.AddTriangleBillboard(centerBottom, currBottom, prevBottom, -upDir, -upDir, -upDir,
                                                                   Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currBottom, faceColor);
                    }
                }

                prevBottom = currBottom;
                prevTop    = currTop;
            }
        }
Ejemplo n.º 12
0
        private void DrawTarget()
        {
            var s     = _session;
            var focus = s.TrackingAi.Construct.Data.Repo.FocusData;

            for (int i = 0; i < s.TrackingAi.TargetState.Length; i++)
            {
                if (focus.Target[i] <= 0)
                {
                    continue;
                }
                var lockMode = focus.Locked[i];

                var targetState  = s.TrackingAi.TargetState[i];
                var displayCount = 0;
                foreach (var icon in _targetIcons.Keys)
                {
                    int iconLevel;
                    if (!IconStatus(icon, targetState, out iconLevel))
                    {
                        continue;
                    }

                    Vector3D   offset;
                    Vector2    localOffset;
                    float      scale;
                    MyStringId textureName;
                    var        iconInfo = _targetIcons[icon][iconLevel];
                    iconInfo.GetTextureInfo(i, displayCount, s, out textureName, out scale, out offset, out localOffset);

                    var color = Color.White;
                    switch (lockMode)
                    {
                    case FocusData.LockModes.None:
                        color = Color.White;
                        break;

                    case FocusData.LockModes.Locked:
                        color = s.Count < 60 ? Color.White : new Color(255, 255, 255, 64);
                        break;

                    case FocusData.LockModes.ExclusiveLock:
                        color = s.SCount < 30 ? Color.White : new Color(255, 255, 255, 64);
                        break;
                    }

                    var skipSize = !s.Settings.ClientConfig.ShowHudTargetSizes && icon.Equals("size");

                    if (!skipSize)
                    {
                        MyTransparentGeometry.AddBillboardOriented(textureName, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, scale, BlendTypeEnum.PostPP);
                    }

                    if (focus.ActiveId == i && displayCount == 0)
                    {
                        if (!skipSize)
                        {
                            var focusTexture = focus.ActiveId == 0 ? _focus : _focusSecondary;
                            MyTransparentGeometry.AddBillboardOriented(focusTexture, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, scale, BlendTypeEnum.PostPP);
                        }
                        else
                        {
                            var     focusColor = focus.ActiveId == 0 ? Color.Red : Color.LightBlue;
                            MyQuadD quad;
                            var     up   = (Vector3)s.CameraMatrix.Up;
                            var     left = (Vector3)s.CameraMatrix.Left;

                            MyUtils.GetBillboardQuadOriented(out quad, ref offset, 0.002f, 0.002f, ref left, ref up);
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, FocusTextureMap.P0, FocusTextureMap.P1, FocusTextureMap.P3, FocusTextureMap.Material, 0, offset, focusColor, BlendTypeEnum.PostPP);
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, FocusTextureMap.P0, FocusTextureMap.P2, FocusTextureMap.P3, FocusTextureMap.Material, 0, offset, focusColor, BlendTypeEnum.PostPP);
                        }
                    }

                    displayCount++;
                }

                MyEntity target;
                if (i == focus.ActiveId && MyEntities.TryGetEntityById(focus.Target[focus.ActiveId], out target))
                {
                    var targetSphere = target.PositionComp.WorldVolume;
                    var targetCenter = targetSphere.Center;
                    var screenPos    = s.Camera.WorldToScreen(ref targetCenter);
                    var screenScale  = 0.1 * s.ScaleFov;

                    if (Vector3D.Transform(targetCenter, s.Camera.ViewMatrix).Z > 0)
                    {
                        screenPos.X *= -1;
                        screenPos.Y  = -1;
                    }

                    var dotpos = new Vector2D(MathHelper.Clamp(screenPos.X, -0.98, 0.98), MathHelper.Clamp(screenPos.Y, -0.98, 0.98));

                    dotpos.X *= (float)(screenScale * _session.AspectRatio);
                    dotpos.Y *= (float)screenScale;
                    screenPos = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);
                    MyTransparentGeometry.AddBillboardOriented(_active, Color.White, screenPos, s.CameraMatrix.Left, s.CameraMatrix.Up, (float)screenScale * 0.075f, BlendTypeEnum.PostPP);

                    if (s.Tick20)
                    {
                        s.HudUi.AddText(text: $"RANGE: {targetState.RealDistance:#.0}  -  SIZE: {targetState.SizeExtended}", x: i == 0 ? 0f : -0.345f, y: 0.83f, element: Hud.ElementNames.Element0, ttl: 18, color: i == 0 ? Color.OrangeRed : Color.MediumOrchid, justify: Hud.Justify.Center, fontType: Hud.FontType.Shadow, fontSize: 5, heightScale: 0.75f);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        internal void DrawTextures()
        {
            _aspectratio       = _session.Camera.ViewportSize.Y / _session.Camera.ViewportSize.X;
            _cameraWorldMatrix = _session.Camera.WorldMatrix;

            #region WeaponHudDisplay
            //inlined becuase there can be many and too many method calls
            if (WeaponsToDisplay.Count > 0)
            {
                CurrWeaponDisplayPos = new Vector2((_session.Camera.ViewportSize.X * .25f) * _metersInPixel, (_session.Camera.ViewportSize.Y * .125f) * _metersInPixel);

                var ticksSinceUpdate = _session.Tick - _lastHudUpdateTick;

                var reset = false;
                if (ticksSinceUpdate >= _minUpdateTicks)
                {
                    _weapontoDraw      = SortDisplayedWeapons(WeaponsToDisplay);
                    _lastHudUpdateTick = _session.Tick;
                }
                else if (ticksSinceUpdate + 1 >= _minUpdateTicks)
                {
                    reset = true;
                }

                #region Background draw
                TextureDrawData backgroundTextureTop;
                if (!_textureDrawPool.TryDequeue(out backgroundTextureTop))
                {
                    backgroundTextureTop = new TextureDrawData();
                }

                TextureDrawData backgroundTextureCenter;
                if (!_textureDrawPool.TryDequeue(out backgroundTextureCenter))
                {
                    backgroundTextureCenter = new TextureDrawData();
                }

                TextureDrawData backgroundTextureBottom;
                if (!_textureDrawPool.TryDequeue(out backgroundTextureBottom))
                {
                    backgroundTextureBottom = new TextureDrawData();
                }


                var bgWidth     = (_currentLargestName * _metersInPixel) + _textOffset;
                var bgStartPosX = CurrWeaponDisplayPos.X - (bgWidth + _padding * 1.5f);

                var bgBorderHeight = bgWidth * .166f;
                var bgCenterHeight = _weapontoDraw.Count > 3 ? ((_weapontoDraw.Count - 2) * _infoPanelOffset) : _infoPanelOffset * 2;

                var bgStartPoxY = CurrWeaponDisplayPos.Y - (bgCenterHeight + _padding);

                backgroundTextureCenter.Material = _infoBackground[1].Material;
                backgroundTextureCenter.Color    = _bgColor * (_session.Session.Config.HUDBkOpacity * 1.8f);
                backgroundTextureCenter.Position = new Vector3D(bgStartPosX, bgStartPoxY, -.1f);
                backgroundTextureCenter.Width    = bgWidth;
                backgroundTextureCenter.Height   = bgCenterHeight;
                backgroundTextureCenter.P0       = _infoBackground[1].P0;
                backgroundTextureCenter.P1       = _infoBackground[1].P1;
                backgroundTextureCenter.P2       = _infoBackground[1].P2;
                backgroundTextureCenter.P3       = _infoBackground[1].P3;

                _textureAddList.Add(backgroundTextureCenter);

                backgroundTextureTop.Material = _infoBackground[0].Material;
                backgroundTextureTop.Color    = _bgColor * (_session.Session.Config.HUDBkOpacity * 1.8f);
                backgroundTextureTop.Position = new Vector3D(bgStartPosX, bgStartPoxY + bgBorderHeight + bgCenterHeight, -.1f);
                backgroundTextureTop.Width    = bgWidth;
                backgroundTextureTop.Height   = bgBorderHeight;
                backgroundTextureTop.P0       = _infoBackground[0].P0;
                backgroundTextureTop.P1       = _infoBackground[0].P1;
                backgroundTextureTop.P2       = _infoBackground[0].P2;
                backgroundTextureTop.P3       = _infoBackground[0].P3;

                _textureAddList.Add(backgroundTextureTop);

                backgroundTextureBottom.Material = _infoBackground[2].Material;
                backgroundTextureBottom.Color    = _bgColor * (_session.Session.Config.HUDBkOpacity * 1.8f);
                backgroundTextureBottom.Position = new Vector3D(bgStartPosX, bgStartPoxY - (bgBorderHeight + bgCenterHeight), -.1f);
                backgroundTextureBottom.Width    = bgWidth;
                backgroundTextureBottom.Height   = bgBorderHeight;
                backgroundTextureBottom.P0       = _infoBackground[2].P0;
                backgroundTextureBottom.P1       = _infoBackground[2].P1;
                backgroundTextureBottom.P2       = _infoBackground[2].P2;
                backgroundTextureBottom.P3       = _infoBackground[2].P3;

                _textureAddList.Add(backgroundTextureBottom);
                #endregion

                if (reset)
                {
                    _currentLargestName = 0;
                }

                for (int i = 0; i < _weapontoDraw.Count; i++)
                {
                    TextDrawRequest textInfo;
                    TextureDrawData reloadTexture;
                    TextureDrawData heatTexture;

                    var weapon     = _weapontoDraw[i].HighestValueWeapon;
                    var name       = weapon.System.WeaponName + ": ";
                    var textOffset = name.Length * _WeaponHudFontHeight;
                    textOffset += _textOffset;

                    if (weapon.State.Sync.Reloading && weapon.State.Sync.Reloading && weapon.Comp.Session.Tick - weapon.LastLoadedTick > 30)
                    {
                        if (!_textureDrawPool.TryDequeue(out reloadTexture))
                        {
                            reloadTexture = new TextureDrawData();
                        }

                        reloadTexture.Material = _reloadingTexture.Material;
                        reloadTexture.Color    = Color.Red * _session.UiOpacity;
                        reloadTexture.Position = new Vector3D(CurrWeaponDisplayPos.X - _reloadWidthOffset, CurrWeaponDisplayPos.Y + _reloadHeightOffset, -.1f);
                        reloadTexture.Width    = _reloadWidth;
                        reloadTexture.Height   = _reloadHeight;
                        reloadTexture.P0       = _reloadingTexture.P0;
                        reloadTexture.P1       = _reloadingTexture.P1;
                        reloadTexture.P2       = _reloadingTexture.P2;
                        reloadTexture.P3       = _reloadingTexture.P3;

                        _textureAddList.Add(reloadTexture);
                    }

                    if (!_textDrawPool.TryDequeue(out textInfo))
                    {
                        textInfo = new TextDrawRequest();
                    }

                    textInfo.Text     = name;
                    textInfo.Color    = Color.White * _session.UiOpacity;
                    textInfo.X        = CurrWeaponDisplayPos.X - textOffset;
                    textInfo.Y        = CurrWeaponDisplayPos.Y;
                    textInfo.FontSize = _WeaponHudFontSize;
                    _textAddList.Add(textInfo);


                    if (weapon.HeatPerc > 0)
                    {
                        if (!_textureDrawPool.TryDequeue(out heatTexture))
                        {
                            heatTexture = new TextureDrawData();
                        }
                        int heatBarIndex;
                        if (weapon.State.Sync.Overheated)
                        {
                            heatBarIndex = 10;
                        }
                        else
                        {
                            heatBarIndex = (int)(weapon.HeatPerc * 10);
                        }

                        heatTexture.Material = _heatBarTexture[heatBarIndex].Material;
                        heatTexture.Color    = Color.Transparent;
                        heatTexture.Position = new Vector3D(CurrWeaponDisplayPos.X - (_heatWidth * 1.5f), CurrWeaponDisplayPos.Y - _heatHeightOffset, -.1f);
                        heatTexture.Width    = _heatWidth;
                        heatTexture.Height   = _heatHeight;
                        heatTexture.P0       = _heatBarTexture[heatBarIndex].P0;
                        heatTexture.P1       = _heatBarTexture[heatBarIndex].P1;
                        heatTexture.P2       = _heatBarTexture[heatBarIndex].P2;
                        heatTexture.P3       = _heatBarTexture[heatBarIndex].P3;

                        _textureAddList.Add(heatTexture);
                    }

                    if (_weapontoDraw[i].WeaponStack > 1)
                    {
                        if (!_textDrawPool.TryDequeue(out textInfo))
                        {
                            textInfo = new TextDrawRequest();
                        }

                        textInfo.Text     = $"(x{_weapontoDraw[i].WeaponStack})";
                        textInfo.Color    = Color.LightSteelBlue * _session.UiOpacity;
                        textInfo.X        = CurrWeaponDisplayPos.X - (textOffset + ((textInfo.Text.Length * _metersInPixel) * 1.1f) + _padding);
                        textInfo.Y        = CurrWeaponDisplayPos.Y;
                        textInfo.FontSize = _WeaponHudFontSize * .75f;
                        _textAddList.Add(textInfo);
                    }

                    CurrWeaponDisplayPos.Y -= _infoPanelOffset + (_padding * .5f);

                    if (reset)
                    {
                        _weaponStackedInfoPool.Enqueue(_weapontoDraw[i]);
                    }
                }

                if (reset)
                {
                    _weapontoDraw.Clear();
                    _weaponInfoListPool.Enqueue(_weapontoDraw);
                }
            }
            #endregion

            #region UV Offset based draws
            for (int i = 0; i < _textAddList.Count; i++)
            {
                var textAdd  = _textAddList[i];
                var position = new Vector3D(textAdd.X, textAdd.Y, -.1);
                position = Vector3D.Transform(position, _cameraWorldMatrix);

                var height  = textAdd.FontSize * _metersInPixel;
                var width   = height * _aspectratio;
                var textPos = position;

                for (int j = 0; j < textAdd.Text.Length; j++)
                {
                    var             cm = _characterMap[textAdd.Text[j]];
                    TextureDrawData tdd;

                    if (!_textureDrawPool.TryDequeue(out tdd))
                    {
                        tdd = new TextureDrawData();
                    }

                    tdd.Material = cm.Material;
                    tdd.Color    = textAdd.Color;
                    tdd.Position = textPos;
                    tdd.Up       = _cameraWorldMatrix.Up;
                    tdd.Left     = _cameraWorldMatrix.Left;
                    tdd.Width    = width;
                    tdd.Height   = height;
                    tdd.P0       = cm.P0;
                    tdd.P1       = cm.P1;
                    tdd.P2       = cm.P2;
                    tdd.P3       = cm.P3;

                    _uvDrawList.Add(tdd);

                    textPos -= (_cameraWorldMatrix.Left * height);
                }

                _textDrawPool.Enqueue(textAdd);
            }

            for (int i = 0; i < _textureAddList.Count; i++)
            {
                var tdd = _textureAddList[i];

                tdd.Position = Vector3D.Transform(tdd.Position, _cameraWorldMatrix);
                tdd.Up       = _cameraWorldMatrix.Up;
                tdd.Left     = _cameraWorldMatrix.Left;
                _uvDrawList.Add(tdd);
            }

            for (int i = 0; i < _uvDrawList.Count; i++)
            {
                var textureToDraw = _uvDrawList[i];

                MyQuadD quad;
                MyUtils.GetBillboardQuadOriented(out quad, ref textureToDraw.Position, textureToDraw.Width, textureToDraw.Height, ref textureToDraw.Left, ref textureToDraw.Up);

                if (textureToDraw.Color != Color.Transparent)
                {
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                }
                else
                {
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                }

                _textureDrawPool.Enqueue(textureToDraw);
            }
            #endregion

            #region Simple based draws
            for (int i = 0; i < _simpleDrawList.Count; i++)
            {
                var textureToDraw = _simpleDrawList[i];
                var scale         = 0.075 * Math.Tan(_session.Camera.FovWithZoom * textureToDraw.Height);

                textureToDraw.Position = Vector3D.Transform(textureToDraw.Position, _cameraWorldMatrix);
                scale = 1 * scale;

                MyTransparentGeometry.AddBillboardOriented(textureToDraw.Material, textureToDraw.Color, textureToDraw.Position, _cameraWorldMatrix.Left, _cameraWorldMatrix.Up, (float)scale, textureToDraw.Blend);

                _textureDrawPool.Enqueue(textureToDraw);
            }
            #endregion

            WeaponsToDisplay.Clear();
            _textAddList.Clear();
            _textureAddList.Clear();
            _uvDrawList.Clear();
            _simpleDrawList.Clear();
            TexturesToAdd = 0;
        }
Ejemplo n.º 14
0
        private void DrawActiveLeads()
        {
            var s     = _session;
            var focus = s.TrackingAi.Construct.Data.Repo.FocusData;

            MyEntity target;

            if (!MyEntities.TryGetEntityById(focus.Target[focus.ActiveId], out target) && target.Physics == null)
            {
                return;
            }

            var targetSphere = target.PositionComp.WorldVolume;

            float    maxLeadLength;
            Vector3D fullAveragePos;

            if (!ComputeLead(target, targetSphere.Center, out maxLeadLength, out fullAveragePos))
            {
                return;
            }

            var lineStart   = targetSphere.Center;
            var lineNormDir = Vector3D.Normalize(fullAveragePos - lineStart);
            var ray         = new RayD(lineStart, lineNormDir);

            var rayDist = s.CameraFrustrum.Intersects(ray);

            if (!s.Camera.IsInFrustum(ref targetSphere) || rayDist == null)
            {
                return;
            }

            var lineEnd      = lineStart + (lineNormDir * maxLeadLength);
            var endScreenPos = s.Camera.WorldToScreen(ref lineEnd);

            var worldLine = new LineD(lineEnd, lineStart, maxLeadLength);

            var obb        = new MyOrientedBoundingBoxD(target.PositionComp.LocalAABB, target.PositionComp.WorldMatrixRef);
            var lineLength = obb.Intersects(ref worldLine) ?? 0;

            if (lineLength < 0.2f)
            {
                return;
            }

            var lineScale = (float)(0.1 * s.ScaleFov);

            var startScreenPos = s.Camera.WorldToScreen(ref lineStart);
            var scaledAspect   = lineScale * _session.AspectRatio;

            var      scale              = s.Settings.ClientConfig.HudScale;
            var      fontScale          = scale * s.ScaleFov;
            Vector3D fursthestScreenPos = Vector3D.Zero;
            double   furthestDist       = 0;
            var      element            = 0;

            for (int i = 0; i < _leadInfos.Count; i++)
            {
                var info = _leadInfos[i];

                if (obb.Contains(ref info.Position))
                {
                    continue;
                }

                var screenPos       = s.Camera.WorldToScreen(ref info.Position);
                var lockedScreenPos = MyUtils.GetClosestPointOnLine(ref startScreenPos, ref endScreenPos, ref screenPos);

                var distSqr = Vector3D.DistanceSquared(lockedScreenPos, startScreenPos);
                if (distSqr > furthestDist)
                {
                    furthestDist       = distSqr;
                    fursthestScreenPos = lockedScreenPos;
                }

                var textColor = !info.WillHit ? new Vector4(1, 1, 1, 1) : new Vector4(1, 0.025f, 0.025f, 1);

                string textLine1     = (i + 1).ToString();
                var    fontFocusSize = !info.WillHit ? 8 : 11;
                var    fontSize      = (float)Math.Round(fontFocusSize * fontScale, 2);
                var    fontHeight    = 0.75f;
                var    fontAge       = -1;
                var    fontJustify   = Hud.Justify.Center;
                var    fontType      = Hud.FontType.Shadow;
                var    elementId     = 2000 + element++;
                s.HudUi.AddText(text: textLine1, x: (float)lockedScreenPos.X, y: (float)lockedScreenPos.Y, elementId: elementId, ttl: fontAge, color: textColor, justify: fontJustify, fontType: fontType, fontSize: fontSize, heightScale: fontHeight);
            }

            var endDotPos = new Vector2D(fursthestScreenPos.X, fursthestScreenPos.Y);

            endDotPos.X *= scaledAspect;
            endDotPos.Y *= lineScale;

            var lineEndScreenPos = Vector3D.Transform(new Vector3D(endDotPos.X, endDotPos.Y, -0.1), s.CameraMatrix);

            var culledLineStart      = lineEnd - (lineNormDir * lineLength);
            var culledStartScreenPos = s.Camera.WorldToScreen(ref culledLineStart);

            var culledStartDotPos = new Vector2D(culledStartScreenPos.X, culledStartScreenPos.Y);

            culledStartDotPos.X *= scaledAspect;
            culledStartDotPos.Y *= lineScale;

            var lineStartScreenPos = Vector3D.Transform(new Vector3D(culledStartDotPos.X, culledStartDotPos.Y, -0.1), s.CameraMatrix);

            var lineColor     = new Vector4(0.5f, 0.5f, 1, 1);
            var lineMagnitude = lineEndScreenPos - lineStartScreenPos;

            MyTransparentGeometry.AddLineBillboard(_laserLine, lineColor, lineStartScreenPos, lineMagnitude, 1f, lineScale * 0.005f);

            var avgScreenPos       = s.Camera.WorldToScreen(ref fullAveragePos);
            var avgLockedScreenPos = MyUtils.GetClosestPointOnLine(ref startScreenPos, ref endScreenPos, ref avgScreenPos);

            var dotpos = new Vector2D(avgLockedScreenPos.X, avgLockedScreenPos.Y);

            dotpos.X          *= scaledAspect;
            dotpos.Y          *= lineScale;
            avgLockedScreenPos = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);

            var size                = (float)((0.00125f * scale) * s.ScaleFov);
            var left                = (Vector3)s.CameraMatrix.Left;
            var up                  = (Vector3)s.CameraMatrix.Up;
            var repColor            = new Vector4(1, 1, 1, 1);
            var time                = s.Tick % 20; // forward and backward total time
            var increase            = time < 10;
            var directionalTimeStep = increase ? time : 19 - time;
            var textureMap          = s.HudUi.PaintedTexture[directionalTimeStep];

            MyQuadD quad;

            MyUtils.GetBillboardQuadOriented(out quad, ref avgLockedScreenPos, size, size, ref left, ref up);
            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureMap.P0, textureMap.P1, textureMap.P3, textureMap.Material, 0, avgLockedScreenPos, repColor, BlendTypeEnum.PostPP);
            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureMap.P0, textureMap.P2, textureMap.P3, textureMap.Material, 0, avgLockedScreenPos, repColor, BlendTypeEnum.PostPP);

            _leadInfos.Clear();
        }
        public void Render()
        {
            if (MyAPIGateway.Utilities.IsDedicated)
            {
                return;
            }
            var gravity = Vector3.TransformNormal(MyGravityProviderSystem.CalculateTotalGravityInPoint(Entity.GetPosition()),
                                                  Entity.PositionComp.WorldMatrixNormalizedInv);
            Vector3 windDir      = Vector3.TransformNormal(WindVector, Entity.PositionComp.WorldMatrixNormalizedInv);
            float   windStrength = 0;
            {
                var freq  = new Vector4(1.975f, 0.973f, 0.375f, 0.193f);
                var x     = (float)MySession.Static.ElapsedGameTime.TotalSeconds * WindStrength + (float)((Vector3D)WindVector).Dot(Entity.GetPosition());
                var waves = freq * x;
                waves = new Vector4(Math.Abs(((waves.X + 0.5f) % 1) * 2 - 1), Math.Abs(((waves.Y + 0.5f) % 1) * 2 - 1),
                                    Math.Abs(((waves.Z + 0.5f) % 1) * 2 - 1), Math.Abs(((waves.W + 0.5f) % 1) * 2 - 1));
                waves = waves * waves * (new Vector4(3) - new Vector4(2) * waves);

                windStrength = (waves.X + waves.Y + waves.Z + waves.W) * 0.25f;
            }


            var parent          = Entity;
            var parentRenderObj = parent.Get <MyRenderComponentBase>();

            while (parentRenderObj == null && parent != null)
            {
                parent          = parent.Parent;
                parentRenderObj = parent.Get <MyRenderComponentBase>();
            }

            if (parentRenderObj == null)
            {
                return;
            }

            var skeleton = Entity.Get <MySkeletonComponent>();

            if (_prevTickPosition.HasValue)
            {
                var pp = _prevTickPosition.Value;
                // Apply a transform to the cloth such that:  transform(CurrentPos, ClothDataNew) == transform(PrevPos, ClothDataOld)
                var transform = (Matrix)(pp * Entity.PositionComp.WorldMatrixInvScaled);
                foreach (var cloth in _cloths)
                {
                    cloth.ApplyTransform(transform);
                }
            }

            _prevTickPosition = Entity.PositionComp.WorldMatrix;
            for (var id = 0; id < _cloths.Length; id++)
            {
                var cloth   = _cloths[id];
                var section = Definition.Quads[id];
                if (skeleton != null)
                {
                    foreach (var binding in section.Bindings)
                    {
                        int boneIndex;
                        var bone = skeleton.FindBone(binding.Bone, out boneIndex);
                        if (bone == null)
                        {
                            continue;
                        }

                        for (var yo = 0; yo < binding.YCount; yo++)
                        {
                            var by = binding.Y + yo;
                            var fy = by / (float)(section.Def.ResY - 1);
                            var p0 = Vector3.Lerp(section.Def.V00, section.Def.V01, fy);
                            var p1 = Vector3.Lerp(section.Def.V10, section.Def.V11, fy);
                            for (var xo = 0; xo < binding.XCount; xo++)
                            {
                                var bx         = binding.X + xo;
                                var idx        = section.Def.ResX * by + bx;
                                var fx         = bx / (float)(section.Def.ResX - 1);
                                var bindPos    = Vector3.Lerp(p0, p1, fx);
                                var bindPosRel = Vector3.Transform(bindPos, ref bone.Transform.AbsoluteBindTransformInv);
                                var currPos    = Vector3.Transform(bindPosRel, ref skeleton.BoneAbsoluteTransforms[boneIndex]);
                                cloth.Particles[idx].Position = currPos;
                            }
                        }
                    }
                }

                var region      = (BoundingBoxD)cloth.CalculateInflatedBox(MyEngineConstants.UPDATE_STEPS_PER_SECOND * 2f);
                var regionWorld = region.TransformFast(Entity.PositionComp.WorldMatrix);
                var entities    = MyEntities.GetEntitiesInAABB(ref regionWorld);
                cloth.SphereColliders.Clear();
                cloth.CapsuleColliders.Clear();
                var invWorld = Entity.PositionComp.WorldMatrixInvScaled;
                foreach (var ent in entities)
                {
                    foreach (var collider in ent.Components.GetComponents <ClothColliderComponent>())
                    {
                        Cloth.Sphere[]  spheres;
                        Cloth.Capsule[] capsules;
                        collider.GetColliders(out spheres, out capsules);
                        var conv = (Matrix)(ent.WorldMatrix * invWorld);
                        foreach (var s in spheres)
                        {
                            cloth.SphereColliders.Add(new Cloth.Sphere(Vector3.Transform(s.P0, conv), s.Radius));
                        }
                        foreach (var c in capsules)
                        {
                            cloth.CapsuleColliders.Add(new Cloth.Capsule(new Line
                            {
                                From        = Vector3.Transform(c.Line.From, conv),
                                To          = Vector3.Transform(c.Line.To, conv),
                                Direction   = Vector3.TransformNormal(c.Line.Direction, conv),
                                Length      = c.Line.Length,
                                BoundingBox = c.Line.BoundingBox
                            }, c.Radius));
                        }
                    }
                }

                cloth.Gravity       = gravity;
                cloth.WindDirection = windDir;
                cloth.WindStrength  = windStrength;
                cloth.Simulate();

                var qs  = cloth.QuadStream;
                var pts = cloth.Particles;
                for (var i = 0; i < qs.Length; i += 4)
                {
//                    var quad = new MyQuadD
//                    {
//                        Point0 = pts[qs[i]].Position,
//                        Point1 = pts[qs[i + 1]].Position,
//                        Point2 = pts[qs[i + 2]].Position,
//                        Point3 = pts[qs[i + 3]].Position
//                    };
//                    MyTransparentGeometry.AddAttachedQuad(_mtl, ref quad, Vector4.One, ref quad.Point0, parentRenderObj.GetRenderObjectID());
                    var pt0 = pts[qs[i]];
                    var pt1 = pts[qs[i + 1]];
                    var pt2 = pts[qs[i + 2]];
                    var pt3 = pts[qs[i + 3]];
                    MyTransparentGeometry.AddTriangleBillboard(pt0.Position, pt1.Position, pt2.Position, -pt0.Normal, -pt1.Normal, -pt2.Normal, pt0.Uv, pt1.Uv,
                                                               pt2.Uv, _mtl, parentRenderObj.GetRenderObjectID(), pt0.Position);

                    MyTransparentGeometry.AddTriangleBillboard(pt0.Position, pt2.Position, pt3.Position, -pt0.Normal, -pt2.Normal, -pt3.Normal, pt0.Uv, pt2.Uv,
                                                               pt3.Uv, _mtl, parentRenderObj.GetRenderObjectID(), pt3.Position);
//                    quad.Point0 = Vector3D.Transform(quad.Point0, Entity.WorldMatrix);
//                    quad.Point1 = Vector3D.Transform(quad.Point1, Entity.WorldMatrix);
//                    quad.Point2 = Vector3D.Transform(quad.Point2, Entity.WorldMatrix);
//                    quad.Point3 = Vector3D.Transform(quad.Point3, Entity.WorldMatrix);
//                    MyTransparentGeometry.AddQuad(_mtl, ref quad, Vector4.One, ref quad.Point0);
                }
            }

            _initialRun = false;
        }
Ejemplo n.º 16
0
            internal void Draw(uint renderId, DefenseShields shield)
            {
                try
                {
                    var ib = _backing.IndexBuffer[_lod];

                    int index       = 0;
                    var damageColor = shield.GetModulatorColor();
                    damageColor.W = 0.5f;

                    while (index < _impactRings.Count)
                    {
                        bool retain = false;

                        var impactRingData = _impactRings[index];

                        float progress;
                        float ringIntesity;
                        float ringSize;
                        float ringSizeCofficient;

                        if (impactRingData.AnimationStartClock <= ImpactRingExpandTicks)
                        {
                            progress           = ((float)impactRingData.AnimationStartClock / ImpactRingExpandTicks) * 0.75f + 0.25f;
                            ringIntesity       = (progress * 0.5f) + 0.5f;
                            ringSize           = 1 - ((1 - progress) * (1 - progress));
                            ringSizeCofficient = 0.5f / ringSize;
                        }
                        else
                        {
                            progress           = 1 - (((float)impactRingData.AnimationStartClock - ImpactRingExpandTicks) / ImpactRingFadeTicks);
                            ringIntesity       = (progress * 0.5f) + 0.5f;
                            ringSize           = 1;
                            ringSizeCofficient = 0.5f;
                        }

                        impactRingData.AnimationStartClock++;

                        var v4 = new Vector4
                        {
                            W = damageColor.W,
                            X = damageColor.X * 2f * ringIntesity,
                            Y = damageColor.Y * 2f * ringIntesity,
                            Z = damageColor.Z * 2f * ringIntesity
                        };

                        if (impactRingData.LodLevel == _lod)
                        {
                            for (int x = 0; x < impactRingData.RingTriangles.Count; x++)
                            {
                                TriangleData triangleData = impactRingData.RingTriangles[x];

                                int i = triangleData.TriangleIndex * 3;

                                var i0 = ib[i];
                                var i1 = ib[i + 1];
                                var i2 = ib[i + 2];

                                var v0 = _vertexBuffer[i0];
                                var v1 = _vertexBuffer[i1];
                                var v2 = _vertexBuffer[i2];

                                var n0 = _normalBuffer[i0];
                                var n1 = _normalBuffer[i1];
                                var n2 = _normalBuffer[i2];
                                MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2,
                                                                           n0, n1, n2,
                                                                           triangleData.UVInfoV0 * ringSizeCofficient + HalfShift,
                                                                           triangleData.UVInfoV1 * ringSizeCofficient + HalfShift,
                                                                           triangleData.UVInfoV2 * ringSizeCofficient + HalfShift,
                                                                           _impactRingMaterial, renderId, (v0 + v1 + v2) / 3, v4, BlendTypeEnum.PostPP);
                            }

                            if (impactRingData.AnimationStartClock <= ImpactRingExpandTicks + ImpactRingFadeTicks)
                            {
                                retain = true;
                            }
                        }

                        if (retain)
                        {
                            index++;
                        }
                        else
                        {
                            var last     = _impactRings.Count - 1;
                            var lastData = _impactRings[last];
                            _impactRings.RemoveAtFast(last);
                            Session.Instance.RingPool.Return(lastData);

                            //_impactRings[index] = _impactRings[_impactRings.Count - 1];
                            //_impactRings.RemoveAt(_impactRings.Count - 1);
                        }
                    }

                    /* Superseded
                     * if (ImpactsFinished && !_refresh) return;
                     * var ib = _backing.IndexBuffer[_lod];
                     * Vector4 color;
                     * if (!ImpactsFinished)
                     * {
                     *  color = _waveColor;
                     *  _faceMaterial = _faceWave;
                     * }
                     * else
                     * {
                     *  color = _refreshColor;
                     *  _faceMaterial = _faceCharge;
                     * }
                     * for (int i = 0, j = 0; i < ib.Length; i += 3, j++)
                     * {
                     *  var face = _triColorBuffer[j];
                     *  if (face != 1 && face != 2) continue;
                     *
                     *  var i0 = ib[i];
                     *  var i1 = ib[i + 1];
                     *  var i2 = ib[i + 2];
                     *
                     *  var v0 = _vertexBuffer[i0];
                     *  var v1 = _vertexBuffer[i1];
                     *  var v2 = _vertexBuffer[i2];
                     *
                     *  var n0 = _normalBuffer[i0];
                     *  var n1 = _normalBuffer[i1];
                     *  var n2 = _normalBuffer[i2];
                     *
                     *  MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2, n0, n1, n2, _v20, _v21, _v22, _faceMaterial, renderId, (v0 + v1 + v2) / 3, color);
                     * }
                     */
                }
                catch (Exception ex) { Log.Line($"Exception in IcoSphere Draw - renderId {renderId.ToString()}: {ex}"); }
            }
Ejemplo n.º 17
0
        internal void DrawTextures()
        {
            var ticksSinceUpdate = _session.Tick - _lastHudUpdateTick;
            var reset            = false;

            _cameraWorldMatrix = _session.Camera.WorldMatrix;

            if (NeedsUpdate)
            {
                UpdateHudSettings();
            }

            if (WeaponsToDisplay.Count > 0)
            {
                if (ticksSinceUpdate >= _minUpdateTicks)
                {
                    _weapontoDraw      = SortDisplayedWeapons(WeaponsToDisplay);
                    _lastHudUpdateTick = _session.Tick;
                }
                else if (ticksSinceUpdate + 1 >= _minUpdateTicks)
                {
                    reset = true;
                }

                DrawHud(reset);
            }

            #region Proccess Custom Additions
            for (int i = 0; i < _textAddList.Count; i++)
            {
                var textAdd = _textAddList[i];

                var height = textAdd.FontSize;
                var width  = textAdd.FontSize * _aspectratioInv;
                textAdd.Position.Z = _viewPortSize.Z;
                var textPos = Vector3D.Transform(textAdd.Position, _cameraWorldMatrix);

                for (int j = 0; j < textAdd.Text.Length; j++)
                {
                    var cm = _characterMap[textAdd.Font][textAdd.Text[j]];

                    TextureDrawData tdd;

                    if (!_textureDrawPool.TryDequeue(out tdd))
                    {
                        tdd = new TextureDrawData();
                    }

                    tdd.Material = cm.Material;
                    tdd.Color    = textAdd.Color;
                    tdd.Position = textPos;
                    tdd.Up       = _cameraWorldMatrix.Up;
                    tdd.Left     = _cameraWorldMatrix.Left;
                    tdd.Width    = width;
                    tdd.Height   = height;
                    tdd.P0       = cm.P0;
                    tdd.P1       = cm.P1;
                    tdd.P2       = cm.P2;
                    tdd.P3       = cm.P3;
                    tdd.UvDraw   = true;
                    tdd.Simple   = textAdd.Simple;

                    _drawList.Add(tdd);

                    textPos -= _cameraWorldMatrix.Left * height;
                }

                _textDrawPool.Enqueue(textAdd);
            }

            for (int i = 0; i < _textureAddList.Count; i++)
            {
                var tdd = _textureAddList[i];
                tdd.Position.Z = _viewPortSize.Z;
                tdd.Position   = Vector3D.Transform(tdd.Position, _cameraWorldMatrix);
                tdd.Up         = _cameraWorldMatrix.Up;
                tdd.Left       = _cameraWorldMatrix.Left;
                _drawList.Add(tdd);
            }
            #endregion

            for (int i = 0; i < _drawList.Count; i++)
            {
                var textureToDraw = _drawList[i];

                if (textureToDraw.Simple)
                {
                    textureToDraw.Position.X = (textureToDraw.Position.X / (-_viewPortSize.X) * (_viewPortSize.X - 100) + 100);
                    textureToDraw.Position.Y = (textureToDraw.Position.Y / (-_viewPortSize.Y) * (_viewPortSize.Y - 100) + 100);
                }


                if (textureToDraw.UvDraw)
                {
                    MyQuadD quad;
                    MyUtils.GetBillboardQuadOriented(out quad, ref textureToDraw.Position, textureToDraw.Width, textureToDraw.Height, ref textureToDraw.Left, ref textureToDraw.Up);

                    if (textureToDraw.Color != Color.Transparent)
                    {
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                    }
                    else
                    {
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                    }
                }
                else
                {
                    textureToDraw.Position = Vector3D.Transform(textureToDraw.Position, _cameraWorldMatrix);

                    MyTransparentGeometry.AddBillboardOriented(textureToDraw.Material, textureToDraw.Color, textureToDraw.Position, _cameraWorldMatrix.Left, _cameraWorldMatrix.Up, textureToDraw.Height, textureToDraw.Blend);
                }
                if (!textureToDraw.Persistant)
                {
                    _textureDrawPool.Enqueue(textureToDraw);
                }
            }

            WeaponsToDisplay.Clear();
            _textAddList.Clear();
            _textureAddList.Clear();
            _drawList.Clear();
            TexturesToAdd = 0;
        }
Ejemplo n.º 18
0
            internal void Draw(uint renderId, bool sphereOnCamera, DefenseShields shield)
            {
                try
                {
                    var ib = _backing.IndexBuffer[_lod];

                    int index       = 0;
                    var damageColor = shield.GetModulatorColor();
                    damageColor.W = 0.5f;

                    while (index < ImpactRings.Count)
                    {
                        bool retain = false;

                        var impactRingData = ImpactRings[index];

                        float progress;
                        float ringIntesity;
                        float ringSize;
                        float ringSizeCofficient;

                        if (impactRingData.AnimationStartClock <= ImpactRingExpandTicks)
                        {
                            progress           = ((float)impactRingData.AnimationStartClock / ImpactRingExpandTicks) * 0.75f + 0.25f;
                            ringIntesity       = (progress * 0.5f) + 0.5f;
                            ringSize           = 1 - ((1 - progress) * (1 - progress));
                            ringSizeCofficient = 0.5f / ringSize;
                        }
                        else
                        {
                            progress           = 1 - (((float)impactRingData.AnimationStartClock - ImpactRingExpandTicks) / ImpactRingFadeTicks);
                            ringIntesity       = (progress * 0.5f) + 0.5f;
                            ringSize           = 1;
                            ringSizeCofficient = 0.5f;
                        }

                        impactRingData.AnimationStartClock++;


                        var v4 = new Vector4
                        {
                            W = damageColor.W,
                            X = damageColor.X * 2f * ringIntesity,
                            Y = damageColor.Y * 2f * ringIntesity,
                            Z = damageColor.Z * 2f * ringIntesity
                        };

                        if (impactRingData.LodLevel == _lod)
                        {
                            if (sphereOnCamera)
                            {
                                for (int x = 0; x < impactRingData.RingTriangles.Count; x++)
                                {
                                    TriangleData triangleData = impactRingData.RingTriangles[x];

                                    int i = triangleData.TriangleIndex * 3;

                                    var i0 = ib[i];
                                    var i1 = ib[i + 1];
                                    var i2 = ib[i + 2];

                                    var v0 = _vertexBuffer[i0];
                                    var v1 = _vertexBuffer[i1];
                                    var v2 = _vertexBuffer[i2];

                                    var n0 = _normalBuffer[i0];
                                    var n1 = _normalBuffer[i1];
                                    var n2 = _normalBuffer[i2];
                                    MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2,
                                                                               n0, n1, n2,
                                                                               triangleData.UVInfoV0 * ringSizeCofficient + HalfShift,
                                                                               triangleData.UVInfoV1 * ringSizeCofficient + HalfShift,
                                                                               triangleData.UVInfoV2 * ringSizeCofficient + HalfShift,
                                                                               _impactRingMaterial, renderId, (v0 + v1 + v2) / 3, v4, BlendTypeEnum.PostPP);
                                }
                            }

                            if (impactRingData.AnimationStartClock <= ImpactRingExpandTicks + ImpactRingFadeTicks)
                            {
                                retain = true;
                            }
                        }

                        if (retain)
                        {
                            index++;
                        }
                        else
                        {
                            var last     = ImpactRings.Count - 1;
                            var lastData = ImpactRings[last];
                            ImpactRings.RemoveAtFast(last);
                            Session.Instance.RingPool.Return(lastData);
                            Session.Instance.ActiveShieldRings--;
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in IcoSphere Draw - renderId {renderId.ToString()}: {ex}"); }
            }
Ejemplo n.º 19
0
        private void DrawActiveMarks()
        {
            var s = _session;

            var time                = s.Tick % 20; // forward and backward total time
            var increase            = time < 10;
            var directionalTimeStep = increase ? time  : 19 - time;
            var textureMap          = s.HudUi.PaintedTexture[directionalTimeStep];
            var colorStep           = s.Tick % 120;
            var amplify             = colorStep <= 60;
            var modifyStep          = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
            var cMod1               = MathHelper.Clamp(amplify ? (colorStep * modifyStep) :  2 - (+(colorStep * modifyStep)), 0.1f, 1f);
            var left                = (Vector3)s.CameraMatrix.Left;
            var up            = (Vector3)s.CameraMatrix.Up;
            var scale         = s.Settings.ClientConfig.HudScale;
            var screenScale   = 0.1 * s.ScaleFov;
            var size          = (float)((0.0025f * scale) * s.ScaleFov);
            var invScaler     = MathHelper.Clamp(1 / s.ScaleFov, 0, 20);
            var fontScale     = scale * s.ScaleFov;
            var invScaleLimit = 4.2;

            if (invScaler >= invScaleLimit)
            {
                fontScale *= (invScaler / invScaleLimit);
                size      *= (float)(invScaler / invScaleLimit);
                invScaler  = MathHelper.Clamp(20f / invScaler, 1, 20);
            }

            var fontYOffset = (float)((-0.05f * scale) * invScaler);

            for (int i = 0; i < s.ActiveMarks.Count; i++)
            {
                var mark       = s.ActiveMarks[i];
                var player     = mark.Item1;
                var repColor   = mark.Item2;
                var fakeTarget = mark.Item3;

                var textColor = new Vector4(repColor.X, repColor.Y, repColor.Z, cMod1 * repColor.W);

                var targetCenter = fakeTarget.GetFakeTargetInfo(s.TrackingAi).WorldPosition;
                var viewSphere   = new BoundingSphereD(targetCenter, 100f);
                if (!s.Camera.IsInFrustum(ref viewSphere))
                {
                    continue;
                }

                var screenPos = s.Camera.WorldToScreen(ref targetCenter);

                Vector3D drawPos = screenPos;
                if (Vector3D.Transform(targetCenter, s.Camera.ViewMatrix).Z > 0)
                {
                    drawPos.X *= -1;
                    drawPos.Y  = -1;
                }

                var dotpos = new Vector2D(MathHelper.Clamp(drawPos.X, -0.98, 0.98), MathHelper.Clamp(drawPos.Y, -0.98, 0.98));
                dotpos.X *= (float)(screenScale * _session.AspectRatio);
                dotpos.Y *= (float)screenScale;
                drawPos   = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);


                MyQuadD quad;
                MyUtils.GetBillboardQuadOriented(out quad, ref drawPos, size, size, ref left, ref up);
                MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureMap.P0, textureMap.P1, textureMap.P3, textureMap.Material, 0, drawPos, repColor, BlendTypeEnum.PostPP);
                MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureMap.P0, textureMap.P2, textureMap.P3, textureMap.Material, 0, drawPos, repColor, BlendTypeEnum.PostPP);

                string textLine1   = player.DisplayName;
                var    fontSize    = (float)Math.Round(10 * fontScale, 1);
                var    fontHeight  = 0.75f;
                var    fontAge     = -1;
                var    fontJustify = Hud.Justify.Center;
                var    fontType    = Hud.FontType.Shadow;
                var    elementId   = 3102 + (100 + i);
                s.HudUi.AddText(text: textLine1, x: (float)screenPos.X, y: (float)screenPos.Y + fontYOffset, elementId: elementId, ttl: fontAge, color: textColor, justify: fontJustify, fontType: fontType, fontSize: fontSize, heightScale: fontHeight);
            }
        }
Ejemplo n.º 20
0
            public void Draw(uint renderId)
            {
                try
                {
                    //Log.Line($"Start Draw");
                    //DSUtils.Sw.Start();
                    var faceMaterial = _faceId2;
                    var ib           = _backing.IndexBuffer[_lod];
                    var v21          = new Vector2(0.5f, 0);
                    var v22          = new Vector2(0.5f);
                    for (int i = 0, j = 0; i < ib.Length; i += 3, j++)
                    {
                        var i0 = ib[i];
                        var i1 = ib[i + 1];
                        var i2 = ib[i + 2];

                        var v0 = _vertexBuffer[i0];
                        var v1 = _vertexBuffer[i1];
                        var v2 = _vertexBuffer[i2];

                        var n0    = _normalBuffer[i0];
                        var n1    = _normalBuffer[i1];
                        var n2    = _normalBuffer[i2];
                        var color = _triColorBuffer[j];
                        if (color == _currentColor)
                        {
                            faceMaterial = _faceId1;
                        }
                        else if (color == _pulseColor)
                        {
                            faceMaterial = _faceId1;
                        }
                        else if (color == _test1Color)
                        {
                            faceMaterial = _faceId1;
                        }
                        else if (color == _test2Color)
                        {
                            faceMaterial = _faceId1;
                        }
                        else if (color == _waveColor)
                        {
                            faceMaterial = _faceId1;
                        }
                        else if (color == _waveComingColor)
                        {
                            faceMaterial = _faceId1;
                        }
                        else if (color == _wavePassedColor)
                        {
                            faceMaterial = _faceId1;
                        }
                        else if (color == _chargeColor)
                        {
                            faceMaterial = _faceId1;
                        }
                        MyTransparentGeometry.AddTriangleBillboard(v0, v1, v2, n0, n1, n2, Vector2.Zero, v21, v22, faceMaterial, renderId, (v0 + v1 + v2) / 3, color);
                    }

                    //DSUtils.StopWatchReport("IcoDraw", -1);
                }
                catch (Exception ex) { Log.Line($"Exception in IcoSphere Draw - renderId {renderId}: {ex}"); }
            }
Ejemplo n.º 21
0
        private void AgingTextDraw()
        {
            var up   = (Vector3)_cameraWorldMatrix.Up;
            var left = (Vector3)_cameraWorldMatrix.Left;

            foreach (var textAdd in _agingTextRequests.Values)
            {
                textAdd.Position.Z = _viewPortSize.Z;
                var requestPos = textAdd.Position;
                requestPos.Z = _viewPortSize.Z;
                var widthScaler = textAdd.Font == FontType.Shadow ? ShadowSizeScaler : 1f;

                var textPos = Vector3D.Transform(requestPos, _cameraWorldMatrix);
                switch (textAdd.Justify)
                {
                case Justify.Center:
                    textPos += _cameraWorldMatrix.Left * (((textAdd.MessageWidth * ShadowWidthScaler) * 0.5f) * widthScaler);
                    break;

                case Justify.Right:
                    textPos -= _cameraWorldMatrix.Left * ((textAdd.MessageWidth * ShadowWidthScaler) * widthScaler);
                    break;

                case Justify.Left:
                    textPos -= _cameraWorldMatrix.Right * ((textAdd.MessageWidth * ShadowWidthScaler) * widthScaler);
                    break;

                case Justify.None:
                    textPos -= _cameraWorldMatrix.Left * ((textAdd.FontSize * 0.5f) * widthScaler);
                    break;
                }

                var height = textAdd.FontSize * textAdd.HeightScale;
                var remove = textAdd.Ttl-- < 0;

                for (int i = 0; i < textAdd.Data.Count; i++)
                {
                    var textData = textAdd.Data[i];
                    textData.WorldPos.Z = _viewPortSize.Z;

                    if (textData.UvDraw)
                    {
                        var     width = (textData.ScaledWidth * widthScaler) * _session.AspectRatioInv;
                        MyQuadD quad;
                        MyUtils.GetBillboardQuadOriented(out quad, ref textPos, width, height, ref left, ref up);

                        if (textAdd.Color != Vector4.Zero)
                        {
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textData.P0, textData.P1, textData.P3, textData.Material, 0, textPos, textAdd.Color, textData.Blend);
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textData.P0, textData.P2, textData.P3, textData.Material, 0, textPos, textAdd.Color, textData.Blend);
                        }
                        else
                        {
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textData.P0, textData.P1, textData.P3, textData.Material, 0, textPos, textData.Blend);
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textData.P0, textData.P2, textData.P3, textData.Material, 0, textPos, textData.Blend);
                        }
                    }

                    textPos -= _cameraWorldMatrix.Left * textData.ScaledWidth;

                    if (remove)
                    {
                        textAdd.Data.Remove(textData);
                        _textDataPool.Return(textData);
                    }
                }

                textAdd.Data.ApplyRemovals();
                AgingTextRequest request;
                if (textAdd.Data.Count == 0 && _agingTextRequests.TryRemove(textAdd.ElementId, out request))
                {
                    _agingTextRequests.Remove(textAdd.ElementId);
                    _agingTextRequestPool.Return(request);
                }
            }
            AgingTextures = _agingTextRequests.Count > 0;
        }
Ejemplo n.º 22
0
        public static void DrawTransparentCylinder(ref MatrixD worldMatrix,
                                                   float radiusBase, float radiusTop, float length, int wireDivideRatio,
                                                   Vector4 faceColor, Vector4 lineColor,
                                                   MyStringId?faceMaterial     = null, MyStringId?lineMaterial = null, float lineThickness = 0.01f,
                                                   BlendTypeEnum lineBlendType = BlendTypeEnum.Standard, BlendTypeEnum faceBlendType = BlendTypeEnum.Standard,
                                                   bool capEnds = true)
        {
            Vector3D dir          = worldMatrix.Forward;
            Vector3D centerBottom = worldMatrix.Translation;
            Vector3D centerTop    = worldMatrix.Translation + dir * length;

            Vector3D currBottom = Vector3D.Zero;
            Vector3D currTop    = Vector3D.Zero;

            Vector3D prevBottom = Vector3D.Zero;
            Vector3D prevTop    = Vector3D.Zero;

            float stepDeg = 360f / wireDivideRatio;

            for (int i = 0; i <= wireDivideRatio; i++)
            {
                float angle = MathHelper.ToRadians(i * stepDeg);

                currBottom.X = radiusBase * Math.Cos(angle);
                currBottom.Y = radiusBase * Math.Sin(angle);
                currBottom.Z = 0;
                currBottom   = Vector3D.Transform(currBottom, worldMatrix);

                currTop.X = radiusTop * Math.Cos(angle);
                currTop.Y = radiusTop * Math.Sin(angle);
                currTop.Z = -length;
                currTop   = Vector3D.Transform(currTop, worldMatrix);

                if (lineMaterial.HasValue)
                {
                    MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, currBottom, (currTop - currBottom), 1f, lineThickness, lineBlendType);
                }

                if (i > 0)
                {
                    if (lineMaterial.HasValue)
                    {
                        MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, prevBottom, (currBottom - prevBottom), 1f, lineThickness, lineBlendType);
                        MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, prevTop, (currTop - prevTop), 1f, lineThickness, lineBlendType);
                    }

                    if (faceMaterial.HasValue)
                    {
                        var quad = new MyQuadD()
                        {
                            Point0 = prevTop,
                            Point1 = currTop,
                            Point2 = currBottom,
                            Point3 = prevBottom
                        };
                        MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, faceColor, ref currTop, blendType: faceBlendType);

                        if (capEnds)
                        {
                            var color = faceColor.ToLinearRGB(); // HACK keeping color consistent with AddQuad() and AddLineBillboard()

                            MyTransparentGeometry.AddTriangleBillboard(centerTop, currTop, prevTop, dir, dir, dir,
                                                                       Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currTop, color, faceBlendType);

                            MyTransparentGeometry.AddTriangleBillboard(centerBottom, currBottom, prevBottom, -dir, -dir, -dir,
                                                                       Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currBottom, color, faceBlendType);
                        }
                    }
                }

                prevBottom = currBottom;
                prevTop    = currTop;
            }
        }