We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Modify mouse/cursor displacement ratio
Page Index Toggle Pages: 1
Modify mouse/cursor displacement ratio (Read 1132 times)
Modify mouse/cursor displacement ratio
Feb 19th, 2006, 10:10am
 
I link the computer mouse to a moving sculpture (robot) and use its trajectory through mouseX and mouseY instructions to interact with a Processing sketch. I would like to decrease the amplification ratio between cursor and mouse coordinates, in fact I would like to invert it: when the mouse is moving 1 meter, the cursor moves 10cm.
Do you think this is easily feasible?
Re: Modify mouse/cursor displacement ratio
Reply #1 - Feb 20th, 2006, 1:04pm
 
like this?
Code:

void setup(){
size(200, 200);
background(255);
rect(0, 0, 100, 100);
}
void draw(){
}
void mouseDragged(){
if(mouseX < 100 && mouseY < 100){
stroke(0);
point(mouseX, mouseY);
stroke(255, 0, 0);
point(mouseX * 2, mouseY * 2);
}
}
Re: Modify mouse/cursor displacement ratio
Reply #2 - Feb 23rd, 2006, 4:11pm
 
Not exactly.
What you obtain by multiplying (rather, for my purpose, dividing)mouseX and mouseY is to change the ratio between the cursor displacement and the actual displacement inside the Processing sketch frame. What I need is different: it is a different ratio between the mouse displacement and the cursor displacement.
So, my feeling is that it has more to do with the computer OS (XP in my case) than with Processing. But maybe some of you guys have a clue how to do it?
Re: Modify mouse/cursor displacement ratio
Reply #3 - Feb 23rd, 2006, 4:55pm
 
What exactly is the "cursor" Are you refering to the robot or the mouse pointer on screen You could hide the mouse pointer with noCursor and draw your own if that's what you mean.

Or perhaps just go into settings in the Control Panel and slow the mouse speed right down.
Re: Modify mouse/cursor displacement ratio
Reply #4 - Feb 23rd, 2006, 8:36pm
 
OPen the control panel, then mouse, then search in there for "acceleration" or suchlike, and drop that down to as low as you need.
Re: Modify mouse/cursor displacement ratio
Reply #5 - Feb 24th, 2006, 3:23pm
 
is it something like this you're thinking of:

Code:

// moves a point after the mouse at half rate

Mover m;
float C = 2; // the value of the displacement.. 1 = realtime, 2 = halftime, 0.5 = doubletime

void setup()
{
size(300,300);
m = new Mover(width/2,height/2);
}

void draw()
{
background(255);
m.draw(mousePressed);
}

void keyPressed()
{
if(key == ' ') m.setPos(mouseX,mouseY);
}


class Mover
{
float x, y;
Mover(float X, float Y)
{
x = X;
y = Y;
}

void setPos(float X, float Y)
{
x = X;
y = Y;
}

void move()
{
x += (mouseX-pmouseX)/C;
y += (mouseY-pmouseY)/C;
}

void draw(boolean move)
{
if(move) move();
smooth();
stroke(0);
fill(255);
ellipse(x,y,5,5);
noSmooth();
}
}


Change C to different values to get different results

Then if you want to find the new "mouse" position just get m.x and m.y

enjoy

-seltar
Re: Modify mouse/cursor displacement ratio
Reply #6 - Feb 28th, 2006, 6:53pm
 
I like the way your point moves so slowly, Seltar. But it's not what I need, because your point is just a point and cannot be mistaken with the pointer (what I called "cursor" in my previous posts, right st33d!), that is, take a sketch like "Storing input" given in the input examples, the circles follow the pointer position and will not follow your point (x,y). I want my pointer to move slowly, much slower than what you can get with the mouse settings of the control panel and be followed by the circles.
Anyway I found a way to get it with a C++ Windows API:

#include <windows.h>
int main(int argc, char *argv[])
{
    static POINT pt;
    POINT pt2;
    POINT pt3;
    BOOL bContinue = TRUE;
    const SHORT Mask = 32768;

GetCursorPos(&pt);
    while (bContinue)
    {
    if (GetKeyState(VK_ESCAPE) & Mask)
    bContinue = FALSE;
    GetCursorPos(&pt2);
pt3.x = (pt2.x - pt.x)/10 + pt.x;
pt3.y = (pt2.y - pt.y)/10 + pt.y;
   
    SetCursorPos(pt3.x,pt3.y);
GetCursorPos(&pt);
    Sleep(1);
    }
    return 0;
}  
It's not perfect but it works.
Thanks a lot for your help!
Re: Modify mouse/cursor displacement ratio
Reply #7 - Feb 28th, 2006, 8:16pm
 
Java Robot has set mouse position.. you could calculate some stepping there i guess.. but cool that you got it working in c++ Smiley
Page Index Toggle Pages: 1