Light attached to a node, not moving with it

I had a longer intro to my problem but I hit create topic and it had an error creating the topic so I lost what I typed.

Basically I was playing around and merging a few examples of lighting and terrain. I made a new node and attached a point light to it. When I move the node the light doesnt move with the node. Here is my code, please point out if I made any dumb mistakes.

thanks!

[java]

import com.jme3.light.DirectionalLight;

import com.jme3.light.PointLight;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Sphere;

import com.jme3.util.TangentBinormalGenerator;

import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.renderer.Camera;

import com.jme3.scene.Node;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import java.util.ArrayList;

import java.util.List;

import jme3tools.converters.ImageToAwt;

public class GBlur extends SimpleApplication

{

float angle;

PointLight pl;

Geometry lightMdl;

private TerrainQuad terrain;

Material mat_terrain;

Node orbit;

public static void main(String[] args)

{

GBlur app = new GBlur();

app.start();

}

@Override

public void simpleInitApp()

{

orbit = new Node("Orbit");

//orbit.setLocalTranslation(0, -15, 0);

flyCam.setMoveSpeed(50);

Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");

TangentBinormalGenerator.generate(teapot.getMesh(), true);

teapot.setLocalScale(2f);

Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");

// mat.selectTechnique("GBuf");

mat.setFloat("Shininess", 12);

mat.setBoolean("UseMaterialColors", true);

// mat.setTexture("ColorRamp", assetManager.loadTexture("Textures/ColorRamp/cloudy.png"));

//

// mat.setBoolean("VTangent", true);

// mat.setBoolean("Minnaert", true);

// mat.setBoolean("WardIso", true);

// mat.setBoolean("VertexLighting", true);

// mat.setBoolean("LowQuality", true);

// mat.setBoolean("HighQuality", true);

mat.setColor("Ambient", ColorRGBA.Black);

mat.setColor("Diffuse", ColorRGBA.Gray);

mat.setColor("Specular", ColorRGBA.Gray);

teapot.setMaterial(mat);

// rootNode.attachChild(teapot);

orbit.attachChild(teapot);

Geometry teapot2 = teapot.clone();

teapot2.setLocalTranslation(0, 2, 0);

teapot2.setLocalScale(5f);

teapot2.getMaterial().setColor("Diffuse", ColorRGBA.Orange);

// rootNode.attachChild(teapot2);

orbit.attachChild(teapot2);

lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));

lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));

lightMdl.getMesh().setStatic();

//rootNode.attachChild(lightMdl);

orbit.attachChild(lightMdl);

pl = new PointLight();

pl.setColor(ColorRGBA.Magenta);

pl.setRadius(40f);

//rootNode.addLight(pl);

orbit.addLight(pl);

DirectionalLight dl = new DirectionalLight();

dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());

dl.setColor(ColorRGBA.White);

rootNode.addLight(dl);

Node test = orbit.clone(true);

rootNode.attachChild(orbit);

rootNode.attachChild(test);

/** 1. Create terrain material and load four textures into it. /

mat_terrain = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");

/
* 1.1) Add ALPHA map (for red-blue-green coded splat textures) /

mat_terrain.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));

/
* 1.2) Add GRASS texture into the red layer (Tex1). /

Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex1", grass);

mat_terrain.setFloat("Tex1Scale", 64f);

/
* 1.3) Add DIRT texture into the green layer (Tex2) /

Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");

dirt.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex2", dirt);

mat_terrain.setFloat("Tex2Scale", 32f);

/
* 1.4) Add ROAD texture into the blue layer (Tex3) /

Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");

rock.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex3", rock);

mat_terrain.setFloat("Tex3Scale", 128f);

/
* 2. Create the height map /

AbstractHeightMap heightmap = null;

Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");

heightmap = new ImageBasedHeightMap(

ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));

heightmap.load();

/
* 3. We have prepared material and heightmap. Now we create the actual terrain:

  • 3.1) We create a TerrainQuad and name it "my terrain".
  • 3.2) A good value for terrain tiles is 64x64 – so we supply 64+1=65.
  • 3.3) We prepared a heightmap of size 512x512 – so we supply 512+1=513.
  • 3.4) As LOD step scale we supply Vector3f(1,1,1).
  • 3.5) At last, we supply the prepared heightmap itself.

    /

    terrain = new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap());

    /
    * 4. We give the terrain its material, position & scale it, and attach it. /

    terrain.setMaterial(mat_terrain);

    terrain.setLocalTranslation(0, -100, 0);

    terrain.setLocalScale(2f, 1f, 2f);

    rootNode.attachChild(terrain);

    /
    * 5. The LOD (level of detail) depends on were the camera is: */

    List<Camera> cameras = new ArrayList<Camera>();

    cameras.add(getCamera());

    TerrainLodControl control = new TerrainLodControl(terrain, cameras);

    terrain.addControl(control);

    }

    @Override

    public void simpleUpdate(float tpf)

    {

    // cam.setLocation(new Vector3f(2.0632997f, 1.9493936f, 2.6885238f));

    // cam.setRotation(new Quaternion(-0.053555284f, 0.9407851f, -0.17754152f, -0.28378546f));

    // try

    // {

    // //System.out.println("Light list0: "+orbit.getWorldLightList().get(0) );

    // //System.out.println("Light list1: "+orbit.getWorldLightList().get(1));

    orbit.setLocalTranslation(orbit.getLocalTranslation().add(new Vector3f(0, -tpf, 0)));

    // PointLight orbitlight = ((PointLight) orbit.getWorldLightList().get(0));

    // orbitlight.setPosition(orbit.getLocalTranslation().add(new Vector3f(0, -tpf, 0)));

    // System.out.println("setting Orbitnode" + orbit.getLocalTranslation());

    // System.out.println("setting orbitlight" + orbitlight.getPosition());

    // System.out.println();

    // }

    // catch (Exception e)

    // {

    // }

    angle += tpf;

    angle %= FastMath.TWO_PI;

    //0.5f

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 2f, -tpf, FastMath.sin(angle) * 2f));

    lightMdl.setLocalTranslation(pl.getPosition());

    }

    }

    [/java]

As far as I know, light attached to a node means that this light will affect only this node and its children. If you want to move a light you must set its local translation… :slight_smile:

PointLight doesnt have local translation, only setposition which I am setting

[java]

pl.setPosition(new Vector3f(FastMath.cos(angle) * 2f, -tpf, FastMath.sin(angle) * 2f));

[/java]



I am setting the node which contrains the light localTranslation.

[java]

orbit.setLocalTranslation(orbit.getLocalTranslation().add(new Vector3f(0, -tpf, 0)));

[/java]

Unless I’m wrong, apparently the light’s position is unaffected by it’s parent node transform?

if it were then you’d set pl’s position same as lightMdl’s local translation

but I think it’s called setPosition for that reason, that it’s not a localTranslaiton

pre type="java"






package org.jme3.tests;











import java.util.ArrayList;


import java.util.List;





import jme3tools.converters.ImageToAwt;





import com.jme3.app.SimpleApplication;


import com.jme3.light.DirectionalLight;


import com.jme3.light.PointLight;


import com.jme3.material.Material;


import com.jme3.math.ColorRGBA;


import com.jme3.math.FastMath;


import com.jme3.math.Vector3f;


import com.jme3.renderer.Camera;


import com.jme3.scene.Geometry;


import com.jme3.scene.Node;


import com.jme3.scene.shape.Sphere;


import com.jme3.terrain.geomipmap.TerrainLodControl;


import com.jme3.terrain.geomipmap.TerrainQuad;


import com.jme3.terrain.heightmap.AbstractHeightMap;


import com.jme3.terrain.heightmap.ImageBasedHeightMap;


import com.jme3.texture.Texture;


import com.jme3.texture.Texture.WrapMode;


import com.jme3.util.TangentBinormalGenerator;











public class GBlur


extends


SimpleApplication


{





float angle;


PointLight pl;


Geometry lightMdl;


private TerrainQuad terrain;


Material mat_terrain;


Node orbit;








public static


void


main(


String[] args )


{


GBlur app =


new GBlur();


app.start();


}








@Override


public


void


simpleInitApp()


{


orbit =


new Node(


“Orbit” );


// orbit.setLocalTranslation(0, -15, 0);


flyCam.setMoveSpeed( 50 );


Geometry teapot =


(Geometry)assetManager.loadModel( “Models/Teapot/Teapot.obj” );


TangentBinormalGenerator.generate(


teapot.getMesh(),


true );


teapot.setLocalScale( 2f );


Material mat =


new Material(


assetManager,


“Common/MatDefs/Light/Lighting.j3md” );


// mat.selectTechnique(“GBuf”);


mat.setFloat(


“Shininess”,


12 );


mat.setBoolean(


“UseMaterialColors”,


true );


// mat.setTexture(“ColorRamp”, assetManager.loadTexture(“Textures/ColorRamp/cloudy.png”));


//


// mat.setBoolean(“VTangent”, true);


// mat.setBoolean(“Minnaert”, true);


// mat.setBoolean(“WardIso”, true);


// mat.setBoolean(“VertexLighting”, true);


// mat.setBoolean(“LowQuality”, true);


// mat.setBoolean(“HighQuality”, true);


mat.setColor(


“Ambient”,


ColorRGBA.Black );


mat.setColor(


“Diffuse”,


ColorRGBA.Gray );


mat.setColor(


“Specular”,


ColorRGBA.Gray );


teapot.setMaterial( mat );


// rootNode.attachChild(teapot);


orbit.attachChild( teapot );


Geometry teapot2 =


teapot.clone();


teapot2.setLocalTranslation(


0,


2,


0 );


teapot2.setLocalScale( 5f );


teapot2.getMaterial().setColor(


“Diffuse”,


ColorRGBA.Orange );


// rootNode.attachChild(teapot2);


orbit.attachChild( teapot2 );


lightMdl =


new Geometry(


“Light”,


new Sphere(


10,


10,


0.1f ) );


lightMdl.setMaterial( assetManager.loadMaterial( “Common/Materials/RedColor.j3m” ) );


lightMdl.getMesh().setStatic();


// rootNode.attachChild(lightMdl);


orbit.attachChild( lightMdl );


pl =


new PointLight();


pl.setColor( ColorRGBA.Magenta );


pl.setRadius( 40f );


// rootNode.addLight(pl);


orbit.addLight( pl );


DirectionalLight dl =


new DirectionalLight();


dl.setDirection( new Vector3f(


-1,


-1,


-1 ).normalizeLocal() );


dl.setColor( ColorRGBA.White );


rootNode.addLight( dl );


Node test =


orbit.clone( true );


// Node test2 =


// test.clone( true );


rootNode.attachChild( orbit );


rootNode.attachChild( test );


// test2.setLocalTranslation(


// -10,


// 0,


// 0 );


// rootNode.attachChild( test2 );


/** 1. Create terrain material and load four textures into it. /


mat_terrain =


new Material(


assetManager,


“Common/MatDefs/Terrain/Terrain.j3md” );


/
* 1.1) Add ALPHA map (for red-blue-green coded splat textures) /


mat_terrain.setTexture(


“Alpha”,


assetManager.loadTexture( “Textures/Terrain/splat/alphamap.png” ) );


/
* 1.2) Add GRASS texture into the red layer (Tex1). /


Texture grass =


assetManager.loadTexture( “Textures/Terrain/splat/grass.jpg” );


grass.setWrap( WrapMode.Repeat );


mat_terrain.setTexture(


“Tex1”,


grass );


mat_terrain.setFloat(


“Tex1Scale”,


64f );


/
* 1.3) Add DIRT texture into the green layer (Tex2) /


Texture dirt =


assetManager.loadTexture( “Textures/Terrain/splat/dirt.jpg” );


dirt.setWrap( WrapMode.Repeat );


mat_terrain.setTexture(


“Tex2”,


dirt );


mat_terrain.setFloat(


“Tex2Scale”,


32f );


/
* 1.4) Add ROAD texture into the blue layer (Tex3) /


Texture rock =


assetManager.loadTexture( “Textures/Terrain/splat/road.jpg” );


rock.setWrap( WrapMode.Repeat );


mat_terrain.setTexture(


“Tex3”,


rock );


mat_terrain.setFloat(


“Tex3Scale”,


128f );


/
* 2. Create the height map */


AbstractHeightMap heightmap =


null;


Texture heightMapImage =


assetManager.loadTexture( “Textures/Terrain/splat/mountains512.png” );


heightmap =


new ImageBasedHeightMap(


ImageToAwt.convert(


heightMapImage.getImage(),


false,


true,


0 ) );


heightmap.load();


/**

    1. We have prepared material and heightmap. Now we create the actual terrain:

  • 3.1) We create a TerrainQuad and name it “my terrain”.

  • 3.2) A good value for terrain tiles is 64x64 – so we supply 64+1=65.

  • 3.3) We prepared a heightmap of size 512x512 – so we supply 512+1=513.

  • 3.4) As LOD step scale we supply Vector3f(1,1,1).

  • 3.5) At last, we supply the prepared heightmap itself.


    /


    terrain =


    new TerrainQuad(


    “my terrain”,


    65,


    513,


    heightmap.getHeightMap() );


    /
    * 4. We give the terrain its material, position & scale it, and attach it. /


    terrain.setMaterial( mat_terrain );


    terrain.setLocalTranslation(


    0,


    -100,


    0 );


    terrain.setLocalScale(


    2f,


    1f,


    2f );


    rootNode.attachChild( terrain );


    /
    * 5. The LOD (level of detail) depends on were the camera is: */


    List cameras =


    new ArrayList();


    cameras.add( getCamera() );


    TerrainLodControl control =


    new TerrainLodControl(


    terrain,


    cameras );


    terrain.addControl( control );


    }








    @Override


    public


    void


    simpleUpdate(


    float tpf )


    {


    // cam.setLocation(new Vector3f(2.0632997f, 1.9493936f, 2.6885238f));


    // cam.setRotation(new Quaternion(-0.053555284f, 0.9407851f, -0.17754152f, -0.28378546f));


    // try


    // {


    // //System.out.println("Light list0: "+orbit.getWorldLightList().get(0) );


    // //System.out.println("Light list1: "+orbit.getWorldLightList().get(1));


    orbit.setLocalTranslation( orbit.getLocalTranslation().add(


    new Vector3f(


    2 * tpf,


    -tpf,


    -5

  • tpf ) ) );


    // PointLight orbitlight = ((PointLight) orbit.getWorldLightList().get(0));


    // orbitlight.setPosition(orbit.getLocalTranslation().add(new Vector3f(0, -tpf, 0)));


    // System.out.println(“setting Orbitnode” + orbit.getLocalTranslation());


    // System.out.println(“setting orbitlight” + orbitlight.getPosition());


    // System.out.println();


    // }


    // catch (Exception e)


    // {


    // }


    angle +=


    tpf;


    angle %=


    FastMath.TWO_PI;


    // 0.5f


    // light’s position is unaffected by it’s parent node?!!


    pl.setPosition( new Vector3f(


    orbit.getLocalTranslation().getX()

  • FastMath.cos( angle )

  • 2f,


    orbit.getLocalTranslation().getY(),


    orbit.getLocalTranslation().getZ()

  • FastMath.sin( angle )

  • 2f ) );


    lightMdl.setLocalTranslation( new Vector3f(


    FastMath.cos( angle ) * 2f,


    0,


    FastMath.sin( angle ) * 2f ) );


    }


    }



    /pre

    but then this means in the above example that if you replace the line:

    rootNode.attachChild( orbit );

    with:

    pre type="java"
    Node n =new Node();


    n.attachChild( orbit );


    n.setLocalTranslation(-4,5,6 );


    rootNode.attachChild( n );
    /pre

    the pl’s position will no longer be right, to fix use orbit.getWorldTranslation() inside pl.setPosition

    pre type="java"
    pl.setPosition( new Vector3f(


    orbit.getWorldTranslation().getX()

  • FastMath.cos( angle )

  • 2f,


    orbit.getWorldTranslation().getY(),


    orbit.getWorldTranslation().getZ()

  • FastMath.sin( angle )

  • 2f ) );
    /pre

    sorry about the indentation

mhhh…I could have swore we had a LightNode, but can’t find it…lol…this has to be done…



Lights are not part of the scene graph, when you “attach” a light to a Node, you just say “this light light this node and its children”.



To make a light part of the scene graph (and thus make it move with its parent node) you would need to attach it to a LightNode.

But…this does not exists :p.

Really, it’s exactly like a CameraNode, but with a light instead of a camera, it’s a Node, with a control that transforms the light with the Node transform.

@nehon but it does light everything else, even if not part of the node , or so it seems

You say that if the light is inside a Node it would not light ie. object in the parent of that Node?

pNode->node2->teapot

pNode->node2->light

pNode->teapot2



teapot2 is not lit by node2->light ?

I mean, after LightNode is implemented.

cyuczieekc said:
teapot2 is not lit by node2->light ?

No it doesn't.

really the LightNode just allow you to move the light according to it's parent, but the light can be set on the rootNode.
ie (pseudo code)
[java]
PointLight light = new PointLight ();
rootNode.attachLight(light);
Node torchNode=assetManager.loadSomeTorchModel();
LightNode lightNode=new LightNode(light);
torchNode.attachChild(lightNode);
rootNode.attachChild(torchNode);
[/java]
this will result, i a torch model with a lightNode attached on it. The light will move with the torch model...but, since it's set to light the rootNode, it will lit anything that is in it's light radius.
1 Like

that didn’t work

EDIT: I should’ve been more specific PointLight.setPosition takes world coords, instead of local

[java]pl.setPosition(lightMdl.getWorldTranslation());[/java]


scrubalub said:
that didn't work

You mean this? seems to work for me, on the moving teapot that is
http://i.imgur.com/P255M.jpg
`pre type="java"`
package org.jme3.tests;



import java.util.ArrayList;

import java.util.List;

import jme3tools.converters.ImageToAwt;

import com.jme3.app.SimpleApplication;

import com.jme3.light.DirectionalLight;

import com.jme3.light.PointLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Sphere;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import com.jme3.util.TangentBinormalGenerator;



public class GBlur extends SimpleApplication {

float angle;

PointLight pl;

Geometry lightMdl;

private TerrainQuad terrain;

Material mat_terrain;

Node orbit;



public static void main(String[] args) {

GBlur app = new GBlur();

app.start();

}



@Override

public void simpleInitApp() {

orbit = new Node("Orbit");

// orbit.setLocalTranslation(0, -15, 0);

flyCam.setMoveSpeed(50);

Geometry teapot = (Geometry) assetManager

.loadModel("Models/Teapot/Teapot.obj");

TangentBinormalGenerator.generate(teapot.getMesh(), true);

teapot.setLocalScale(2f);

Material mat = new Material(assetManager,

"Common/MatDefs/Light/Lighting.j3md");

// mat.selectTechnique("GBuf");

mat.setFloat("Shininess", 12);

mat.setBoolean("UseMaterialColors", true);

// mat.setTexture("ColorRamp",

// assetManager.loadTexture("Textures/ColorRamp/cloudy.png"));

//

// mat.setBoolean("VTangent", true);

// mat.setBoolean("Minnaert", true);

// mat.setBoolean("WardIso", true);

// mat.setBoolean("VertexLighting", true);

// mat.setBoolean("LowQuality", true);

// mat.setBoolean("HighQuality", true);

mat.setColor("Ambient", ColorRGBA.Black);

mat.setColor("Diffuse", ColorRGBA.Gray);

mat.setColor("Specular", ColorRGBA.Gray);

teapot.setMaterial(mat);

// rootNode.attachChild(teapot);

orbit.attachChild(teapot);

Geometry teapot2 = teapot.clone();

teapot2.setLocalTranslation(0, 2, 0);

teapot2.setLocalScale(5f);

teapot2.getMaterial().setColor("Diffuse", ColorRGBA.Orange);

// rootNode.attachChild(teapot2);

orbit.attachChild(teapot2);

lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));

lightMdl.setMaterial(assetManager

.loadMaterial("Common/Materials/RedColor.j3m"));

lightMdl.getMesh().setStatic();

// rootNode.attachChild(lightMdl);

orbit.attachChild(lightMdl);

pl = new PointLight();

pl.setColor(ColorRGBA.Magenta);

pl.setRadius(40f);

// rootNode.addLight(pl);

orbit.addLight(pl);

DirectionalLight dl = new DirectionalLight();

dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());

dl.setColor(ColorRGBA.White);

rootNode.addLight(dl);

Node test = orbit.clone(true);

// Node test2 =

// test.clone( true );

// rootNode.attachChild(orbit);

Node n = new Node();

n.attachChild(orbit);

n.setLocalTranslation(-4, 5, 6);

rootNode.attachChild(n);

rootNode.attachChild(test);

// test2.setLocalTranslation(

// -10,

// 0,

// 0 );

// rootNode.attachChild( test2 );

/** 1. Create terrain material and load four textures into it. */

mat_terrain = new Material(assetManager,

"Common/MatDefs/Terrain/Terrain.j3md");

/** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */

mat_terrain

.setTexture("Alpha", assetManager

.loadTexture("Textures/Terrain/splat/alphamap.png"));

/** 1.2) Add GRASS texture into the red layer (Tex1). */

Texture grass = assetManager

.loadTexture("Textures/Terrain/splat/grass.jpg");

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex1", grass);

mat_terrain.setFloat("Tex1Scale", 64f);

/** 1.3) Add DIRT texture into the green layer (Tex2) */

Texture dirt = assetManager

.loadTexture("Textures/Terrain/splat/dirt.jpg");

dirt.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex2", dirt);

mat_terrain.setFloat("Tex2Scale", 32f);

/** 1.4) Add ROAD texture into the blue layer (Tex3) */

Texture rock = assetManager

.loadTexture("Textures/Terrain/splat/road.jpg");

rock.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex3", rock);

mat_terrain.setFloat("Tex3Scale", 128f);

/** 2. Create the height map */

AbstractHeightMap heightmap = null;

Texture heightMapImage = assetManager

.loadTexture("Textures/Terrain/splat/mountains512.png");

heightmap = new ImageBasedHeightMap(ImageToAwt.convert(

heightMapImage.getImage(), false, true, 0));

heightmap.load();

/**

* 3. We have prepared material and heightmap. Now we create the actual

* terrain: 3.1) We create a TerrainQuad and name it "my terrain". 3.2)

* A good value for terrain tiles is 64x64 -- so we supply 64+1=65. 3.3)

* We prepared a heightmap of size 512x512 -- so we supply 512+1=513.

* 3.4) As LOD step scale we supply Vector3f(1,1,1). 3.5) At last, we

* supply the prepared heightmap itself.

*/

terrain = new TerrainQuad("my terrain", 65, 513,

heightmap.getHeightMap());

/**

* 4. We give the terrain its material, position & scale it, and attach

* it.

*/

terrain.setMaterial(mat_terrain);

terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(2f, 1f, 2f);

rootNode.attachChild(terrain);

/** 5. The LOD (level of detail) depends on were the camera is: */

List cameras = new ArrayList();

cameras.add(getCamera());

TerrainLodControl control = new TerrainLodControl(terrain, cameras);

terrain.addControl(control);

}



@Override

public void simpleUpdate(float tpf) {

// cam.setLocation(new Vector3f(2.0632997f, 1.9493936f, 2.6885238f));

// cam.setRotation(new Quaternion(-0.053555284f, 0.9407851f,

// -0.17754152f, -0.28378546f));

// try

// {

// //System.out.println("Light list0: "+orbit.getWorldLightList().get(0)

// );

// //System.out.println("Light list1: "+orbit.getWorldLightList().get(1));

orbit.setLocalTranslation(orbit.getLocalTranslation().add(

new Vector3f(2 * tpf, -tpf, -5 * tpf)));

// PointLight orbitlight = ((PointLight)

// orbit.getWorldLightList().get(0));

// orbitlight.setPosition(orbit.getLocalTranslation().add(new

// Vector3f(0, -tpf, 0)));

// System.out.println("setting Orbitnode" +

// orbit.getLocalTranslation());

// System.out.println("setting orbitlight" + orbitlight.getPosition());

// System.out.println();

// }

// catch (Exception e)

// {

// }

angle += tpf;

angle %= FastMath.TWO_PI;

// 0.5f

// light's position is unaffected by it's parent node?!!

// pl.setPosition(new Vector3f(orbit.getLocalTranslation().getX()

// + FastMath.cos(angle) * 2f, orbit.getLocalTranslation().getY(),

// orbit.getLocalTranslation().getZ() + FastMath.sin(angle) * 2f));

pl.setPosition(new Vector3f(orbit.getWorldTranslation().getX()

+ FastMath.cos(angle) * 2f, orbit.getWorldTranslation().getY(),

orbit.getWorldTranslation().getZ() + FastMath.sin(angle) * 2f));

lightMdl.setLocalTranslation(new Vector3f(FastMath.cos(angle) * 2f, 0,

FastMath.sin(angle) * 2f));

}

}
`/pre`
or even better:
`pre type="java"`
lightMdl.setLocalTranslation(new Vector3f(FastMath.cos(angle) * 2f, 0,

FastMath.sin(angle) * 2f));

pl.setPosition(lightMdl.getWorldTranslation());
`/pre`

[java]

lightMdl.setLocalTranslation(new Vector3f(FastMath.cos(angle) * 2f, 0,

FastMath.sin(angle) * 2f));

pl.setPosition(lightMdl.getWorldTranslation());[/java]



I understand what I was doing wrong now. Thanks for posting this snippet.



I was trying to set the lightmdl to the position of the light, but I should of been doing whats cited above. (Moving the lightmodel then setting the light to that position

1 Like

Ok, check last SVN revision, i added LightNode.

Look at TestLightNode for en example on how to use it.

1 Like