Exemplo n.º 1
0
        //  Add cockpit decal and all surounding triangles. Method needs intersection, but result of the intersection must be with ideal glass, not any other part of a miner ship.
        public static void Add(MyCockpitGlassDecalTexturesEnum decalTexture, float decalSize, float angle, float alpha,
                               ref MyIntersectionResultLineTriangleEx idealIntersection, bool alphaBlendByAngle)
        {
            MyCockpitGlassDecalsBuffer buffer = GetBuffer(decalTexture);

            //	Polomer decalu a scale faktor pre vypocet textury.
            //  Decal size is something as radius of a decal, so when converting from real metres to texture space, we need to divide by 2.0
            float decalScale = 1.0f / decalSize / 2.0f;

            Vector3 rightVector = MyMwcUtils.Normalize(idealIntersection.Triangle.InputTriangle.Vertex0 - idealIntersection.IntersectionPointInObjectSpace);
            Vector3 upVector    = MyMwcUtils.Normalize(Vector3.Cross(rightVector, idealIntersection.NormalInObjectSpace));

            //  We create world matrix for the decal and then rotate the matrix, so we can extract rotated right/up vectors/planes for texture coord0 calculations
            Matrix decalMatrix = Matrix.CreateRotationZ(angle) * Matrix.CreateWorld(idealIntersection.IntersectionPointInObjectSpace, idealIntersection.NormalInObjectSpace, upVector);

            //	Right plane
            MyPlane rightPlane;

            rightPlane.Point  = idealIntersection.IntersectionPointInObjectSpace;
            rightPlane.Normal = MyUtils.GetTransformNormalNormalized(Vector3.Right, ref decalMatrix);

            //	Up plane
            MyPlane upPlane;

            upPlane.Point  = idealIntersection.IntersectionPointInObjectSpace;
            upPlane.Normal = MyUtils.GetTransformNormalNormalized(Vector3.Up, ref decalMatrix);

            float?maxAngle = null;

            if (alphaBlendByAngle == false)
            {
                maxAngle = MyCockpitGlassDecalsConstants.MAX_NEIGHBOUR_ANGLE;
            }

            BoundingSphere decalSphere = new BoundingSphere(idealIntersection.IntersectionPointInObjectSpace, decalSize);

            m_neighbourTriangles.Clear();
            //idealIntersection.PhysObject.GetTrianglesIntersectingSphere(ref decalSphere, idealIntersection.NormalInObjectSpace, maxAngle, idealIntersection.TriangleHelperIndex, m_neighbourTriangles, buffer.MaxNeighbourTriangles);
            idealIntersection.Entity.GetTrianglesIntersectingSphere(ref decalSphere, idealIntersection.NormalInObjectSpace, maxAngle, m_neighbourTriangles, buffer.MaxNeighbourTriangles);

            int trianglesToAdd = m_neighbourTriangles.Count;// +1;

            if (buffer.CanAddTriangles(trianglesToAdd) == true)
            {
                //  Decal on triangleVertexes we hit
//                buffer.Add(idealIntersection.Triangle.InputTriangle, idealIntersection.NormalInObjectSpace, ref rightPlane, ref upPlane, decalScale, color, alphaBlendByAngle, ref decalSphere);

                //  Create decal for every neighbour triangleVertexes
                for (int i = 0; i < m_neighbourTriangles.Count; i++)
                {
                    buffer.Add(m_neighbourTriangles[i].Vertexes, idealIntersection.NormalInObjectSpace, ref rightPlane, ref upPlane, decalScale, alpha, alphaBlendByAngle, ref decalSphere);
                }
            }
        }
Exemplo n.º 2
0
        //  Add cockpit decal and all surounding triangles. Method needs intersection, but result of the intersection must be with ideal glass, not any other part of a miner ship.
        public static void Add(MyCockpitGlassDecalTexturesEnum decalTexture, float decalSize, float angle, float alpha,
            ref MyIntersectionResultLineTriangleEx idealIntersection, bool alphaBlendByAngle)
        {
            MyCockpitGlassDecalsBuffer buffer = GetBuffer(decalTexture);

            //	Polomer decalu a scale faktor pre vypocet textury.
            //  Decal size is something as radius of a decal, so when converting from real metres to texture space, we need to divide by 2.0
            float decalScale = 1.0f / decalSize / 2.0f;

            Vector3 rightVector = MyMwcUtils.Normalize(idealIntersection.Triangle.InputTriangle.Vertex0 - idealIntersection.IntersectionPointInObjectSpace);
            Vector3 upVector = MyMwcUtils.Normalize(Vector3.Cross(rightVector, idealIntersection.NormalInObjectSpace));

            //  We create world matrix for the decal and then rotate the matrix, so we can extract rotated right/up vectors/planes for texture coord0 calculations
            Matrix decalMatrix = Matrix.CreateRotationZ(angle) * Matrix.CreateWorld(idealIntersection.IntersectionPointInObjectSpace, idealIntersection.NormalInObjectSpace, upVector);

            //	Right plane
            MyPlane rightPlane;
            rightPlane.Point = idealIntersection.IntersectionPointInObjectSpace;
            rightPlane.Normal = MyUtils.GetTransformNormalNormalized(Vector3.Right, ref decalMatrix);

            //	Up plane
            MyPlane upPlane;
            upPlane.Point = idealIntersection.IntersectionPointInObjectSpace;
            upPlane.Normal = MyUtils.GetTransformNormalNormalized(Vector3.Up, ref decalMatrix);

            float? maxAngle = null;
            if (alphaBlendByAngle == false) maxAngle = MyCockpitGlassDecalsConstants.MAX_NEIGHBOUR_ANGLE;

            BoundingSphere decalSphere = new BoundingSphere(idealIntersection.IntersectionPointInObjectSpace, decalSize);
            m_neighbourTriangles.Clear();
            //idealIntersection.PhysObject.GetTrianglesIntersectingSphere(ref decalSphere, idealIntersection.NormalInObjectSpace, maxAngle, idealIntersection.TriangleHelperIndex, m_neighbourTriangles, buffer.MaxNeighbourTriangles);
            idealIntersection.Entity.GetTrianglesIntersectingSphere(ref decalSphere, idealIntersection.NormalInObjectSpace, maxAngle, m_neighbourTriangles, buffer.MaxNeighbourTriangles);

            int trianglesToAdd = m_neighbourTriangles.Count;// +1;
            if (buffer.CanAddTriangles(trianglesToAdd) == true)
            {
                //  Decal on triangleVertexes we hit
//                buffer.Add(idealIntersection.Triangle.InputTriangle, idealIntersection.NormalInObjectSpace, ref rightPlane, ref upPlane, decalScale, color, alphaBlendByAngle, ref decalSphere);

                //  Create decal for every neighbour triangleVertexes
                for (int i = 0; i < m_neighbourTriangles.Count; i++)
                {
                    buffer.Add(m_neighbourTriangles[i].Vertexes, idealIntersection.NormalInObjectSpace, ref rightPlane, ref upPlane, decalScale, alpha, alphaBlendByAngle, ref decalSphere);
                }
            }
        }
Exemplo n.º 3
0
 static MyCockpitGlassDecalsBuffer GetBuffer(MyCockpitGlassDecalTexturesEnum decalTexture)
 {
     return(m_buffers[(int)decalTexture]);
 }
Exemplo n.º 4
0
 static MyCockpitGlassDecalsBuffer GetBuffer(MyCockpitGlassDecalTexturesEnum decalTexture)
 {
     return m_buffers[(int)decalTexture];
 }