Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (623) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Normal Vectors on non-flat polygons  (Read 1787 times) 0 Members and 1 Guest are viewing this topic.
nickdotjava

Junior Devvie

I have fallen to the dark side. &nbsp;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."
Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

 « 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 ]
nickdotjava

Junior Devvie

I have fallen to the dark side. &nbsp;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.

Thanks.

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
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 , 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.

Same here! Sucks, don't it?

Hellomynameis Charlie Dobbie.
nickdotjava

Junior Devvie

I have fallen to the dark side. &nbsp;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."
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?

Hellomynameis Charlie Dobbie.
nickdotjava

Junior Devvie

I have fallen to the dark side. &nbsp;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."
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.
Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

 « 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 ]
nickdotjava

Junior Devvie

I have fallen to the dark side. &nbsp;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.

 ClaasJG (18 views) 2015-04-27 13:36:51 BurntPizza (32 views) 2015-04-23 03:42:11 theagentd (35 views) 2015-04-22 16:23:07 Riven (50 views) 2015-04-16 10:48:47 Duke0200 (59 views) 2015-04-16 01:59:01 Fairy Tailz (42 views) 2015-04-14 20:13:12 Riven (45 views) 2015-04-12 21:36:37 bus hotdog (61 views) 2015-04-10 02:39:32 CopyableCougar4 (66 views) 2015-04-10 00:51:04 BurntPizza (71 views) 2015-04-06 22:06:58
 theagentd 23x BurntPizza 17x wessles 15x alwex 11x 65K 11x kingroka123 11x kevglass 8x Olo 7x Ecumene 7x ra4king 7x Rayvolution 7x Riven 7x chrislo27 7x Hanksha 7x KevinWorkman 6x KudoDEV 4x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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