Mouse cursor

Hello,



How to change the appearance of the mouse cursor when the mouse is over an element?



Thank you

the cursor is hide when it is on the element and a picture following the cursor.

when I move the cursor quickly, the picture moves more slowly than the movement of the mouse!

ok, how do you update the position of your mouse picture?

the code



[java]

protected Node guiNode = new Node("Gui Node");



public void initialize()

{

modifiercurseur();



shootables = new Node("Shootables");

state.getRootNode().attachChild(shootables);

shootables.attachChild(Tableau1("Tableau1"));

}



public void update

{

// change cursor=================================================================

Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);

Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);

direction.subtractLocal(origin).normalizeLocal();



Ray ray = new Ray(origin, direction);

CollisionResults results = new CollisionResults();

shootables.collideWith(ray, results);



if (results.size() > 0)

{

CollisionResult closest = results.getClosestCollision();

curseurmodifier.setLocalTranslation(closest.getContactPoint());



Quaternion q = new Quaternion();

q.lookAt(closest.getContactNormal(), Vector3f.UNIT_Y);

curseurmodifier.setLocalRotation(q);

mouseInput.setCursorVisible(false);

state.getRootNode().attachChild(curseurmodifier);

}



else

{

state.getRootNode().detachChild(curseurmodifier);

mouseInput.setCursorVisible(true);

}

//=====================================================================================================



player.setWalkDirection(walkDirection);

cam.setLocation(player.getPhysicsLocation());

float tpf = timer.getTimePerFrame();

stateManager.update(tpf);

stateManager.render(renderManager);

renderManager.render(tpf);

}



// ==================================================================================================

// the cursor is hide when it is on this element

protected Spatial Tableau1(String name)

{

Spatial tableau1 = assetManager.loadModel("Tableaux/untitled.obj");

tableau1.move(-5f, 4.5f, 0.5f);

Quaternion quaternion = new Quaternion();

Vector3f axis = new Vector3f();

axis.set(90, 0, 0);

quaternion.fromAngleAxis(-55, axis);

tableau1.setLocalRotation(quaternion);

return tableau1;

}



// ==================================================================================================

protected void modifiercurseur()

{

Quad box = new Quad(0.6f,0.6f);

curseurmodifier = new Geometry("Box", box );

Material mat_brick = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

mat_brick.setTexture("ColorMap",assetManager.loadTexture("image2993.png"));

curseurmodifier.setMaterial(mat_brick);

}

}



[/java]

There is no built in way to do this.

Maybe look on the awt side to use the system cursors.



another way would be to have a picture in the gui viewport, and handle the display of the mouse yourself , in your application.

Ok thank you nehon



I use

[java]

if

{

mouseInput.setCursorVisible(false);

state.getRootNode().attachChild(Geometry geometry);

}

else

{

state.getRootNode().detachChild(Geometry geometry);

mouseInput.setCursorVisible(true));

}

[/java]



but the render is bad!

well…bad like what?

what’s the issue exactly?