Hi, guys:
Is there any way to set mouse cursor to a given position ?
I can Cam.lookat() but I need to set the cursor to the center.
Anyone knowe how?
Well, this question turns out to be :
Is lwjgl using java.awt or javafx ? Can I import and use java.awt in my project without any conflict with the engine ?
Could you please elaborate a little on what you are trying to do? That makes it easier to give good replies.
Just tried awt.robot and it works
Codes here :
CollisionResults results = new CollisionResults();
CollisionResults resultsc = new CollisionResults();
Vector2f click2d = inputManager.getCursorPosition().clone();
Vector3f click3d = cam.getWorldCoordinates(click2d, 0f).clone();
Vector3f click3dir= cam.getWorldCoordinates(click2d, 1f).subtractLocal(click3d).normalizeLocal();
Ray raym = new Ray(click3d,click3dir);
Ray rayc = new Ray(cam.getLocation(), cam.getDirection());
floorQ.collideWith(raym, results);
floorQ.collideWith(rayc, resultsc);
if(keys[201] && (results.size()>0)){
click3d = results.getClosestCollision().getContactPoint();
click3dir = resultsc.getClosestCollision().getContactPoint();
// cam.setLocation(cam.getLocation().add(click3d.subtract(click3dir)));
cam.lookAt(results.getClosestCollision().getContactPoint(), Vector3f.UNIT_Z);
theb.setLocalTranslation(results.getClosestCollision().getContactPoint());
helloText[1].setText("Centered"+results.size());
Robot rb = null;
try {
rb = new Robot();
} catch (AWTException ex) {
Logger.getLogger(SelectAppState.class.getName()).log(Level.SEVERE, null, ex);
}
// the screen resolution is 1366X768
rb.mouseMove(683,384);
keys[201] = false;
This code seems very strange… like a long way to go for a simple thing.
What is it that you are doing exactly?
Er…
I am not a prof. programer…
What I am doing is:
floorQ is a Quad and acts as a floor.
when mouseLeft clicked keys[201] will set true.
and Cam will turn to the position where the cursor pointed. --cam.lookAt() where axie Z is world up vector.
or cam can move to a new potion to set cursor in the center of screen. – cam.setLocation()
My problerm was I can turn the cam but cursor kept the old position on the screen.
It looks like cursor follows the cam instead of cam follows the cursor.
I use a boolean array to monitor inputs.
private Boolean keys[];
inputManager.addMapping("201", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addMapping("202", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
inputManager.addMapping("203", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
private final ActionListener actionListenerc = new ActionListener() { //ActionListener is a listener interface!
@Override
public void onAction(String name, boolean keyPressed, float tpf) {
keys[Integer.parseInt(name)] =keyPressed;
}
}
};
I know what the code is doing. I just don’t know why it’s doing it.
It looks like it’s doing a lot of work just to rotate the camera when you move the mouse. Which is something ALL of the standard camera controls do just fine without all of this work.