Exemplo n.º 1
0
        /// <summary>
        /// Load the model and texture of the JBoundingSphere if we want to render it in the world.
        /// </summary>
        /// <param name="loader"></param>
        public void LoadSphereModel(JLoader loader)
        {
            SphereModelData = JObjFileLoader.LoadObj(SphereModelPath);
            SphereModel     = loader.LoadToVAO(SphereModelData.Vertices, SphereModelData.TextureCoords, SphereModelData.Normals, SphereModelData.Indices);
            JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathUnselected));

            SphereTexturedModel = new JTexturedModel(SphereModel, texture);
            SphereEntity        = new JEntity(SphereTexturedModel, new Vector3(50, 0, -50), new Vector3(0, 0, 1), 0.5f);
        }
        private JRawModel generateTerrain(JLoader loader)
        {
            Console.WriteLine("Generating terrain...");
            float[,] test = JNoise.GenerateNoiseMap(100, 100, 20.0f, 4, 0.5f, 2.0f);

            int count = VERTEX_COUNT * VERTEX_COUNT;

            heights = new float[VERTEX_COUNT, VERTEX_COUNT];
            float[] vertices      = new float[count * 3];
            float[] normals       = new float[count * 3];
            float[] textureCoords = new float[count * 2];
            uint[]  indices       = new uint[6 * (VERTEX_COUNT - 1) * (VERTEX_COUNT - 1)];
            int     vertexPointer = 0;

            for (int i = 0; i < VERTEX_COUNT; i++)
            {
                for (int j = 0; j < VERTEX_COUNT; j++)
                {
                    vertices[vertexPointer * 3] = (float)j / ((float)VERTEX_COUNT - 1) * SIZE;
                    float height = JMathUtils.HeightCurve2(test[j, i]) * MAX_HEIGHT;
                    vertices[vertexPointer * 3 + 1] = height;
                    heights[j, i] = height;
                    vertices[vertexPointer * 3 + 2] = (float)i / ((float)VERTEX_COUNT - 1) * SIZE;
                    Vector3 normal = CalculateNormal(j, i, test);
                    normals[vertexPointer * 3]           = normal.X;
                    normals[vertexPointer * 3 + 1]       = normal.Y;
                    normals[vertexPointer * 3 + 2]       = normal.Z;
                    textureCoords[vertexPointer * 2]     = (float)j / ((float)VERTEX_COUNT - 1);
                    textureCoords[vertexPointer * 2 + 1] = (float)i / ((float)VERTEX_COUNT - 1);
                    vertexPointer++;
                }
            }
            int pointer = 0;

            for (uint gz = 0; gz < VERTEX_COUNT - 1; gz++)
            {
                for (uint gx = 0; gx < VERTEX_COUNT - 1; gx++)
                {
                    uint topLeft     = (uint)(gz * VERTEX_COUNT) + gx;
                    uint topRight    = topLeft + 1;
                    uint bottomLeft  = (uint)((gz + 1) * VERTEX_COUNT) + gx;
                    uint bottomRight = bottomLeft + 1;
                    indices[pointer++] = topLeft;
                    indices[pointer++] = bottomLeft;
                    indices[pointer++] = topRight;
                    indices[pointer++] = topRight;
                    indices[pointer++] = bottomLeft;
                    indices[pointer++] = bottomRight;
                }
            }

            Console.WriteLine("Terrain generation complete...");

            return(loader.LoadToVAO(vertices, textureCoords, normals, indices));
        }
Exemplo n.º 3
0
 private void SetupVAO(JLoader loader)
 {
     // Just X and Z vertices. We will set Y to 0 everywhere for flat quad.
     float[] vertices = { -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1 };
     WaterQuad = loader.LoadToVAO(vertices, 2);
 }