├── min.js.gz ├── micro.js.gz ├── zopfli.exe ├── .gitattributes ├── README.md ├── cedarcantab ├── min.js.gz └── zopfli.exe ├── marcel.K ├── 2DPhysicsEngine │ ├── 1 │ │ └── Main.html │ ├── 2 │ │ └── Main.html │ ├── 3 │ │ └── Simulation.js │ ├── 4 │ │ └── Simulation.js │ ├── 5 │ │ └── Simulation.js │ ├── 6 │ │ ├── Shapes │ │ │ ├── Polygon.js │ │ │ ├── Circle.js │ │ │ ├── Rectangle.js │ │ │ └── Shape.js │ │ └── Simulation.js │ ├── 7 │ │ ├── Shapes │ │ │ ├── Circle.js │ │ │ ├── Rectangle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── Simulation.js │ ├── 8 │ │ ├── Shapes │ │ │ ├── Circle.js │ │ │ ├── Rectangle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── Simulation.js │ ├── 9 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── CollisionDetection.js │ ├── 10 │ │ ├── CollisionManifold.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── CollisionDetection.js │ ├── 11 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ ├── CollisionDetection.js │ │ └── CollisionManifold.js │ ├── 12 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ ├── CollisionDetection.js │ │ └── CollisionManifold.js │ ├── 13 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── CollisionManifold.js │ ├── 14 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── CollisionManifold.js │ ├── 15 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ ├── Rigidbody.js │ │ └── CollisionManifold.js │ ├── 16 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ ├── CollisionManifold.js │ │ ├── Rigidbody.js │ │ └── Simulation.js │ ├── 17 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ ├── CollisionManifold.js │ │ ├── Rigidbody.js │ │ └── Simulation.js │ ├── 18 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ ├── CollisionManifold.js │ │ └── Simulation.js │ ├── 19 │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── CollisionManifold.js │ ├── 20 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ ├── 21 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ ├── 22 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Circle.js │ │ │ ├── Rectangle.js │ │ │ ├── Shape.js │ │ │ └── Polygon.js │ ├── 23 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Circle.js │ │ │ ├── Rectangle.js │ │ │ ├── Shape.js │ │ │ └── Polygon.js │ ├── 24 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Circle.js │ │ │ ├── Rectangle.js │ │ │ ├── Shape.js │ │ │ └── Polygon.js │ ├── 25 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── BoundingBox.js │ │ │ └── Polygon.js │ ├── 26 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 27 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 28 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 29 │ │ ├── Material.js │ │ ├── Joints │ │ │ ├── JointConnection.js │ │ │ ├── ForceJoint.js │ │ │ └── Joint.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 30 │ │ ├── Material.js │ │ ├── Joints │ │ │ ├── JointConnection.js │ │ │ ├── ForceJoint.js │ │ │ └── Joint.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 31 │ │ ├── Material.js │ │ ├── Joints │ │ │ ├── JointConnection.js │ │ │ ├── Joint.js │ │ │ └── ForceJoint.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 32 │ │ ├── Material.js │ │ ├── Joints │ │ │ ├── JointConnection.js │ │ │ ├── Joint.js │ │ │ └── ForceJoint.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 33 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ ├── Joints │ │ │ ├── JointConnection.js │ │ │ ├── Joint.js │ │ │ └── ForceJoint.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 34 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ ├── Joints │ │ │ ├── JointConnection.js │ │ │ ├── Joint.js │ │ │ └── ForceJoint.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ ├── 35 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ ├── Optimizations │ │ │ ├── CollisionGroups.js │ │ │ └── BoundingBox.js │ │ └── Joints │ │ │ ├── JointConnection.js │ │ │ ├── Joint.js │ │ │ └── ForceJoint.js │ ├── 36 │ │ ├── Material.js │ │ ├── joints │ │ │ ├── JointConnection.js │ │ │ ├── Joint.js │ │ │ └── ForceJoints.js │ │ ├── shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ ├── optimizations │ │ │ ├── CollisionGroups.js │ │ │ └── BoundingBox.js │ │ └── Vector2.js │ ├── 19.1 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ │ └── CollisionManifold.js │ ├── 20.1 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ ├── 20.2 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ ├── 20.3 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── Polygon.js │ │ │ └── Shape.js │ ├── 25.1 │ │ ├── Material.js │ │ └── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ ├── BoundingBox.js │ │ │ └── Polygon.js │ ├── 26.1 │ │ ├── Material.js │ │ ├── Shapes │ │ │ ├── Rectangle.js │ │ │ ├── Circle.js │ │ │ └── Polygon.js │ │ └── Optimizations │ │ │ └── BoundingBox.js │ └── 33.old │ │ ├── Material.js │ │ ├── Shapes │ │ ├── Rectangle.js │ │ ├── Circle.js │ │ └── Polygon.js │ │ ├── Joints │ │ ├── JointConnection.js │ │ ├── Joint.js │ │ └── ForceJoint.js │ │ └── Optimizations │ │ └── BoundingBox.js └── README.md └── xem ├── 1 └── index.html ├── 2 └── index.html ├── 3 └── index.html └── 4 └── index.html /min.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xem/2Dphysics/HEAD/min.js.gz -------------------------------------------------------------------------------- /micro.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xem/2Dphysics/HEAD/micro.js.gz -------------------------------------------------------------------------------- /zopfli.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xem/2Dphysics/HEAD/zopfli.exe -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2DPhysics 2 | ========= 3 | 4 | https://xem.github.io/2Dphysics/index.html 5 | -------------------------------------------------------------------------------- /cedarcantab/min.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xem/2Dphysics/HEAD/cedarcantab/min.js.gz -------------------------------------------------------------------------------- /cedarcantab/zopfli.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xem/2Dphysics/HEAD/cedarcantab/zopfli.exe -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/6/Shapes/Polygon.js: -------------------------------------------------------------------------------- 1 | class Polygon extends Shape{ 2 | constructor(vertices){ 3 | super(vertices); 4 | } 5 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/19.1/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 1.0; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.1/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 1.0; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.2/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 1.0; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.3/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 1.0; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/21/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/22/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/23/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.0; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/24/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.3; 4 | this.friction = 0.01; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/25.1/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.6; 4 | this.friction = 0.3; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/25/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.3; 4 | this.friction = 0.01; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/26.1/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/26/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/27/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/28/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/29/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/30/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/31/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/32/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/34/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/35/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33.old/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.bounce = 0.5; 4 | this.friction = 0.05; 5 | } 6 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/36/Material.js: -------------------------------------------------------------------------------- 1 | class Material{ 2 | constructor(){ 3 | this.restitution = 0.5; 4 | this.friction = 0.01; 5 | } 6 | } -------------------------------------------------------------------------------- /xem/1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /marcel.K/README.md: -------------------------------------------------------------------------------- 1 | Forked from https://gitlab.com/Marcel.K/tutorials 2 | 3 | See also his YouTube channel: https://www.youtube.com/@pixel_physics 4 | 5 | And his book: https://www.amazon.fr/gp/product/B0FL1K2ZZ5 -------------------------------------------------------------------------------- /xem/2/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/10/CollisionManifold.js: -------------------------------------------------------------------------------- 1 | class ContactManifold{ 2 | constructor(depth,normal,penetrationPoint){ 3 | this.depth = depth; 4 | this.normal = normal; 5 | this.penetrationPoint = penetrationPoint; 6 | } 7 | 8 | //we need this method later 9 | resolveCollision(){ 10 | 11 | } 12 | 13 | // also for later use 14 | positionalCorrection(){ 15 | 16 | } 17 | 18 | draw(ctx){ 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/6/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | } 8 | 9 | draw(ctx){ 10 | super.draw(ctx); 11 | // drawing the actual circle 12 | DrawUtils.strokePoint(this.position, this.radius, "black"); 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/4/Simulation.js: -------------------------------------------------------------------------------- 1 | class Simulation{ 2 | constructor(){ 3 | 4 | } 5 | 6 | update(dt){ 7 | //## checking if mouse input is still working## 8 | console.log("MousePos x:"+mousePos.x + " y: "+mousePos.y); 9 | console.log("button-left pressed: "+ mouseDownLeft+" - button-right pressed: "+mouseDownRight); 10 | } 11 | 12 | 13 | draw(ctx){ 14 | 15 | } 16 | 17 | onKeyboardPressed(evt){ 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/5/Simulation.js: -------------------------------------------------------------------------------- 1 | class Simulation{ 2 | constructor(){ 3 | 4 | } 5 | 6 | update(dt){ 7 | //## checking if mouse input is still working## 8 | console.log("MousePos x:"+mousePos.x + " y: "+mousePos.y); 9 | console.log("button-left pressed: "+ mouseDownLeft+" - button-right pressed: "+mouseDownRight); 10 | } 11 | 12 | 13 | draw(ctx){ 14 | 15 | } 16 | 17 | onKeyboardPressed(evt){ 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/8/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | draw(ctx){ 11 | super.draw(ctx); 12 | // drawing the actual circle 13 | DrawUtils.strokePoint(this.position, this.radius, "black"); 14 | } 15 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/7/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | 11 | draw(ctx){ 12 | super.draw(ctx); 13 | // drawing the actual circle 14 | DrawUtils.strokePoint(this.position, this.radius, "black"); 15 | } 16 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/29/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | } 8 | 9 | draw(){ 10 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 11 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 12 | DrawUtils.drawLine(start, end, "orange"); 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/10/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/11/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/12/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/13/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/14/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/15/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/16/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/17/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/18/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/19/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/21/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/6/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/7/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/8/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/9/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/19.1/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.1/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.2/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.3/Shapes/Rectangle.js: -------------------------------------------------------------------------------- 1 | class Rectangle extends Polygon{ 2 | constructor(position, width, height){ 3 | super([ 4 | new Vector2(position.x - width/2,position.y - height/2), 5 | new Vector2(position.x + width/2,position.y - height/2), 6 | new Vector2(position.x + width/2,position.y + height/2), 7 | new Vector2(position.x - width/2,position.y + height/2) 8 | ]); 9 | 10 | this.position = position; 11 | this.width = width; 12 | this.height = height; 13 | } 14 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/10/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/11/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/12/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/13/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/14/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/15/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/16/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/17/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/18/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/19/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/21/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/9/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/19.1/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.1/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.2/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.3/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | draw(ctx){ 15 | super.draw(ctx); 16 | // drawing the actual circle 17 | DrawUtils.strokePoint(this.position, this.radius, this.color); 18 | } 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/30/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | this.color = "orange" 8 | } 9 | 10 | draw(){ 11 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 12 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 13 | DrawUtils.drawLine(start, end, this.color); 14 | } 15 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/31/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | this.color = "orange" 8 | } 9 | 10 | draw(){ 11 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 12 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 13 | DrawUtils.drawLine(start, end, this.color); 14 | } 15 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/32/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | this.color = "orange" 8 | } 9 | 10 | draw(){ 11 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 12 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 13 | DrawUtils.drawLine(start, end, this.color); 14 | } 15 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/10/CollisionDetection.js: -------------------------------------------------------------------------------- 1 | class CollisionDetection{ 2 | 3 | static circleVsCircle(shapeCircleA, shapeCircleB){ 4 | let centroidA = shapeCircleA.getCentroid() 5 | let centroidB = shapeCircleB.getCentroid() 6 | 7 | let direction = Sub(centroidB, centroidA); 8 | let circleARadius = shapeCircleA.getRadius(); 9 | let circleBRadius = shapeCircleB.getRadius(); 10 | 11 | 12 | if(direction.Length() < circleARadius+circleBRadius){ 13 | return true; 14 | }else{ 15 | return false; 16 | } 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/9/CollisionDetection.js: -------------------------------------------------------------------------------- 1 | class CollisionDetection{ 2 | 3 | static circleVsCircle(shapeCircleA, shapeCircleB){ 4 | let centroidA = shapeCircleA.getCentroid() 5 | let centroidB = shapeCircleB.getCentroid() 6 | 7 | let direction = Sub(centroidB, centroidA); 8 | let circleARadius = shapeCircleA.getRadius(); 9 | let circleBRadius = shapeCircleB.getRadius(); 10 | 11 | 12 | if(direction.Length() < circleARadius+circleBRadius){ 13 | return true; 14 | }else{ 15 | return false; 16 | } 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/1/Main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 2D Physics Engine 6 | 7 | 11 | 12 | 13 | 14 | 15 | 16 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/7/Shapes/Polygon.js: -------------------------------------------------------------------------------- 1 | class Polygon extends Shape{ 2 | constructor(vertices){ 3 | super(vertices); 4 | let centroid = MathHelper.calcCentroid(vertices); 5 | this.setCentroid(centroid); 6 | } 7 | 8 | draw(ctx){ 9 | // drawing all edges 10 | for(let i=1;i 0){ 7 | this.invMass = 1.0 / mass; 8 | } 9 | 10 | this.forceAccumulator = new Vector2(0,0); 11 | this.velocity = new Vector2(0,0); 12 | 13 | } 14 | 15 | addForce(force){ 16 | this.forceAccumulator.Add(force); 17 | } 18 | 19 | addVelocity(velocity){ 20 | this.velocity.Add(velocity); 21 | } 22 | 23 | setVelocity(velocity){ 24 | this.velocity = velocity.Cpy(); 25 | } 26 | 27 | update(deltaTime){ 28 | integrate(deltaTime); 29 | } 30 | 31 | draw(ctx){ 32 | 33 | } 34 | 35 | integrate(deltaTime){ 36 | 37 | } 38 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | this.color = "orange" 8 | } 9 | 10 | getAnchorAPos(){ 11 | return this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 12 | } 13 | 14 | getAnchorBPos(){ 15 | return this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 16 | } 17 | 18 | draw(){ 19 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 20 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 21 | DrawUtils.drawLine(start, end, this.color); 22 | } 23 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/34/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | this.color = "orange" 8 | } 9 | 10 | getAnchorAPos(){ 11 | return this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 12 | } 13 | 14 | getAnchorBPos(){ 15 | return this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 16 | } 17 | 18 | draw(){ 19 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 20 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 21 | DrawUtils.drawLine(start, end, this.color); 22 | } 23 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/35/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | this.color = "orange" 8 | } 9 | 10 | getAnchorAPos(){ 11 | return this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 12 | } 13 | 14 | getAnchorBPos(){ 15 | return this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 16 | } 17 | 18 | draw(){ 19 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 20 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 21 | DrawUtils.drawLine(start, end, this.color); 22 | } 23 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33.old/Joints/JointConnection.js: -------------------------------------------------------------------------------- 1 | class JointConnection{ 2 | constructor(rigidBodyA, anchorAId, rigidBodyB, anchorBId){ 3 | this.rigidBodyA = rigidBodyA; 4 | this.anchorAId = anchorAId; 5 | this.rigidBodyB = rigidBodyB; 6 | this.anchorBId = anchorBId; 7 | this.color = "orange" 8 | } 9 | 10 | getAnchorAPos(){ 11 | return this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 12 | } 13 | 14 | getAnchorBPos(){ 15 | return this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 16 | } 17 | 18 | draw(){ 19 | let start = this.rigidBodyA.shape.getAnchorPos(this.anchorAId); 20 | let end = this.rigidBodyB.shape.getAnchorPos(this.anchorBId); 21 | DrawUtils.drawLine(start, end, this.color); 22 | } 23 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/7/Shapes/Shape.js: -------------------------------------------------------------------------------- 1 | class Shape{ 2 | constructor(vertices){ 3 | this.vertices = vertices; 4 | 5 | // Abstract class - avoids creation of a Shape object 6 | if(new.target === Shape){ 7 | throw new TypeError("Cannot construct Abstract instances directly of class 'Shape'"); 8 | } 9 | } 10 | 11 | setCentroid(position){ 12 | this.centroid = position; 13 | } 14 | 15 | draw(ctx){ 16 | // drawing all edges 17 | for(let i=1;i 2 | 3 | -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/29/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/30/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/31/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/32/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/34/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/35/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33.old/Joints/Joint.js: -------------------------------------------------------------------------------- 1 | class Joint{ 2 | constructor(jointConnection){ 3 | this.jointConnection = jointConnection; 4 | this.rigiA = this.jointConnection.rigidBodyA; 5 | this.anchorAId = this.jointConnection.anchorAId; 6 | 7 | this.rigiB = this.jointConnection.rigidBodyB; 8 | this.anchorBId = this.jointConnection.anchorBId; 9 | 10 | 11 | // Abstract class - avoids creation of a Joint object 12 | if(new.target === Joint){ 13 | throw new TypeError("Cannot construct Abstract instances directly of class 'Joint'"); 14 | } 15 | } 16 | 17 | getAnchorAPos(){ 18 | return this.rigiA.shape.getAnchorPos(this.anchorAId); 19 | } 20 | 21 | getAnchorBPos(){ 22 | return this.rigiB.shape.getAnchorPos(this.anchorBId); 23 | } 24 | 25 | updateConnectionA(){} 26 | updateConnectionB(){} 27 | draw(){ 28 | this.jointConnection.draw(); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/13/Shapes/Polygon.js: -------------------------------------------------------------------------------- 1 | class Polygon extends Shape{ 2 | constructor(vertices){ 3 | super(vertices); 4 | let centroid = MathHelper.calcCentroid(vertices); 5 | this.setCentroid(centroid); 6 | 7 | 8 | this.normals = MathHelper.calcNormals(vertices); 9 | } 10 | 11 | rotate(radiansDelta){ 12 | super.rotate(radiansDelta); 13 | this.normals = MathHelper.calcNormals(this.vertices); 14 | } 15 | 16 | draw(ctx){ 17 | super.draw(ctx); 18 | // drawing the centroid 19 | DrawUtils.drawPoint(this.centroid, 5, "black"); 20 | 21 | // drawing normals 22 | for(let i=0;i 0){ 7 | this.invMass = 1.0 / mass; 8 | } 9 | 10 | this.forceAccumulator = new Vector2(0,0); 11 | this.velocity = new Vector2(0,0); 12 | 13 | } 14 | 15 | addForce(force){ 16 | this.forceAccumulator.Add(force); 17 | } 18 | 19 | addVelocity(velocity){ 20 | this.velocity.Add(velocity); 21 | } 22 | 23 | setVelocity(velocity){ 24 | this.velocity = velocity.Cpy(); 25 | } 26 | 27 | update(deltaTime){ 28 | this.integrate(deltaTime); 29 | } 30 | 31 | integrate(deltaTime){ 32 | 33 | } 34 | 35 | getShape(){ 36 | return this.shape; 37 | } 38 | 39 | log(){ 40 | console.log( 41 | "Force: x = "+this.forceAccumulator.x + " y = "+this.forceAccumulator.y+ 42 | "\nVelocity: x = "+this.velocity.x+" y = "+this.velocity.y); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/31/Joints/ForceJoint.js: -------------------------------------------------------------------------------- 1 | class ForceJoint extends Joint{ 2 | constructor(connection, strength){ 3 | super(connection); 4 | this.strength = strength; 5 | } 6 | 7 | updateConnectionA(){ 8 | if(this.rigiA.isKinematic) return; 9 | 10 | let anchorAPos = this.getAnchorAPos(); 11 | let anchorBPos = this.getAnchorBPos(); 12 | 13 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 14 | let direction = Sub(anchorBPos, anchorAPos); 15 | this.rigiA.addForceAtPoint(anchorBPos, Scale(direction, this.strength*forceHalving)); 16 | } 17 | 18 | updateConnectionB(){ 19 | if(this.rigiB.isKinematic) return; 20 | 21 | let anchorAPos = this.getAnchorAPos(); 22 | let anchorBPos = this.getAnchorBPos(); 23 | 24 | let forceHalving = this.rigiA.isKinematic ? 1 : 0.5; 25 | let direction = Sub(anchorAPos, anchorBPos); 26 | this.rigiB.addForceAtPoint(anchorAPos, Scale(direction, this.strength*forceHalving)); 27 | } 28 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/32/Joints/ForceJoint.js: -------------------------------------------------------------------------------- 1 | class ForceJoint extends Joint{ 2 | constructor(connection, strength){ 3 | super(connection); 4 | this.strength = strength; 5 | } 6 | 7 | updateConnectionA(){ 8 | if(this.rigiA.isKinematic) return; 9 | 10 | let anchorAPos = this.getAnchorAPos(); 11 | let anchorBPos = this.getAnchorBPos(); 12 | 13 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 14 | let direction = Sub(anchorBPos, anchorAPos); 15 | this.rigiA.addForceAtPoint(anchorBPos, Scale(direction, this.strength*forceHalving)); 16 | } 17 | 18 | updateConnectionB(){ 19 | if(this.rigiB.isKinematic) return; 20 | 21 | let anchorAPos = this.getAnchorAPos(); 22 | let anchorBPos = this.getAnchorBPos(); 23 | 24 | let forceHalving = this.rigiA.isKinematic ? 1 : 0.5; 25 | let direction = Sub(anchorAPos, anchorBPos); 26 | this.rigiB.addForceAtPoint(anchorAPos, Scale(direction, this.strength*forceHalving)); 27 | } 28 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33/Joints/ForceJoint.js: -------------------------------------------------------------------------------- 1 | class ForceJoint extends Joint{ 2 | constructor(connection, strength){ 3 | super(connection); 4 | this.strength = strength; 5 | } 6 | 7 | updateConnectionA(){ 8 | if(this.rigiA.isKinematic) return; 9 | 10 | let anchorAPos = this.getAnchorAPos(); 11 | let anchorBPos = this.getAnchorBPos(); 12 | 13 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 14 | let direction = Sub(anchorBPos, anchorAPos); 15 | this.rigiA.addForceAtPoint(anchorBPos, Scale(direction, this.strength*forceHalving)); 16 | } 17 | 18 | updateConnectionB(){ 19 | if(this.rigiB.isKinematic) return; 20 | 21 | let anchorAPos = this.getAnchorAPos(); 22 | let anchorBPos = this.getAnchorBPos(); 23 | 24 | let forceHalving = this.rigiA.isKinematic ? 1 : 0.5; 25 | let direction = Sub(anchorAPos, anchorBPos); 26 | this.rigiB.addForceAtPoint(anchorAPos, Scale(direction, this.strength*forceHalving)); 27 | } 28 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/34/Joints/ForceJoint.js: -------------------------------------------------------------------------------- 1 | class ForceJoint extends Joint{ 2 | constructor(connection, strength){ 3 | super(connection); 4 | this.strength = strength; 5 | } 6 | 7 | updateConnectionA(){ 8 | if(this.rigiA.isKinematic) return; 9 | 10 | let anchorAPos = this.getAnchorAPos(); 11 | let anchorBPos = this.getAnchorBPos(); 12 | 13 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 14 | let direction = Sub(anchorBPos, anchorAPos); 15 | this.rigiA.addForceAtPoint(anchorBPos, Scale(direction, this.strength*forceHalving)); 16 | } 17 | 18 | updateConnectionB(){ 19 | if(this.rigiB.isKinematic) return; 20 | 21 | let anchorAPos = this.getAnchorAPos(); 22 | let anchorBPos = this.getAnchorBPos(); 23 | 24 | let forceHalving = this.rigiA.isKinematic ? 1 : 0.5; 25 | let direction = Sub(anchorAPos, anchorBPos); 26 | this.rigiB.addForceAtPoint(anchorAPos, Scale(direction, this.strength*forceHalving)); 27 | } 28 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/35/Joints/ForceJoint.js: -------------------------------------------------------------------------------- 1 | class ForceJoint extends Joint{ 2 | constructor(connection, strength){ 3 | super(connection); 4 | this.strength = strength; 5 | } 6 | 7 | updateConnectionA(){ 8 | if(this.rigiA.isKinematic) return; 9 | 10 | let anchorAPos = this.getAnchorAPos(); 11 | let anchorBPos = this.getAnchorBPos(); 12 | 13 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 14 | let direction = Sub(anchorBPos, anchorAPos); 15 | this.rigiA.addForceAtPoint(anchorBPos, Scale(direction, this.strength*forceHalving)); 16 | } 17 | 18 | updateConnectionB(){ 19 | if(this.rigiB.isKinematic) return; 20 | 21 | let anchorAPos = this.getAnchorAPos(); 22 | let anchorBPos = this.getAnchorBPos(); 23 | 24 | let forceHalving = this.rigiA.isKinematic ? 1 : 0.5; 25 | let direction = Sub(anchorAPos, anchorBPos); 26 | this.rigiB.addForceAtPoint(anchorAPos, Scale(direction, this.strength*forceHalving)); 27 | } 28 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33.old/Joints/ForceJoint.js: -------------------------------------------------------------------------------- 1 | class ForceJoint extends Joint{ 2 | constructor(connection, strength){ 3 | super(connection); 4 | this.strength = strength; 5 | } 6 | 7 | updateConnectionA(){ 8 | if(this.rigiA.isKinematic) return; 9 | 10 | let anchorAPos = this.getAnchorAPos(); 11 | let anchorBPos = this.getAnchorBPos(); 12 | 13 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 14 | let direction = Sub(anchorBPos, anchorAPos); 15 | this.rigiA.addForceAtPoint(anchorBPos, Scale(direction, this.strength*forceHalving)); 16 | } 17 | 18 | updateConnectionB(){ 19 | if(this.rigiB.isKinematic) return; 20 | 21 | let anchorAPos = this.getAnchorAPos(); 22 | let anchorBPos = this.getAnchorBPos(); 23 | 24 | let forceHalving = this.rigiA.isKinematic ? 1 : 0.5; 25 | let direction = Sub(anchorAPos, anchorBPos); 26 | this.rigiB.addForceAtPoint(anchorAPos, Scale(direction, this.strength*forceHalving)); 27 | } 28 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/28/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/29/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/30/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/31/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/32/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/34/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/35/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33.old/Shapes/Circle.js: -------------------------------------------------------------------------------- 1 | class Circle extends Shape{ 2 | 3 | constructor(position, radius){ 4 | super([new Vector2(position.x,position.y), new Vector2(position.x + radius, position.y)]) 5 | this.position = position; 6 | this.radius = radius; 7 | this.setCentroid(position); 8 | } 9 | 10 | getRadius(){ 11 | return this.radius; 12 | } 13 | 14 | calculateInertia(mass){ 15 | return 0.5 * mass * this.radius * this.radius; 16 | } 17 | 18 | calculateBoundingBox(){ 19 | this.boundingBox.topLeft.x = this.position.x - this.radius; 20 | this.boundingBox.topLeft.y = this.position.y - this.radius; 21 | this.boundingBox.bottomRight.x = this.position.x + this.radius; 22 | this.boundingBox.bottomRight.y = this.position.y + this.radius; 23 | } 24 | 25 | isPointInside(pos){ 26 | let distanceToCenter = Sub(this.centroid, pos).Length(); 27 | return this.radius > distanceToCenter; 28 | } 29 | 30 | draw(ctx){ 31 | super.draw(ctx); 32 | // drawing the actual circle 33 | DrawUtils.strokePoint(this.position, this.radius, this.color); 34 | } 35 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/36/joints/ForceJoints.js: -------------------------------------------------------------------------------- 1 | class ForceJoint extends Joint{ 2 | constructor(connection, strength){ 3 | super(connection); 4 | this.strength = strength; 5 | } 6 | 7 | updateConnectionA(){ 8 | if(this.rigiA.isKinematic) return; 9 | 10 | let anchorAPos = this.getAnchorAPos(); 11 | let anchorBPos = this.getAnchorBPos(); 12 | let direction = Sub(anchorBPos, anchorAPos); 13 | direction.Normalize(); 14 | 15 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 16 | this.rigiA.addForceAtPoint(anchorBPos, Scale(direction, this.strength * forceHalving)); 17 | } 18 | 19 | updateConnectionB(){ 20 | if(this.rigiB.isKinematic) return; 21 | 22 | let anchorAPos = this.getAnchorAPos(); 23 | let anchorBPos = this.getAnchorBPos(); 24 | let direction = Sub(anchorAPos, anchorBPos); 25 | direction.Normalize(); 26 | 27 | let forceHalving = this.rigiB.isKinematic ? 1 : 0.5; 28 | this.rigiB.addForceAtPoint(anchorAPos, Scale(direction, this.strength * forceHalving)); 29 | } 30 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/8/Shapes/Shape.js: -------------------------------------------------------------------------------- 1 | class Shape{ 2 | constructor(vertices){ 3 | this.vertices = vertices; 4 | 5 | // Abstract class - avoids creation of a Shape object 6 | if(new.target === Shape){ 7 | throw new TypeError("Cannot construct Abstract instances directly of class 'Shape'"); 8 | } 9 | } 10 | 11 | setCentroid(position){ 12 | this.centroid = position; 13 | } 14 | 15 | draw(ctx){ 16 | // drawing all edges 17 | for(let i=1;i distanceToCenter; 27 | } 28 | 29 | draw(ctx){ 30 | super.draw(ctx); 31 | DrawUtils.strokePoint(this.position, this.radius, this.color); 32 | } 33 | } -------------------------------------------------------------------------------- /xem/4/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/17/Rigidbody.js: -------------------------------------------------------------------------------- 1 | class Rigidbody{ 2 | constructor(shape, mass){ 3 | this.shape = shape; 4 | this.mass = mass; 5 | this.invMass = 0; 6 | if(mass > 0){ 7 | this.invMass = 1.0 / mass; 8 | } 9 | 10 | this.forceAccumulator = new Vector2(0,0); 11 | this.velocity = new Vector2(0,0); 12 | } 13 | 14 | addForce(force){ 15 | this.forceAccumulator.Add(force); 16 | } 17 | 18 | addVelocity(velocity){ 19 | this.velocity.Add(velocity); 20 | } 21 | 22 | setVelocity(velocity){ 23 | this.velocity = velocity.Cpy(); 24 | } 25 | 26 | update(deltaTime){ 27 | this.log(); 28 | this.integrate(deltaTime); 29 | } 30 | 31 | integrate(deltaTime){ 32 | //semi implicit Euler 33 | let acceleration = Scale(this.forceAccumulator, this.invMass); 34 | this.velocity = Add(this.velocity,Scale(acceleration, deltaTime)); 35 | let deltaPosition = Scale(this.velocity, deltaTime); 36 | this.shape.move(deltaPosition); 37 | 38 | this.forceAccumulator = new Vector2(0,0); 39 | } 40 | 41 | getShape(){ 42 | return this.shape; 43 | } 44 | 45 | log(){ 46 | console.log( 47 | "Force: x = "+this.forceAccumulator.x + " y = "+this.forceAccumulator.y+ 48 | "\nVelocity: x = "+this.velocity.x+" y = "+this.velocity.y); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/36/optimizations/CollisionGroups.js: -------------------------------------------------------------------------------- 1 | const CollisionGroups = { 2 | GROUP0: { id: 1 << 0, name: "GROUP0"}, 3 | GROUP1: { id: 1 << 1, name: "GROUP1"}, 4 | GROUP2: { id: 1 << 2, name: "GROUP2"}, 5 | GROUP3: { id: 1 << 3, name: "GROUP3"}, 6 | 7 | GROUP4: { id: 1 << 4, name: "GROUP4"}, 8 | GROUP5: { id: 1 << 5, name: "GROUP5"}, 9 | GROUP6: { id: 1 << 6, name: "GROUP6"}, 10 | GROUP7: { id: 1 << 7, name: "GROUP7"}, 11 | } 12 | 13 | // 1111 1111 / 256 14 | DEFAULT_COLLISION = 15 | CollisionGroups.GROUP0.id | 16 | CollisionGroups.GROUP1.id | 17 | CollisionGroups.GROUP2.id | 18 | CollisionGroups.GROUP3.id | 19 | CollisionGroups.GROUP4.id | 20 | CollisionGroups.GROUP5.id | 21 | CollisionGroups.GROUP6.id | 22 | CollisionGroups.GROUP7.id; 23 | 24 | 25 | const CollisionMatrix = { 26 | [CollisionGroups.GROUP0.id] : DEFAULT_COLLISION, 27 | [CollisionGroups.GROUP1.id] : DEFAULT_COLLISION, 28 | [CollisionGroups.GROUP2.id] : DEFAULT_COLLISION, 29 | [CollisionGroups.GROUP3.id] : DEFAULT_COLLISION, 30 | [CollisionGroups.GROUP4.id] : DEFAULT_COLLISION, 31 | [CollisionGroups.GROUP5.id] : DEFAULT_COLLISION, 32 | [CollisionGroups.GROUP6.id] : DEFAULT_COLLISION, 33 | [CollisionGroups.GROUP7.id] : DEFAULT_COLLISION 34 | } 35 | -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/9/Shapes/Shape.js: -------------------------------------------------------------------------------- 1 | class Shape{ 2 | constructor(vertices){ 3 | this.vertices = vertices; 4 | this.color = "black"; 5 | 6 | // Abstract class - avoids creation of a Shape object 7 | if(new.target === Shape){ 8 | throw new TypeError("Cannot construct Abstract instances directly of class 'Shape'"); 9 | } 10 | } 11 | 12 | setCentroid(position){ 13 | this.centroid = position; 14 | } 15 | 16 | setColor(color){ 17 | this.color = color; 18 | } 19 | 20 | getCentroid(){ 21 | return this.centroid; 22 | } 23 | 24 | draw(ctx){ 25 | // drawing all edges 26 | for(let i=1;i leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/27/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/28/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/29/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/30/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/31/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/32/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/34/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/35/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/26.1/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/33.old/Optimizations/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | ctx.beginPath(); 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | let width = this.bottomRight.x - this.topLeft.x; 34 | let height = this.bottomRight.y - this.topLeft.y; 35 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 36 | ctx.stroke(); 37 | ctx.strokeStyle = "black"; 38 | } 39 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/20.1/Shapes/Shape.js: -------------------------------------------------------------------------------- 1 | class Shape{ 2 | constructor(vertices){ 3 | this.vertices = vertices; 4 | this.color = "black"; 5 | 6 | // Abstract class - avoids creation of a Shape object 7 | if(new.target === Shape){ 8 | throw new TypeError("Cannot construct Abstract instances directly of class 'Shape'"); 9 | } 10 | } 11 | 12 | setCentroid(position){ 13 | this.centroid = position; 14 | } 15 | 16 | setColor(color){ 17 | this.color = color; 18 | } 19 | 20 | getCentroid(){ 21 | return this.centroid.Cpy(); 22 | } 23 | 24 | draw(ctx){ 25 | // drawing all edges 26 | for(let i=1;i leftX && otherLeftX < rightX; 20 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 21 | 22 | return intersectX && intersectY; 23 | } 24 | 25 | draw(){ 26 | ctx.beginPath(); 27 | 28 | if(this.isColliding){ 29 | ctx.strokeStyle = "red"; 30 | }else{ 31 | ctx.strokeStyle = "grey"; 32 | } 33 | 34 | let width = this.bottomRight.x - this.topLeft.x; 35 | let height = this.bottomRight.y - this.topLeft.y; 36 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 37 | ctx.stroke(); 38 | ctx.strokeStyle = "black"; 39 | ctx.closePath(); 40 | } 41 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/25.1/Shapes/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | console.log(this.isColliding); 28 | ctx.beginPath(); 29 | if(this.isColliding){ 30 | ctx.strokeStyle = "red"; 31 | }else{ 32 | ctx.strokeStyle = "grey"; 33 | } 34 | let width = this.bottomRight.x - this.topLeft.x; 35 | let height = this.bottomRight.y - this.topLeft.y; 36 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 37 | ctx.stroke(); 38 | ctx.strokeStyle = "black"; 39 | } 40 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/25/Shapes/BoundingBox.js: -------------------------------------------------------------------------------- 1 | class BoundingBox{ 2 | constructor(){ 3 | this.topLeft = new Vector2(0,0); 4 | this.bottomRight = new Vector2(0,0); 5 | this.isColliding = false; 6 | } 7 | 8 | intersect(otherBoundingBox){ 9 | let leftX = this.topLeft.x; 10 | let rightX = this.bottomRight.x; 11 | let topY = this.topLeft.y; 12 | let bottomY = this.bottomRight.y; 13 | 14 | let otherLeftX = otherBoundingBox.topLeft.x; 15 | let otherRightX = otherBoundingBox.bottomRight.x; 16 | let otherTopY = otherBoundingBox.topLeft.y; 17 | let otherBottomY = otherBoundingBox.bottomRight.y; 18 | 19 | 20 | let intersectX = otherRightX > leftX && otherLeftX < rightX; 21 | let intersectY = otherTopY < bottomY && otherBottomY > topY; 22 | 23 | return intersectX && intersectY; 24 | } 25 | 26 | draw(){ 27 | console.log(this.isColliding); 28 | ctx.beginPath(); 29 | if(this.isColliding){ 30 | ctx.strokeStyle = "red"; 31 | }else{ 32 | ctx.strokeStyle = "grey"; 33 | } 34 | let width = this.bottomRight.x - this.topLeft.x; 35 | let height = this.bottomRight.y - this.topLeft.y; 36 | ctx.rect(this.topLeft.x, this.topLeft.y, width, height); 37 | ctx.stroke(); 38 | ctx.strokeStyle = "black"; 39 | } 40 | } -------------------------------------------------------------------------------- /marcel.K/2DPhysicsEngine/26/Shapes/Polygon.js: -------------------------------------------------------------------------------- 1 | class Polygon extends Shape{ 2 | constructor(vertices){ 3 | super(vertices); 4 | let centroid = MathHelper.calcCentroid(vertices); 5 | this.setCentroid(centroid); 6 | this.normals = MathHelper.calcNormals(vertices); 7 | } 8 | 9 | rotate(radiansDelta){ 10 | super.rotate(radiansDelta); 11 | this.normals = MathHelper.calcNormals(this.vertices); 12 | } 13 | 14 | calculateInertia(mass){ 15 | let inertia = 0; 16 | let massPerTriangleFace = mass / this.vertices.length; 17 | for(let i=0; i 2 | 3 | 4 | 5 | 2D Physics Engine 6 | 7 | 11 | 12 | 13 | 14 | 15 | 16 | 56 | 57 | 58 | --------------------------------------------------------------------------------