// MoveCommand public static Dictionary<string, Object> GetMoveCommandArgs(Vector direction, double speed) { args = new Dictionary<string, Object>(); args.Add("Direction", direction); args.Add("Speed", speed); return args; }
public static Dictionary<string, Object> GetSetPositionArgs(Vector positionVector, bool isRelative) { args = new Dictionary<string, Object>(); args.Add("PositionVector", positionVector); args.Add("IsRelative", isRelative); return args; }
public Matrix(Vector x, Vector y, Vector z, Vector o) { _m11 = x.X; _m12 = x.Y; _m13 = x.Z; _m21 = y.X; _m22 = y.Y; _m23 = y.Z; _m31 = z.X; _m32 = z.Y; _m33 = z.Z; _m41 = o.X; _m42 = o.Y; _m43 = o.Z; }
public override void Move(double elapsedTime) { _speed = 2 * Math.PI * _radius / _timeToRotate; _currentAngle += elapsedTime * 2 * Math.PI / _timeToRotate; if (_currentAngle > 2 * Math.PI) { _currentAngle -= 2 * Math.PI; } _direction = new Vector(-1 * Math.Sin(_currentAngle), Math.Cos(_currentAngle)); base.Move(elapsedTime); }
public static double Distance(Vector v1, Vector v2) { double XDiff = v1.X - v2.X; double YDiff = v1.Y - v2.Y; double length = System.Math.Sqrt(XDiff * XDiff + YDiff * YDiff); return length; }
private Vector CalculateCatmullRom(double t, Vector p1, Vector p2, Vector p3, Vector p4) { double t2 = t * t; double t3 = t2 * t; double b1 = 0.5 * (-t3 + 2 * t2 - t); double b2 = 0.5 * (3 * t3 - 5 * t2 + 2); double b3 = 0.5 * (-3 * t3 + 4 * t2 + t); double b4 = 0.5 * (t3 - t2); return (p1 * b1 + p2 * b2 + p3 * b3 + p4 * b4); }
public Vector MeasureFont(string text, double maxWidth) { Vector dimensions = new Vector(); foreach (char c in text) { CharacterData data = _characterData[c]; dimensions.X += data.XAdvance; dimensions.Y = Math.Max(dimensions.Y, data.Height + data.YOffset); } return dimensions; }
public Sprite(Texture texture, Vector startingPosition, double width, double height) { if (width <= 0) width = texture.Width; if (height <= 0) height = texture.Height; _xPosition = startingPosition.X; _yPosition = startingPosition.Y; _texture = texture; SetScale(width / texture.Width, height / texture.Height); InitVertexPositions(new Vector(_xPosition, _yPosition, 0), width, height); this.Color = new Color(1, 1, 1, 1); SetUVs(new Point(0, 0), new Point(1, 1)); }
public override void Update(double elapsedTime) { if (_mouse.LeftHeld) { wasMovingLastFrame = true; Vector direction = Vector.Normalize(new Vector(_mouse.Position) - _parent.Model.Center); SingletonFactory.GetEventHub().SendEvent("MoveCommand", this, EventArgWriteUtil.GetMoveCommandArgs(direction, ConfigSettings.PLAYER_SPEED), _parent); } else if (wasMovingLastFrame) { wasMovingLastFrame = false; SingletonFactory.GetEventHub().SendEvent("MoveCommand", this, EventArgWriteUtil.GetMoveCommandArgs(new Vector(0, 0), 0), _parent); } else if (ControlMapping.IsKeyPressed(InputCommand.PositionRight)) { Vector positionVector = new Vector(100, 0); SingletonFactory.GetEventHub().SendEvent("SetPositionCommand", this, EventArgWriteUtil.GetSetPositionArgs(positionVector), _parent); } }
private static bool IsSeparatingAxis(Vector sepAxisPoint1, Vector sepAxisPoint2, Vector thirdPoint, CollisionRectangle otherRectangle) { Vector[] otherQuadPoints = new Vector[4]; otherQuadPoints[0] = otherRectangle.TopLeft; otherQuadPoints[1] = otherRectangle.TopRight; otherQuadPoints[2] = otherRectangle.BottomLeft; otherQuadPoints[3] = otherRectangle.BottomRight; Vector separatingAxis = sepAxisPoint2 - sepAxisPoint1; Vector normalAxis = new Vector(separatingAxis.Y, -separatingAxis.X); bool referenceSign = normalAxis * (thirdPoint - sepAxisPoint1) >= 0; foreach (Vector cornerOfSecondRect in otherQuadPoints) { bool sign = normalAxis * (cornerOfSecondRect - sepAxisPoint1) >= 0; // A point of the other quad is one the same side as thirdPoint if (sign == referenceSign) { return false; } } // All points of the other quad are on the other side of the edge. Therefore the edge is a separating axis return true; }
public ForwardFacingMovement(String subclass, Vector direction, double speed) : base(subclass, direction, speed) { _previousDirection = new Vector(direction.X, direction.Y); }
public Vector CrossProduct(Vector v) { double nx = Y * v.Z - Z * v.Y; double ny = Z * v.X - X * v.Z; double nz = X * v.Y - Y * v.X; return new Vector(nx, ny, nz); }
//-------------------------- // Vector addition and subtraction and scalar multiplication methods and overloads //-------------------------- public Vector Add(Vector r) { return new Vector(X + r.X, Y + r.Y, Z + r.Z); }
public AnimatedSprite GetAnimatedSprite(String textureName, int xPos, int yPos, double width, double height) { Vector startingPosition = new Vector(xPos, yPos); AnimatedSprite animatedSprite = new AnimatedSprite(this.Get(textureName), startingPosition, width, height); return animatedSprite; }
public Sprite GetSprite(String textureName, int xPos, int yPos, double width, double height) { Vector startingPosition = new Vector(xPos, yPos); Sprite sprite = new Sprite(this.Get(textureName), startingPosition, width, height); return sprite; }
public static Vector Normalize(Vector v) { double r = v.Length; if (r != 0.0) // prevent division by zero { return new Vector(v.X / r, v.Y / r, v.Z / r); } else { return new Vector(0, 0, 0); } }
public Vector Subtract(Vector r) { return new Vector(X - r.X, Y - r.Y, Z - r.Z); }
public Vector GetScale() { Vector result = new Vector(); result.X = (new Vector(_m11, _m12, _m13)).Length; result.Y = (new Vector(_m21, _m22, _m23)).Length; result.Z = (new Vector(_m31, _m32, _m33)).Length; return result; }
public void SetTranslation(Vector translation) { _m41 = translation.X; _m42 = translation.Y; _m43 = translation.Z; }
public void Move(Vector vector) { double newX = this.Center.X + vector.X; double newY = this.Center.Y + vector.Y; double newZ = this.Center.Z + vector.Z; SetPosition(new Vector(newX, newY, newZ)); }
public VerticalMenu(double x, double y, Input.Input input) { _input = input; _position = new Vector(x, y, 0); Spacing = 50; }
public MovementComponent(string name, Vector direction, double speed) : base(name, ComponentType.Movement) { _direction = Vector.Normalize(direction); _speed = speed; }
public void SetRotate(Vector axis, double angle) { double angleSin = Math.Sin(angle); double angleCos = Math.Cos(angle); double a = 1.0 - angleCos; double ax = a * axis.X; double ay = a * axis.Y; double az = a * axis.Z; _m11 = ax * axis.X + angleCos; _m12 = ax * axis.Y + axis.Z * angleSin; _m13 = ax * axis.Z - axis.Y * angleSin; _m21 = ay * axis.X - axis.Z * angleSin; _m22 = ay * axis.Y + angleCos; _m23 = ay * axis.Z + axis.X * angleSin; _m31 = az * axis.X + axis.Y * angleSin; _m32 = az * axis.Y - axis.X * angleSin; _m33 = az * axis.Z + angleCos; }
//-------------------------- // Dot product and cross product methods and overload //-------------------------- public double DotProduct(Vector v) { return (v.X * X) + (Y * v.Y) + (Z * v.Z); }
public void SetScale(Vector scale) { _m11 = scale.X; _m22 = scale.Y; _m33 = scale.Z; }
//-------------------------- // Vector equality method and overloads //-------------------------- public bool Equals(Vector v) { return (X == v.X) && (Y == v.Y) && (Z == v.Z); }
public void SetPosition(Vector position) { Matrix m = new Matrix(); m.SetTranslation(new Vector(_xPosition, _yPosition, 0)); ApplyMatrix(m.Inverse()); m.SetTranslation(position); ApplyMatrix(m); }
public Sprite(Texture texture, Vector startingPosition) : this(texture, startingPosition, texture.Width, texture.Height) { }
public static void InitConfigSettings(string assemblyMainDirectory) { assembly_main_dir = assemblyMainDirectory + @"\"; prop_dir_root = assemblyMainDirectory + @"\Assets\Properties\"; Dictionary<string, string> configProps = PropertyUtil.LoadPropertiesFromFile(prop_dir_root + @"master.prop"); starting_screen_width = int.Parse(configProps["starting_screen_width"]); starting_screen_height = int.Parse(configProps["starting_screen_height"]); texture_directory = configProps["texture_directory"]; camera_buffer = int.Parse(configProps["camera_buffer"]); camera_type = configProps["camera_type"]; int x = configProps.ContainsKey("camera_scroll_direction_x") ? int.Parse(configProps["camera_scroll_direction_x"]) : 0; int y = configProps.ContainsKey("camera_scroll_direction_y") ? int.Parse(configProps["camera_scroll_direction_y"]) : 0; camera_scroll_direction = new Vector(x, y); clock_speed = double.Parse(configProps["clock_speed"]); player_speed = double.Parse(configProps["player_speed"]); default_non_player_speed = double.Parse(configProps["default_non_player_speed"]); gravity_pps = double.Parse(configProps["gravity_pps"]); max_x_velocity = double.Parse(configProps["max_x_velocity"]); max_y_velocity = double.Parse(configProps["max_y_velocity"]); log_directory = configProps["log_directory"]; }
// Set sprite's quad centered at 'position', with dimensions 'width' and 'height' private void InitVertexPositions(Vector position, double width, double height) { double halfWidth = width / 2; double halfHeight = height / 2; _vertexPositions[0] = new Vector(position.X - halfWidth, position.Y + halfHeight, position.Z); _vertexPositions[1] = new Vector(position.X + halfWidth, position.Y + halfHeight, position.Z); _vertexPositions[2] = new Vector(position.X - halfWidth, position.Y - halfHeight, position.Z); _vertexPositions[3] = new Vector(position.X + halfWidth, position.Y + halfHeight, position.Z); _vertexPositions[4] = new Vector(position.X + halfWidth, position.Y - halfHeight, position.Z); _vertexPositions[5] = new Vector(position.X - halfWidth, position.Y - halfHeight, position.Z); _width = width; _height = height; // Since this method implicitly un-rotates the matrix, we must re-rotate it. double rotation = _rotation; _rotation = 2 * Math.PI; SetRotation(rotation); }