Refactor
This commit is contained in:
@@ -131,7 +131,7 @@
|
|||||||
|
|
||||||
<!-- <polygon class="wall" points="-10,10 10,30 -10,40 -20,20" /> -->
|
<!-- <polygon class="wall" points="-10,10 10,30 -10,40 -20,20" /> -->
|
||||||
<!-- <polygon class="wall" points="-20,-10 0,10 -20,20 -30,0" /> -->
|
<!-- <polygon class="wall" points="-20,-10 0,10 -20,20 -30,0" /> -->
|
||||||
<!-- <polygon class="wall" points="-20,-10 20,10 -20,20 -30,0" /> -->
|
<polygon class="wall" points="-20,-10 20,10 -20,20 -30,0" />
|
||||||
|
|
||||||
<!-- <polygon class="wall" points="-20,-50 -10,-50 -10,-60 -20,-60" /> -->
|
<!-- <polygon class="wall" points="-20,-50 -10,-50 -10,-60 -20,-60" /> -->
|
||||||
<!-- <polygon class="wall" points="20,50 10,50 10,60 20,60" /> -->
|
<!-- <polygon class="wall" points="20,50 10,50 10,60 20,60" /> -->
|
||||||
@@ -536,6 +536,8 @@ const Move = (() => {
|
|||||||
return vector;
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function bounceVector(v, run, rise) {
|
||||||
const vec1 = vector(v.x, v.y);
|
const vec1 = vector(v.x, v.y);
|
||||||
const vec2 = vector(run, rise);
|
const vec2 = vector(run, rise);
|
||||||
|
|
||||||
@@ -568,14 +570,24 @@ const Move = (() => {
|
|||||||
// 5. Add the first projection prA to the reverse of the second -prB
|
// 5. Add the first projection prA to the reverse of the second -prB
|
||||||
// var new_vx:Number = prA_vx - prB_vx;
|
// var new_vx:Number = prA_vx - prB_vx;
|
||||||
// var new_vy:Number = prA_vy - prB_vy;
|
// var new_vy:Number = prA_vy - prB_vy;
|
||||||
newX = prAvx - prBvx;
|
return {
|
||||||
newY = prAvy - prBvy;
|
x: prAvx - prBvx,
|
||||||
|
y: prAvy - prBvy,
|
||||||
|
vec1,
|
||||||
|
vec2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
drawLine(p.x, p.y, p.x + vec2.rightNormal.x , p.y + vec2.rightNormal.y, "black"); // edge normal vector
|
// contact.velocity = { x: prAvx - prBvx, y: prAvy - prBvy };
|
||||||
drawLine(p.x, p.y, p.x + newX, p.y + newY, "blue"); // bounced velocity vector
|
contact.velocity = bounceVector(v, run, rise);
|
||||||
|
|
||||||
|
// edge normal vector
|
||||||
|
drawLine(p.x, p.y, p.x + contact.velocity.vec2.rightNormal.x , p.y + contact.velocity.vec2.rightNormal.y, "black");
|
||||||
|
// bounced velocity vector
|
||||||
|
drawLine(p.x, p.y, p.x + contact.velocity.x, p.y + contact.velocity.y, "blue");
|
||||||
|
|
||||||
if (det < 0) {
|
if (det < 0) {
|
||||||
Velocity[entity_id] = { x: newX, y: newY };
|
Velocity[entity_id] = contact.velocity;
|
||||||
Position[entity_id] = contact.position;
|
Position[entity_id] = contact.position;
|
||||||
} else {
|
} else {
|
||||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 52 KiB |
Reference in New Issue
Block a user