3d lighting

well i read this source code that had the lighting done pretty good
but it was kind of hard to understand ( not the lighting part, but everything else )

so I wrote my own program but using the lighting part of the source code, and…my lighting doesnt work.

this is my class code for the geometry + lighting part


GeometryInfo gf = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
		gf.setTextureCoordinateParams(1,2);
		gf.setTextureCoordinates(0,txt);
		gf.setStripCounts(strips);
		gf.setCoordinates(pts);
		gf.setContourCounts(contours);
		
		NormalGenerator ng = new NormalGenerator();
		ng.setCreaseAngle ((float) Math.toRadians(30));
		ng.generateNormals(gf);
		
		Appearance app = new Appearance();
		Material mat = new Material();
		mat.setShininess(0.01f);
		mat.setEmissiveColor(0.0f, 0.0f, 0.0f);
		mat.setAmbientColor(0.1f, 0.1f, 0.1f);
		app.setMaterial(mat);
		
		try{

		TextureLoader txtLoader = new TextureLoader(new java.net.URL(texture),null);
		Texture2D textImg = (Texture2D) txtLoader.getTexture();
		TextureAttributes texatt=new TextureAttributes(TextureAttributes.BLEND, new Transform3D(), new Color4f(1.0f, 1.0f, 1.0f, 1.0f), TextureAttributes.NICEST);
		app.setTextureAttributes(texatt);
		app.setTexture(textImg);
		}catch(java.net.MalformedURLException e){
			System.out.println("he");
		}
		setGeometry(gf.getGeometryArray());
		setAppearance(app);

and this is the tester class that I use for both the other source code and my code.

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.vp.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class LandTest extends Applet
{
	SimpleUniverse u;
	BoundingSphere bounds;
	ViewingPlatform ourView;
	OrbitBehavior B;
	
	public void init()
	{
		setLayout(new BorderLayout());
		GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
		Canvas3D c = new Canvas3D(config);
		u = new SimpleUniverse(c);
		BranchGroup scene = createSceneGraph();
		u.addBranchGraph(scene);
		
		ourView = u.getViewingPlatform();
		ourView.setNominalViewingTransform();
		
		B = new OrbitBehavior(c);
		B.setSchedulingBounds(bounds);
		ourView.setViewPlatformBehavior(B);
		
		add("Center",c);
	}

    public BranchGroup createSceneGraph() 
    {
      	BranchGroup objRoot = new BranchGroup();
		bounds = new BoundingSphere();
		
		String texturePath="file://localhost/"+System.getProperty("user.dir")+"/stone.jpg";
		
		Land s = new Land(6, 6, texturePath);
		
		Color3f alColour = new Color3f(0.4f, 0.4f, 0.4f);
		AmbientLight aLgt = new AmbientLight(alColour);
		aLgt.setInfluencingBounds(bounds);
		
		Color3f DirColour = new Color3f(0.35f, 0.35f, 0.3f);
		Vector3f DirVec = new Vector3f(0.5f, -0.2f, 0.6f);
		
		
		DirectionalLight DirLig = new DirectionalLight(DirColour, DirVec);
		DirLig.setInfluencingBounds(bounds);
		
		
		objRoot.addChild(DirLig);
		objRoot.addChild(aLgt);
		objRoot.addChild(s);
		objRoot.compile();
		return objRoot;
	}
	

    public static void main(String[] args) {
        new MainFrame(new LandTest(), 256, 256);
    }
}

Dont really have time to examien your code ind etail but here are a few standard problems:

(1) Make sure you have peoper normals on your geometry.

(2) Make sure you have a proper activation bounds on your light.

ugh, i is really beginner

for (1) I just tried random normal values because i dont really know much about normals (0,10,30,60,120,270) and it didnt work
SO can you tell me what radian means??? i guess that would help alot, and HOW DO YOU CALCULATE THE APPROPRIATE RADIAN

for(2) im pretty sure its not that, sinc it works with the other object

nvm ^^ I figureded it out

but can someone tell me how to determine the radian for NormalGenerator

The fold angle for the normal generator is how extreme the difference in normals between 2 planes has to be to be considered a hard fold and not smoothed out. At one extreme, it would look “flat shaded” because every traignmle would be treated as a flat facet. At the other extreme, everything would be smoothed out and there would be no sharp edges anywhere.

FInding the “right” one rally depends on your data and the look youa re trying to accomplish.

I use 2 different oens in JNWN one for “organic shapes” that rounds everything bu the msot exctreme angles and one for “inorganic shapes” that makes most triangle to triangle joins hard-edges.