Jump to content
  • Advertisement

Archived

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

Andos

Angle between 2 points used to calculate light.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

(Newbie - untextured 3D engine) Isn''t there a formula to calculate the angle between to points with only sin, cos or tan? I''m going to use this first to find the angle (for two spots in a polygon) then add 90 degrees to the result and then find the angle between the light spot and the result from before + the 90 degrees. Then find the distance and substract it from the above. Then fin % of the damn thing and calculate how dark a colour in my 3D object should be... Can you give me any hints on doing this? Making light in an untextured 3D model? Please don''t write strange coding language... I''m quite an idiot on that point. I''m having my own coding language, and I don''t think any of you know that...

Share this post


Link to post
Share on other sites
Advertisement
Oh i think I found out...

To find the angle i can use this formula:

Tan-1( (Za - Zb) / (Xa - Xb) )

Share this post


Link to post
Share on other sites
Hi there,

in C ( I think math.h ) is a function called atan2 which computes the angle between the origin and a vector. The normal atan (Tan-1)may results in an ambigous angle

Good luck

Share this post


Link to post
Share on other sites
Um, Andos, you''re describing cosine shading. If you have a polygonal surface and a light L whose direction is described by a vector, L.v, the magnitude of light incident on the surface is the dot product of the surface normal and the light direction.

%lighting = dotp( N, L.v );

The surface normal for a triangle can be determined as the cross product of the vectors describing two of its sides. Add one more cross product per additional polygon vertex.

N = crossp( (v2 - v1), (v2 - v3) );
normalize( N );


Done.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!