Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / finally got normals to calculate

Author
Message
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 4th Jan 2016 06:29
i dont know why but i was struggling really bad on this one. I had lots of people show me code functions, some examples but it just wasn't enough detail for me to figure it out. There is allot of information on the internet on how its calculated also.... but again not enough detail for me to figure it out.

then i stumbled on this

http://fullonsoftware.co.uk/snippets/content/Math_-_Calculating_Face_Normals.pdf

I some how managed to link that with some stuff Phaelax explained to me ages ago.... and came up with this:

(im using a few arrays in there to store my values)


this seams to do the trick but i had to invert the y axis.... im not sure why.
so this is a triangle and it sets all vertex points to the same direction calculated.
I know its possible to do a smoother job but this is the first time i ever got it to work.

I will attach my matrix functions to demonstrate it in a few mins...

Sign up for NaGaCreMo!
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 4th Jan 2016 06:33 Edited at: 4th Jan 2016 06:39
ok here is the example matrix commands i made ages ago.....now calculating normals...


i currently have the sun direction pointing the way the camera points to make sure the normals are correct.

(press escape to free the mouse lock)


Sign up for NaGaCreMo!

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Jan 2016 08:33 Edited at: 4th Jan 2016 08:37
This is the code I use, which is a little more efficient. I don't claim to have written the code, a friend of mine helped me with it. I'm taking the 3D points from a memblock, but the principle is the same.
The result is in Vector V1. You can apply this to all 3 corners of your triangle once calculated.

There is a better, smoother solution which I haven't progressed to yet. You should take adjoining vertices and average the normals out to give you a smoother final look. That is, vertex normals in the same position should point in the same direction. Like me, it looks like you have normals in the same position, pointing in different directions.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Jan 2016 11:23
I have the same issue with inverted Y normals for some reason, I'm glad I'm not alone! - and doubly glad to see some normals calculation code!

Login to post a reply

Server time is: 2024-09-29 09:22:59
Your offset time is: 2024-09-29 09:22:59