[SOLVED] Camera Node and Spot Light and Mouse Cursor - How?

I have “drag’n’drop” camera made using camera node (which means my mouse cursor is visible and I can move it around screen and when I keep LMB pressed i move screen around X, Y along with cursor).

What I need now is 2 spotlights:

  • 1 attached to the mouse cursor itself (so it enlightens objects the cursor is pointing at),
  • 1 attached to the camera (so it enlightens everything near the middle of my view),

How do I do that?

Thanks in advance for help.

You move the light along with the cursor and the camera.

Yeah, that’s the whole idea… How?

using setPositon and setDirection on the light.

That’s what I was afraid of… Mirroring camera or cursor movements…

Can’t this be done by attaching light to a node? Can’t I use something like Light Node (I found this thing somewhere but seems to be working with Point Light and not with Spot Light - unless I do something wrong of course).

What do you think these do? :chimpanzee_smile:

These what? Monkey emoticon? No idea :stuck_out_tongue:

Seriously I have no idea what You’re talking about, please elaborate… I’m a simple person…

I did something like this:

SpotLight spot = new SpotLight();
spot.setSpotRange(100f);                           // distance
spot.setSpotInnerAngle(15f * FastMath.DEG_TO_RAD); // inner light cone (central beam)
spot.setSpotOuterAngle(35f * FastMath.DEG_TO_RAD); // outer light cone (edge of the light)
spot.setColor(ColorRGBA.White.mult(1.3f));         // light color
spot.setDirection(new Vector3f(0f,0f,-1f));
rootNode.addLight(spot);
LightNode lightNode=new LightNode("spotLight", spot);
cameranode.attachChild(lightNode);

but I don’t see any light.

The CameraNode. They do exactly the same thing, updating the position each frame. If you do your own Control that does the movement you can further configure them to your liking.

If you attach the light to a Node it will only affect children of that Node.

As I hope You see in my code I didn’t. I used
http://jmonkeyengine.googlecode.com/svn/trunk/engine/src/test/jme3test/light/TestLightNode.java
and attached my light to the root node, then referenced it in the Light Node. And as I wrote before - I don’t see a light. It worked with Point Light though…

in a Control update method:

light.setPosition(cursor.getWorldLocation());
light.setDirection(cursor.getWorldRotation().mult(Vector3f.UNIT_Z));

or for the camera:
light.setPosition(cam.getLocation());
light.setDirection(cam.getDirection());

And for a Camera Node? Because getLocation/getDirection doesn’t work for Camera Node. Or for any other node for that matter, because having “guys with spotlights” would be usefull in a future anyway…

Same as the code for the cursor but why use a camera node when you have a camera?

a) Because that’s the only way of custom camera controls that someone was nice enough to present to me in details in another topic some time ago. I’m new to this 3d stuff so for now I’m basing everything on the few tutorials available and nice poeple on the forums :smile:
b) Because of the ability to attach objects to that “Camera” in the future.

[EDIT] Great thanks, it works in init (I see a light) so it probably will work in update loop as well :smile: Btw. it seems to be WorldTranslation not WorldLocation. As for cursor - how You do that? I mean there seems to be no default object like “cursor” in Jmonkey…

But if you have a CameraNode you have a Camera…

Funny thing - Light pushed into update loop have this strange effect of “painting” over the objects. Permanently! I mean wherever it goes becomes white but doesn’t become normal when I point light in different direction… What’s going on?

[EDIT] False alarm - I managed to get rid of this effect by decalring light outside any function and splitting it’s code between init and update.

[EDIT 2] Af for cursor position there is little trouble. I tried to use inputManager.getCursorPosition() but it’s output is 2f vector, and setPosition requires 3f vector. How do I marry those two? I found some conversion method on the tutorials but they wont work because they use cam (default FPS camera) to get world position. In my case mouse cursor and camera move separately…

Sooo… Mouse coordinates without the use of default FlyByCamera… Anyone?

Imagine a RTS game with mouse cursor enlighting the area on the ground… That would be it…

I dont know about normen, but I am not sure on what you want.
You want an headlamp ? Or you want the ray intersection of your mouse to be an lamp ?
If its the fist case, attach the lamp to the camera Node.
In the second case, use rays intersection, there is an example how to do it in the test cases.

Pls. don’t think in FPS camera terms. As for Your question the answer is: neither. I need free moving mouse cursor (which I already have simply by disabling default FlyByCamera) to be the lamp. Where cursor is there should be light. Cursor moves, light folows, camera stays stationary. That’s what I need.

And all examples out there assume either FPS or TPS both of which are useless to me.

Problem is that built-in function to get mouse coordinates gives numbers in screen-relative scale (2 dimensions) and I need 3d world-relative mouse coordinates. Need to translate one to the other (based only on cursor location).

So I presume you have to first translate cursor screen coordinates into your scene coordinates and then point light onto those you got?

Everything you need is in the wiki:http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:mouse_picking

Take a look at Pick a Target Using the Mouse Pointer