Strange math problem
in
Programming Questions
•
1 month ago
- int srad = 0;
- int boxX = 0;
- void setup() {
- size(400,200,P3D);
- }
- void draw() {
- background(0);
- pushMatrix();
- translate(width/2,height/2,-1000);
- noStroke();
- fill(200);
- sphere(height/2);
- srad = floor(screenX(height/2,0,0) - width/2);
- boxX = (mouseX - width/2) * (srad/(height/2));
- translate(boxX,0,height/2);
- fill(50);
- box(height/100);
- popMatrix();
- }
- void mouseClicked() {
- println(mouseX - width/2 + " * (" + srad + "/(" + height/2 + ")) = " + boxX);
- }
I've probably just got my math wrong or something, but in this sketch boxX is always zero and I don't know why. If the first translation's z is ≥ 0 it works, but if it's negative boxX is always zero.
I print out how boxX is calculated but the equation doesn't equal zero, yet boxX is set to zero somehow. Why does boxX equal zero for every mouseX?
1