private void CheckLinesToClear() { if (!LinesToClear.Any()) { for (int row = 0; row < TowerData.GetLength(0); row++) { bool isCleared = true; for (int col = 0; col < TowerData.GetLength(1); col++) { if (TowerData[row, col] == BlockValue.Empty || TowerData[row, col] == BlockValue.Cleared) { isCleared = false; continue; } } if (isCleared) { LinesToClear.Add(row); ClearState = ClearState.Mark; } } MarkLinesForClear(); } }
private void MoveLinesDown() { if (LinesToClear.Any()) { Thread.Sleep(100); int linesToMove = 0; for (int row = LinesToClear.Max(); row > 0; row--) { if (LinesToClear.Contains(row)) { linesToMove++; } else { for (int col = 0; col < TowerData.GetLength(1); col++) { if (TowerData[row, col] != BlockValue.Empty) { BlockValue tempVal = TowerData[row, col]; TowerData[row, col] = BlockValue.Empty; TowerData[row + linesToMove, col] = tempVal; } } } } LinesToClear.Clear(); ClearState = ClearState.Check; } }
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 EllipsoidSurfaceNormals() { _globeShape = new Ellipsoid(1, 1, _semiMinorAxis); _window = Device.CreateWindow(800, 600, "Chapter 2: Ellipsoid Surface Normals"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); _instructions = new HeadsUpDisplay(); _instructions.Texture = Device.CreateTexture2D( Device.CreateBitmapFromText("Up - Increase semi-minor axis\nDown - Decrease semi-minor axis", new Font("Arial", 24)), TextureFormat.RedGreenBlueAlpha8, false); _instructions.Color = Color.Black; _clearState = new ClearState(); CreateScene(); /////////////////////////////////////////////////////////////////// _sceneState.Camera.Eye = Vector3D.UnitY; _sceneState.Camera.ZoomToTarget(2 * _globeShape.MaximumRadius); }
public override void Clear(ClearState clearState) { ApplyFramebuffer(); ApplyScissorTest(clearState.ScissorTest); ApplyColorMask(clearState.ColorMask); ApplyDepthMask(clearState.DepthMask); // TODO: StencilMaskSeparate if (_clearColor != clearState.Color) { GL.ClearColor(clearState.Color); _clearColor = clearState.Color; } if (_clearDepth != clearState.Depth) { GL.ClearDepth((double)clearState.Depth); _clearDepth = clearState.Depth; } if (_clearStencil != clearState.Stencil) { GL.ClearStencil(clearState.Stencil); _clearStencil = clearState.Stencil; } GL.Clear(TypeConverterGL3x.To(clearState.Buffers)); }
public void OperatorCommandInClearStateShouldBeInvariantTest() { var calc = CalculatorFactory.BuildNew(); var state = new ClearState(calc); state.Notify(new OperatorCommand("+")); Assert.IsTrue(calc.State is ClearState); }
public void PointCommandInClearStateShouldChangeToAccumulatorStateTest() { var calc = CalculatorFactory.BuildNew(); var state = new ClearState(calc); state.Notify(PointCommand.Instance); Assert.IsTrue(calc.State is AccumulatorState); }
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 void PointCommandShouldSetAccumulatorTest() { var calc = CalculatorFactory.BuildNew(); var state = new ClearState(calc); Assert.IsTrue(calc.CPU.Accumulator.IsEmpty); state.Notify(PointCommand.Instance); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "0."); }
public DepthBufferPrecision() { _globeShape = Ellipsoid.Wgs84; _nearDistance = 1; _cubeRootFarDistance = 300; _window = Device.CreateWindow(800, 600, "Chapter 6: Depth Buffer Precision"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyUp += OnKeyUp; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _sceneState.DiffuseIntensity = 0.45f; _sceneState.SpecularIntensity = 0.05f; _sceneState.AmbientIntensity = 0.5f; _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); _sceneState.Camera.ZoomToTarget(_globeShape.MaximumRadius); /////////////////////////////////////////////////////////////////// _globe = new TessellatedGlobe(); _globe.Shape = _globeShape; _globe.NumberOfSlicePartitions = 64; _globe.NumberOfStackPartitions = 32; _globe.Texture = Device.CreateTexture2D(new Bitmap("world_topo_bathy_200411_3x5400x2700.jpg"), TextureFormat.RedGreenBlue8, false); _globe.Textured = true; _plane = new Plane(_window.Context); _plane.XAxis = 0.6 * _globeShape.MaximumRadius * Vector3D.UnitX; _plane.YAxis = 0.6 * _globeShape.MinimumRadius * Vector3D.UnitZ; _plane.OutlineWidth = 3; _cubeRootPlaneHeight = 100.0; UpdatePlaneOrigin(); _viewportQuad = new ViewportQuad(_window.Context, null); _framebuffer = _window.Context.CreateFramebuffer(); _depthFormatIndex = 1; _depthTestLess = true; _logarithmicDepthConstant = 1; UpdatePlanesAndDepthTests(); _clearState = new ClearState(); /////////////////////////////////////////////////////////////////// _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; UpdateHUD(); }
public void Write() { SecurityCenterDocument doc = _state.Doc; doc.DefaultGroup = ClearState.ConvertNoteGroup(_state.ClearGroup, _state.Password, false); doc.LastUpdated = DateTime.Now; doc.Schema = Schema.CurrentSchema; doc.Security = new Security(); doc.Security.Hash = CryptoFactory.Instance.GetPwdHashService().Encrypt(_state.Password, ""); using (FileStream fs = new FileStream(Environment.CurrentDirectory + "\\Security.dat", FileMode.Create)) { XmlSerializer xs = new XmlSerializer(typeof(SecurityCenterDocument)); xs.Serialize(fs, doc); } }
public Tower() { TowerData = new BlockValue[Constants.TowerHeight, Constants.TowerWidth]; for (int row = 0; row < TowerData.GetLength(0); row++) { for (int col = 0; col < TowerData.GetLength(1); col++) { TowerData[row, col] = BlockValue.Empty; } } LinesToClear = new List <int>(); ClearState = ClearState.Check; }
public void WriteExample() { ClearState state = new ClearState(); state.Password = _pwd; Note safe0 = _note0; Note safe1 = _note1; state.ClearGroup.Elements.Add(safe0); state.ClearGroup.Elements.Add(safe1); DocumentWriter writer = new DocumentWriter(state); writer.Write(); }
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 Jitter() { _window = Device.CreateWindow(800, 600, "Chapter 5: Jitter"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyUp += OnKeyUp; _sceneState = new SceneState(); _clearState = new ClearState(); _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Black; CreateCamera(); CreateAlgorithm(); }
// Use this for initialization void Start() { enterEffectState = new EnterEffectState(); playState = new PlayState(); deadState = new DeadState(); clearState = new ClearState(); currentState = State_StageSequence.ENTER; //oldState = currentState; oldState = State_StageSequence.START; stateMachine.Add(State_StageSequence.ENTER, enterEffectState.StageEnter, enterEffectState.StageUpdate, enterEffectState.StageExit); stateMachine.Add(State_StageSequence.PLAY, playState.StageEnter, playState.StageUpdate, playState.StageExit); stateMachine.Add(State_StageSequence.DEAD, deadState.StageEnter, deadState.StageUpdate, deadState.StageExit); stateMachine.Add(State_StageSequence.EXIT, clearState.StageEnter, clearState.StageUpdate, clearState.StageExit); }
public TerrainShading() { _window = Device.CreateWindow(800, 600, "Chapter 11: Terrain Shading"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _window.Keyboard.KeyUp += OnKeyUp; _sceneState = new SceneState(); _sceneState.Camera.PerspectiveFarPlaneDistance = 4096; _sceneState.DiffuseIntensity = 0.9f; _sceneState.SpecularIntensity = 0.05f; _sceneState.AmbientIntensity = 0.05f; _clearState = new ClearState(); /////////////////////////////////////////////////////////////////// TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap("ps-e.lg.png")); _tile = new VertexDisplacementMapTerrainTile(_window.Context, terrainTile); _tile.HeightExaggeration = 30; _tile.ColorMapTexture = Device.CreateTexture2D(new Bitmap("ps_texture_1k.png"), TextureFormat.RedGreenBlue8, false); _tile.ColorRampHeightTexture = Device.CreateTexture2D(new Bitmap("ColorRamp.jpg"), TextureFormat.RedGreenBlue8, false); _tile.ColorRampSlopeTexture = Device.CreateTexture2D(new Bitmap("ColorRampSlope.jpg"), TextureFormat.RedGreenBlue8, false); _tile.BlendRampTexture = Device.CreateTexture2D(new Bitmap("BlendRamp.jpg"), TextureFormat.Red8, false); _tile.GrassTexture = Device.CreateTexture2D(new Bitmap("Grass.jpg"), TextureFormat.RedGreenBlue8, false); _tile.StoneTexture = Device.CreateTexture2D(new Bitmap("Stone.jpg"), TextureFormat.RedGreenBlue8, false); _tile.BlendMaskTexture = Device.CreateTexture2D(new Bitmap("BlendMask.jpg"), TextureFormat.Red8, false); /////////////////////////////////////////////////////////////////// double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5; _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere); _camera.CenterPoint = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0); _camera.MinimumRotateRate = 1.0; _camera.MaximumRotateRate = 1.0; _camera.RotateRateRangeAdjustment = 0.0; _camera.RotateFactor = 0.0; _sceneState.Camera.ZoomToTarget(tileRadius); /////////////////////////////////////////////////////////////////// _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Black; 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); }
private void MarkLinesForClear() { if (LinesToClear.Any()) { foreach (int line in LinesToClear) { for (int col = 0; col < TowerData.GetLength(1); col++) { if (TowerData[line, col] != BlockValue.Cleared) { TowerData[line, col] = BlockValue.Cleared; } } } ClearState = ClearState.Clear; } }
private void Update() { switch (clearState) { case ClearState.NONE: if (player != null && player.currentHP <= 0) { waitStartTime = Time.fixedTime; clearState = ClearState.GAMEOVER; } if (targetList != null && IsDeadAllTarget()) { waitStartTime = Time.fixedTime; clearState = ClearState.CLEAR; timer.EndTimer(); } break; case ClearState.CLEAR: if (Time.fixedTime > waitStartTime + clearWaitTime) { animator.SetTrigger("clear"); clearState = ClearState.ToTitle; waitStartTime = Time.fixedTime; } break; case ClearState.GAMEOVER: if (Time.fixedTime > waitStartTime + overWaitTime) { animator.SetTrigger("failed"); clearState = ClearState.ToTitle; waitStartTime = Time.fixedTime; } break; case ClearState.ToTitle: if (Time.fixedTime > waitStartTime + cleaeToTitleTime) { SceneManager.LoadScene("Title"); } break; } }
private int ClearLines() { if (LinesToClear.Any()) { Thread.Sleep(100); foreach (int line in LinesToClear) { for (int col = 0; col < TowerData.GetLength(1); col++) { TowerData[line, col] = BlockValue.Empty; } } ClearState = ClearState.Move; } return(LinesToClear.Count()); }
public void Clear(ClearState state = ClearState.Random, params string[] keys) { if (state == ClearState.Random) { foreach (string key in keys) { DataPool V; if (dic.TryGetValue(key, out V)) { V.Clear(); dic.Remove(key); } PlayerPrefs.DeleteKey(key); } } else { dic.Clear(); PlayerPrefs.DeleteAll(); } }
public TerrainRayCasting() { _window = Device.CreateWindow(800, 600, "Chapter 11: Terrain Ray Casting"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _sceneState.Camera.PerspectiveFarPlaneDistance = 4096; _clearState = new ClearState(); /////////////////////////////////////////////////////////////////// // 创建地形高程对象 TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap(@"ps-e.lg.png")); // 创建地形图形可渲染对象 _tile = new RayCastedTerrainTile(terrainTile); // 地形高度缩放因子(可以使高山更高) _tile.HeightExaggeration = 30; /////////////////////////////////////////////////////////////////// // 根据地形设置相机位置 double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5; _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere); _camera.CenterPoint = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0); _camera.MinimumRotateRate = 1.0; _camera.MaximumRotateRate = 1.0; _camera.RotateRateRangeAdjustment = 0.0; _camera.RotateFactor = 0.0; _sceneState.Camera.ZoomToTarget(tileRadius); /////////////////////////////////////////////////////////////////// _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Black; UpdateHUD(); }
public void LoadFromFile(string file) { SecurityCenterDocument doc; using (FileStream fs = new FileStream(file, FileMode.Open)) { XmlSerializer ser = new XmlSerializer(typeof(SecurityCenterDocument)); doc = (SecurityCenterDocument)ser.Deserialize(fs); } ICryptoService hashService = CryptoFactory.Instance.GetPwdHashService(); if (hashService.Encrypt(_pwd, "") != doc.Security.Hash) { throw new WrongPasswordException(); } _state = new ClearState(); _state.Doc = doc; _state.Password = _pwd; _state.ClearGroup = ClearState.ConvertNoteGroup(doc.DefaultGroup, _pwd, true); _state.ClearGroup.Name = "<default>"; }
public StatePresenter(IGameStateUseCase gameStateUseCase, InputState inputState, JudgeState judgeState, ClearState clearState) { _disposable = new CompositeDisposable(); _tokenSource = new CancellationTokenSource(); _states = new List <BaseState> { inputState, judgeState, clearState, }; _gameStateUseCase = gameStateUseCase; Init(); _gameStateUseCase.gameState .Where(x => x != GameState.None) .Subscribe(state => { // TickAsync(state, _tokenSource.Token).Forget(); }) .AddTo(_disposable); }
public Triangle() { _window = Device.CreateWindow(800, 600, "Chapter 3: Triangle"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _clearState = new ClearState(); string vs = @"#version 330 layout(location = og_positionVertexLocation) in vec4 position; uniform mat4 og_modelViewPerspectiveMatrix; void main() { gl_Position = og_modelViewPerspectiveMatrix * position; }"; string fs = @"#version 330 out vec3 fragmentColor; uniform vec3 u_color; void main() { fragmentColor = u_color; }"; ShaderProgram sp = Device.CreateShaderProgram(vs, fs); ((Uniform <Vector3F>)sp.Uniforms["u_color"]).Value = new Vector3F(1, 0, 0); /////////////////////////////////////////////////////////////////// Mesh mesh = new Mesh(); VertexAttributeFloatVector3 positionsAttribute = new VertexAttributeFloatVector3("position", 3); mesh.Attributes.Add(positionsAttribute); IndicesUnsignedShort indices = new IndicesUnsignedShort(3); mesh.Indices = indices; IList <Vector3F> positions = positionsAttribute.Values; positions.Add(new Vector3F(0, 0, 0)); positions.Add(new Vector3F(1, 0, 0)); positions.Add(new Vector3F(0, 0, 1)); indices.AddTriangle(new TriangleIndicesUnsignedShort(0, 1, 2)); VertexArray va = _window.Context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw); /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); renderState.FacetCulling.Enabled = false; renderState.DepthTest.Enabled = false; _drawState = new DrawState(renderState, sp, va); /////////////////////////////////////////////////////////////////// _sceneState.Camera.ZoomToTarget(1); }
public SubdivisionSphere1() { _window = Device.CreateWindow(800, 600, "Chapter 4: Subdivision Sphere 1"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere); _clearState = new ClearState(); string vs = @"#version 330 layout(location = og_positionVertexLocation) in vec4 position; out vec3 worldPosition; out vec3 positionToLight; out vec3 positionToEye; uniform mat4 og_modelViewPerspectiveMatrix; uniform vec3 og_cameraEye; uniform vec3 og_cameraLightPosition; void main() { gl_Position = og_modelViewPerspectiveMatrix * position; worldPosition = position.xyz; positionToLight = og_cameraLightPosition - worldPosition; positionToEye = og_cameraEye - worldPosition; }"; string fs = @"#version 330 in vec3 worldPosition; in vec3 positionToLight; in vec3 positionToEye; out vec3 fragmentColor; uniform vec4 og_diffuseSpecularAmbientShininess; uniform sampler2D og_texture0; float LightIntensity(vec3 normal, vec3 toLight, vec3 toEye, vec4 diffuseSpecularAmbientShininess) { vec3 toReflectedLight = reflect(-toLight, normal); float diffuse = max(dot(toLight, normal), 0.0); float specular = max(dot(toReflectedLight, toEye), 0.0); specular = pow(specular, diffuseSpecularAmbientShininess.w); return (diffuseSpecularAmbientShininess.x * diffuse) + (diffuseSpecularAmbientShininess.y * specular) + diffuseSpecularAmbientShininess.z; } vec2 ComputeTextureCoordinates(vec3 normal) { return vec2(atan(normal.y, normal.x) * og_oneOverTwoPi + 0.5, asin(normal.z) * og_oneOverPi + 0.5); } void main() { vec3 normal = normalize(worldPosition); float intensity = LightIntensity(normal, normalize(positionToLight), normalize(positionToEye), og_diffuseSpecularAmbientShininess); fragmentColor = intensity * texture(og_texture0, ComputeTextureCoordinates(normal)).rgb; }"; ShaderProgram sp = Device.CreateShaderProgram(vs, fs); /////////////////////////////////////////////////////////////////// Mesh mesh = SubdivisionSphereTessellatorSimple.Compute(5); VertexArray va = _window.Context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw); _primitiveType = mesh.PrimitiveType; /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); //_renderState.RasterizationMode = RasterizationMode.Line; renderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder; _drawState = new DrawState(renderState, sp, va); /////////////////////////////////////////////////////////////////// Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); //Bitmap bitmap = new Bitmap("world_topo_bathy_200411_3x5400x2700.jpg"); //Bitmap bitmap = new Bitmap("world.topo.200412.3x5400x2700.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _sceneState.Camera.ZoomToTarget(1); }
async Task On(ClearState _) => await ClearState();
public VectorData() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _window = Device.CreateWindow(800, 600, "Chapter 7: Vector Data"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _window.Keyboard.KeyUp += OnKeyUp; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); Context context = _window.Context; // 创建帧缓冲对象 _framebuffer = context.CreateFramebuffer(); _clearBlack = new ClearState(); _clearBlack.Color = Color.Black; _clearWhite = new ClearState(); _clearWhite.Color = Color.White; // 创建视口矩形 _quad = new DayNightViewportQuad(context); _globe = new DayNightGlobe(context); _globe.Shape = globeShape; _globe.UseAverageDepth = true; _globe.DayTexture = Device.CreateTexture2D(new Bitmap("NE2_50M_SR_W_4096.jpg"), TextureFormat.RedGreenBlue8, false); _globe.NightTexture = Device.CreateTexture2D(new Bitmap("land_ocean_ice_lights_2048.jpg"), TextureFormat.RedGreenBlue8, false); _countries = new ShapefileRenderer("110m_admin_0_countries.shp", context, globeShape, new ShapefileAppearance() { PolylineWidth = 1.0, PolylineOutlineWidth = 1.0 }); _states = new ShapefileRenderer("110m_admin_1_states_provinces_lines_shp.shp", context, globeShape, new ShapefileAppearance() { PolylineWidth = 1.0, PolylineOutlineWidth = 1.0 }); _rivers = new ShapefileRenderer("50m-rivers-lake-centerlines.shp", context, globeShape, new ShapefileAppearance() { PolylineColor = Color.LightBlue, PolylineOutlineColor = Color.LightBlue, PolylineWidth = 1.0, PolylineOutlineWidth = 0.0 }); _populatedPlaces = new ShapefileRenderer("110m_populated_places_simple.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("032.png") }); _airports = new ShapefileRenderer("airprtx020.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("car-red.png") }); _amtrakStations = new ShapefileRenderer("amtrakx020.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("paper-plane--arrow.png") }); _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; _showVectorData = true; _sceneState.DiffuseIntensity = 0.5f; _sceneState.SpecularIntensity = 0.1f; _sceneState.AmbientIntensity = 0.4f; _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); UpdateHUD(); }