public GlobeRayCasting() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _window = Device.CreateWindow(800, 600, "Chapter 4: Globe Ray Casting"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); _clearState = new ClearState(); _window.Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e) { if (e.Key == KeyboardKey.P) { CenterCameraOnPoint(); } else if (e.Key == KeyboardKey.C) { CenterCameraOnGlobeCenter(); } }; Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _globe = new RayCastedGlobe(_window.Context); _globe.Shape = globeShape; _globe.Texture = _texture; _globe.ShowWireframeBoundingBox = true; _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); }
public Multithreading() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _workerWindow = Device.CreateWindow(1, 1); _window = Device.CreateWindow(800, 600, "Chapter 10: Multithreading"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); _clearState = new ClearState(); Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _globe = new RayCastedGlobe(_window.Context); _globe.Shape = globeShape; _globe.Texture = _texture; _globe.UseAverageDepth = true; /////////////////////////////////////////////////////////////////// _doneQueue.MessageReceived += ProcessNewShapefile; _requestQueue.MessageReceived += new ShapefileWorker(_workerWindow.Context, globeShape, _doneQueue).Process; // 2ND_EDITION: Draw order _requestQueue.Post(new ShapefileRequest("110m_admin_0_countries.shp", new ShapefileAppearance())); _requestQueue.Post(new ShapefileRequest("110m_admin_1_states_provinces_lines_shp.shp", new ShapefileAppearance())); _requestQueue.Post(new ShapefileRequest("airprtx020.shp", new ShapefileAppearance() { Bitmap = new Bitmap("paper-plane--arrow.png") })); _requestQueue.Post(new ShapefileRequest("amtrakx020.shp", new ShapefileAppearance() { Bitmap = new Bitmap("car-red.png") })); _requestQueue.Post(new ShapefileRequest("110m_populated_places_simple.shp", new ShapefileAppearance() { Bitmap = new Bitmap("032.png") })); #if SINGLE_THREADED _requestQueue.ProcessQueue(); #else _requestQueue.StartInAnotherThread(); #endif /////////////////////////////////////////////////////////////////// _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); }
public ClipmapTerrainOnGlobe() { _window = Device.CreateWindow(800, 600, "Chapter 13: Clipmap Terrain on a Globe"); _ellipsoid = Ellipsoid.Wgs84; WorldWindTerrainSource terrainSource = new WorldWindTerrainSource(); EsriRestImagery imagery = new EsriRestImagery(); _clipmap = new GlobeClipmapTerrain(_window.Context, terrainSource, imagery, _ellipsoid, 511); _clipmap.HeightExaggeration = 1.0f; _sceneState = new SceneState(); _sceneState.DiffuseIntensity = 0.90f; _sceneState.SpecularIntensity = 0.05f; _sceneState.AmbientIntensity = 0.05f; _sceneState.Camera.FieldOfViewY = Math.PI / 3.0; _clearState = new ClearState(); _clearState.Color = Color.White; _sceneState.Camera.PerspectiveNearPlaneDistance = 0.000001 * _ellipsoid.MaximumRadius; _sceneState.Camera.PerspectiveFarPlaneDistance = 10.0 * _ellipsoid.MaximumRadius; _sceneState.SunPosition = new Vector3D(200000, 300000, 200000) * _ellipsoid.MaximumRadius; _lookCamera = new CameraLookAtPoint(_sceneState.Camera, _window, _ellipsoid); _lookCamera.Range = 1.5 * _ellipsoid.MaximumRadius; _globe = new RayCastedGlobe(_window.Context); _globe.Shape = _ellipsoid; Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _globe.Texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _clearDepth = new ClearState(); _clearDepth.Buffers = ClearBuffers.DepthBuffer | ClearBuffers.StencilBuffer; _window.Keyboard.KeyDown += OnKeyDown; _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.PreRenderFrame += OnPreRenderFrame; _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; UpdateHUD(); }
public GlobeRayCasting() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _window = Device.CreateWindow(800, 600, "Chapter 4: Globe Ray Casting"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; //_sceneState = new SceneState(); //_camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); SetupVR(globeShape); _clearState = new ClearState(); //_window.Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e) //{ // if (e.Key == KeyboardKey.P) // { // CenterCameraOnPoint(); // } // else if (e.Key == KeyboardKey.C) // { // CenterCameraOnGlobeCenter(); // } //}; _leftEyeFrameBuffer = _window.Context.CreateFramebuffer(); _rightEyeFrameBuffer = _window.Context.CreateFramebuffer(); _doubleViewportQuad = new DoubleViewportQuad(_window.Context); Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _globe = new RayCastedGlobe(_window.Context); _globe.Shape = globeShape; _globe.Texture = _texture; _globe.ShowWireframeBoundingBox = true; _leftEyeSceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); // 相机参数变换需要更新SceneState的内部变换矩阵 UpdateLeftEyeSceneState(); _rightEyeSceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); // 相机参数变换需要更新SceneState的内部变换矩阵 UpdateRightEyeSceneState(); }
public Curves() { _semiMinorAxis = Ellipsoid.ScaledWgs84.Radii.Z; SetShape(); _window = Device.CreateWindow(800, 600, "Chapter 2: Curves"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); _clearState = new ClearState(); _texture = Device.CreateTexture2D(new Texture2DDescription(1, 1, TextureFormat.RedGreenBlue8)); WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, 3); pixelBuffer.CopyFromSystemMemory(new byte[] { 0, 255, 127 }); _texture.CopyFromBuffer(pixelBuffer, ImageFormat.RedGreenBlue, ImageDatatype.UnsignedByte, 1); _instructions = new HeadsUpDisplay(); _instructions.Color = Color.Black; _sampledPoints = new BillboardCollection(_window.Context); _sampledPoints.Texture = Device.CreateTexture2D(Device.CreateBitmapFromPoint(8), TextureFormat.RedGreenBlueAlpha8, false); _sampledPoints.DepthTestEnabled = false; _ellipsoid = new RayCastedGlobe(_window.Context); _ellipsoid.Texture = _texture; _polyline = new Polyline(); _polyline.Width = 3; _polyline.DepthTestEnabled = false; _plane = new Plane(_window.Context); _plane.Origin = Vector3D.Zero; _plane.OutlineWidth = 3; CreateScene(); /////////////////////////////////////////////////////////////////// _sceneState.Camera.Eye = Vector3D.UnitY; _sceneState.Camera.ZoomToTarget(2 * _globeShape.MaximumRadius); }
public Curves() { _semiMinorAxis = Ellipsoid.ScaledWgs84.Radii.Z; // 根据椭球对象的尺寸计算表面设定点的三维坐标 SetShape(); // 创建主窗口 _window = Device.CreateWindow(800, 600, "Chapter 2: Curves"); // 设置主窗口回调函数 _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; // 创建主场景OpenGL状态存储对象 _sceneState = new SceneState(); // 设置主场景照相机类型(固定观察一点的照相机) _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); // 创建状态(scissor/color/depth/stencil)清除对象 _clearState = new ClearState(); // 创建单色纹理对象(用于对椭球着色) // 因为RayCastedGlobe对象的颜色只能通过其Texture接口设置 _texture = Device.CreateTexture2D(new Texture2DDescription(1, 1, TextureFormat.RedGreenBlue8)); WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, 3); pixelBuffer.CopyFromSystemMemory(new byte[] { 0, 255, 127 }); _texture.CopyFromBuffer(pixelBuffer, ImageFormat.RedGreenBlue, ImageDatatype.UnsignedByte, 1); // 创建窗口表面的信息显示对象 _instructions = new HeadsUpDisplay(); // 设置信息显示前景色 _instructions.Color = Color.Black; // 创建椭球表面采样点billboard显示集合对象 _sampledPoints = new BillboardCollection(_window.Context); // 创建并设置billboard显示纹理为直径8个窗口像素的点 _sampledPoints.Texture = Device.CreateTexture2D(Device.CreateBitmapFromPoint(8), TextureFormat.RedGreenBlueAlpha8, false); // 关闭采样点billboard集合显示对象的深度测试(使其在任何角度都可见) _sampledPoints.DepthTestEnabled = false; // 创建RayCastedGlobe椭球绘制对象并设置纹理 _ellipsoid = new RayCastedGlobe(_window.Context); _ellipsoid.Texture = _texture; // 创建椭球表面曲线显示对象 _polyline = new Polyline(); // 设置线宽并关闭深度测试 _polyline.Width = 3; _polyline.DepthTestEnabled = false; // 创建参考面显示对象 _plane = new Plane(_window.Context); _plane.Origin = Vector3D.Zero; _plane.OutlineWidth = 3; // 创建主场景 CreateScene(); /////////////////////////////////////////////////////////////////// // 设置主照相机观察方向 _sceneState.Camera.Eye = Vector3D.UnitY; // 根据视场重新调整相机位置 _sceneState.Camera.ZoomToTarget(2 * _globeShape.MaximumRadius); }
public unsafe UserControl1() { try { InitializeComponent(); if (this.DesignMode) { return; } this.MouseWheel += UserControl1_MouseWheel; //释放组件 Disposed += OnDispose; //this.MouseMove += UserControl1_MouseMove ; GraphicsDeviceOptions options = new GraphicsDeviceOptions( debug: false, swapchainDepthFormat: PixelFormat.R16_UNorm, syncToVerticalBlank: true, resourceBindingModel: ResourceBindingModel.Improved); #if DEBUG options.Debug = true; #endif //获取当前窗体的Hwnd var hwnd = this.Handle; var p = hwnd.ToPointer(); //这里创建的sld windows消息捕获出现了问题, //获取运行进程的handle var instance = Process.GetCurrentProcess().Handle; _gd = VeldridStartup.CreateVulkanGraphicsDeviceForWin32(options, hwnd, instance, this.Width, this.Height); _factory = new DisposeCollectorResourceFactory(_gd.ResourceFactory); _scene = new PongGlobe.Scene.Scene(this.Width, this.Height); var globeRender = new RayCastedGlobe(_scene); var shareRender = new ShareRender(_scene); this.renders.Add(shareRender); this.renders.Add(globeRender); //创建完相关对象后注册事件 this.GraphicsDeviceCreated += OnGraphicsDeviceCreated; this.GraphicsDeviceDestroyed += OnDeviceDestroyed; this.Rendering += PreDraw; this.Rendering += Draw; GraphicsDeviceCreated?.Invoke(_gd, _factory, _gd.MainSwapchain); _window = new Sdl2Window(hwnd, false); //创建一个计时器 sw = Stopwatch.StartNew(); previousElapsed = sw.Elapsed.TotalSeconds; //this.ParentForm.Shown += ParentForm_Shown; //开始运行 //Run(); //创建一个线程执行run,使用多线程之后便需要考虑不同线程变量同步的问题了,例如isrunning变量的修改需要lock之后再修改,有时可以使用线程安全的集合来处理不同线程的变量交换, //c#封装了很多,这些都不是问题_coomadList并不是线程安全的,在主线程创建,在子线程使用,这样问题并不大,当时两个子线程同时使用commandLits便可能出现问题 //这里的渲染仍然是单线程的,每个不同的render都可以独开线程并提交渲染任务 _renderTask = Task.Factory.StartNew(() => { Run(); }); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }