예제 #1
0
        protected override DX11IndexedGeometry GetGeom(DX11RenderContext context, int slice)
        {
            Torus t = new Torus(this.FResX[slice], this.FResY[slice], this.FSize[slice], this.FThick[slice],
                this.FPY[slice], this.FPX[slice], this.FPR[slice], this.FCY[slice]);

            return context.Primitives.Torus(t);
        }
예제 #2
0
        public DX11IndexedGeometry Torus(Torus settings)
        {
            int   resX   = settings.ResolutionX;
            int   resY   = settings.ResolutionY;
            float radius = settings.Radius;
            float thick  = settings.Thickness;
            float phasey = settings.PhaseY;
            float phasex = settings.PhaseX;
            float rot    = settings.Rotation;
            float cy     = settings.CY;

            List <Pos4Norm3Tex2Vertex> vertices = new List <Pos4Norm3Tex2Vertex>();
            List <int> indices = new List <int>();

            float pi     = (float)Math.PI;
            float pidiv2 = pi * 0.5f;
            float twopi  = pi * 2.0f;

            int stride = resY + 1;

            for (int i = 0; i <= resY; i++)
            {
                float u = (float)i / (float)resY;
                //u *= cy;

                float outerAngle = (float)i * twopi / (float)resY - pidiv2;

                Matrix transform = Matrix.Translation(radius, 0, 0) * Matrix.RotationY(outerAngle * rot);


                for (int j = 0; j <= resX; j++)
                {
                    float fj = (float)j * cy;

                    float v = 1 - (float)j / resX;

                    float innerAngle = fj * twopi / (float)resX + pi;
                    float dy         = (float)Math.Sin(innerAngle) * phasey;
                    float dx         = (float)Math.Cos(innerAngle) * phasex;

                    Pos4Norm3Tex2Vertex vertex = new Pos4Norm3Tex2Vertex();

                    Vector3 normal   = new Vector3(dx, dy, 0);
                    Vector3 position = normal * thick / 2;
                    vertex.TexCoords = new Vector2(u, v);
                    vertex.Normals   = Vector3.TransformNormal(normal, transform);

                    position        = Vector3.TransformCoordinate(position, transform);
                    vertex.Position = new Vector4(position.X, position.Y, position.Z, 1.0f);

                    vertices.Add(vertex);

                    int nextI = (i + 1) % stride;
                    int nextJ = (j + 1) % stride;

                    indices.Add(j * stride + i);
                    indices.Add(nextJ * stride + i);
                    indices.Add(j * stride + nextI);

                    indices.Add(j * stride + nextI);
                    indices.Add(nextJ * stride + i);
                    indices.Add(nextJ * stride + nextI);
                }
            }

            DX11IndexedGeometry geom = DX11IndexedGeometry.CreateFrom <Pos4Norm3Tex2Vertex>(context, vertices.ToArray(), indices.ToArray(), Pos4Norm3Tex2Vertex.Layout);

            geom.Tag            = settings;
            geom.PrimitiveType  = settings.PrimitiveType;
            geom.HasBoundingBox = false;
            geom.BoundingBox    = new BoundingBox(new Vector3(-radius), new Vector3(radius));

            return(geom);
        }
예제 #3
0
        public DX11IndexedGeometry Torus(Torus settings)
        {
            int resX = settings.ResolutionX;
            int resY = settings.ResolutionY;
            float radius = settings.Radius;
            float thick = settings.Thickness;
            float phasey = settings.PhaseY;
            float phasex = settings.PhaseX; 
            float rot = settings.Rotation;
            float cy = settings.CY;

            List<Pos4Norm3Tex2Vertex> vertices = new List<Pos4Norm3Tex2Vertex>();
            List<int> indices = new List<int>();

            float pi = (float)Math.PI;
            float pidiv2 = pi * 0.5f;
            float twopi = pi * 2.0f;

            int stride = resY + 1;

            for (int i = 0; i <= resY; i++)
            {
                float u = (float)i / (float)resY;
                //u *= cy;

                float outerAngle = (float)i * twopi / (float)resY - pidiv2;

                Matrix transform = Matrix.Translation(radius, 0, 0) * Matrix.RotationY(outerAngle*rot);

                
                for (int j = 0; j <= resX; j++)
                {
                    float fj = (float)j * cy;

                    float v = 1 - (float)j / resX;

                    float innerAngle = fj * twopi / (float)resX + pi;
                    float dy = (float)Math.Sin(innerAngle)*phasey;
                    float dx = (float)Math.Cos(innerAngle)*phasex;

                    Pos4Norm3Tex2Vertex vertex = new Pos4Norm3Tex2Vertex();

                    Vector3 normal = new Vector3(dx, dy, 0);
                    Vector3 position = normal * thick / 2;
                    vertex.TexCoords = new Vector2(u, v);
                    vertex.Normals = Vector3.TransformNormal(normal, transform);

                    position = Vector3.TransformCoordinate(position, transform);
                    vertex.Position = new Vector4(position.X, position.Y, position.Z, 1.0f);

                    vertices.Add(vertex);

                    int nextI = (i + 1) % stride;
                    int nextJ = (j + 1) % stride;

                    indices.Add(j * stride + i);
                    indices.Add(nextJ * stride + i);
                    indices.Add(j * stride + nextI);

                    indices.Add(j * stride + nextI);               
                    indices.Add(nextJ * stride + i);
                    indices.Add(nextJ * stride + nextI);
                }
            }

            DX11IndexedGeometry geom = DX11IndexedGeometry.CreateFrom<Pos4Norm3Tex2Vertex>(context, vertices.ToArray(), indices.ToArray(), Pos4Norm3Tex2Vertex.Layout);
            geom.Tag = settings;
            geom.PrimitiveType = settings.PrimitiveType;
            geom.HasBoundingBox = false;
            geom.BoundingBox = new BoundingBox(new Vector3(-radius), new Vector3(radius));

            return geom;
        }