First person shooter mouse
in
Programming Questions
•
4 months ago
Hello! I'm attempting to make a GUI for controlling a robot, and I need FPS style mouse controls. I thought I figured out how it's done in games, but it turns out I have no idea. This is what I have....
- import processing.core.*;
import java.awt.Robot;
public class FPSMouse extends PApplet {
public static void main(String args[]) {
PApplet.main(new String[] { "--present", "FPSMouse" });
}
int margin = 100;
Robot robot;
PFont f;
float rmx, rmy;
public void setup() {
size(displayWidth,displayHeight);
noCursor();
frameRate(1000);
f = createFont ("Arial",16,true);
println("height: "+displayHeight+" width: "+displayWidth);
try{ robot = new Robot(); }
catch(Throwable e){}
}
public void draw() {
background(204);
robot.mouseMove(frame.getX()+this.getX()+round(width/2),
frame.getY()+this.getY()+round(height/2));
rmx += mouseX-width/2;
rmy += mouseY-height/2;
rmx = rmx>=width/2+margin?width/2+margin:rmx;
rmx = rmx<=width/2-margin?width/2-margin:rmx;
rmy = rmy>=height/2+margin?height/2+margin:rmy;
rmy = rmy<=height/2-margin?height/2-margin:rmy;
if (rmx > width/2) { rmx-=1; }
else if (rmx < width/2) { rmx+=1; }
if (rmy > height/2) { rmy-=1; }
else if (rmy < height/2) { rmy+=1; }
noFill();
ellipse(rmx,rmy, 7,7);
textFont(f,16);
fill(0);
text("X: "+(rmx-(width/2))+", Y: "+(-(rmy-(height/2))),10,100);
text(((rmx-(width/2))/margin),10,150);
text((-(rmy-(height/2))/margin),10,165);
noFill();
rect(width/2+margin, height/2+margin,-(margin*2),-(margin*2),7);
}
public boolean sketchFullScreen() {
return true;
}
}
It's unresponsive and slow and just disappointing. Is there a better way of doing this? Thanks!
p.s. I'm using Eclipse, not the Processing IDE, in case you were wondering...
p.s. I'm using Eclipse, not the Processing IDE, in case you were wondering...
1