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.NX = this.PX = this.X = X;
|
||||||
this.NY = this.PY = this.Y = Y;
|
this.NY = this.PY = this.Y = Y;
|
||||||
this.MX = this.MY = 0;
|
this.MX = this.MY = 0;
|
||||||
this.MouseTouched = false;
|
|
||||||
this.Active = true;
|
this.Active = true;
|
||||||
this.Update = function(TimeDelta, Bounds)
|
this.Update = function(TimeDelta, Bounds)
|
||||||
{
|
{
|
||||||
if (!this.Active)
|
if (!this.Active)
|
||||||
|
{
|
||||||
|
this.NX = this.X;
|
||||||
|
this.NY = this.Y;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
// do a verlet step
|
// do a verlet step
|
||||||
var VX = this.X - this.PX;
|
var VX = this.X - this.PX;
|
||||||
var VY = this.Y - this.PY;
|
var VY = this.Y - this.PY;
|
||||||
|
@ -93,19 +96,10 @@ var Mass = function(X, Y, Weight)
|
||||||
}
|
}
|
||||||
this.Apply = function()
|
this.Apply = function()
|
||||||
{
|
{
|
||||||
if (this.MouseTouched)
|
this.PX = this.X;
|
||||||
{
|
this.PY = this.Y;
|
||||||
this.MouseTouched = false;
|
this.X = this.NX;
|
||||||
this.PX = this.X = this.MX;
|
this.Y = this.NY;
|
||||||
this.PY = this.Y = this.MY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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 coefm1;
|
||||||
var coefm2;
|
var coefm2;
|
||||||
if (!this.Mass1.Active || this.Mass1.MouseTouched)
|
if (!this.Mass1.Active)
|
||||||
{
|
{
|
||||||
coefm1 = 0;
|
coefm1 = 0;
|
||||||
coefm2 = 1;
|
coefm2 = 1;
|
||||||
}
|
}
|
||||||
else if (!this.Mass2.Active || this.Mass2.MouseTouched)
|
else if (!this.Mass2.Active)
|
||||||
{
|
{
|
||||||
coefm1 = 1;
|
coefm1 = 1;
|
||||||
coefm2 = 0;
|
coefm2 = 0;
|
||||||
|
@ -218,16 +212,15 @@ var DragMoveListener = function(e)
|
||||||
var MouseX = e.layerX - c.offsetLeft;
|
var MouseX = e.layerX - c.offsetLeft;
|
||||||
var MouseY = e.layerY - c.offsetTop;
|
var MouseY = e.layerY - c.offsetTop;
|
||||||
var m = v.Masses[DragID]
|
var m = v.Masses[DragID]
|
||||||
m.MX = MouseX + DragOffsetX;
|
m.X = MouseX + DragOffsetX;
|
||||||
m.MY = MouseY + DragOffsetY;
|
m.Y = MouseY + DragOffsetY;
|
||||||
m.MouseTouched = true;
|
|
||||||
}
|
}
|
||||||
var DragEndListener = function(e)
|
var DragEndListener = function(e)
|
||||||
{
|
{
|
||||||
//v.Masses[DragID].Active = true;
|
|
||||||
DragID = -1;
|
|
||||||
c.removeEventListener("mouseup", DragEndListener);
|
c.removeEventListener("mouseup", DragEndListener);
|
||||||
c.removeEventListener("mousemove", DragMoveListener);
|
c.removeEventListener("mousemove", DragMoveListener);
|
||||||
|
v.Masses[DragID].Active = true;
|
||||||
|
DragID = -1;
|
||||||
c.addEventListener("mousedown", DragStartListener);
|
c.addEventListener("mousedown", DragStartListener);
|
||||||
}
|
}
|
||||||
var DragStartListener = function(e)
|
var DragStartListener = function(e)
|
||||||
|
@ -247,7 +240,7 @@ var DragStartListener = function(e)
|
||||||
DragID = k;
|
DragID = k;
|
||||||
DragOffsetX = DX;
|
DragOffsetX = DX;
|
||||||
DragOffsetY = DY;
|
DragOffsetY = DY;
|
||||||
//m.Active = false;
|
m.Active = false;
|
||||||
c.removeEventListener("mousedown", DragStartListener);
|
c.removeEventListener("mousedown", DragStartListener);
|
||||||
c.addEventListener("mousemove", DragMoveListener);
|
c.addEventListener("mousemove", DragMoveListener);
|
||||||
c.addEventListener("mouseup", DragEndListener);
|
c.addEventListener("mouseup", DragEndListener);
|
||||||
|
|
Loading…
Reference in New Issue