XNA calculate normals for linesegment

Posted by Gerhman on Game Development See other posts from Game Development or by Gerhman
Published on 2013-11-03T11:24:43Z Indexed on 2013/11/03 16:12 UTC
Read the original article Hit count: 278

Filed under:
|
|
|
|

I am quite new to 3D graphical programming and thus far only understand that normal somehow define the direction in which a vertex faces and therefore the direction in which light is reflected. I have now idea how they are calculated though, only that they are defined by a Vector3.

For a visualizer that I am creating I am importing a bunch of coordinate which represent layer upon layer of line segments. At the moment I am only using a vertex buffer and adding the start and end point of each line and then rendering a linelist.

The thing is now that I need to calculate the normal for the vertices of these line segments so that I can get some realistic lighting. I have no idea how to calculate these normal but I know they all face sideways and not up or down. To calculate them all I have are the start and end positions of each line segment. The below image is a representation of what I think I need to do in the case of an example layer:

enter image description here

The red arrows represent the normal that should be calculates, the blue text represent the coordinates of the vertices and the green numbers represent their indices.

I would greatly appreciate it if someone could please explain to me how I should calculate these normal.

© Game Development or respective owner

Related posts about XNA

Related posts about c#