And get rid of the stupid MouseTouched stuff.
parent
863117a795
commit
16d07323ed
37
main.js
37
main.js
|
@ -51,12 +51,15 @@ var Mass = function(X, Y, Weight)
|
|||
this.NX = this.PX = this.X = X;
|
||||
this.NY = this.PY = this.Y = Y;
|
||||
this.MX = this.MY = 0;
|
||||
this.MouseTouched = false;
|
||||
this.Active = true;
|
||||
this.Update = function(TimeDelta, Bounds)
|
||||
{
|
||||
if (!this.Active)
|
||||
{
|
||||
this.NX = this.X;
|
||||
this.NY = this.Y;
|
||||
return;
|
||||
}
|
||||
// do a verlet step
|
||||
var VX = this.X - this.PX;
|
||||
var VY = this.Y - this.PY;
|
||||
|
@ -93,19 +96,10 @@ var Mass = function(X, Y, Weight)
|
|||
}
|
||||
this.Apply = function()
|
||||
{
|
||||
if (this.MouseTouched)
|
||||
{
|
||||
this.MouseTouched = false;
|
||||
this.PX = this.X = this.MX;
|
||||
this.PY = this.Y = this.MY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.PX = this.X;
|
||||
this.PY = this.Y;
|
||||
this.X = this.NX;
|
||||
this.Y = this.NY;
|
||||
}
|
||||
this.PX = this.X;
|
||||
this.PY = this.Y;
|
||||
this.X = this.NX;
|
||||
this.Y = this.NY;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,12 +116,12 @@ var Constraint = function(Mass1, Mass2)
|
|||
|
||||
var coefm1;
|
||||
var coefm2;
|
||||
if (!this.Mass1.Active || this.Mass1.MouseTouched)
|
||||
if (!this.Mass1.Active)
|
||||
{
|
||||
coefm1 = 0;
|
||||
coefm2 = 1;
|
||||
}
|
||||
else if (!this.Mass2.Active || this.Mass2.MouseTouched)
|
||||
else if (!this.Mass2.Active)
|
||||
{
|
||||
coefm1 = 1;
|
||||
coefm2 = 0;
|
||||
|
@ -218,16 +212,15 @@ var DragMoveListener = function(e)
|
|||
var MouseX = e.layerX - c.offsetLeft;
|
||||
var MouseY = e.layerY - c.offsetTop;
|
||||
var m = v.Masses[DragID]
|
||||
m.MX = MouseX + DragOffsetX;
|
||||
m.MY = MouseY + DragOffsetY;
|
||||
m.MouseTouched = true;
|
||||
m.X = MouseX + DragOffsetX;
|
||||
m.Y = MouseY + DragOffsetY;
|
||||
}
|
||||
var DragEndListener = function(e)
|
||||
{
|
||||
//v.Masses[DragID].Active = true;
|
||||
DragID = -1;
|
||||
c.removeEventListener("mouseup", DragEndListener);
|
||||
c.removeEventListener("mousemove", DragMoveListener);
|
||||
v.Masses[DragID].Active = true;
|
||||
DragID = -1;
|
||||
c.addEventListener("mousedown", DragStartListener);
|
||||
}
|
||||
var DragStartListener = function(e)
|
||||
|
@ -247,7 +240,7 @@ var DragStartListener = function(e)
|
|||
DragID = k;
|
||||
DragOffsetX = DX;
|
||||
DragOffsetY = DY;
|
||||
//m.Active = false;
|
||||
m.Active = false;
|
||||
c.removeEventListener("mousedown", DragStartListener);
|
||||
c.addEventListener("mousemove", DragMoveListener);
|
||||
c.addEventListener("mouseup", DragEndListener);
|
||||
|
|
Loading…
Reference in New Issue