Hi, i'm gonna posting the entire code of a really simple class. In this class i have a cameraNode to move in the scene, load a 3DS model and try to set a light. The problem is that the light always moves with the camera and never stays in a fixed position and i don't know how to do that.
So my questions are:
1)Can anybody make changes to the code so i have a fixed light instead of a "following light"?
2)Can anybody show me how could i use a lightNode instead of a setRenderState(lightState)?
3)Is there a way to assign a name to a 3d model loaded so i can check the getTargetMesh on a PickResult?
Here is the code (i'm pretty sure that the problem is located only in the initGame method, so you may skip the rest of the code).
Remember i load a 3d model so if you run it you must change the line to load a 3ds model of yours!
/**
* Tutorial 2 shows how to build our own Application framework for Flag Rush.
* For Flag Rush Tutorial Series.
*
* @author Mark Powell
*/
public class SimpleExample extends BaseGame {
I can use both LightNode and SimpleLightNode to achive correct results in my own classes.
I don't do anything very different than you.
But when I take your code and make a class in my IDE from it, it shows lots of deprecated API calls and some unknown classes. Maybe your copy of jME is outdated or maybe you are using outdated commands with the current version.
We had a similar discussion before, in this thread:
Deprecated methods? Strange! I've downloaded jme v0.9 no more than 3 weeks ago!
I know that a directional light comes with parallalels rays, and this is exactly what i want, but i would like that the light always come from one absolute direction to another fixed absolute direction (for example to x=-1,y=-1,z=-1) also if i rotate the camera.
In my code, if i rotate the cameraNode, light follows my rotation!! By this way, for example, i can never see the "black" side of my object, because lightState always lights my object!
Can anybody show me how to get that light direction fixed, also if i rotate the camera node?
My english is poor, i know, so i hope i have explained exactly what i need!
there are many changes all over the time. the newest version is in the cvs.
but if you only download the 0.9 release you should not have problems now.
EDIT: the old GUI-system (Hudpanels etc.) has been dropped completely - do not learn it!
But I also have 2 possible solutions for you:
one solution:
here is a snipped of code, that I use normally, test it
(it is similar to yours, but uses SimpleLightNode class instead of LightNode):
//create a light
DirectionalLight pl=new DirectionalLight();
//color the light white
pl.setDiffuse(ColorRGBA.white);
pl.setSpecular(ColorRGBA.white);
pl.setAmbient(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
//enable the light
pl.setEnabled(true);
//configure the light state
LightState globalLight = display.getRenderer().createLightState();
globalLight.setEnabled(true);
globalLight.detachAll();
globalLight.attach(pl);
//This node will hold my light
SimpleLightNode ln = new SimpleLightNode("A node for my light",pl);
//set the lightstate for the scene (used the root node from SimpleGame)
rootNode.attachChild(ln);
rootNode.setRenderState(globalLight);
//remark: you can translate and rotate the light node "ln" now...
//translations will work with point light / spot light only
//rotations will work with spot light / directional light only
rootNode.updateRenderState();
another solution:
There is a method "setDirection(Vector3f direction)" in DirectionalLight.
Try to pass some vectors into the method to play around and experiment with the method.