relative movement of map to mouse/finger/cursor
in
Android Processing
•
1 year ago
Hello,
I tried to grasp this problem for 3 days now. I'm quite inexperienced in programming and would be glad to get some insight by you people:
I want to draw a circle on a "map"/space and when I drag that map, the circle moves the distance traveled by the cursor. However, the circle should not jump to the cursors position or do any jump at all. It should start from its last position, thus moving relative to the cursor/mouse/finger.
I want to get this whole thing running on my android phone (HTC One X). Here's the code I managed to produce so far:
I tried to grasp this problem for 3 days now. I'm quite inexperienced in programming and would be glad to get some insight by you people:
I want to draw a circle on a "map"/space and when I drag that map, the circle moves the distance traveled by the cursor. However, the circle should not jump to the cursors position or do any jump at all. It should start from its last position, thus moving relative to the cursor/mouse/finger.
I want to get this whole thing running on my android phone (HTC One X). Here's the code I managed to produce so far:
- int circle01X, circle01Y, circle01Size;
float distmouseX, distmouseY;
color circleColor;
color bgColor;
void setup() {
bgColor = color(50);
circleColor = color(200, 50, 50);
background(bgColor);
size(displayWidth, displayHeight);
ellipseMode(CENTER);
circle01X = 300; // starting X position of circle
circle01Y = 600; // starting Y position of circle
circle01Size = 240; // size of circle
}
void draw() {
background(bgColor);
fill(circleColor);
ellipse(circle01X, circle01Y, circle01Size, circle01Size);
}
void mouseDragged() {
// calculates the distance traveled by the cursor for each axis
distmouseX = dist(mouseX, 0, pmouseX, 0);
distmouseY = dist(0, mouseY, 0, pmouseY);
// adds the traveled distance to the position of the circle
if (mouseX <= pmouseX && mouseY <= pmouseY) {
circle01X -= int(distmouseX);
circle01Y -= int(distmouseY);
} else if (mouseX >= pmouseX && mouseY <= pmouseY) {
circle01X += int(distmouseX);
circle01Y -= int(distmouseY);
} else if (mouseX >= pmouseX && mouseY >= pmouseY) {
circle01X += int(distmouseX);
circle01Y += int(distmouseY);
} else if (mouseX <= pmouseX && mouseY >= pmouseY) {
circle01X -= int(distmouseX);
circle01Y += int(distmouseY);
}
}
1