• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# calculating normals

This topic is 6583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello! Somebody, please tell me how to calculate normals for a square. I have a square consisting of 4 points. (a.x, a.y, a.z, b.x, ...) But how do I give that square a normal? I would like to see some code, not some replies like: search the net... thanx. --- marius http://fr.ee/linux

##### Share on other sites
It is very easy, if you make the assumption that your rectangle is flat.

just do it like this:

a-----b
|ooooo|
|ooooo|
c-----d

no you just need to do the cross product between two of the vectors going from one of the point to the two points next to it.
example:

normal = (c - a ) x ( b - a )

Simple!

there are problems though..
you shading wont be nice though if you just use one normal for each surface..
and the method i have shown will give you the same normal for each corner, so that wouldnt help either..

Edited by - ZubZorro on January 13, 2001 4:00:23 AM

##### Share on other sites
The normal of any point on a polygon (triangle, quad, octagon, etc...)

v1 = lastpoint - currentpoint;
v2 = nextpoint - currentpoint;

normalize v1 and v2

calculate the cross product of v1 & v2
The result is the normal for the current point.

http://tannara.2y.net/Graphics/Theory/finding_the_normal_of_a_surface.htm

l8r,
Rob
http://tannara.2y.net/

##### Share on other sites
Once you find the normal of the surface, would you then set the normal of each of those vertexes to the calculated surface normal?

##### Share on other sites
ok VERY basic question.. by lastpoint-currentpoint do you mean the distance between them? i.e sqrt(x^2+y^2+z^2). or is it
vector1.x = lastpointx - currentpointx
vector1.y = lastpointy - currentpointy
vector1.z = lastpointz - currentpointz

##### Share on other sites
The second. When I wrote v1 = lastpoint - currentpoint I meant it as vector math so...
v1.X = LastPoint.X - CurrentPoint.X;
v1.Y = LastPoint.Y - CurrentPoint.Y;
v1.Z = LastPoint.Z - CurrentPoint.Z;

I''ve also updated my page with calculating normals with some sample code.

http://tannara.2y.net/Graphics/Theory/finding_the_normal_of_a_surface.htm

l8r,
Rob
http://tannara.2y.net/

##### Share on other sites
Thanx, everybody. Got them working.
i needed them on a terrain engine that I was creating. But now the entire terrain is all blocky. Check the url below for the topic.

http://www.gamedev.net/community/forums/topic.asp?topic_id=37246

---
marius
http://fr.ee/linux

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015827
×