private static Squared <Unit> triangleArea(Difference2 u, Difference2 v) { var a = u.NumericValue; var b = v.NumericValue; return(Squared <Unit> .FromValue(Math.Abs(a.X * b.Y - a.Y * b.X) * 0.5f)); }
public override void Draw(Squared.Render.Frame frame) { const float LightmapScale = 1f; LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, Width, Height, 0, 0, 1 ); ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black); Renderer.RenderLighting(frame, frame, 1); if (ShowOutlines) Renderer.RenderOutlines(frame, 2, true); using (var gb = GeometryBatch.New(frame, 3, Game.ScreenMaterials.Get(Game.ScreenMaterials.ScreenSpaceGeometry, blendState: BlendState.Opaque))) for (var i = 0; i < Receivers.Length; i++) { var r = Receivers[i]; var size = new Vector2(8, 8); var bounds = new Bounds(r.Position - size, r.Position + size); var color = new Color(r.ReceivedLight.X, r.ReceivedLight.Y, r.ReceivedLight.Z, 1.0f) * r.ReceivedLight.W; // Console.WriteLine("Receiver {0} at {1}: {2}", i, r.Position, r.ReceivedLight); gb.AddFilledQuad(bounds, color); } }
public override void Draw(Squared.Render.Frame frame) { const float LightmapScale = 1f; LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, Width, Height, 0, 0, 1 ); ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black); Renderer.RenderLighting(frame, frame, 1); using (var bg = BatchGroup.New(frame, 2)) { var dc = new BitmapDrawCall(TestImage, new Vector2(0, 550), 0.55f); using (var bb = BitmapBatch.New(bg, 0, Renderer.Materials.ScreenSpaceBitmap)) bb.Add(ref dc); dc.Position.X += 600; dc.Textures = new TextureSet(dc.Texture, RampTexture); using (var bb2 = BitmapBatch.New(bg, 1, Renderer.IlluminantMaterials.ScreenSpaceRampBitmap, samplerState2: SamplerState.LinearClamp)) bb2.Add(ref dc); } if (ShowOutlines) Renderer.RenderOutlines(frame, 2, true); }
public void Calculate(double input, double output) { var calculator = new Squared(); var testResult = calculator.Calculate(input); var result = output; Assert.AreEqual(testResult, result); }
protected GameEvent(Position2 position, Unit visibleRadius, Unit audibleRadius) { this.Position = position; this.VisibleRadius = visibleRadius; this.AudibleRadius = audibleRadius; this.MaxRadius = visibleRadius > audibleRadius ? visibleRadius : audibleRadius; this.maxRadiusSquared = this.MaxRadius.Squared; }
internal SpawnPoint(SpawnController spawner, Squared.Tiled.Object obj) { SpawnController = spawner; Size = new Vector2(obj.Width, obj.Height); Position = new Vector2(obj.X, obj.Y) + Size / 2; OriginalPosition = new Vector2(obj.X, obj.Y) + Size / 2; Name = obj.Name; Properties = obj.Properties; GameObjectType = obj.Type; }
public void CalculatesAccelerationCorrectly( float gValue, float massValue, float distanceSquaredValueWithSign) { var g = new GravitationalConstant(gValue); var mass = new Mass(massValue); var distanceSquaredValue = Math.Abs(distanceSquaredValueWithSign); var distanceSquared = new Squared <Unit>(distanceSquaredValue); var expectedAcceleration = gValue * massValue / distanceSquaredValue; var acceleration = g.AccelerationAtDistance(mass, distanceSquared); acceleration.NumericValue.Should() .BeApproximatelyOrBothNaNOrInfinity(expectedAcceleration); }
public NavQuad(Position2 SW, Position2 SE, Position2 NW, Position2 NE) { this.SW = SW; this.SE = SE; this.NW = NW; this.NE = NE; this.Center = new Position2((SW.NumericValue + SE.NumericValue + NW.NumericValue + NE.NumericValue) / 4); this.uDiff1 = SE - SW; this.vDiff1 = NW - SW; this.uDiff2 = NW - NE; this.vDiff2 = SE - NE; this.area1 = triangleArea(this.uDiff1, this.vDiff1); this.area2 = triangleArea(this.uDiff2, this.vDiff2); this.Links = this.links.AsReadOnly(); }
internal SpawnPoint(SpawnController spawner, Squared.Tiled.Object obj) { SpawnController = spawner; Size = new Vector2(obj.Width, obj.Height); Position = new Vector2(obj.X, obj.Y) + Size / 2; OriginalPosition = new Vector2(obj.X, obj.Y) + Size / 2; Name = obj.Name; Properties = obj.Properties; EntityType = obj.Type; // Immediately spawn some entities. switch (EntityType) { case "spawn": case "boss": AlwaysSpawned = true; Spawn(); break; } }
public override void Draw(Squared.Render.Frame frame) { const float LightmapScale = 1f; LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, Width, Height, 0, 0, 1 ); CreateRenderTargets(); var args = new float[] { MagnitudeScale, MiddleGray, AppliedAverageLuminance, MaximumLuminance }; using (var bg = BatchGroup.ForRenderTarget( frame, -1, Lightmap, (dm, _) => Renderer.IlluminantMaterials.SetGammaCompressionParameters(args[0], args[1], args[2], args[3]) )) { ClearBatch.AddNew(bg, 0, LightmapMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0); Renderer.RenderLighting(frame, bg, 1, intensityScale: 1 / MagnitudeScale); }; ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black); using (var bb = BitmapBatch.New( frame, 1, Game.ScreenMaterials.Get(Renderer.IlluminantMaterials.ScreenSpaceGammaCompressedBitmap, blendState: BlendState.Opaque) )) bb.Add(new BitmapDrawCall(Lightmap, Vector2.Zero)); if (ShowOutlines) Renderer.RenderOutlines(frame, 2, true); }
static void Main(string[] args) { string entered = ""; while (!entered.ToLower().Equals("exit")) { Console.WriteLine("How many iterations to calculate Square? (Type 'Exit' to cancel)"); entered = Console.ReadLine(); Console.WriteLine("Entered: " + entered); //Console.WriteLine(entered); int iterations = new StringToIntConverter(entered).Success ? new StringToIntConverter(entered).Result : 0; string resultOutput = ""; for (int i = 1; i <= iterations; i++) { int squared = new Squared(i).Result; resultOutput += (squared).ToString() + (i == iterations ? "" : ", "); } Console.WriteLine(resultOutput.ToString()); } }
void Run() { Squared s = new Squared(); var val = s.Calculate(int.MinValue); val = s.Calculate(int.MaxValue); var testSuite = new[] { new { N = -100, D = -100, E = 1, M = "Message" } }; //Test(num, den, -1, $"Div {num} by {den} test passed"); Fraction fraction = new Fraction(); fraction.Numerator = 0; var Passed = false; try { fraction.Denominator = 0; } catch (DivideByZeroException) { Passed = true; } Debug.WriteLine($"The test passed : {Passed}"); }
public override void Draw(Squared.Render.Frame frame) { CreateRenderTargets(); LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, BackgroundLightmap.Width, BackgroundLightmap.Height, 0, 0, 1 ); using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) { ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 0; i < 1; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) { ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 1; i < Layers.Length; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } if (ShowBrickSpecular) using (var bricksLightGroup = BatchGroup.ForRenderTarget(frame, 2, ForegroundLightmap)) { ClearBatch.AddNew(bricksLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(0, 0, 0, 255), clearZ: 0, clearStencil: 0); ForegroundRenderer.RenderLighting(frame, bricksLightGroup, 2); } if (ShowAOShadow) using (var aoShadowFirstPassGroup = BatchGroup.ForRenderTarget(frame, 3, AOShadowScratch)) { ClearBatch.AddNew(aoShadowFirstPassGroup, 1, LightmapMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(aoShadowFirstPassGroup, 2, Game.ScreenMaterials.ScreenSpaceHorizontalGaussianBlur5Tap)) { bb.Add(new BitmapDrawCall(Foreground, Vector2.Zero, 1f / LightmapScale)); } } using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) { ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(40, 40, 40, 255), clearZ: 0, clearStencil: 0); BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2); if (ShowBrickSpecular) { using (var foregroundLightBatch = BitmapBatch.New(backgroundLightGroup, 3, MaskedForegroundMaterial)) { var dc = new BitmapDrawCall( ForegroundLightmap, Vector2.Zero ); dc.Textures = new TextureSet(dc.Textures.Texture1, BricksLightMask); foregroundLightBatch.Add(dc); } } else { ForegroundRenderer.RenderLighting(frame, backgroundLightGroup, 3); } if (ShowAOShadow) using (var aoShadowBatch = BitmapBatch.New(backgroundLightGroup, 4, AOShadowMaterial)) { var dc = new BitmapDrawCall( AOShadowScratch, new Vector2(0, 4) ); dc.MultiplyColor = Color.Black; dc.AddColor = Color.White; aoShadowBatch.Add(dc); } } using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) { ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(127, 127, 127, 255), clearZ: 0, clearStencil: 0); ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2); } SetRenderTargetBatch.AddNew(frame, 49, null); ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0); if (ShowLightmap) { using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) { var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale); bb.Add(dc); } } else { var dc = new BitmapDrawCall(Background, Vector2.Zero); var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend); using (var bb = BitmapBatch.New(frame, 55, material)) { dc.Textures = new TextureSet(Background, BackgroundLightmap); dc.SortKey = 0; bb.Add(dc); } ParticleRenderer.Draw(frame, 56); using (var bb = BitmapBatch.New(frame, 57, material)) { dc.Textures = new TextureSet(Foreground, ForegroundLightmap); dc.SortKey = 1; bb.Add(dc); } } if (ShowOutlines || (Dragging != null)) BackgroundRenderer.RenderOutlines(frame, 59, true); }
public override void Draw (Squared.Render.Frame frame) { CreateRenderTargets(); LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, BackgroundLightmap.Width, BackgroundLightmap.Height, 0, 0, 1 ); using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) { ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 0; i < 1; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) { ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 1; i < Layers.Length; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) { ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(32, 32, 32, 255), clearZ: 0, clearStencil: 0); BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2); } using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) { ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(96, 96, 96, 255), clearZ: 0, clearStencil: 0); ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2); } SetRenderTargetBatch.AddNew(frame, 49, null); ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0); if (ShowLightmap) { using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) { var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale); bb.Add(dc); } ParticleRenderer.Draw(frame, 56); } else { var dc = new BitmapDrawCall(Background, Vector2.Zero); var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend); using (var bb = BitmapBatch.New(frame, 55, material)) { dc.Textures = new TextureSet(Background, BackgroundLightmap); dc.SortKey = 0; bb.Add(dc); } ParticleRenderer.Draw(frame, 56); using (var bb = BitmapBatch.New(frame, 57, material)) { dc.Textures = new TextureSet(Foreground, ForegroundLightmap); dc.SortKey = 1; bb.Add(dc); } } if (ShowOutlines || (Dragging != null)) BackgroundRenderer.RenderOutlines(frame, 59, true); }
public static void SetupBounds(Squared.Tiled.Map map) { int width = (map.Width + 2) * map.TileWidth; int height = (map.Height + 2) * map.TileHeight; rectangleTree = new RectangleTree<Entity>(lol, new Rectangle(-Runtime.CurrentLevel.TileSize, -Runtime.CurrentLevel.TileSize, width, height)); foreach (Entity entity in dynamicEntities) { rectangleTree.Add(entity); } }
public void SqauredTest() { Assert.AreEqual(1.44, Squared.Square(b)); }
public void SquaredTest() { Assert.AreEqual(64, Squared.Square((double)a)); }
private void Form1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { result.Text = "0"; value = 0; lblEquation.Text = ""; } switch (e.KeyChar.ToString()) { case "0": zero.PerformClick(); break; case "1": one.PerformClick(); break; case "2": two.PerformClick(); break; case "3": three.PerformClick(); break; case "4": four.PerformClick(); break; case "5": five.PerformClick(); break; case "6": six.PerformClick(); break; case "7": seven.PerformClick(); break; case "8": eight.PerformClick(); break; case "9": nine.PerformClick(); break; case "+": add.PerformClick(); break; case "-": minus.PerformClick(); break; case "×": multiply.PerformClick(); break; case "*": multiply.PerformClick(); break; case "/": divide.PerformClick(); break; case "=": btnEqual.PerformClick(); break; case "√": SquareRoot.PerformClick(); break; case "←": backspace.PerformClick(); break; case "¹/×": reciprocal.PerformClick(); break; case ".": dec.PerformClick(); break; case "ײ": Squared.PerformClick(); break; default: break; } if (e.KeyChar == (char)Keys.Back) { backspace.PerformClick(); } if (e.KeyChar == (char)Keys.Enter) { btnEqual.PerformClick(); } }
void SpawnEntity(Squared.Tiled.Object e) { // ew. switch (e.Type) { case "player": // Only applies when the game starts on this map. player.X = e.X; player.Y = e.Y; break; case "door": SpawnEntity(new Entities.Door(this, e.X, e.Y, // door position Dir.left, // direction? e.Properties["destination"], Convert.ToInt32(e.Properties["destinationX"]), Convert.ToInt32(e.Properties["destinationY"]))); break; case "ripper": SpawnEntity(new Entities.Enemies.Ripper(this, e.X, e.Y)); break; case "hopper": SpawnEntity(new Entities.Enemies.Hopper(this, e.X, e.Y)); break; default: throw new System.Exception(String.Format("Engine::MapSwitch Unknown entity type {0}", e.Type)); } }
/// <summary> /// Returns the typed square root of the squared acceleration. /// </summary> public static Acceleration Sqrt(this Squared <Acceleration> square) => new Acceleration(square.NumericValue.Sqrted());
/// <summary> /// Returns the typed square root of the squared speed. /// </summary> public static Speed Sqrt(this Squared <Speed> square) => new Speed(square.NumericValue.Sqrted());
/// <summary> /// Returns the typed square root of the squared unit value. /// </summary> public static Unit Sqrt(this Squared <Unit> square) => new Unit(square.NumericValue.Sqrted());
public override void Draw(ref Squared.Render.Convenience.ImperativeRenderer renderer) { renderer.OutlineRectangle(Bounds, Color.White); }
public dynamic Square(dynamic a) { result = Squared.Square(a); return(result); }
public int Square(int a) { solution = Squared.Square(a); return(solution); }