Exemple #1
0
        public void SubDivideNoNormalize(List <Triangle> triList, List <PositionTexture> vertexList)
        {
            Vector3d a1 = Vector3d.Lerp(vertexList[B].Position, vertexList[C].Position, .5f);
            Vector3d b1 = Vector3d.Lerp(vertexList[C].Position, vertexList[A].Position, .5f);
            Vector3d c1 = Vector3d.Lerp(vertexList[A].Position, vertexList[B].Position, .5f);

            Vector2d a1uv = Vector2d.Lerp(Vector2d.Create(vertexList[B].Tu, vertexList[B].Tv), Vector2d.Create(vertexList[C].Tu, vertexList[C].Tv), .5f);
            Vector2d b1uv = Vector2d.Lerp(Vector2d.Create(vertexList[C].Tu, vertexList[C].Tv), Vector2d.Create(vertexList[A].Tu, vertexList[A].Tv), .5f);
            Vector2d c1uv = Vector2d.Lerp(Vector2d.Create(vertexList[A].Tu, vertexList[A].Tv), Vector2d.Create(vertexList[B].Tu, vertexList[B].Tv), .5f);

            //a1.Normalize();
            //b1.Normalize();
            //c1.Normalize();

            int aIndex = vertexList.Count;
            int bIndex = vertexList.Count + 1;
            int cIndex = vertexList.Count + 2;

            vertexList.Add(PositionTexture.CreatePosRaw(a1, a1uv.X, a1uv.Y));
            vertexList.Add(PositionTexture.CreatePosRaw(b1, b1uv.X, b1uv.Y));
            vertexList.Add(PositionTexture.CreatePosRaw(c1, c1uv.X, c1uv.Y));

            triList.Add(Triangle.Create(A, cIndex, bIndex));
            triList.Add(Triangle.Create(B, aIndex, cIndex));
            triList.Add(Triangle.Create(C, bIndex, aIndex));
            triList.Add(Triangle.Create(aIndex, bIndex, cIndex));
        }
        private static void CreateGalaxyImage(RenderContext renderContext)
        {
            if (milkyWayImage == null)
            {
                milkyWayImage = Planets.LoadPlanetTexture("http://cdn.worldwidetelescope.org/webclient/images/milkywaybar.jpg");
            }


            int subdivs = 50;

            double lat, lng;

            int    index  = 0;
            double latMin = 64;
            double latMax = -64;
            double lngMin = -64;
            double lngMax = 64;

            //// Create a vertex buffer
            galaxyImageVertexBuffer = new PositionTextureVertexBuffer((subdivs + 1) * (subdivs + 1));
            PositionTexture[] verts = (PositionTexture[])galaxyImageVertexBuffer.Lock();

            int      x1, y1;
            double   latDegrees  = latMax - latMin;
            double   lngDegrees  = lngMax - lngMin;
            double   scaleFactor = 60800000.0;
            double   ecliptic    = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI;
            Vector3d point;

            double textureStepX = 1.0f / subdivs;
            double textureStepY = 1.0f / subdivs;

            for (y1 = 0; y1 <= subdivs; y1++)
            {
                if (y1 != subdivs)
                {
                    lat = latMax - (textureStepY * latDegrees * (double)y1);
                }
                else
                {
                    lat = latMin;
                }

                for (x1 = 0; x1 <= subdivs; x1++)
                {
                    if (x1 != subdivs)
                    {
                        lng = lngMin + (textureStepX * lngDegrees * (double)x1);
                    }
                    else
                    {
                        lng = lngMax;
                    }
                    index = y1 * (subdivs + 1) + x1;
                    point = Vector3d.Create(lng * scaleFactor, 0, (lat - 28) * scaleFactor);
                    point.RotateY(213.0 / 180 * Math.PI);
                    point.RotateZ((-62.87175) / 180 * Math.PI);
                    point.RotateY((-192.8595083) / 180 * Math.PI);
                    point.RotateX(ecliptic);
                    verts[index] = PositionTexture.CreatePosRaw(point, (float)(1f - x1 * textureStepX), (float)(/*1f - */ (y1 * textureStepY)));
                    //verts[index].Position = point;
                    //verts[index].Tu = (float)(1f - x1 * textureStepX);
                    //verts[index].Tv = (float)(/*1f - */(y1 * textureStepY));
                }
            }
            galaxyImageVertexBuffer.Unlock();
            galaxyImageTriangleCount = (subdivs) * (subdivs) * 2;
            Uint16Array ui16array = new Uint16Array(subdivs * subdivs * 6);

            UInt16[] indexArray = (UInt16[])(object)ui16array;

            for (y1 = 0; y1 < subdivs; y1++)
            {
                for (x1 = 0; x1 < subdivs; x1++)
                {
                    index = (y1 * subdivs * 6) + 6 * x1;
                    // First triangle in quad
                    indexArray[index]     = (ushort)(y1 * (subdivs + 1) + x1);
                    indexArray[index + 2] = (ushort)((y1 + 1) * (subdivs + 1) + x1);
                    indexArray[index + 1] = (ushort)(y1 * (subdivs + 1) + (x1 + 1));

                    // Second triangle in quad
                    indexArray[index + 3] = (ushort)(y1 * (subdivs + 1) + (x1 + 1));
                    indexArray[index + 5] = (ushort)((y1 + 1) * (subdivs + 1) + x1);
                    indexArray[index + 4] = (ushort)((y1 + 1) * (subdivs + 1) + (x1 + 1));
                }
            }
            galaxyImageIndexBuffer = Tile.PrepDevice.createBuffer();
            Tile.PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, galaxyImageIndexBuffer);
            Tile.PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
        }