private void Initialize() { _sphereData = new SphereData(sphereDataFilePathXml, true); // Create the writeable bitmap will be used to write and update. _bitmap = new WriteableBitmap(windowWidth, windowHeight, 96, 96, PixelFormats.Bgr32, null); // Define the rectangle of the writeable image we will modify. // The size is that of the writeable bitmap. _rect = new Int32Rect(0, 0, _bitmap.PixelWidth, _bitmap.PixelHeight); // Calculate the number of bytes per pixel. int bytesPerPixel = (_bitmap.Format.BitsPerPixel + 7) / 8; // Stride is bytes per pixel times the number of pixels. // Stride is the byte width of a single rectangle row. _stride = _bitmap.PixelWidth * bytesPerPixel; // Create a byte array for a the entire size of bitmap. _frameBuffer = new FrameBuffer(_bitmap.PixelWidth, _bitmap.PixelHeight, bytesPerPixel); //Set light direction _lightDirection = new Vector3(1.0f, -0.5f, 0.7f); _lightDirection.Normalize(); }
public void RenderData(SphereData sphereData, float rotation, float colorLerpProgress, Vector3 lightDir) { List <SphereElement> spheres = sphereData.Spheres; float rotationSin = (float)Math.Sin(rotation); float rotationCos = (float)Math.Cos(rotation); foreach (var sphere in spheres) { sphere.screenZ = sphere.x * rotationCos + sphere.z * rotationSin; } Task[] tasks = new Task[spheres.Count]; for (int taskIndex = 0; taskIndex < spheres.Count; ++taskIndex) { var sphere = spheres[taskIndex]; tasks[taskIndex] = Task.Run(() => RenderSphere(sphere, rotationSin, rotationCos, colorLerpProgress, lightDir)); } Task.WaitAll(tasks); }