Exemplo n.º 1
0
 public TexturedSphere(double centerX, double centerY, double centerZ, float radius, int[] bitmap, int width, int height)
     : base(centerX, centerY, centerZ, radius)
 {
     textureMap    = new SphericalMapping(width, height);
     textureWidth  = width;
     textureBitmap = bitmap;
 }
Exemplo n.º 2
0
 public TexturedSphere(double centerX, double centerY, double centerZ, float radius, Bitmap texture)
     : base(centerX, centerY, centerZ, radius)
 {
     textureMap    = new SphericalMapping(texture.Width, texture.Height);
     textureWidth  = texture.Width;
     textureBitmap = Util.getNativeTextureBitmap(texture);
 }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="equation"></param>
        /// <param name="sizex"></param>
        /// <param name="sizey"></param>
        /// <param name="discTexture"></param>
        /// <param name="backgroundTexture"></param>
        /// <param name="cameraTilt"></param>
        /// <param name="trace">If true, the steps of RungeKutta integration will be stored in a list, so that they can be studied after.</param>
        public RayTracer(KerrBlackHoleEquation equation, int sizex, int sizey, Bitmap discTexture, Bitmap backgroundTexture, double cameraTilt, double cameraYaw, bool trace = false)
        {
            this.equation          = equation;
            this.sizex             = sizex;
            this.sizey             = sizey;
            this.discTexture       = discTexture;
            this.backgroundTexture = backgroundTexture;
            this.cameraTilt        = cameraTilt;
            this.trace             = trace;
            this.cameraYaw         = cameraYaw;

            lock (backgroundTexture)
            {
                this.backgroundMap = new SphericalMapping(backgroundTexture.Width, backgroundTexture.Height);
            }

            lock (discTexture)
            {
                this.discMap = new DiscMapping(equation.Rmstable, equation.Rdisk, discTexture.Width, discTexture.Height);
            }

            if (trace)
            {
                this.RayPoints = new List <Tuple <double, double, double> >();
            }
        }
Exemplo n.º 4
0
 public Horizon(Bitmap texture, bool checkered)
 {
     this.checkered = checkered;
     if (texture != null)
     {
         textureMap    = new SphericalMapping(texture.Width, texture.Height);
         textureWidth  = texture.Width;
         textureBitmap = Util.getNativeTextureBitmap(texture);
     }
 }
Exemplo n.º 5
0
 public Sky(Bitmap texture, double radius)
 {
     this.radius = radius;
     radiusSqr   = radius * radius;
     if (texture != null)
     {
         textureMap    = new SphericalMapping(texture.Width, texture.Height);
         textureWidth  = texture.Width;
         textureBitmap = Util.getNativeTextureBitmap(texture);
     }
 }
Exemplo n.º 6
0
        public void AddSphere(int segments, float radius, MeshMaterial material)
        {
            if (!parts.ContainsKey(material))
            {
                throw new InvalidOperationException("Material not created by the meshbuilder");
            }
            TangentVertex[] vertices;
            short[]         indices;
            // Source: http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/sphere_cylinder/

            // Maak ringen van vertices van onder naar boven


            int i = 0;

            float phi, theta;
            float phiStep, thetaStep;
            float phiStart, phiEnd, thetaStart, thetaEnd;

            phiStep   = MathHelper.TwoPi / segments;
            thetaStep = MathHelper.Pi / segments;

            phiStart   = 0;
            phiEnd     = MathHelper.TwoPi;
            thetaStart = -MathHelper.PiOver2 + thetaStep;
            thetaEnd   = MathHelper.PiOver2;

            int numRings       = (int)Math.Round((thetaEnd - thetaStart) / thetaStep);
            int numVertsOnRing = (int)Math.Round((phiEnd - phiStart) / phiStep);



            int numVertices = 1 + numRings * numVertsOnRing + 1;


            vertices = new TangentVertex[numVertices];

            // Bottom vertex: (0,-1,0)
            vertices[i].pos = new Microsoft.Xna.Framework.Vector3(0, -1, 0);
            i++;

            theta = thetaStart;
            for (int iRing = 0; iRing < numRings; iRing++, theta += thetaStep)
            {
                phi = 0;
                for (int iVert = 0; iVert < numVertsOnRing; iVert++, phi += phiStep)
                {
                    vertices[i].pos = new Microsoft.Xna.Framework.Vector3(
                        (float)Math.Cos(theta) * (float)Math.Cos(phi),
                        (float)Math.Sin(theta),
                        -(float)Math.Cos(theta) * (float)Math.Sin(phi));
                    i++;
                }
            }
            // Top vertex: (0,1,0)
            vertices[i].pos = new Microsoft.Xna.Framework.Vector3(0, 1, 0);
            i++;


            // Generate normals
            for (int j = 0; j < vertices.Length; j++)
            {
                vertices[j].normal = Microsoft.Xna.Framework.Vector3.Normalize(vertices[j].pos);
            }


            int numIndices = (numVertsOnRing * 2 * 3) * numRings;

            indices = new short[numIndices];
            i       = 0;

            // Triangle fan at bottom and top, elsewhere strips between the rings

            // Top and bottom fan

            for (int iVert = 0; iVert < numVertsOnRing - 1; iVert++)
            {
                // Bottom fan
                indices[i] = (short)(0); i++;
                indices[i] = (short)(1 + iVert); i++;
                indices[i] = (short)(1 + (iVert + 1)); i++;

                // Top fan
                indices[i] = (short)(numVertices - 1); i++;
                indices[i] = (short)(1 + (numRings - 1) * numVertsOnRing + (iVert + 1)); i++;
                indices[i] = (short)(1 + (numRings - 1) * numVertsOnRing + iVert); i++;
            }

            // Top and bottom final fan
            indices[i] = (short)(0); i++;
            indices[i] = (short)(1 + numVertsOnRing - 1); i++;
            indices[i] = (short)(1 + 0); i++;

            indices[i] = (short)(numVertices - 1); i++;
            indices[i] = (short)(1 + (numRings - 1) * numVertsOnRing + 0); i++;
            indices[i] = (short)(1 + (numRings - 1) * numVertsOnRing + numVertsOnRing - 1); i++;

            // Strips
            for (int iRing = 0; iRing < numRings - 1; iRing++)
            {
                for (int iVert = 0; iVert < numVertsOnRing - 1; iVert++)
                {
                    indices[i] = (short)(1 + numVertsOnRing * iRing + iVert); i++;
                    indices[i] = (short)(1 + numVertsOnRing * (iRing + 1) + iVert); i++;
                    indices[i] = (short)(1 + numVertsOnRing * iRing + (iVert + 1)); i++;

                    indices[i] = (short)(1 + numVertsOnRing * iRing + (iVert + 1)); i++;
                    indices[i] = (short)(1 + numVertsOnRing * (iRing + 1) + iVert); i++;
                    indices[i] = (short)(1 + numVertsOnRing * (iRing + 1) + (iVert + 1)); i++;
                }
                // Final gap:
                indices[i] = (short)(1 + numVertsOnRing * iRing + (numVertsOnRing - 1)); i++;
                indices[i] = (short)(1 + numVertsOnRing * (iRing + 1) + (numVertsOnRing - 1)); i++;
                indices[i] = (short)(1 + numVertsOnRing * iRing + (0)); i++;

                indices[i] = (short)(1 + numVertsOnRing * iRing + (0)); i++;
                indices[i] = (short)(1 + numVertsOnRing * (iRing + 1) + (numVertsOnRing - 1)); i++;
                indices[i] = (short)(1 + numVertsOnRing * (iRing + 1) + (0)); i++;
            }

            var mapping = new SphericalMapping();

            var data = parts[material];

            foreach (var index in indices)
            {
                data.Positions.Add(vertices[index].pos * radius);
                data.Normals.Add(vertices[index].normal);
                data.Texcoords.Add(mapping.Map(data.Positions[data.Positions.Count - 1].ToSlimDX()).xna() * 3);
            }
        }