   Normal Calculator?
  Ok after hours upon hours of trying to debug my normals (And that's excluding my previous attempts at debugging these), I just can't get them to come out right. I've even gone back and added methods to my models to enable displaying of the vert normals (Which doesn't seem right either, given each vertex only has one line coming out of it, there should be Number_of_Connected_Faces lines as each vert in a face draws a line from the raw vertex position + the face normal). Anyhow I digress. I'm in a real personal hell right now, so I pose the question, does anyone know of any decent (Yet easy to use) calculus type of graphing software that will allow me to basically  plug in vertices, connect them together to form a poly and calculate the normal for both the face and the verts themselves, just to determine if my calculations are right? Because at this point, I'm not totally convinced I'm right. Obviously I must not be.Thanks in advance. I apologize if the question has been asked before; I did do a search and nothing really came up. (For reference, I searched for Normal Calculator; thinking Normal would hit Normal and Normals)On a side note, how does one go about getting a point in the middle of an n-gon? I'm thinking something along the lines of doing a = v0-v2, b = v1-v2. Then doing some sort of sqrt somewhere in there. I will eventually need to know to draw a normal coming out of the center of a face.   
  Nope. I dont know any, but the process is simple, and should be easy to debug.For a triangle ABC the normal is normalize(AB cross AC). Given A at (0,0) B at (1,0) and C at (0,1) you should get (0,0,1) as your normal. That will validate your math functions.If your poligon isn't a triangle, you should triangulate it.As to your other question Barycentric coordinates.;Quote:For a triangle ABC the normal is normalize(AB cross AC).Is that (A * B) Cross (A * C)?  I always thought it was basically, Normal = (B-C cross A-C ) / length, where length = sqrt( (Normal.x * Normal.x) + (Normal.y * Normal.y) + (Normal.z * Normal.z) )?   I know, it is simple. You'd think I'd not have any problems with it. But it's just not flying.Quote: Given A at (0,0) B at (1,0) and C at (0,1) you should get (0,0,1) as your normal.*scratches head* A, B, and C are only 2d coordinates?Quote:If your poligon isn't a triangle, you should triangulate it.I've made my engine support N-Gons basically -- n-points per face, per poly, per mesh. It all works, exporter and all. It's just these damn normals I can't get to work right. I've even tried triangulating the meshes before export so that the calculations were being performed are for triangles instead of n-gons and it still doesn't seem like the calculations are right. Basically I get no shade-difference, and when I turn my normal-display on, the lines projecting from the verts don't seem like where they should be projecting out to. Because of the lack of shade I know the normals are likely not right. My SurfaceComposition class is right (Made up of texture and materials), because the models are being drawn with the proper textures. The light class is creating a light. So the only thing left is something that is heavily suspect to me -- the normals.;Quote:Original post by StakFallTQuote:For a triangle ABC the normal is normalize(AB cross AC).Is that (A * B) Cross (A * C)?  I always thought it was basically, Normal = (B-C cross A-C ) / length, where length = sqrt( (Normal.x * Normal.x) + (Normal.y * Normal.y) + (Normal.z * Normal.z) )?   I know, it is simple. You'd think I'd not have any problems with it. But it's just not flying.You got it right. Do you have an example where it doesn't work? Try to simplify things until you have a single triangle and you can see precisely what your program is doing.Quote:Quote: Given A at (0,0) B at (1,0) and C at (0,1) you should get (0,0,1) as your normal.*scratches head* A, B, and C are only 2d coordinates?No, they should be A at (0,0,0), B at (1,0,0) and C at (0,1,0).Quote:Quote:If your poligon isn't a triangle, you should triangulate it.I've made my engine support N-Gons basically -- n-points per face, per poly, per mesh. It all works, exporter and all. It's just these damn normals I can't get to work right. I've even tried triangulating the meshes before export so that the calculations were being performed are for triangles instead of n-gons and it still doesn't seem like the calculations are right. Basically I get no shade-difference, and when I turn my normal-display on, the lines projecting from the verts don't seem like where they should be projecting out to. Because of the lack of shade I know the normals are likely not right. My SurfaceComposition class is right (Made up of texture and materials), because the models are being drawn with the proper textures. The light class is creating a light. So the only thing left is something that is heavily suspect to me -- the normals.You should start with a simple model, using only triangles. Once that works, build something simple with general polygons, and it shouldn't be much more difficult: You can start by taking three consecutive vertices in the polygon and use the formula above.Have you tried reversing the sign of the normals? Perhaps you just have them pointing the wrong way...;  I took your suggestion. I was already only rendering cubes, but I took it down to a single triangle. The Normals look right now. However, they looked like they might've been in the wrong direction, so I reversed them. they look more right now, but they still don't seem to be doing anything. Over the time I've spent working on this project, lots and lots of "temporary" code was put in throughout, for testing. I'm going back through stuff and stripping out any rem'ed blocks and any hardset light and materials. So far I've removed ALOT of stuff but still no shade differences. It's like the triangle's texture is full-bright, not "washed out" but just like no shading at all. I would've thought, that even if my normals were set incorrectly, I would've gotten some sort of display-anomaly pointing to itself for me to go "Oh yeah, that's probably because I got the normals messed up a little bit.".   ;Quote:Normal = (B-C cross A-C ) / length, where length = sqrt( (Normal.x * Normal.x) + (Normal.y * Normal.y) + (Normal.z * Normal.z) )Just double-checking. You calculate the cross first, then the length, then divide, correct? I.e., not all in one statement.;  Yeah, and I just now got it! A few things that I changed that fixed it. Because of the enormity of my project (Basically every component of a game (Textures, Materials, Lights, etc) has a class for managing that) things inter-operate between classes. About 3 or 4 class calls deep was a while in in my material manager that was basically: while (<blah> = <blah)   *Sigh* old habits die hard I guess, should've obviously been ==. And materials weren't being loaded into the Graphics-API driver's material array. Which could've been ok if I were copying my own material class to a material compatible with the graphics-api; don't remember if I were doing that. Thanks much for all the replies!Anyhow, without textures applied, it looks great. But now when I apply the texture I loose any shading. I suspect it's something to do with my TextureStageStates, which were almost non-existant except for bout 3 or 4 state-settings, 2 were for texture-filtering, so I think I need to revisit that, and that's probably for another thread since this forum is for the math side of things.