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 / Vector TO sun or Sun screen position?

Author
Message
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 16th Sep 2017 12:37
So the sun shines on a vector.
I would like to be able to work out the direction vector from the camera to the sun, but I appear to be missing some information to be able to calculate it, such as the sun position.

The sun position in screen co-ords would be most useful.

Nieb posted a useful function for setting the Sun with pitch / yaw



Could this be used in conjunction with camera position/angle to work out the angle to sun or screen co-ords?
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 16th Sep 2017 21:42 Edited at: 16th Sep 2017 21:49
You want GetScreenXFrom3D( x, y, z ) while x,y,z is the camera position + direction of the sun

I prefer to work with vectors because it is easier to work with/faster to calculate because angles need sin/cos which are "heavy" calculations

if you set the sun direction by yourself then it IS the sun direction as the sun moves with your camera position
if you just want the default sun direction from AppGameKit then it's
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 17th Sep 2017 16:12
Well, I wanted a direction vector from the camera to the sun, but I eventually worked it out using the pitch / yaw stuff in Nieb's example.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 18th Sep 2017 11:58 Edited at: 18th Sep 2017 11:59
In general, the sunlight is given as a directional vector. So there is no position in the space.
So if you want to make a position from such a vector. Multiply the negative sunlight vector with a fictitious distance. (i dont know is the vector 'from sun' or 'to sun' e.g. not negate the vector)
Then subtract the camera Position from the resulting vector and normalize the result.
Now you have your directionalvector camera-> sun.

sun_pos = (-sun_vec) * distance
cam_to_sun_vec = normalize(sun_pos-cam_pos)
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine

Login to post a reply

Server time is: 2024-04-19 04:32:53
Your offset time is: 2024-04-19 04:32:53