Skip to content

Latest commit

 

History

History
28 lines (18 loc) · 1.26 KB

chapter-12-moving_with_vector2D.md

File metadata and controls

28 lines (18 loc) · 1.26 KB

Moving to Vector2D

We already had developed a fantastic PhysicEngine class, supporting some Newton's laws, and we rely on the Entity attributes (x,y), (dx,dy) and (ax, ay) for respectively position, velocity and acceleration, but also Material attributes and the mass of this entity

We also used the World object as PhysicEngine world's limited context with the play area, the gravity and a clear identified Material to define physic attributes of the play area where the Entity will move on.

It is now time to use some Math to compute things with a Vector2D class.

The Vector2D

A Vector2D is math entity used to define a force on a 2D world. It basically contains 2 attributes: x and y.

The Vector2D class diagram

This new class must be used to define our Entity position, velocity and acceleration :

public class Entity<T>{
    public Vector2D position;
    public Vector2D velocity;
    public Vector2D acceleration;
}