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.

Code Snippets / Perfect Day Night Cycle

Author
Message
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 26th Jun 2006 17:16
not perfect yet though, i just made it in a hurry and sorry if the code is a mess.

make a new project and unzip all the media in the attachment into your project folder, and use following code.

Attachments

Login to view attachments
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 26th Jun 2006 17:26
If you want to add moon also, put the attached image into your project folder again and change the code into following:
Its all ambient based, so any object you put in your level will be effected by the light.

Attachments

Login to view attachments
TEH_CODERER
20
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 26th Jun 2006 17:26
Don't have time at the moment but I will definately try this later. I dislike the fog commands as the fog differs on certain objects. Hard to describe but if you've experienced it you'll know what I mean.

[url]andrewneale2004@yahoo.com[/url]
http://www.elbsoftware.dbspot.com
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 26th Jun 2006 18:05
theres a bug about fog and particles, they dont work together.
And such problems with fog applied to certain objects can be easily solved thats what i experienced.
Xarshi
18
Years of Service
User Offline
Joined: 25th Dec 2005
Location: Ohio
Posted: 26th Jun 2006 21:34 Edited at: 26th Jun 2006 21:36
Dude,you beat me to making flares. You beat me to everything! WHY DO YOU HAVE TO BE SO GOOD!!!???

Actually,what you could do is make the thing check for any lights,and make lens flares for all the lights. But oh well. And I like the day/night cycle too. You pump out all kinds of amazing things

all ben needs is his band,his guitar,and his computer
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 26th Jun 2006 23:34
thanks benny, glad if it helps.
one thing id like to say is, code doesnt have to be perfect with anything, just your media should be good enough to hide the lack of a good code.
And im not the actual author of this flare code,and forgot who originally wrote it, just tweaked it alittle bit.
Aaaand yes, if you change the light object which you put into the function, then it will have lens flares.
Chris Franklin
18
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 27th Jun 2006 00:08
Nice work

Btw i've got a new msn but you've removed yours so i can't re add ya

Stunt man 2 http://forum.thegamecreators.com/?m=forum_view&t=79827&b=8&p=0
WHITEKNUCKLE IS BACK! Check the wip boards for more info
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 27th Jun 2006 13:50 Edited at: 27th Jun 2006 13:51
Sorry Chris, nothing personal to you, as you are a kind fella. But i was getting too many guys on my list from these forums, so i decided to remove it.
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 27th Jun 2006 23:32
Looks good. You should do a check to see if the sun is below the horizon so that you can't see the lens flares through the terrain.

CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 27th Jun 2006 23:47
yeh, you can check it if the sun y is below 0.0 for this demo, i just kept it there to see where the sun is

In actual usage, i do cast a ray to the sun to see if its behind hills or any buildings to determine if the sun is visible to camera or not, so i can check the visibilty of the flares as well.
TobiasWK
18
Years of Service
User Offline
Joined: 4th Sep 2005
Location: Denmark
Posted: 28th Jun 2006 12:34
wow... just checked the code snippet... fantasic.
nice code and it looks really great.

just wondered: were do I change the speed of the rotation?

thx


Need a place for your images? Try uploadimago.net
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 28th Jun 2006 13:09


The blue# value increases upto 255 and goes back to 0 which means a cycle of 255+255 = 510



the a# value is a wrapvalue as you see which it wraps from 0 to 360
if you divide 360 to 510;
360 / 510 = 0.7058823529

soo to every 1 cycle of blue# you have to set 0.7058etc. to a# cycle.

soooo for every 0.1 cycle of blue#, all you do is divide 0.7058etc to 10 as well. that will slow down the rotation, to make it faster you have to multiply with 10 instead dividing.

just make the whole thing about rotation and ambience into a function which will be easier to use if you want.

And adding some reddish for the dusk and dawn hours would give you a better effect. i think ill add it to this one soon. Just a side note, if you want to add it yourself; Set Object Emissive command is the only one i found effecting the textured objects final color. so its your friend.
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 30th Jun 2006 03:44
The control of the ambient is impressive, and better than I've been able to come up with. However, the positioning of the sun is not correct. You are using simplistic plane trig functions to simulate what is really described by two complex spherical trig functions. The angle the sun path makes with the horizon in your program seems to vary based upon the direction (azimuth) the viewer selects, which does not occur anywhere on earth. Also, if it did, one particular view the user can select shows the sun rising purely vertically, which can only happen at the equator and, for that matter, only on two particular days of the year, namely the equinoxes. I can take a stab on the correct formulas for you if you wish. However, although you effectively increment the time of day, you must also define two fixed parameters for the scene inorder to correctly position the sun: (1) the particular latitude of the terrain, AND (2) a particular date in the year for the scene, since they both figure into the relevant equations. (The date of year will empirically determine solar declination - angular distance of the sun from the celestial equator). Pick them and I'll do the work. Warning: if you pick a latitude that is not in the so-called temperate zone (North of the Tropic of Cancer and South of the Arctic circle, or the corresponding range in the Southern hemisphere) the implementation of the equations gets much more complicated.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 30th Jun 2006 16:00
well, ill just consider game is in the equador then
its for games dude, not for some scientific research or somethin like that.
X Trade
20
Years of Service
User Offline
Joined: 19th Feb 2004
Location: near bristol, UK
Posted: 30th Jun 2006 22:17
but it would be nice if it were realistic in that kinda way.. attention to detail is what makes games so great!

www.AoFP.co.uk
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 7th Aug 2006 12:56
test
Wolf Dreamer
18
Years of Service
User Offline
Joined: 13th Sep 2005
Location: the land of chaotic dreams
Posted: 9th Aug 2006 23:14
Seriously cool.

Even if the game was based on real world Earth, I doubt most people would be checking to see what angle the sun was rising and setting at.
Never heard anyone say: "It was a great game as far as the graphics, music, and gameplay itself, however the one thing that really bothered me, and ruined the entire experience, was that the sunrise was just 2% too far to the east. You could tell by the lush greenery that is was either spring or summer, so there is no way possible it'd be in that position."

The math should be online somewhere if any wanted to make a game with the proper coordinates though. I'm sure the national weather service keeps track of sunrises and sunsets, and their exact angle, on their webpage somewhere.

And some people do notice the little touches to detail, so they'd appreciate it. The overwhelming majority almost certainly won't even notice though.

Its like I always say, some gamers stop and listen to the crickets making noise in the waving grass at night, and others just stop long enough to use a flamethrower to roast the noisy little bastards.

---
The moon didn't seem to rotate, we seeing the same side of it always. It didn't wax and wane either. That wasn't what the example was about, so obviously I didn't expect it to. Also, the moon is a bmp and you can't really rotate that.

I wonder if there are any government websites with a 3D model of the moon that is public domain.

Would you be able to have an invisible light source that allowed only parts of the moon to be lit up at various times of the month in the game, or would it be easier to just have a differant model used? Or would differant .bmps loaded up at various times work better than a model to begin with?

The last sane human being in a world gone mad.
If you were a cockroach, what type of cockroach would you be?
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 15th Aug 2006 18:02
I could make you a perfect day-night cycle with precise values of the sun earth and moon positions and rotations with everything 3d, but then your players wouldnt play your game while watching the beautiful sun set :p
Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 15th Aug 2006 21:21
Cucumber, another really great example. The only things that I could think of which would make this even better is setting a horizon warp for the sun/moon, so they are larger when on the horizon and smaller when overhead, and ensuring that the flares dont show when the sun is behind an object such as the terrain.

Really cool stuff.

"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit." - Aristotle
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 23rd Aug 2006 00:09
Alquerian:
You can easily stop the flares to hide behind terrains, but you will need to set up a ray casting system of your own.
About the setting a horizon effect, i suggest making a cone attached to the sun plain nicely proportioned and always facing the camera naturally with a nice texture, and playing with its diffuse value going between yellow and red.
Also you can use 2 or more plains to get the glowing effect as well, but you will need to try alot of times i think.
Good luck
Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 23rd Aug 2006 00:56
CuCuMBeR,
This being your example and thread, I thin we all would love if you tried it

Applyby has Flies in his Eyes.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 23rd Aug 2006 21:21
I am sorry really, but my ray casting wouldnt fit into your own game straight away. you would need to make alot of changes and be sure programming your own would be easier.
I suggest looking at the newton.dll or something smiliar for less coding.
I might later send the better sun if i have time though.
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 28th Aug 2006 00:24
I'd like to try this but the media won't download. Have tried 3 times.

gbuilder.

SEMPRON 2400+, 512mb Ram, ATI RADEON™ 9550 256MB DDR Graphics card, WindowsXP Professional.
The admiral
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 31st Aug 2006 09:48
Hey I was wondering I have a 24 hour game time system how would I make it so that the sun orientated itself to the time of day like if it was 12 oclock it would be above the world and so on because I would much rarther that the sun move and update it self with the gametime than me just keep moving it from wherever it was.

The admiral
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Sep 2006 22:27
Could you please provide a screenshot?

The admiral
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 2nd Sep 2006 01:18
How would that help....I was looking for a formula to calculate the position of the sun based on the time of day.

The admiral

Login to post a reply

Server time is: 2024-05-04 11:37:31
Your offset time is: 2024-05-04 11:37:31