/// <summary> /// Копирование геометрий выделенных фигур в свою геометрию /// </summary> private void GrabGeometry() { // захватываем геометрию выбранных фигур var path = new SerializableGraphicsPath(); foreach (var fig in _selected) { path.Path.SetMarkers(); path.Path.AddPath(fig.GetTransformedPath(), false); } // нарисовать рамку вокруг выбранных фигур if (IsFrameVisible) { var bounds = path.Path.GetBounds(); path.Path.AddRectangle(bounds); } // выбираем разрешённые операции // если выбрана только одна фигура - просто используем её AllowedOperations // иначе - разрешаем все операции var allowedOperations = _selected.Count == 1 ? _selected.First().Geometry.AllowedOperations : AllowedOperations.All; // присваиваем геометрию Geometry = new PrimitiveGeometry(path, allowedOperations); // сбрасываем преобразование в единичную матрицу Transform = new SerializableGraphicsMatrix(); }
public GeometryManager(SurfaceManager surfaces) { this.surfaces = surfaces; ConsoleBackground = new PrimitiveGeometry(surfaces.ConsoleBackground); ConsoleFont = new FontGeometry(surfaces.ConsoleFontSurface, surfaces.ConsoleFont); }
public GeometryManager(SurfaceManager surfaces) { this.Primitives = new PrimitiveGeometry(surfaces.Primitives); this.PrimitivesOverlay = new PrimitiveGeometry(surfaces.PrimitivesOverlay); var font = Font.FromJsonFile("data/fonts/inconsolata.json"); this.Text = new FontGeometry(surfaces.Text, font) { SizeCoefficient = new Vector2(1, -1) }; this.Buildings = new BuildingGeometry(surfaces.Buildings); this.sprites = surfaces.Sprites; this.NavMesh = new PrimitiveGeometry(surfaces.NavMesh); }
private void drawProjectilePathPreview(PrimitiveGeometry geo) { var s = this.body.Shape; var dVector = this.aimDirection.Vector; var v = new Velocity2(dVector * 0.9f) + this.body.Velocity; var p = s.Center + new Difference2(dVector * s.Radius.NumericValue * 1.5f); geo.LineWidth = 0.05f; geo.Color = Color.Gray; for (int i = 0; i < 50; i++) { var acceleration = Vector2.Zero; foreach (var body in this.game.Bodies) { var shape = body.Shape; var difference = shape.Center - p; var distanceSquared = difference.LengthSquared; var a = Constants.G * body.Mass / distanceSquared.NumericValue; var dirNormal = difference.Direction.Vector; acceleration += dirNormal * a; } var speedFactor = Math.Min(0.5f / acceleration.Length.Sqrted(), 0.5f / v.Speed.NumericValue.Squared()); var t = TimeSpan.One * speedFactor; v += new Velocity2(acceleration * (float)t.NumericValue); var p2 = p + v * t; geo.DrawLine(p.Vector, p2.Vector); p = p2; } }
public void Draw(PrimitiveGeometry geo) { geo.Color = this.Color; geo.DrawLine(this.From, this.To); }
public GraphicsManager() { // Load Shader Programs. ShaderProgram simpleShader = new ShaderProgram(VertexShader.FromFile("data/shaders/simple_vs.glsl"), FragmentShader.FromFile("data/shaders/simple_fs.glsl")); ShaderProgram uvShader = new ShaderProgram(VertexShader.FromFile("data/shaders/uvcolor_vs.glsl"), FragmentShader.FromFile("data/shaders/uvcolor_fs.glsl")); // Create matrix uniforms used for rendering. this.modelview = new Matrix4Uniform("modelviewMatrix"); this.projection = new Matrix4Uniform("projectionMatrix"); this.hudMatrix = new Matrix4Uniform("modelviewMatrix"); // Font Font quartz = Font.FromJsonFile("data/fonts/Quartz.json"); // Create the surfaces #region Background surface Texture t = new Texture("data/graphics/omega-nebula.jpg"); this.BackgroundSurface = new IndexedSurface <UVColorVertexData>(); this.BackgroundSurface.AddSettings( this.hudMatrix, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.BackgroundSurface.SetShaderProgram(uvShader); this.BackgroundGeometry = new Sprite2DGeometry(this.BackgroundSurface); this.BackgroundGeometry.Size = new Vector2(1280, -720); this.BackgroundGeometry.Color.A = (byte)100; #endregion #region Planet Surface t = new Texture("data/graphics/planet.png"); this.PlanetSurface = new IndexedSurface <UVColorVertexData>(); this.PlanetSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.PlanetSurface.SetShaderProgram(uvShader); this.PlanetGeometry = new Sprite2DGeometry(this.PlanetSurface); this.PlanetGeometry.Size = new Vector2(2, 2); #endregion #region Asteroid Surface t = new Texture("data/graphics/asteroid.png"); this.AsteroidSurface = new IndexedSurface <UVColorVertexData>(); this.AsteroidSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.AsteroidSurface.SetShaderProgram(uvShader); this.AsteroidGeometry = new Sprite2DGeometry(this.AsteroidSurface); this.AsteroidGeometry.Size = new Vector2(2, 2); #endregion #region Space Core Surface t = new Texture("data/graphics/spacecore.png"); this.SpaceCoreSurface = new IndexedSurface <UVColorVertexData>(); this.SpaceCoreSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.SpaceCoreSurface.SetShaderProgram(uvShader); this.SpaceCoreGeometry = new Sprite2DGeometry(this.SpaceCoreSurface); this.SpaceCoreGeometry.Size = new Vector2(30, 30); #endregion #region Jumper Surface t = new Texture("data/graphics/jumper.png"); this.JumperSurface = new IndexedSurface <UVColorVertexData>(); this.JumperSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.JumperSurface.SetShaderProgram(uvShader); this.JumperGeometry = new Sprite2DGeometry(this.JumperSurface); this.JumperGeometry.Size = Jumper.Size; #endregion #region Trail Surface this.TrailSurface = new IndexedSurface <PrimitiveVertexData>(); this.TrailSurface.AddSettings( this.modelview, this.projection, SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.TrailSurface.SetShaderProgram(simpleShader); this.TrailGeometry = new PrimitiveGeometry(this.TrailSurface); this.TrailGeometry.Color = Color.Cyan; #endregion #region Score Surface t = new Texture("data/fonts/Quartz.png"); this.ScoreSurface = new IndexedSurface <UVColorVertexData>(); this.ScoreSurface.AddSettings( this.hudMatrix, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.ScoreSurface.SetShaderProgram(uvShader); this.ScoreGeometry = new FontGeometry(this.ScoreSurface, quartz); this.ScoreGeometry.Height = 32; this.ScoreGeometry.SizeCoefficient = new Vector2(1, -1); #endregion #region Overlay surface this.OverlaySurface = new IndexedSurface <PrimitiveVertexData>(); this.OverlaySurface.AddSettings( this.hudMatrix, this.projection, SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.OverlaySurface.SetShaderProgram(simpleShader); this.OverlayGeometry = new PrimitiveGeometry(this.OverlaySurface); this.OverlayGeometry.Color = Color.Cyan; this.OverlayGeometry.Color.A = (byte)150; #endregion }