示例#1
0
        protected override void OnLoad(System.EventArgs e)
        {
            sbyte a = -100;

            Console.WriteLine(a);
            Console.WriteLine((byte)a);

            VSync = VSyncMode.On;

            float aspectRatio = ClientSize.Width / (float)(ClientSize.Height);

            currentCamera = new QuatCamera(aspectRatio);

            shader = new Shader();
            shader.CreateShader();
            Matrix4 proj = currentCamera.getProjectionMatrix();

            shader.setUniformMatrix4("projection_matrix", ref proj);
            Matrix4 view = currentCamera.getViewMatrix();

            shader.setUniformMatrix4("view_matrix", ref view);

            meshes = new Mesh[1];
            for (int i = 0; i < meshes.Length; i++)
            {
                //meshes[i] = MeshBuilder.create(scalar, (i*5)+1,true);
                meshes[i] = new Mesh();
                List <Vector3f> vert;
                List <int>      ind;
                SurfaceExtractor.extract(scalar, out vert, out ind, (i * 5) + 1, false);

                Vector3[] vertA = V2V(vert.ToArray());
                Vector3[] normA = Mesh.calcNormals(vertA, ind).ToArray();
                meshes[i].Create(vertA, normA, ind.ToArray());
            }


            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

            // Other state
            GL.Enable(EnableCap.DepthTest);
            GL.ClearColor(System.Drawing.Color.MidnightBlue);

            shader.Use();
        }
        public static ChunkJobResult CreateChunk(ChunkJob Job)
        {
            ChunkJobResult result = new ChunkJobResult();

            try {
                Stopwatch s = new Stopwatch();
                s.Start();
                SE.OpenSimplexNoise noise = new SE.OpenSimplexNoise(1);

                result.Error       = null;
                result.OriginalJob = Job;
                result.DebugPrint  = "";


                ExtractionInput input = new ExtractionInput();
                input.Isovalue   = 0;
                input.LODSides   = Job.LOD;
                input.Resolution = new Util.Vector3i(Job.Resolution, Job.Resolution, Job.Resolution);
                input.Size       = new Vector3(Job.CellSize, Job.CellSize, Job.CellSize);

                int numTimesSampled = 0;

                input.Sample = (float x, float y, float z) => {
                    numTimesSampled++;
                    float res = sample(noise, x + Job.Min.x, y + Job.Min.y, z + Job.Min.z);
                    return(res);
                };

                ExtractionResult ExResult = SurfaceExtractor.ExtractSurface(input);
                result.Result = ExResult;



                s.Stop();
                result.ProcessingTime = s.ElapsedMilliseconds;
            }
            catch (System.Exception exc) {
                result.Error = "Error in thread " + Job.ThreadID + ": " + exc.Message + ", Stacktrace: " + exc.StackTrace;
            }
            return(result);
        }