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  
  Normal Vectors on non-flat polygons  (Read 1731 times)
0 Members and 1 Guest are viewing this topic.
Offline nickdotjava

Junior Devvie




I have fallen to the dark side.  I'm using DX9


« Posted 2003-06-25 20:18:44 »

If I have a polygon that bends, how should I specify the normal vector?  If I understand correctly, normals are needed for light to reflect off of it.

Thanks.

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2003-06-25 21:14:59 »

If you have a polygon that bends then you've either got some |33t hardware thats above consumer level, or you're going to have to tessalate it into flat surfaces.

To find the normal for a flat surface, you can take the cross product of two vectors that lie on the the surface. To calculate vertex normals you probably want to avarage the normals for all the surrounding faces.

To find out how normals are used in plain old GL lighting, google for the blinn light model.

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

Junior Devvie




I have fallen to the dark side.  I'm using DX9


« Reply #2 - Posted 2003-06-25 21:40:19 »

Well, for example, here's the polygon I want to create a normal of:

1  
2  
3  
4  
5  
6  
7  
        gl.begin(GL.POLYGON);
            gl.vertex3f(-20.0f, 40.0f, 0.0f);
            gl.vertex3f(-60.0f, 30.0f, -20.0f);
            gl.vertex3f(0.0f, 40.0f, -70.0f);
            gl.vertex3f(60.0f, 30.0f, -20.0f);
            gl.vertex3f(20.0f, 40.0f, 0.0f);
        gl.end();


Also, how do I do it for strips or fans?

And my graphics card is an S3 Savage IX/MX with 8MB.   Smiley

Thanks.

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #3 - Posted 2003-06-25 22:34:05 »

Quote
Well, for example, here's the polygon I want to create a normal of:


Without waving my hands around trying to visualize those vertices Wink, I'll take a guess that the points don't lie in any common plane - this is generally a bad thing!  Non-simple/self-intersecting polygons, non-convex polygons and polygons with holes in are not guaranteed to be rendered correctly.  If the points of a polygon don't exist all on a single plane, it's quite easy for that polygon to be self-intersecting after viewing or modelling transformations.

Either break that polygon into smaller polygons, or (better) draw the surface as a triangle strip.


Quote
And my graphics card is an S3 Savage IX/MX with 8MB.   Smiley


Same here! Grin Sucks, don't it? Roll Eyes

Hellomynameis Charlie Dobbie.
Offline nickdotjava

Junior Devvie




I have fallen to the dark side.  I'm using DX9


« Reply #4 - Posted 2003-06-25 22:56:50 »

How do I do normals for strips?

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #5 - Posted 2003-06-25 22:58:46 »

Oh, and as for creating normals:

Normals are specified on a per-vertex basis, so the multiple faces of a single triangle strip/fan don't necessarily have the same normal, thus there's no concept of a single normal for that strip/fan.

For most (flat) faces the normal vector will be the same for all vertices defining that face, so you just set it before the first vertex.  OpenGL (being a state machine) will keep that normal set for the subsequent vertices.

Does that make sense? Huh

Hellomynameis Charlie Dobbie.
Offline nickdotjava

Junior Devvie




I have fallen to the dark side.  I'm using DX9


« Reply #6 - Posted 2003-06-25 23:02:23 »

That does make sense.  But for a strip, what if they're not on the same plane?  Several vertices will be on multiple triangles.  Which triangle should I assign each one to?  Or should I take an average?  Or the cross product of a line from each triangle?

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #7 - Posted 2003-06-25 23:27:44 »

Correct, when you're sharing vertices between faces you need to share the normal vector as well.  As Orangy said, you'll need to calculate the normals for the surrounding faces and average them.  This makes the model look a lot "rounder", so if you're after a boxy appearance with sharp specular highlights, lit triangle strips may not be for you.

Hellomynameis Charlie Dobbie.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #8 - Posted 2003-06-26 06:34:15 »

..and you want to avoid GL.POLYGON for exactly the reasons llisted above. No hardware ever actually renders polygons like that, it is always converted into triangles first. This means that it can be triangulated in a way you don't expect, and is dependant on drivers. If you specify the triangles yourself, you'll save yourself a lot of headache.

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

Junior Devvie




I have fallen to the dark side.  I'm using DX9


« Reply #9 - Posted 2003-06-26 14:34:03 »

Thanks guys.  This also partially fixed my culling problem.

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
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 (95 views)
2014-11-29 21:32:03

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

toopeicgaming1999 (151 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!