private void GenerateToneMapLookupTexture(State state, float gamma, float gammaRate, int saturatePower, float saturateCoef) { const int samples = 32; const float scale = 1.0f / samples; const int size = 16 * samples; double v9 = gamma * gammaRate * 1.5f; var array = new Vector2[size]; for (int i = 1; i < size; i++) { double v11 = Math.Exp(-i * scale); double v10 = Math.Pow(1.0f - v11, v9); v11 = v10 * 2.0f - 1.0f; for (int j = 0; j < saturatePower; j++) { v11 *= v11; v11 *= v11; v11 *= v11; v11 *= v11; } array[i] = new Vector2(( float )v10, ( float )(v10 * saturateCoef * (samples / ( double )i) * (1.0 - v11))); } if (mToneMapLookupTexture == null) { mToneMapLookupTexture = new Texture(state, TextureTarget.Texture2D, PixelInternalFormat.Rg16f, size, 1, PixelFormat.Rg, PixelType.HalfFloat); } GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, size, 1, PixelFormat.Rg, PixelType.Float, array); }
//keep player who see character //when character walk send to list internal float CalculateDistant() { var distantVector3 = target - Position; var distantVector2 = new System.Numerics.Vector2(distantVector3.X, distantVector3.Z); return(MathF.Sqrt(distantVector2.LengthSquared())); }
public Vector2 GetClosestTerrainExit(Vector2 location) { if (IsWalkable(location)) { return(location); } double trueX = location.X; double trueY = location.Y; double angle = Math.PI / 4; double rr = (location.X - trueX) * (location.X - trueX) + (location.Y - trueY) * (location.Y - trueY); double r = Math.Sqrt(rr); // x = r * cos(angle) // y = r * sin(angle) // r = distance from center // Draws spirals until it finds a walkable spot while (!IsWalkable((float)trueX, (float)trueY)) { trueX = location.X + r * Math.Cos(angle); trueY = location.Y + r * Math.Sin(angle); angle += Math.PI / 4; r += 1; } return(new Vector2((float)trueX, (float)trueY)); }
public List <ByteVector2> GetTilesInLine(ByteVector2 from, ByteVector2 to) { // TODO: check null List <ByteVector2> toReturn = new List <ByteVector2>(); System.Numerics.Vector2 dest = new System.Numerics.Vector2(to.X, to.Y); System.Numerics.Vector2 curStep = new System.Numerics.Vector2(from.X, from.Y); ByteVector2 toAdd; System.Numerics.Vector2 dir = new System.Numerics.Vector2(to.X, to.Y) - curStep; dir = System.Numerics.Vector2.Normalize(dir) / 4; double distance = System.Numerics.Vector2.Distance(curStep, dest); double curDistance = 0; do { toAdd = new ByteVector2((byte)curStep.X, (byte)curStep.Y); toReturn.Add(toAdd); curStep += dir; curDistance += 0.25f; }while (curDistance < distance); return(toReturn); }
public override void Start() { texture = "zooi.png"; position = new System.Numerics.Vector2(100, 100); }
public OriginOffsetContainer(RectangleOrRoundedRectangleGeometry geometry, WinCompData.Expressions.Vector2 expression) { IsAnimated = true; Geometry = geometry; OffsetExpression = expression; OffsetValue = new Sn.Vector2(0, 0); }
/// <summary> /// Constructs a Vector4 from the given Vector2 and a Z and W component. /// </summary> /// <param name="value">The vector to use as the X and Y components.</param> /// <param name="z">The Z component.</param> /// <param name="w">The W component.</param> public Vector4(Vector2 value, Single z, Single w) { X = value.X; Y = value.Y; Z = z; W = w; }
private bool CreateVector2(string label, ref Num.Vector2 v, MinMaxDescription minMax) { switch (minMax.Type) { case MinMaxDescriptionType.ZeroToOne: return(ImGui.SliderFloat2(label, ref v, 0, 1)); case MinMaxDescriptionType.MinusOneToOne: return(ImGui.SliderFloat2(label, ref v, -1, 1)); case MinMaxDescriptionType.ZeroToInfinity: return(ImGui.DragFloat2(label, ref v, this.DragSpeed, 0, float.MaxValue)); case MinMaxDescriptionType.Custom: if ((minMax.Max - minMax.Min) < SliderDragThreshold) { return(ImGui.SliderFloat2(label, ref v, minMax.Min, minMax.Max)); } return(ImGui.DragFloat2(label, ref v, this.DragSpeed, minMax.Min, minMax.Max)); case MinMaxDescriptionType.MinusInfinityToInfinity: default: return(ImGui.DragFloat2(label, ref v, this.DragSpeed)); } }
/// <summary> /// converts the mouse position from global window position to the game window's coordinates and overrides Nez.Input with /// the new value. This keeps input working properly in the game window. /// </summary> void OverrideMouseInput() { // ImGui.GetCursorScreenPos() is the position of top-left pixel in windows drawable area var offset = new System.Numerics.Vector2(ImGui.GetCursorScreenPos().X, ImGui.GetCursorScreenPos().Y); // remove window position offset from our raw input. this gets us normalized back to the top-left origin. // We are essentilly removing any input delta that is not in the game window. var normalizedPos = Input.RawMousePosition.ToVector2().ToSimd() - offset; var scaleX = ImGui.GetContentRegionAvail().X / _lastRenderTarget.Width; var scaleY = ImGui.GetContentRegionAvail().Y / _lastRenderTarget.Height; var scale = new System.Numerics.Vector2(scaleX, scaleY); // scale the rest of the input since it is in a scaled window (the offset portion is not scaled since // it is outside the scaled portion) normalizedPos /= scale; // trick the input system. Take our normalizedPos and undo the scale and offsets (do the // reverse of what Input.scaledPosition does) so that any consumers of mouse input can get // the correct coordinates. var unNormalizedPos = normalizedPos / Input.ResolutionScale; unNormalizedPos += Input.ResolutionOffset; var mouseState = Input.CurrentMouseState; var newMouseState = new MouseState((int)unNormalizedPos.X, (int)unNormalizedPos.Y, mouseState.ScrollWheelValue, mouseState.LeftButton, mouseState.MiddleButton, mouseState.RightButton, mouseState.XButton1, mouseState.XButton2); Input.SetCurrentMouseState(newMouseState); }
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e) { Vector2 size = new System.Numerics.Vector2((float)this.ActualWidth, (float)this.ActualHeight); if (m_interactionTracker != null) { m_interactionTracker.MinPosition = new Vector3(-size.X, 0, 0); m_interactionTracker.MaxPosition = new Vector3(size.X, 0, 0); if (Content != null) { var positionExpression = m_compositor.CreateExpressionAnimation("-tracker.Position"); positionExpression.SetReferenceParameter("tracker", m_interactionTracker); m_contentVisual = ElementCompositionPreview.GetElementVisual(Content); m_contentVisual.StartAnimation("Offset", positionExpression); m_contentVisual.Size = size; if (m_setUpExpressions && m_progressAnimation == null) { m_progressAnimation = m_compositor.CreateExpressionAnimation( "clamp(visual.Offset.X / visual.Size.X, -1, 1)"); m_progressAnimation.SetReferenceParameter("visual", m_contentVisual); m_rootVisual.Properties.StartAnimation("NormalizedProgress", m_progressAnimation); } } } }
public bool HasGlobalVision(Vector2 coords) { Vector2 vector = TranslateToNavGrid(coords); NavigationGridCell cell = GetCell((short)vector.X, (short)vector.Y); return(cell != null && cell.HasFlag(NavigationGridCellFlags.HAS_GLOBAL_VISION)); }
public ImGuiManager(ImGuiOptions options = null) { if (options == null) { options = new ImGuiOptions(); } _gameWindowFirstPosition = options._gameWindowFirstPosition; _gameWindowTitle = options._gameWindowTitle; _gameWindowFlags = options._gameWindowFlags; LoadSettings(); _renderer = new ImGuiRenderer(Core.Instance); _renderer.RebuildFontAtlas(options); Core.Emitter.AddObserver(CoreEvents.SceneChanged, OnSceneChanged); NezImGuiThemes.DarkTheme1(); // find all Scenes _sceneSubclasses = ReflectionUtils.GetAllSubclasses(typeof(Scene), true); // tone down indent ImGui.GetStyle().IndentSpacing = 12; // find all themes _themes = typeof(NezImGuiThemes).GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); }
public void AnalogVUMeter_CanSetDialFixPoint() { var newPoint = new System.Numerics.Vector2(0.4f, 1.6f); sut.DialRelativeFixPoint = newPoint; Assert.AreEqual(newPoint, sut.DialRelativeFixPoint); }
public static void NewFrame(Vector2 size, Vector2 scale, Vector2 mousePosition, uint mouseMask, ref float mouseWheel, bool[] mousePressed, ref double g_Time) { ImGuiIOPtr io = ImGui.GetIO(); io.DisplaySize = size; io.DisplayFramebufferScale = scale; double currentTime = SDL.SDL_GetTicks() / 1000D; io.DeltaTime = g_Time > 0D ? (float)(currentTime - g_Time) : (1f / 60f); g_Time = currentTime; io.MousePos = mousePosition; io.MouseDown[0] = mousePressed[0] || (mouseMask & SDL.SDL_BUTTON(SDL.SDL_BUTTON_LEFT)) != 0; io.MouseDown[1] = mousePressed[1] || (mouseMask & SDL.SDL_BUTTON(SDL.SDL_BUTTON_RIGHT)) != 0; io.MouseDown[2] = mousePressed[2] || (mouseMask & SDL.SDL_BUTTON(SDL.SDL_BUTTON_MIDDLE)) != 0; mousePressed[0] = mousePressed[1] = mousePressed[2] = false; io.MouseWheel = mouseWheel; mouseWheel = 0f; SDL.SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1); ImGui.NewFrame(); }
private void DrawGridInternal( CanvasDrawingSession ds, Color stroke, CanvasStrokeStyle ss, ref Rect2 rect, double offsetX, double offsetY, double cellWidth, double cellHeight, bool isStroked, double strokeWidth) { double ox = rect.X; double oy = rect.Y; double sx = ox + offsetX; double sy = oy + offsetY; double ex = ox + rect.Width; double ey = oy + rect.Height; for (double x = sx; x < ex; x += cellWidth) { var p0 = new N.Vector2((float)x, (float)oy); var p1 = new N.Vector2((float)x, (float)ey); DrawLineInternal(ds, stroke, ss, isStroked, ref p0, ref p1, strokeWidth); } for (double y = sy; y < ey; y += cellHeight) { var p0 = new N.Vector2((float)ox, (float)y); var p1 = new N.Vector2((float)ex, (float)y); DrawLineInternal(ds, stroke, ss, isStroked, ref p0, ref p1, strokeWidth); } }
private bool IntermediateNeeded(Vector2 currentResolution, RenderTarget2D target, float scale) { // ReSharper disable CompareOfFloatsByEqualityOperator return (scale == 2) ? (currentResolution.X * 2 < target.Width && currentResolution.Y * 2 < target.Height) // ReSharper restore CompareOfFloatsByEqualityOperator : (currentResolution.X / 2 > target.Width && currentResolution.Y / 2 > target.Height); }
public override void SetVelocity() { CalculateDirection(); switch (MyDirection) { case Direction.idle: Velocity = new System.Numerics.Vector2(0, 0); CurrentAnimation = idleAnimation; break; case Direction.left: Velocity = new System.Numerics.Vector2(-speed, 0); CurrentAnimation = runAnimation; break; case Direction.right: Velocity = new System.Numerics.Vector2(speed, 0); CurrentAnimation = runAnimation; break; } if (attacking) { if (AnimationIndex >= attackAnimation.Count - 1) { attacking = false; Fpa = 10; AnimationIndex = 0; } } setAnimation(); }
public UnfoldedCurve(SystemVector2[] points) { Matrices = new Matrix3x2[points.Length]; InverseMatrices = new Matrix3x2[points.Length]; OriginalPoints = new SystemVector2[points.Length]; UnfoldedPoints = new SystemVector2[points.Length]; var matrix = Matrix3x2.CreateTranslation(-points[0]); OriginalPoints = points; for (int count = points.Length, i = 0; i < count; i++) { var originalPoint = points[i]; var point = SystemVector2.Transform(originalPoint, matrix); Matrix3x2 inveseMatrix; Assert.IsTrue(Matrix3x2.Invert(matrix, out inveseMatrix)); Matrices[i] = matrix; InverseMatrices[i] = inveseMatrix; UnfoldedPoints[i] = point; if (i < count - 1) { var originalNextPoint = points[i + 1]; var nextPoint = SystemVector2.Transform(originalNextPoint, matrix); var line = Line.Create(point, nextPoint); var angle = -Mathf.Atan2(-line.A, line.B); matrix *= Matrix3x2.CreateRotation(angle, point); } } }
public void Scale(RenderTarget2D source, RenderTarget2D destination) { _effect.CurrentTechnique = source.Format.IsFloatingPoint() ? _effect.Techniques["Software"] : _effect.Techniques["Hardware"]; Vector2 resolution = new Vector2(source.Width, source.Height); float scaleFactor = (destination.Width > source.Width) ? 2 : 0.5f; RenderTarget2D input = source; while (IntermediateNeeded(resolution, destination, scaleFactor)) { resolution *= scaleFactor; RenderTarget2D output = RenderTargetManager.GetTarget(_device, (int)resolution.X, (int)resolution.Y, source.Format, name:"scaled", usage: RenderTargetUsage.DiscardContents); Draw(input, output); if (input != source) RenderTargetManager.RecycleTarget(input); input = output; } Draw(input, destination); if (input != source) RenderTargetManager.RecycleTarget(input); }
private void drawoXYZ() { SN.Vector3 oz = new SN.Vector3(0, 0, 600); SN.Vector3 oy = new SN.Vector3(0, 600, 0); SN.Vector3 ox = new SN.Vector3(600, 0, 0); List <SN.Vector3> l = new List <SN.Vector3>(); l.Add(ox); l.Add(oy); l.Add(oz); foreach (SN.Vector3 axe in l) { var p3d = camera.ComputePointOnPlane(axe); var oo3d = camera.ComputePointOnPlane(new SN.Vector3(0, 0, 0)); SN.Vector2 p = new SN.Vector2(p3d.X, p3d.Y); SN.Vector2 oo = new SN.Vector2(oo3d.X, oo3d.Y); Color c = Color.Red; if (axe.Y > 0) { c = Color.Yellow; } else if (axe.Z > 0) { c = Color.Green; } this.DrawLine(oo, p, c); // this.DrawLine(oo,new SN.Vector2(300,0), Color.Pink); } }
public PolygonShape() { ShapeType = ShapeType.Polygon; _radius = Settings.b2_polygonRadius; _vertexCount = 0; _centroid = Vector2.Zero; }
public override System.Numerics.Vector2[] Nearest(System.Numerics.Vector2 v) { Vector2[] tmp = new Vector2[5]; int count = 0; double mindist = Math.Pow(v.X, 2) + Math.Pow(v.Y, 2); for (int i = 0; i < x.num; i++) { for (int j = 0; j < y.num; j++) { double curdist = Math.Pow(v.X - i * x.step, 2) + Math.Pow(v.Y - j * y.step, 2); if (curdist < mindist) { count = 1; tmp[0] = new Vector2(i * x.step, j * y.step); mindist = curdist; } else if (curdist == mindist) { tmp[count] = new Vector2(i * x.step, j * y.step); count++; } } } System.Numerics.Vector2[] res = new Vector2[count]; for (int i = 0; i < count; i++) { res[i] = tmp[i]; } return(res); }
public override void GameTick(float millisecondsElapsed) { //new position based on velocity Position = Position + Velocity * millisecondsElapsed / 1000f; //Reverses X velocity if ball hits left wall if (Position.X <= AGAINSTWALLLEFT) { Position -= new System.Numerics.Vector2(Position.X, 0); Velocity = new System.Numerics.Vector2(-(Velocity.X), Velocity.Y); } //Reverses X velocity if ball hits right wall else if (Position.X >= (AGAINSTWALLRIGHT - Diameter)) { Position -= new System.Numerics.Vector2((Position.X - (AGAINSTWALLRIGHT - Diameter)), 0); Velocity = new System.Numerics.Vector2(-(Velocity.X), Velocity.Y); } //BUG: NEED TO FIX BOUNCE PHYSICS, currently goes higher with each bounce //velocity increases over time due to gravity Velocity += new System.Numerics.Vector2(0, 14); if (Velocity.Y <= -maxBallVelocityY) { Velocity = new System.Numerics.Vector2(Velocity.X, -maxBallVelocityY); } if (Velocity.Y >= maxBallVelocityY) { Velocity = new System.Numerics.Vector2(Velocity.X, maxBallVelocityY); } }
private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { var a = new Vector2(10, 10); var b = new Vector2(100, 100); args.DrawingSession.DrawLine(a, b, Colors.Yellow); }
public void SetValue(Vector2 v) { ArrayLength = 2; _value.X = v.X; _value.Y = v.Y; }
void FrameImage() { var fitSize = CalcFitToScreen(); _imageZoom = fitSize.X / _textureSize.X; _imagePosition = (ImGui.GetContentRegionAvail() - fitSize) * 0.5f; }
public void AnalogVUMeter_CanSetScaleStartPoint() { var newPoint = new System.Numerics.Vector2(0.4f, 1.6f); sut.ScaleRelativeStartingPoint = newPoint; Assert.AreEqual(newPoint, sut.ScaleRelativeStartingPoint); }
private int FindNearestPointIndex(SystemVector2[] points, SystemVector2 point) { int count = points.Length; for (int i = 0; i < count - 1; i++) { if (points[i].X < point.X) { continue; } return(i + 1); } return(count - 1); /* var index = 0; * var minDistance = float.MaxValue; * for (int count = points.Length, i = 0; i < count; i++) { * var distance = Mathf.Abs (points[i].X - point.X); * if (distance < minDistance) { * minDistance = distance; * index = i; * } * } * * return index;*/ }
public OriginOffsetContainer(RectangleOrRoundedRectangleGeometry geometry, Sn.Vector2 value) { IsAnimated = false; Geometry = geometry; OffsetExpression = Expression.Vector2(value.X, value.Y); OffsetValue = value; }
// Constructs the root context. TranslationContext(LottieComposition lottieComposition) { Layers = lottieComposition.Layers; StartTime = lottieComposition.InPoint; DurationInFrames = lottieComposition.OutPoint - lottieComposition.InPoint; Size = new Sn.Vector2((float)lottieComposition.Width, (float)lottieComposition.Height); }
public Enemy4(GameWorld world) { gameWorld = world; points = 10; life = 50; Position = new System.Numerics.Vector2(100, -100); spriteSizeX = 16; spriteSizeY = 16; spriteCycle = 0; spriteCount = 3; slowFactor = 0.5f; hitboxRadius = 10; transitionDuration = 100; showHitbox = false; spriteSheet = BitmapFactory.FromResource("graphics/aliens/skitter_spreadsheet_x16x16.png"); fireRate1 = 1f; projectile = new Projectile(gameWorld); projectile.Velocity = new Vector2(0, 400); projectile.spriteSheet = BitmapFactory.FromResource("graphics/projectiles/projectile4_spreadsheet_x11x11.png"); projectile.spriteSizeX = 11; projectile.spriteSizeY = 11; projectile.Scale = new Vector2(1.5f, 1.5f); projectile.collisionMask = new string[] { "enemy", "enemy projectile", "player projectile" }; projectile.collisionDamage = 20; projectile.tag = "enemy projectile"; }
public Enemy9(GameWorld world) { gameWorld = world; points = 40; life = 1000; var rand2 = new Random(); float offset = 3.5f; Position = new System.Numerics.Vector2(rand2.Next(100) * offset, -100); spriteSizeX = 26; spriteSizeY = 30; spriteCycle = 0; spriteCount = 3; slowFactor = 0.5f; hitboxRadius = 10; transitionDuration = 200; showHitbox = false; spriteSheet = BitmapFactory.FromResource("graphics/aliens/brain_spreadsheet_x26x30.png"); explosionSize = 6; fireRate1 = 4f; projectile = new Projectile(gameWorld); projectile.Velocity = new Vector2(0, 200); projectile.spriteSheet = BitmapFactory.FromResource("graphics/projectiles/projectile6_spreadsheet_x11x13.png"); projectile.spriteSizeX = 11; projectile.spriteSizeY = 13; projectile.Scale = new Vector2(2, 2); projectile.collisionMask = new string[] { "enemy", "enemy projectile", "player projectile" }; projectile.collisionDamage = 30; projectile.tag = "enemy projectile"; }
public Enemy7(GameWorld world) { gameWorld = world; points = 15; life = 10; Position = new System.Numerics.Vector2(300, -100); spriteSizeX = 12; spriteSizeY = 10; spriteCycle = 0; spriteCount = 5; slowFactor = 0.5f; hitboxRadius = 5; transitionDuration = 100; showHitbox = false; spriteSheet = BitmapFactory.FromResource("graphics/aliens/drone2_spreadsheet_x12x10.png"); fireRate1 = 5f; projectile = new Projectile(gameWorld); projectile.Velocity = new Vector2(0, 300); projectile.spriteSheet = BitmapFactory.FromResource("graphics/projectiles/projectile6_spreadsheet_x11x13.png"); projectile.spriteSizeX = 11; projectile.spriteSizeY = 13; projectile.Scale = new Vector2(1, 1); projectile.collisionMask = new string[] { "enemy", "enemy projectile", "player projectile" }; projectile.collisionDamage = 10; projectile.tag = "enemy projectile"; }
internal void Update(Contact c) { if (c != null) { if (contacts[0] == null) { contacts[0] = new ContactPoint2D(); } WorldManifold worldManifold; c.GetWorldManifold(out worldManifold); System.Numerics.Vector2 normal = worldManifold.Normal; FixedArray2 <System.Numerics.Vector2> points = worldManifold.Points; if (this.bodyA == c.FixtureA.Body) { contacts[0].normal = -normal; } else { contacts[0].normal = normal; } contacts[0].point = points[0]; } }
public RectangleEmitterShape(Vector2 size, EmissionDirection direction = EmissionDirection.None, bool edgeOnly = false, bool uniform = false) : base(size) { Direction = direction; EdgeOnly = edgeOnly; Uniform = uniform; }
public SvgBuilder Line(Vector2 start, Vector2 end, float width, string stroke) { _parts.Add($"<line x1=\"{start.X * Scale}\" y1=\"{start.Y * Scale}\" x2=\"{end.X * Scale}\" y2=\"{end.Y * Scale}\" stroke=\"{stroke}\" stroke-width=\"{width}\" />"); UpdateMinMax(start, end); return this; }
public OrientedBox2D(float centerX, float centerY, float sizeX, float sizeY, float angle) { center.X = centerX; center.Y = centerY; Angle = angle; Radii = new Vector2(sizeX / 2.0f, sizeY / 2.0f); CalcHelpers(); }
// ReSharper restore NotAccessedField.Global // ReSharper restore MemberCanBePrivate.Global public VertexPositionTextureNormalBinormalTangent(Vector3 position, Vector2 textureCoordinate, Vector3 normal, Vector3 binormal, Vector3 tangent) { Position = position.ToXNA(); TextureCoordinate = textureCoordinate.ToXNA(); Normal = normal.ToXNA(); Binormal = binormal.ToXNA(); Tangent = tangent.ToXNA(); }
public VertexMetadata(float x, float y, float z, float u, float v, Color color, uint faceIndex, uint triangleIndex) { Position = new Vector4(x, y, z, 1f); TextureCoordinate = new Vector2(u, v); Color = color; FaceIndex = faceIndex; TriangleIndex = triangleIndex; }
public SvgBuilder Circle(Vector2 center, float radius, string fill = "blue") { _parts.Add($"<circle cx=\"{center.X * Scale}\" cy=\"{center.Y * Scale}\" r=\"{radius * Scale}\" fill=\"{fill}\"></circle>"); UpdateMinMax(center - new Vector2(radius)); UpdateMinMax(center + new Vector2(radius)); return this; }
public void Operation(Operations operation) { Random rand = new Random(84329); Vector2 v1 = new Vector2(Convert.ToSingle(rand.NextDouble()), Convert.ToSingle(rand.NextDouble())); Vector2 v2 = new Vector2(Convert.ToSingle(rand.NextDouble()), Convert.ToSingle(rand.NextDouble())); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) ExecuteTest(operation, 1000000, v1, v2); }
/// <summary> /// Initializes a new instance of the <see cref="RadialGradientStyle" /> class. /// </summary> /// <param name="unitOriginOffset">The unit origin offset.</param> /// <param name="transform">The transform.</param> /// <param name="gradientStops">The gradient stops.</param> public RadialGradientStyle( Vector2 unitOriginOffset, Matrix3x2 transform, [NotNull] IReadOnlyList<GradientStop> gradientStops) : base(gradientStops) { UnitOriginOffset = unitOriginOffset; GradientTransform = transform; }
public void DrawLine(Vector2 p1, Vector2 p2, Color color, float strokeWidth, CanvasStrokeStyle strokeStyle) { if (m_renderingType == TestSceneRenderingType.Default) { m_drawingSession.DrawLine(p1, p2, color, strokeWidth, strokeStyle); } else { m_drawingSession.DrawLine(p1, p2, Colors.Black); } }
// 每次刷新时,Update 方法都会由粒子系统调用,位置等参数都将被更新,并且返回此粒子是否存活的 bool 值 public bool Update(float elapsedTime) { Velocity += Acceleration * elapsedTime; Position += Velocity * elapsedTime; Rotation += RotationSpeed * elapsedTime; TimeSinceStart += elapsedTime; return TimeSinceStart < Lifetime; }
public void FillEllipse(Vector2 center, float radiusX, float radiusY, Color color) { if (m_renderingType == TestSceneRenderingType.Default) { m_drawingSession.FillEllipse(center, radiusX, radiusY, color); } else { m_drawingSession.DrawEllipse(center, radiusX, radiusY, Colors.Black); } }
/// <summary> /// Move to and stop at a specified position. /// </summary> /// <param name="position"></param> /// <param name="target"></param> /// <returns></returns> public static Vector2 Arrive(Vector2 position, Vector2 target) { /* target_offset = target - position distance = length (target_offset) ramped_speed = max_speed * (distance / slowing_distance) clipped_speed = minimum (ramped_speed, max_speed) desired_velocity = (clipped_speed / distance) * target_offset steering = desired_velocity - velocity */ return Vector2.Zero; }
/// <summary> /// Initializes a new instance of the <see cref="RadialGradientStyle" /> class. /// </summary> /// <param name="center">The center of the gradient ellipse.</param> /// <param name="originOffset">The offset of the gradient origin relative to the center.</param> /// <param name="radius">The radius of the gradient ellipse.</param> /// <param name="angle">The angle of the gradient around the center.</param> /// <param name="gradientStops">The gradient stops.</param> public RadialGradientStyle( Vector2 center, Vector2 originOffset, Vector2 radius, float angle, [NotNull] IReadOnlyList<GradientStop> gradientStops) : base(gradientStops) { UnitOriginOffset = originOffset / radius; GradientTransform = Matrix3x2.CreateScale(radius) * Matrix3x2.CreateRotation(angle) * Matrix3x2.CreateTranslation(center); }
public TextSprite( string text, FontId font = default(FontId), float fontSize = 12, Vector2 position = default(Vector2), Color? color = null) { this.Text = text; this.Font = font; this.FontSize = fontSize; this.Position = position; this.Color = color ?? Color.White; }
public void ExecuteTest(Operations operation, int innerIterations, Vector2 v1, Vector2 v2) { Vector2 res; switch (operation) { case Operations.Add_Operator: for (int i = 0; i < innerIterations; i++) { res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; } break; case Operations.Add_Function: for (int i = 0; i < innerIterations; i++) { Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); } break; case Operations.Sub_Operator: for (int i = 0; i < innerIterations; i++) { res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; } break; case Operations.Sub_Function: for (int i = 0; i < innerIterations; i++) { Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); } break; case Operations.Mul_Operator: for (int i = 0; i < innerIterations; i++) { res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; } break; case Operations.Mul_Function: for (int i = 0; i < innerIterations; i++) { Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); } break; case Operations.Dot: for (int i = 0; i < innerIterations; i++) { Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); } break; case Operations.SquareRoot: for (int i = 0; i < innerIterations; i++) { Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); } break; case Operations.Length_Squared: for (int i = 0; i < innerIterations; i++) { v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); } break; case Operations.Normalize: for (int i = 0; i < innerIterations; i++) { Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); } break; case Operations.Distance_Squared: for (int i = 0; i < innerIterations; i++) { Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); } break; } }
/// <summary> /// Determines if a circle and rectangle intersect. /// </summary> /// <param name="center">The center of the circle.</param> /// <param name="radius">The radius of the circle.</param> /// <param name="rectangle">The rectangle.</param> /// <returns>Returns a <see cref="Vector2" /> representing the normal if a collision occurs; otherwise <c>null</c>.</returns> public static Vector2? GetCircleRectangleCollisionNormal(Vector2 center, float radius, RectangleF rectangle) { var contact = center; if (contact.X < rectangle.Left) contact.X = rectangle.Left; if (contact.X > rectangle.Right) contact.X = rectangle.Right; if (contact.Y < rectangle.Top) contact.Y = rectangle.Top; if (contact.Y > rectangle.Bottom) contact.Y = rectangle.Bottom; var v = new Vector2(contact.X - center.X, contact.Y - center.Y); var length = v.Length(); return length > 0 && length < radius ? v/length : (Vector2?) null; }
public override Kick Execute(ISimulation simulation) { var ballChaser = FootballStrategies.ClosestPlayerToPoint(this.Players, simulation.Ball, 0); var kick = Kick.None; foreach (var player in Players) { if (player == ballChaser) { //messages[player] = "Chaser"; var playersExceptSelf = Players.ToList(); playersExceptSelf.Remove(player); player.Force = SteeringStrategies.Pursue(player, simulation.Ball, 1); if ((player.Position - simulation.Ball.Position).Length() < player.Radius + simulation.Ball.Radius) { var isLeftTeam = this.GoalBounds.Left > 0 ? true : false; PointMass[] arr = new PointMass[7]; playersExceptSelf.CopyTo(arr, 0); arr[4] = new PointMass(1, 1, 1, 1, new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top + (0.2f) * this.GoalBounds.Height), Vector2.Zero); arr[5] = new PointMass(1, 1, 1, 1, new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top + (0.5f) * this.GoalBounds.Height), Vector2.Zero); arr[6] = new PointMass(1, 1, 1, 1, new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top + (0.8f) * this.GoalBounds.Height), Vector2.Zero); arr[4].id = "GT"; arr[5].id = "GM"; arr[6].id = "GB"; ReadOnlyCollection<PointMass> roc = new ReadOnlyCollection<PointMass>(arr); Vector2 middleOfGoal = new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top - (0.5f) * this.GoalBounds.Height); IPointMass kickTarget = ClosestPlayerToPoint(roc, player, 1, middleOfGoal); messages[player] = "Chaser T: " + kickTarget.id; k = kick = FootballStrategies.PassToPlayer(player, kickTarget, simulation.Ball); } else k = kick = Kick.None; } else { messages[player] = isOutsideOfField(player, simulation.PitchBounds) ? "Outside" : "inside"; var allPlayers = simulation.Teams[0].Players.Concat(simulation.Teams[1].Players); if (isOutsideOfField(player, simulation.PitchBounds)) player.Force = SteeringStrategies.Seek(player, Vector2.Zero, player.MaxSpeed); else FootballStrategies.SpreadOut(player, allPlayers, simulation.PitchBounds, 150, 100); } } return kick; }
// 初始化方法被粒子系统调用,用来准备合适的粒子 public void Initialize(Vector2 position, Vector2 velocity, Vector2 acceleration, float lifetime, float scaleX, float scaleY, float rotation, float rotationSpeed) { this.Position = position; this.Velocity = velocity; this.Acceleration = acceleration; this.Lifetime = lifetime; this.ScaleX = scaleX; this.ScaleY = scaleY; this.RotationSpeed = rotationSpeed; // 重置生成时间 this.TimeSinceStart = 0.0f; // 初始化旋转角度 this.Rotation = rotation; }
/// @see Shape.ComputeAABB public override void ComputeAABB(out AABB aabb, ref XForm xf) { Vector2 lower = MathUtils.Multiply(ref xf, _vertices[0]); Vector2 upper = lower; for (int i = 1; i < _vertexCount; ++i) { Vector2 v = MathUtils.Multiply(ref xf, _vertices[i]); lower = Vector2.Min(lower, v); upper = Vector2.Max(upper, v); } Vector2 r = new Vector2(_radius, _radius); aabb.lowerBound = lower - r; aabb.upperBound = upper + r; }
public Sprite( TextureId texture, Vector2 position = default(Vector2), Vector2? scale = null, Vector2? size = null, float rotation = 0, Vector2 origin = default(Vector2), Color? color = null) { this.Texture = texture; this.Position = position; this.Scale = scale ?? Vector2.One; this.Rotation = rotation; this.Size = size ?? Vector2.Zero; this.Origin = origin; this.Color = color ?? Color.White; }
internal MouseJoint(MouseJointDef def) : base(def) { XForm xf1; _bodyB.GetXForm(out xf1); _target = def.target; _localAnchor = MathUtils.MultiplyT(ref xf1, _target); _maxForce = def.maxForce; _impulse = Vector2.Zero; _frequencyHz = def.frequencyHz; _dampingRatio = def.dampingRatio; _beta = 0.0f; _gamma = 0.0f; }
public static int ccw(Vector2 p0, Vector2 p1, Vector2 p2, bool plusOneOnZeroDegrees) { var d1 = p1 - p0; var d2 = p2 - p0; if (d1.X * d2.Y > d1.Y * d2.X) return +1; if (d1.X * d2.Y < d1.Y * d2.X) return -1; if ((d1.X * d2.X < 0) || (d1.Y * d2.Y < 0)) return -1; if (d1.X * d1.X + d1.Y * d1.Y < d2.X * d2.X + d2.Y * d2.Y && plusOneOnZeroDegrees) return +1; return 0; }
private void TranslateArea(ref ControlArea area, Vector2 translation, Points anchoredPoints) { // an anchor can move a side if it has direct control of that side // or it can move the opposite side is that one has no direct anchors // or it can move both of the other 2 sides if neither of those have direct anchors. var leftOrRightAnchored = EitherSelected(anchoredPoints, Points.Left, Points.Right); var topOrBottomAnchored = EitherSelected(anchoredPoints, Points.Top, Points.Bottom); // left and right if (Start.Selected(Points.Left) || (Start.Selected(Points.Right) && !anchoredPoints.Selected(Points.Left)) || !leftOrRightAnchored) area.Left += (int)translation.X; if (Start.Selected(Points.Right) || (Start.Selected(Points.Left) && !anchoredPoints.Selected(Points.Right)) || !leftOrRightAnchored) area.Right += (int)translation.X; // top and bottom if (Start.Selected(Points.Top) || (Start.Selected(Points.Bottom) && !anchoredPoints.Selected(Points.Top)) || !topOrBottomAnchored) area.Top += (int)translation.Y; if (Start.Selected(Points.Bottom) || (Start.Selected(Points.Top) && !anchoredPoints.Selected(Points.Bottom)) || !topOrBottomAnchored) area.Bottom += (int)translation.Y; }
public override void Update(GameTime gameTime) { base.Update(gameTime); _scene.Update((float)gameTime.ElapsedGameTime.TotalSeconds); MouseState mouse = Mouse.GetState(); KeyboardState keyboard = Keyboard.GetState(); Game.IsMouseVisible = false; if (mouse.IsButtonDown(MouseButtons.Right)) { var mousePosition = new Vector2(mouse.X, mouse.Y); var mouseDelta = mousePosition - _resolution.Value / 2; _cameraRotation.Y -= mouseDelta.X * gameTime.Seconds() * 0.1f; _cameraRotation.X -= mouseDelta.Y * gameTime.Seconds() * 0.1f; var rotation = Matrix4x4.CreateFromYawPitchRoll(_cameraRotation.Y, _cameraRotation.X, _cameraRotation.Z); var forward = Vector3.TransformNormal(-Vector3.UnitZ, rotation); var right = Vector3.TransformNormal(Vector3.UnitX, rotation); if (keyboard.IsKeyDown(Keys.W)) _cameraPosition += forward * gameTime.Seconds() * 50; if (keyboard.IsKeyDown(Keys.S)) _cameraPosition -= forward * gameTime.Seconds() * 50f; if (keyboard.IsKeyDown(Keys.A)) _cameraPosition -= right * gameTime.Seconds() * 50f; if (keyboard.IsKeyDown(Keys.D)) _cameraPosition += right * gameTime.Seconds() * 50f; Matrix4x4 invView; Matrix4x4.Invert(rotation * Matrix4x4.CreateTranslation(_cameraPosition), out invView); _camera.View = invView; Mouse.SetPosition((int)_resolution.Value.X / 2, (int)_resolution.Value.Y / 2); //camera.View = Matrix.CreateLookAt(new Vector3(0, 60, -7), new Vector3(50, 30, -50), Vector3.Up); } }
/// <summary> /// Constructs a Vector3 from the given Vector2 and a third value. /// </summary> /// <param name="value">The Vector to extract X and Y components from.</param> /// <param name="z">The Z component.</param> public Vector3(Vector2 value, float z) : this(value.X, value.Y, z) { }
public static void SetSize(this UIElement element, Vector2 value) { element.GetVisual().Size = value; }