Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (540)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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  
  Shadow volume sweetness  (Read 4585 times)
0 Members and 1 Guest are viewing this topic.
Offline Java Cool Dude

Senior Devvie




Java forever


« Posted 2003-08-07 02:51:28 »

http://www.realityflux.com/abba/shadow_volumes.jpg

Source coming soon ^_^
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #1 - Posted 2003-08-07 23:51:49 »

http://www.realityflux.com/abba/fix_it_plz.jpg

Can someone help me getting rid of what I shall point out as "low_poygon_selfshading_model_syndrome"?

Btw this is the class I use to cast em shadows
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  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
import net.java.games.jogl.GL;
import java.io.IOException;

public class model_3D
{
  load_model loader;
  jcd_math.point3f  vertices[],
                    color;
  jcd_math.vec3f    normals[],
                    location,
                    light;

  face       faces[];
  edge       edges[];

  int        display_list_silhouette,
             display_list_model,
             edge_count;
  GL         gl;

  model_3D(load_model loader, GL gl, jcd_math.point3f color,
           String model, jcd_math.vec3f light,jcd_math.vec3f location){

    this.location = location;
    this.loader = loader;
    this.light  = new jcd_math.vec3f(light);
    this.color  = new jcd_math.point3f(color);
    this.gl     = gl;
    relative_light_position();
    load_model(model);
  }

  void relative_light_position(){
    light.sub(location);
  }
  void load_model(String model){

    try{
      loader.load_file(model, this);
    }
    catch(IOException e){}
    create_displayable_model();
    edge_count  = construct_edges();
   }

  void draw_model(){
    gl.glPushMatrix();
    gl.glTranslatef(location.x,location.y,location.z);
    gl.glColor3f(color.x,color.y,color.z);
    gl.glCallList(display_list_model);
    gl.glEndList();
    gl.glPopMatrix();
  }

  void create_displayable_model(){

    gl.glNewList((display_list_model=gl.glGenLists(1)),gl.GL_COMPILE);
    gl.glBegin(gl.GL_TRIANGLES);
    for(int i =0; i< faces.length; i++){
      gl_vertex_normal(i, 2);
      gl_vertex_normal(i, 1);
      gl_vertex_normal(i, 0);
    }

    gl.glEnd();
    gl.glEndList();

    for(int i =0; i<faces.length; i++)
      if(light.Dot(faces[i].normal) + faces[i].D>0)
        faces[i].visible = true;
      else
        faces[i].visible = false;
  }

  void gl_vertex_normal(int face_index, int index){

    gl.glNormal3f(normals[faces[face_index].indices[index]].x,
                  normals[faces[face_index].indices[index]].y,
                  normals[faces[face_index].indices[index]].z);
    set_vertex(vertices[faces[face_index].indices[index]]);
  }

  void set_vertex(jcd_math.point3f p){
    gl.glVertex3f(p.x,p.y,p.z);
  }

  int construct_edges(){

    int edge_progress = 0,
        edge_count    = 0;

    edges = new edge[faces.length*3];

    for(int a = 0; a < faces.length; a++){

      int  i1 = faces[a].indices[0],
           i2 = faces[a].indices[1],
           i3 = faces[a].indices[2];

      if(i1 < i2){
        edges[edge_progress] = new edge();
        edges[edge_progress].indices[0] = i1;
        edges[edge_progress].indices[1] = i2;
        edges[edge_progress].parents[0] = a;
        edges[edge_progress].parents[1] = -1;
        edge_count++;
        edge_progress++;
      }

      if(i2 < i3){
        edges[edge_progress] = new edge();
        edges[edge_progress].indices[0] = i2;
        edges[edge_progress].indices[1] = i3;
        edges[edge_progress].parents[0] = a;
        edges[edge_progress].parents[1] = -1;
        edge_count++;
        edge_progress++;
      }

      if(i3 < i1){
        edges[edge_progress] = new edge();
        edges[edge_progress].indices[0] = i3;
        edges[edge_progress].indices[1] = i1;
        edges[edge_progress].parents[0] = a;
        edges[edge_progress].parents[1] = -1;
        edge_count++;
        edge_progress++;
      }
    }

    for(int a = 0; a < faces.length; a++){

      int  i1 = faces[a].indices[0],
           i2 = faces[a].indices[1],
           i3 = faces[a].indices[2];

      if(i1 > i2)
        for(int b = 0; b < edge_count; b++)
          if((edges[b].indices[0] == i2) &&
             (edges[b].indices[1] == i1) &&
             (edges[b].parents[1] == -1)){
            edges[b].parents[1] = a;
            break;
          }

      if(i2 > i3)
        for(int b = 0; b < edge_count; b++)
          if((edges[b].indices[0] == i3) &&
             (edges[b].indices[1] == i2) &&
             (edges[b].parents[1] == -1)){
            edges[b].parents[1] = a;
            break;
          }

      if(i3> i1)
        for(int b = 0; b < edge_count; b++)
          if((edges[b].indices[0] == i1) &&
             (edges[b].indices[1] == i3) &&
             (edges[b].parents[1] == -1)){
            edges[b].parents[1] = a;
            break;
          }
    }

   return edge_count;
  }

  void cast_shadow(){

    for(int i =0; i<edge_count; i++)
       edges[i].reset();

    gl.glDisable(gl.GL_LIGHTING);
    gl.glDepthMask(false);
    gl.glDepthFunc(gl.GL_LEQUAL);

    gl.glEnable(gl.GL_STENCIL_TEST);
    gl.glColorMask(false,false,false,false);
    gl.glStencilFunc(gl.GL_ALWAYS, 1,~0);

    gl.glFrontFace(gl.GL_CCW);
    gl.glStencilOp(gl.GL_KEEP,gl.GL_KEEP,gl.GL_INCR);
    draw_shadow();

    gl.glFrontFace(gl.GL_CW);
    gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_DECR);
    draw_shadow();

    gl.glFrontFace(gl.GL_CCW);
    gl.glColorMask(true,true,true,true);

    gl.glColor4f(0.1f, 0.1f, 0.1f, .4f);
    gl.glEnable(gl.GL_BLEND);
    gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA);
    gl.glStencilFunc(gl.GL_NOTEQUAL, 0,~0);
    gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP);

    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glBegin(gl.GL_TRIANGLE_STRIP);
    gl.glVertex3f(-100f, 100f,-100f);
    gl.glVertex3f(-100f,-100f,-100f);
    gl.glVertex3f( 100f, 100f,-100f);
    gl.glVertex3f( 100f,-100f,-100f);
    gl.glEnd();
    gl.glPopMatrix();

    gl.glDisable(gl.GL_BLEND);
    gl.glDepthFunc(gl.GL_LEQUAL);
    gl.glDepthMask(true);
    gl.glEnable(gl.GL_LIGHTING);
    gl.glDisable(gl.GL_STENCIL_TEST);
    gl.glShadeModel(gl.GL_SMOOTH);
  }

  void  draw_shadow(){
     int p1, p2,
          a, b;
     jcd_math.point3f v1 = new jcd_math.point3f(),
                      v2 = new jcd_math.point3f();

     gl.glPushMatrix();
     gl.glTranslatef(location.x,location.y,location.z);

     for(int i=0; i<edge_count;i++)
      if((faces[edges[i].parents[0]].visible &&!faces[edges[i].parents[1]].visible)||
         (!faces[edges[i].parents[0]].visible) && (faces[edges[i].parents[1]].visible)){

        if(!faces[edges[i].parents[0]].visible){
          p1 = edges[i].indices[0];
          p2 = edges[i].indices[1];
          a  = 0;
          b  = 1;
        }
        else{
          p1 = edges[i].indices[1];
          p2 = edges[i].indices[0];
          a  = 1;
          b  = 0;
        }

        if(!edges[i].projected[a]){
          v1 = new jcd_math.point3f(vertices[p1]);
          v1.sub(light);
          v1.scale(200);
          edges[i].projection[a] = new jcd_math.point3f(v1);
        }
        else
          v1.set(edges[i].projection[a]);

        if(!edges[i].projected[b]){
          v2 = new jcd_math.point3f(vertices[p2]);
          v2.sub(light);
          v2.scale(200);
        }
        else
          v2.set(edges[i].projection[b]);

        gl.glBegin(gl.GL_TRIANGLE_STRIP);
        set_vertex(vertices[p1]);
        set_vertex(v1);
        set_vertex(vertices[p2]);
        set_vertex(v2);
        gl.glEnd();
      }
      gl.glPopMatrix();
  }

  public static class edge{

    int     indices[] = new int[2],
            parents[] = new int[2];
    boolean draw,
            projected[] = new boolean[2];

    jcd_math.point3f projection[] = new jcd_math.point3f[2];
    public edge(){
    }

    void reset(){
      projected[0] = false;
      projected[1] = false;
    }
  }

  public static class face{

    int     indices[] = new int[3];
    edge    edges[]   = new edge[3];

    float   D,
            length;

    jcd_math.vec3f  normal    = new jcd_math.vec3f();
    boolean         visible;

    public face(int a, int b, int c,jcd_math.point3f p,jcd_math.vec3f normal){

      indices[0]  = a;
      indices[1]  = b;
      indices[2]  = c;
      this.normal = new jcd_math.vec3f(normal);
      length      = normal.length();
      D           = -normal.Dot(new jcd_math.vec3f(p.x,p.y,p.z));

    }
  }
}
Offline aNt

Senior Devvie




AFK


« Reply #2 - Posted 2003-08-08 06:34:31 »

not sure- same thing happens in Xith3d. can anyone shed some light on this matter?



tops...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #3 - Posted 2003-08-08 06:54:19 »

I have noticed some very strange shadow effects using Xith3d.  I am assuming they will get better as the program develops and matures.

Will.

Offline aNt

Senior Devvie




AFK


« Reply #4 - Posted 2003-08-08 10:38:27 »

me 2 its all getting very cool in the world of java. i am making (not port) a little game using all the cool stuff.

and far as i can tell theres only little things to sort - and maybe add some cool new things.

i think the strange choppy shadows are from the other object having choppy polygons anyways? the back shadows in my donut are fine and smooth.

strange.... but look how cool it all is Smiley
Offline jujumen

Senior Newbie




java is the juju within.....


« Reply #5 - Posted 2003-08-08 14:36:16 »

java cool dude
it's possible that  the shadow from your dinosuar is falling on the wrong side of the ball. Check your normals, you might have to renormalize them.

From the land beyond beyond........
across all hope and fear........
i bid you JAVA do appear.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #6 - Posted 2003-08-08 18:28:27 »

I'm guessing, from a quick look over the code, that you're building a silluette of the model, then extruding that to create the shadow volume?

If thats the case, then its because you're reducing an analog state (in/out of the shadow across the polygons) to a binary one (in/out on a polygon level). The complete solution escapes me at the moment, but the general gist of it is that you need to take the whole mesh, and bung it though a process to extrude the correct vertices - imagine cutting the sphere in half, dragging the parts away and connecting them with a long tube.

This way you can use the depth buffer on this new mesh to get a per pixel in/out value. Its usually done in a vertex shader, so try looking on nVidias site for shadow volumes done via that method.

Hope that helps.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #7 - Posted 2003-08-08 18:54:07 »

Looking at ATI Shadow volumes demo, I came to the conclusion that what's causing the "artifact" is nothing less than the low polygon count of the occluder.
I loaded a slightly more complex model and everything looked alright.
PS: Shadow volumes got nothing to do with normals, at least not when the vertices extrusions is done relatively to the light source.
I know 2d pics might be confusing per times as you lose the sense of depth, but the dragon is on the left side of the light whereas the sphere is on the right. So technically their respective shadows can't be projected on each other. On the other hand you can notice the dragon's shadow being perfectly casted on the torus ^_^
Offline TarmTarm

Senior Newbie




Write once, never run.


« Reply #8 - Posted 2003-08-09 07:48:17 »

Do you have the whole demo somewhere?
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #9 - Posted 2003-08-09 13:53:54 »

Nope, but I think I might be able to post some code tonight.
The reason behind the delay is that I had to modify most of my code to make it compatible with MilkShape3D loader, meaning that any model extending .ms3d can cast a realistic shadow ^_^.
Before getting ms3d loader to work, I used to load my models after converting them from .obj to .jcd; I would use Java3D loader to convert em .obj models to something that has the following layout;
Number of vertices
Number of Triangles
Indexed vertex
Indexed Normal
..
..
..
Triangle vertices indices.
Triangle Normal
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  
Vertices 8
Faces 12
15.0 -15.0 15.0
0.0 1.0 6.123234E-17
-15.0 -15.0 -15.0
0.0 1.0 6.123234E-17
-15.0 -15.0 15.0
0.0 1.0 6.123234E-17
15.0 -15.0 -15.0
0.0 1.0 6.123234E-17
15.0 15.0 -15.0
-1.0 0.0 0.0
15.0 15.0 15.0
-1.0 0.0 0.0
-15.0 15.0 -15.0
0.0 -6.123234E-17 1.0
-15.0 15.0 15.0
1.0 0.0 0.0
2 1 0
0.0 1.0 6.123234262925839E-17
1 3 0
0.0 1.0 6.123234262925839E-17
5 0 4
-1.0 0.0 0.0
0 3 4
-1.0 0.0 0.0
3 1 4
0.0 -6.123234262925839E-17 1.0
1 6 4
0.0 -6.123234262925839E-17 1.0
7 6 2
1.0 0.0 0.0
6 1 2
1.0 0.0 0.0
5 4 7
0.0 -1.0 -6.123234262925839E-17
4 6 7
0.0 -1.0 -6.123234262925839E-17
2 0 7
0.0 6.123234262925839E-17 -1.0
0 5 7
0.0 6.123234262925839E-17 -1.0

^ that's a box in jcd format Tongue
I'm still working on per pixel lighting as well as phong shading, vertex shaders imlpementation, but hey  I can call the code Alpha tonight and put it on somewhere Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #10 - Posted 2003-08-09 23:44:32 »

http://www.realityflux.com/abba/Shadows.zip

Lots of bugs, poorly written functions, not optimized etc...
I feel tired and I have to be up at 5 am to go to New Hampshire with my buddies.
Will try to tweak it up within the next few days :-/
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #11 - Posted 2003-08-11 00:01:28 »

The demo now works with any ms3d models, grab it from here
Offline Jens

Senior Devvie




Java for games!


« Reply #12 - Posted 2003-08-12 13:39:36 »

In your demo_main-class you have a print_fps()-method which looks kind of strange:

1  
2  
3  
4  
5  
if(System.currentTimeMillis() - start >=500){
  fps             = count_fps<<1;
  start           = 0;
  count_fps  = 0;
}


It should be System.currentTimeMillis() - start >=1000 or fps             = 2*count_fps. Right?

BTW, this way you can double your framerate.  Cool

Besides this I get some exceptions and a blank gray screen when starting your demo on Linux.

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  
Exception in thread "main" java.lang.NullPointerException
        at demo_main.main(demo_main.java:85)
java.lang.NullPointerException
        at TextureManager.bindTexture(TextureManager.java:31)
        at make_room.make_room(make_room.java:33)
        at make_room.<init>(make_room.java:17)
        at demo_main.initialize(demo_main.java:163)
        at init_renderer.init(init_renderer.java:50)
        at net.java.games.jogl.impl.GLDrawableHelper.init(GLDrawableHelper.java:68)
        at net.java.games.jogl.GLCanvas$InitAction.run(GLCanvas.java:201)
        at net.java.games.jogl.impl.x11.X11GLContext.makeCurrent(X11GLContext.java:146)
        at net.java.games.jogl.impl.x11.X11OnscreenGLContext.makeCurrent(X11OnscreenGLContext.java:111)
        at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:162)
        at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:196)
        at net.java.games.jogl.GLCanvas.display(GLCanvas.java:91)
        at net.java.games.jogl.GLCanvas.paint(GLCanvas.java:102)
        at sun.awt.RepaintArea.paint(RepaintArea.java:177)
        at sun.awt.motif.MComponentPeer.handleEvent(MComponentPeer.java:374)
        at java.awt.Component.dispatchEventImpl(Component.java:3658)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
java.lang.NullPointerException
        at demo_main.keyPressed(demo_main.java:203)
        at java.awt.Component.processKeyEvent(Component.java:5051)
        at java.awt.Component.processEvent(Component.java:4902)
        at java.awt.Component.dispatchEventImpl(Component.java:3598)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1688)
        at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:593)
        at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:765)
        at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:698)
        at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:559)
        at java.awt.Component.dispatchEventImpl(Component.java:3468)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
net.java.games.jogl.GLException: Error making context current
        at net.java.games.jogl.impl.x11.X11GLContext.makeCurrent(X11GLContext.java:141)
        at net.java.games.jogl.impl.x11.X11OnscreenGLContext.makeCurrent(X11OnscreenGLContext.java:111)
        at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:162)
        at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:196)
        at net.java.games.jogl.GLCanvas.display(GLCanvas.java:91)
        at net.java.games.jogl.GLCanvas.paint(GLCanvas.java:102)
        at sun.awt.RepaintArea.paint(RepaintArea.java:177)
        at sun.awt.motif.MComponentPeer.handleEvent(MComponentPeer.java:374)
        at java.awt.Component.dispatchEventImpl(Component.java:3658)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #13 - Posted 2003-08-12 14:49:43 »

I can't comment on your exceptions or frame-rate halving issue, but that "count_fps<<1" actually is a "count_fps * 2"! Grin

Deciding that multiplication isn't cool enough for him, Java Cool Dude has resorted to a binary shift by one, promoting all binary bits in the number to double their original values.  A neat trick, which gets disapproving sighs from the Correctness people, but extra Style Points from the rest of us... Cool Roll Eyes

Hellomynameis Charlie Dobbie.
Offline kevglass

« JGO Spiffy Duke »


Medals: 218
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2003-08-12 14:59:37 »

** Disapproving Sigh **

<cough>Readability</cough>

Kev

Offline Jens

Senior Devvie




Java for games!


« Reply #15 - Posted 2003-08-12 15:04:41 »

Oops, I should have noticed that. Roll Eyes

Java Cool Dude seems to have an extraordinary coding style anyway.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline AndersDahlberg

Junior Devvie





« Reply #16 - Posted 2003-08-12 18:19:43 »

Quote
For instance in the demo I'm showing right here, when I call the function named cast_shadow() it's straight obvious that what it does is actually casting a shadow.


well, yes, but I guess that the "complaint" wasn't against your name per se - but the way it "looks". The java standard is to have

cast_shadow() named as castShadow() Wink

This is only a recommendation and you can of course use whatever you want Smiley

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
Offline aNt

Senior Devvie




AFK


« Reply #17 - Posted 2003-08-13 09:41:50 »

hahhahaha u think hes bad!
Offline kevglass

« JGO Spiffy Duke »


Medals: 218
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #18 - Posted 2003-08-13 17:58:46 »

Just so that your thread isn't contaminated with my posts, I've deleted them. It was obviously a waste of time giving you any form of feedback.

Frankly, I think your code speaks for itself.

Kev

Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #19 - Posted 2003-08-13 18:09:21 »

That's much much better.
I honestly don't give a flying poop about your opinion as you obviously lack the skills and the manners to clearly state it.
Now regarding this last comment
Frankly, I think your code speaks for itself.

it definitely shows your true colors Roll Eyes
I'll keep my code and you'll keep your mindless babbling for now mmmmmmk? Grin
Offline kevglass

« JGO Spiffy Duke »


Medals: 218
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #20 - Posted 2003-08-13 18:12:20 »

My true colours? I did nothing but attempt to give you feedback on your code. You're the one that reduced it to personal attacks on opinion. I'm sorry that you took it the wrong way.

Kev

Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #21 - Posted 2003-08-13 18:20:57 »

You're saying that I personally attacked you correct?
Can you just quote, or even mention one of em attacks that you're accusing me of?
You can't, simply because that never happened, on the other hand I showed the flaws in your posts and how your words are rather poorly chosen.
Go back and read what a feedback really is, all you do is forcing others to a specific coding manner that might not be viewed as pleasant or GOOD from other's perspective.
Also saying stuff as "it speaks for itself" although coated as an opinion, is indeed a personal attack reflecting a "big" man behind an anonymous ip.
Now would you mind not addressing me anymore?
Offline kevglass

« JGO Spiffy Duke »


Medals: 218
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #22 - Posted 2003-08-13 18:22:30 »

Gladly  Cheesy (assuming this doesn't count)

Kev

Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #23 - Posted 2003-08-13 18:29:52 »

Good boy Wink
Offline hawkwind

Junior Devvie




Java games rock!


« Reply #24 - Posted 2003-08-14 11:42:33 »

This tiff, heh heh a graphics joke, has gone to far.  STOP IT!!!  This is damaging my sense of community. Embarrassed

This is the first time I have seen this kind of antaganism...don't much like it. Angry

1) Java Cool Dude has always been helpful on the sun forums, always willing to post example code and images, most of his java3d is excellantly commented.  I appreciated there and here (wish you sent jars not rars though)

2) I am here for IDEAS not syntax,  when someone posts code here I adapt it to my system, in my style.

3) My day-to-day involves merging and blending code into finished apps.  This code comes from a variety of sources, newbie new hires to scruffy unix guru's.  Ya just deal with different approaches.  I have people who insist on m_ prefixes ala M$ and people who see no need for extra keywords like private or protected.

4) Let limit observations to techniques, better image hadling, nio vs regular IO.

5)  There are most likely spelling errors in the above ...tough...bummer...engrish ain't my specialty...but I do get paid well for IDEAS!!!
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #25 - Posted 2003-08-14 21:33:08 »

While Cool's style isn't standard java style - from what I have seen it's consistent so at least he sticks to his own style guidelines Smiley  Code which has no apparent style is ugly to read.

And in another thread Cool was kind enough to post a zip for me with some sample full-screen code Wink

Will.

Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #26 - Posted 2003-08-14 21:57:37 »

Thanks for the good words guys, it brings a warm feeling to my heart  Cry
Anyways  I got per pixel lighting to work (God when I started coding it I thought I'll never get to the end, but now that everything is under control I cna't help but saying it was rather easy Grin)
I'll hopefully include it into my volume shadows tonight and post it as a ZIP wink wink.
Now all I need to is to implement attenuation for more spectacular effects.
/me goes back coding but leaves a sample 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  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
import net.java.games.jogl.GL;
import net.java.games.jogl.GLU;

public class make_room
{
  jcd_math.matrix4f tangent_matrix = new jcd_math.matrix4f();
  load_image        texture_loader = new load_image();
  String            texture_path[] = {"textures/texture_base.png",
                                      "textures/texture_dot3.png"};
  float              x, y, z,
                    texture_st[]   = {0,1,
                                      1,1,
                                      1,0,
                                      0,0},
                    geometry[]     = { -1, -1, -1,
                                        1, -1, -1,
                                        1,  1, -1,
                                       -1,  1, -1};/*To use in final release*/
  int               index,
                    texture_id[]   = new int[2];

  GL                gl;
  GLU               glu;

  make_room(float x, float y, float z,
            GL gl,   GLU glu){
    this.glu = glu;
    this.gl  = gl;
    this.x   = x;
    this.y   = y;
    this.z   = z;
    create_textures();
    tangent_matrix.load_identity();
    tangent_matrix.elements[5] = -1;
  }

  void create_textures(){

    gl.glGenTextures(2, texture_id);

    for(int i =0; i<2; i++){
      gl.glBindTexture(gl.GL_TEXTURE_2D, texture_id[i]);
      texture_loader.generate_texture_info(texture_path[i], gl.GL_RGB);

      glu.gluBuild2DMipmaps(gl.GL_TEXTURE_2D, gl.GL_RGB, texture_loader.width, texture_loader.height,
                            gl.GL_RGB, gl.GL_UNSIGNED_BYTE,texture_loader.data);
      gl.glTexParameterf(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_WRAP_S,gl.GL_CLAMP_TO_BORDER_ARB);
      gl.glTexParameterf(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_WRAP_T,gl.GL_CLAMP_TO_BORDER_ARB);
      gl.glTexParameterf(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MAG_FILTER,gl.GL_LINEAR);
      gl.glTexParameterf(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MIN_FILTER,gl.GL_LINEAR_MIPMAP_LINEAR);
      texture_loader.destroy();
    }
  }

  void draw_room(){

    reset_textures_state(true);
    activate_textures();

    jcd_math.tuple3f light_relative_position  = new jcd_math.tuple3f(25,25,25),
                     lv    = new jcd_math.tuple3f(),
                     lv_ts = new jcd_math.tuple3f();

      gl.glBegin(gl.GL_TRIANGLE_STRIP);

      lv.set(light_relative_position.x + 50f,
             light_relative_position.y + 50f,
             light_relative_position.z - 0f);
      lv.normalize();
      lv_ts.vector_matrix_mul_2(lv, tangent_matrix);
      lv_ts.scale(.5f);
      lv_ts.add(.5f);

      gl.glMultiTexCoord2f(gl.GL_TEXTURE0_ARB, 0, 0);
      gl.glMultiTexCoord2f(gl.GL_TEXTURE1_ARB, 0, 0);

      gl.glColor3f(lv_ts.x,lv_ts.y,lv_ts.z);
      gl.glNormal3f(0, 0, 1);
      gl.glVertex3f(-50, -50, 0);

      lv.set(light_relative_position.x - 50f,
             light_relative_position.y + 50f,
             light_relative_position.z - 0f);
      lv.normalize();

      lv_ts.vector_matrix_mul_2(lv, tangent_matrix);

      lv_ts.scale(.5f);
      lv_ts.add(.5f);

      gl.glMultiTexCoord2f(gl.GL_TEXTURE0_ARB, 1, 0);
      gl.glMultiTexCoord2f(gl.GL_TEXTURE1_ARB, 1, 0);

      gl.glColor3f(lv_ts.x,lv_ts.y,lv_ts.z);
      gl.glNormal3f(0, 0, 1);
      gl.glVertex3f( 50, -50, 0);

      lv.set(light_relative_position.x + 50f,
             light_relative_position.y - 50f,
             light_relative_position.z - 0f);
      lv.normalize();
      lv_ts.vector_matrix_mul_2(lv, tangent_matrix);

      lv_ts.scale(.5f);
      lv_ts.add(.5f);

      gl.glMultiTexCoord2f(gl.GL_TEXTURE0_ARB, 0, 1);
      gl.glMultiTexCoord2f(gl.GL_TEXTURE1_ARB, 0, 1);

      gl.glColor3f(lv_ts.x,lv_ts.y,lv_ts.z);
      gl.glNormal3f(0, 0, 1);
      gl.glVertex3f(-50, 50, 0);

      lv.set(light_relative_position.x - 50f,
             light_relative_position.y - 50f,
             light_relative_position.z - 0f);
      lv.normalize();
      lv_ts.vector_matrix_mul_2(lv, tangent_matrix);

      lv_ts.scale(.5f);
      lv_ts.add(.5f);

      gl.glMultiTexCoord2f(gl.GL_TEXTURE0_ARB, 1, 1);
      gl.glMultiTexCoord2f(gl.GL_TEXTURE1_ARB, 1, 1);

      gl.glColor3f(lv_ts.x,lv_ts.y,lv_ts.z);
      gl.glNormal3f(0, 0, 1);
      gl.glVertex3f(50, 50, 0);
      gl.glEnd();

      reset_textures_state(false);
  }

  void activate_textures(){

    gl.glActiveTexture(gl.GL_TEXTURE0_ARB);
    gl.glBindTexture (gl.GL_TEXTURE_2D, texture_id[1]);
    gl.glEnable(gl.GL_TEXTURE_2D);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE_EXT);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_RGB_EXT,  gl.GL_DOT3_RGB_EXT);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_SOURCE0_RGB_EXT,gl.GL_TEXTURE);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_OPERAND0_RGB_EXT,gl.GL_SRC_COLOR);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_SOURCE1_RGB_EXT,gl.GL_PRIMARY_COLOR_EXT);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_OPERAND1_RGB_EXT,gl.GL_SRC_COLOR);

    gl.glActiveTexture(gl.GL_TEXTURE1_ARB);
    gl.glBindTexture (gl.GL_TEXTURE_2D, texture_id[0]);
    gl.glEnable(gl.GL_TEXTURE_2D);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_TEXTURE_ENV_MODE,gl.GL_COMBINE_EXT);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_COMBINE_RGB_EXT,gl.GL_MODULATE);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_SOURCE0_RGB_EXT,gl.GL_PREVIOUS_EXT);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_OPERAND0_RGB_EXT,gl.GL_SRC_COLOR);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_SOURCE1_RGB_EXT,gl.GL_TEXTURE);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_OPERAND1_RGB_EXT,gl.GL_SRC_COLOR);
  }

  void reset_textures_state(boolean all){

    gl.glActiveTexture(gl.GL_TEXTURE0_ARB);
    gl.glMatrixMode(gl.GL_TEXTURE);
    gl.glLoadIdentity ();
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glDisable(gl.GL_TEXTURE_3D_EXT);
    gl.glDisable(gl.GL_TEXTURE_CUBE_MAP_ARB);
    gl.glDisable(gl.GL_TEXTURE_2D);
    gl.glDisable(gl.GL_TEXTURE_GEN_S);
    gl.glDisable(gl.GL_TEXTURE_GEN_T);
    gl.glDisable(gl.GL_TEXTURE_GEN_R);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_TEXTURE_ENV_MODE,gl.GL_MODULATE);
    gl.glActiveTexture(gl.GL_TEXTURE1_ARB);
    gl.glMatrixMode(gl.GL_TEXTURE);
    gl.glLoadIdentity ();
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glDisable(gl.GL_TEXTURE_3D_EXT);
    gl.glDisable(gl.GL_TEXTURE_CUBE_MAP_ARB);
    gl.glDisable(gl.GL_TEXTURE_2D);
    gl.glDisable(gl.GL_TEXTURE_GEN_S);
    gl.glDisable(gl.GL_TEXTURE_GEN_T);
    gl.glDisable(gl.GL_TEXTURE_GEN_R);
    gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_TEXTURE_ENV_MODE,gl.GL_MODULATE);

    if(all){
      gl.glActiveTexture(gl.GL_TEXTURE2_ARB);
      gl.glMatrixMode(gl.GL_TEXTURE);
      gl.glLoadIdentity ();
      gl.glMatrixMode(gl.GL_MODELVIEW);
      gl.glDisable(gl.GL_TEXTURE_3D_EXT);
      gl.glDisable(gl.GL_TEXTURE_CUBE_MAP_ARB);
      gl.glDisable(gl.GL_TEXTURE_2D);
      gl.glDisable(gl.GL_TEXTURE_GEN_S);
      gl.glDisable(gl.GL_TEXTURE_GEN_T);
      gl.glDisable(gl.GL_TEXTURE_GEN_R);
      gl.glTexEnvf(gl.GL_TEXTURE_ENV,gl.GL_TEXTURE_ENV_MODE,gl.GL_MODULATE);
    }
  }

  void call_texture_coord(int index, int w, int h){

    switch(index){
      case 1: gl.glTexCoord2f(0,h); break;
      case 2: gl.glTexCoord2f(w,h); break;
      case 3: gl.glTexCoord2f(w,0); break;
      case 4: gl.glTexCoord2f(0,0); break;
    }
  }
}
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #27 - Posted 2003-08-14 23:40:26 »

http://www.realityflux.com/abba/sample.jpg
Looking good so far ^_^
Offline Jens

Senior Devvie




Java for games!


« Reply #28 - Posted 2003-08-15 11:42:59 »

Quote
While Cool's style isn't standard java style - from what I have seen it's consistent so at least he sticks to his own style guidelines Smiley  Code which has no apparent style is ugly to read.


It can't be really consistent, because the style of method-calls to the Java/Jogl core is different from calling Cool's own methods. You will always have to jump between the styles (for instance isEmpty() and is_empty()). Nevertheless I agree this discussion is not good for the community-feeling.



Xith3D Getting Started Guide (PDF,HTML,Source)
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.

Mr.CodeIt (23 views)
2014-12-23 03:34:11

rwatson462 (53 views)
2014-12-15 09:26:44

Mr.CodeIt (45 views)
2014-12-14 19:50:38

BurntPizza (85 views)
2014-12-09 22:41:13

BurntPizza (110 views)
2014-12-08 04:46:31

JscottyBieshaar (78 views)
2014-12-05 12:39:02

SHC (89 views)
2014-12-03 16:27:13

CopyableCougar4 (96 views)
2014-11-29 21:32:03

toopeicgaming1999 (155 views)
2014-11-26 15:22:04

toopeicgaming1999 (152 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!