Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 661 times)
0 Members and 1 Guest are viewing this topic.
Offline Soljaragz

Junior Member





« Posted 2006-03-26 03: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 03: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 04: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!
Legends of Yore - The Casual Retro Roguelike
Offline Soljaragz

Junior Member





« Reply #3 - Posted 2006-03-26 17: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 18: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.

 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (26 views)
2014-09-07 01:10:19

mitcheeb (34 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!