Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  3d lighting  (Read 488 times)
0 Members and 1 Guest are viewing this topic.
Offline Soljaragz

Junior Member





« Posted 2006-03-26 05:08:56 »

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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
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);
    }
}
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2006-03-26 05:44:05 »

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.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Soljaragz

Junior Member





« Reply #2 - Posted 2006-03-26 06:34:56 »

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
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Soljaragz

Junior Member





« Reply #3 - Posted 2006-03-26 19:29:00 »

nvm ^^ I figureded it out

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

JGO Coder




Got any cats?


« Reply #4 - Posted 2006-03-26 20:59:31 »

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.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (117 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.208 seconds with 20 queries.