public static Entity2D GetEntity2DAt(Vector2D screenWorldPosition) { foreach (var entity2D in updateables.OfType<Entity2D>()) if (entity2D.Contains(screenWorldPosition)) return entity2D; return null; }
public bool Contains(Vector2D checkPosition) { // Box check (AABB) return position.x + size.x / 2 > checkPosition.x && position.x - size.x / 2 < checkPosition.x && position.y + size.y / 2 > checkPosition.y && position.y - size.y / 2 < checkPosition.y; }
protected Entity2D(Vector2D position, Vector2D size, float mass) { World.Add(this); this.size = size; body = BodyFactory.CreateRectangle(World.world2D, size.x * ToPhysicsSize, size.y * ToPhysicsSize, 1, position * ToPhysicsSize); body.BodyType = BodyType.Dynamic; body.Mass = mass; body.Friction = 0.2f; body.Restitution = 0.98f; body.ApplyLinearImpulse(new Vector2(0.1f, 0.5f)); }
public void AddForce(Vector2D addForce) { body.ApplyLinearImpulse(addForce); }
public Rectangle(Vector2D position, Vector2D size, Color4 color, float mass) : base(position, size, mass) { this.color = color; }
public static RigidBody GetEntity3DAt(Vector2D screenWorldPosition, out JVector direction) { var screenPosition = new JVector(screenWorldPosition.x, 1, screenWorldPosition.y); JMatrix jMatrix = new JMatrix( projectionMatrix.M11, projectionMatrix.M12, projectionMatrix.M13, projectionMatrix.M21, projectionMatrix.M22, projectionMatrix.M23, projectionMatrix.M31, projectionMatrix.M32, projectionMatrix.M33); JMatrix invertedJMatrix; JMatrix.Invert(ref jMatrix, out invertedJMatrix); var rayDirection = JVector.Transform(screenPosition, invertedJMatrix); RigidBody body; JVector normal; float fraction; world3D.CollisionSystem.Raycast(JitterMath.ToJVector(cameraPosition), rayDirection, null, out body, out normal, out fraction); if (body != null && !body.IsStatic) { direction = rayDirection; return body; } direction = new JVector(); return null; }
public static Vector2D Normalize(Vector2D vector) { return vector / vector.Length; }
public static float DotProduct(Vector2D a, Vector2D b) { return a.x * b.x + a.y * b.y; }
public Vector2D MirrorAtNormal(Vector2D normal) { normal = Normalize(normal); return this - 2 * DotProduct(this, normal) * normal; }
public bool Equals(Vector2D other) { return x > other.x - Epsilon && x < other.x + Epsilon && y > other.y - Epsilon && y < other.y + Epsilon; }