private bool ShouldEdgeCast(SSVector2I mPoint1, SSVector2I mPoint2) { var startToEnd = mPoint2 - mPoint1; var normal = new SSVector2I(startToEnd.Y, -1*startToEnd.X); var lightToStart = mPoint1 - Position; return normal.GetDotProduct(lightToStart) > 0; }
public Body(World mWorld, SSVector2I mPosition, bool mIsStatic, int mWidth, int mHeight) { World = mWorld; Position = mPosition; _isStatic = mIsStatic; HalfSize = new SSVector2I(mWidth/2, mHeight/2); Cells = new HashSet<Cell>(); Groups = new HashSet<int>(); GroupsToCheck = new HashSet<int>(); GroupsToIgnoreResolve = new HashSet<int>(); }
public static void MovementLerp(BHEntity mEntity, Vector2i mPosition, int mSteps = 100) { var startPosition = new SSVector2I(mEntity.Position.X, mEntity.Position.Y); var endPosition = new SSVector2I(mPosition.X, mPosition.Y); var timelineLerp = new Timeline(); for (int i = 0; i < mSteps; i++) { float value = i/100f; var lerp = Utils.Math.Vectors.Lerp(startPosition, endPosition, value); timelineLerp.Action(() => mEntity.Position = new Vector2i(lerp.X, lerp.Y)); // LAgs with 10000 test it out timelineLerp.Wait(); } mEntity.TimelinesUpdate.Add(timelineLerp); }
public bool Equals(SSVector2I mVector) { return _x == mVector._x && _y == mVector._y; }
public double GetDotProduct(SSVector2I mVector) { return X*mVector.X + Y*mVector.Y; }
public double GetAngleBetween(SSVector2I mVector) { var cos = GetDotProduct(mVector)/(GetLength()*mVector.GetLength()); return Utils.Math.Angles.ToDegrees((float) Math.Acos(cos)); }
public void Update(float mFrameTime) { if (_isStatic) return; PreviousPosition = Position; var tempVelocity = new SSVector2F(Velocity.X*mFrameTime, Velocity.Y*mFrameTime); var tempPosition = new SSVector2F(Position.X + tempVelocity.X, Position.Y + tempVelocity.Y); Position = new SSVector2I((int) tempPosition.X, (int) tempPosition.Y); var checkedBodies = new HashSet<Body> {this}; var bodiesToCheck = World.GetBodies(this); foreach (var body in bodiesToCheck.OrderBy(x => Velocity.X > 0 ? x.X : -x.X)) { if (checkedBodies.Contains(body)) continue; checkedBodies.Add(body); if (!IsOverlapping(body)) continue; if (OnCollision != null) OnCollision(new CollisionInfo(mFrameTime, body.UserData, body)); if (body.OnCollision != null) body.OnCollision(new CollisionInfo(mFrameTime, UserData, this)); if (GroupsToIgnoreResolve.Any(x => body.Groups.Contains(x))) continue; int encrX = 0, encrY = 0; if (Bottom < body.Bottom && Bottom >= body.Top) encrY = body.Top - Bottom; else if (Top > body.Top && Top <= body.Bottom) encrY = body.Bottom - Top; if (Left < body.Left && Right >= body.Left) encrX = body.Left - Right; else if (Right > body.Right && Left <= body.Right) encrX = body.Right - Left; var overlapX = Left < body.Left ? Right - body.Left : body.Right - Left; var overlapY = Top < body.Top ? Bottom - body.Top : body.Bottom - Top; Position += overlapX > overlapY ? new SSVector2I(0, encrY) : new SSVector2I(encrX, 0); } World.UpdateBody(this); }
public AABBHull(SSVector2I mPosition, SSVector2I mHalfSize) { Position = mPosition; HalfSize = mHalfSize; }
private SSVector2I GetProjection(SSVector2I mPoint) { var lightToPoint = mPoint - Position; return mPoint + lightToPoint*Multiplier; }
private void CastEdgeShadow(SSVector2I mPoint1, SSVector2I mPoint2) { var polygon = new PolygonI(mPoint1, GetProjection(mPoint1), GetProjection(mPoint2), mPoint2); Polygons.Add(polygon); }
public ShadowCaster(SSVector2I mPosition, int mMultiplier = 1) { Position = mPosition; Multiplier = mMultiplier; Polygons = new List<PolygonI>(); }
private CBody Body(SSVector2I mPosition, int mWidth, int mHeight, bool mIsStatic = false) { return new CBody(new Body(_world, mPosition, mIsStatic, mWidth, mHeight)); }
public SSVector2F(SSVector2I mVector2I) { _x = mVector2I.X; _y = mVector2I.Y; }