problem with constraint inside a constructor
in
Programming Questions
•
2 years ago
I have an array of Stamp objects and each time the mouse is clicked a new Stamp object is added to the array. I have mouseX and mouseY positions as arguments for the constructor so that the new object is created where ever the mouse is. I also have a void mouseDragged function setup so that when SHIFT is pressed and the mouse is dragged the user can translate the origin left and and right. To account for this the object also takes moveX and moveY (variables I created to store the current origin coordinates) as arguments, which are subtracted from the mouseX and mouseY coordinates. This was working fine until I tried to constrain the x and y position a circular area of the page. Now when the origin is translated the constraint is keeping the object constrained to the same circular area.
Is there a problem with using a constraint inside a constructor?
Here is the code for the constructor (tempX and tempY are the mouseX and Y position at the time of the stamp objects creation and and temp_moveX and temp_moveY are the coordinates of the origin at the time of the stamps creation) :
Stamp(float tempX, float tempY, float temp_moveX, float temp_moveY, float temp_moveZ) {
currentMoveX = temp_moveX;
currentMoveY = temp_moveY;
currentMoveZ = temp_moveZ;
hypotenuse = dist(temp_moveX, temp_moveY, tempX, tempY);
side1 = tempX-temp_moveX;
side2 = tempY-temp_moveY;
angle = acos((sq(side2)-sq(hypotenuse)-sq(side1)) / (-2*hypotenuse*side1));
x = constrain(tempX - currentMoveX, -(abs(130 * cos(angle))), abs(130 * cos(angle)));
y = constrain(tempY - currentMoveY, -(abs(130 * sin(angle))), abs(130 * sin(angle)));
}
THANK YOU!
Is there a problem with using a constraint inside a constructor?
Here is the code for the constructor (tempX and tempY are the mouseX and Y position at the time of the stamp objects creation and and temp_moveX and temp_moveY are the coordinates of the origin at the time of the stamps creation) :
Stamp(float tempX, float tempY, float temp_moveX, float temp_moveY, float temp_moveZ) {
currentMoveX = temp_moveX;
currentMoveY = temp_moveY;
currentMoveZ = temp_moveZ;
hypotenuse = dist(temp_moveX, temp_moveY, tempX, tempY);
side1 = tempX-temp_moveX;
side2 = tempY-temp_moveY;
angle = acos((sq(side2)-sq(hypotenuse)-sq(side1)) / (-2*hypotenuse*side1));
x = constrain(tempX - currentMoveX, -(abs(130 * cos(angle))), abs(130 * cos(angle)));
y = constrain(tempY - currentMoveY, -(abs(130 * sin(angle))), abs(130 * sin(angle)));
}
THANK YOU!
1