Game Development Community

dev|Pro Game Development Curriculum

Day night cycles with seasons

by Sam Iredale · 03/28/2004 (6:20 am) · 124 comments

Download Code File

This bit of code is an example of how to use elevation and azimuth to dynamically position celestial objects in the game. In this case, I have positioned the sun acording to year length, time of year, day length and time of day, the position of the mission in terms of longitude and latitude, and the axis tilt of the planet of the mission.
I took large portions of Josh ritters day night cycle code for this. But instead of using the time of day to determine the colors to be used for the scene, the elevation of the sun is used instead.

All seasonal settings can be set in the mission file by creating a celestials object like so:

new Celestials(SunCycles) {
axistilt = "24.0";
yearlength = "100";
daylength = "60000";
date = "0";
time = "0";
longitude = "0.0";
latitude = "35.0";
};

The units of each setting is documented in the code. Angles are in degrees. Day length is in real milliseconds. Year length is in game days. Date is day of year. Time is millisecond of the day.

A global pointer to the Celestial class (gCelestials) is set when the object is created. through that pointer the color selected by the class object can be retrieved. The pointer is declaired in Celestials.cc

Some updates were also made to fxSunLight.cc class to make the sun flare grab the solar position from the objeect pointed to by gCelestial.

Enjoy!
Page «Previous 1 2 3 4 5 6 7 Last »
#1
03/28/2004 (8:05 am)
Awesome job. This far exceeds my simple update to TGEDayNight.
#2
03/28/2004 (8:10 am)
Does this keep server and client at the same time of day through network/internet?
#3
03/28/2004 (11:16 am)
Thanks for the contribution! Some screenshots would be nice ;)

I couldn't get the patch file to work, though. I've tried 3 different patch.exe versions, including one that has worked for me before, but none of them could find the target files, even if I point the Torque directory with -d C:\Torque. I'm not a patch expert, so I might be missing something obvious.

It seems to me that your patch was generated from a CVS diff, and it's confusing the patch programs. Any hints?
#4
03/28/2004 (11:22 am)
also does it work with d3d
#5
03/29/2004 (10:02 am)
Took a quick look at the patch file. I think it needs some fixing.

Read it in with a simple editor like Wordpad or Motepad and make the following changes. Do this on a copy of the patch file in case I am wrong!

Starting from the beginning cut the opening list of files from the patch - down to the line just before the first set of = signs. It says,
Index: engine/game/game.cc - leave that line in. Everything above goes away. Those lines involve no changes and are probably screwing up the start of the patch process.

Then, go to the end and cut out the last two patch entries involving trees - they don't belong... they start with...

Index: example/starter.fps/data/shapes/trees/tree2.dts

In this case you do cut out the line and everything to the end. Then save your patch file and try it on a fresh copy of torque.

Also note that he put the celestial.h and celestial.cc files in a subdirectory called /sami - undoubtedly to keep his new files away from the regular torque files. You may want to move them to the game/fx library with the other lighting effects.

Hope that helps.
#6
03/29/2004 (9:15 pm)
Sorry about the bum patch. I was so excited to get the resource posted I "forgot" to test it. I've updated it and the source files with the assumption they will be placed in the game/fx directory.

Next time I get around to this project, I'll add client server communication to set the cycle up properly for all connection objects. It may be a couple of weeks, however.
#7
03/30/2004 (5:30 pm)
I'd love to see this work for multiplayer! The original works really nice as is, but with seasons, which is something I've wanted to have for so long, it would rock all the more. Good job!
#8
04/09/2004 (8:26 pm)
Has anybody discussed the issue of the player's shadow following along with the sun dynamically? I could've sworn I saw a post, resource or something about this issue recently but I can't seem to find it again =S
#9
04/11/2004 (6:31 pm)
could this please be posted as a manual implementation rather than a patch file.
#10
04/11/2004 (6:35 pm)
@Synditech: You could always do what I did, go through the patch piece by piece, its not that complicated.
#11
04/17/2004 (10:05 am)
hey, i got a prob with the skybox gettin cutoff.. Its more noticable the higher up i am, out by the horizon, its just chopped off.. anyone else got this?
#12
04/17/2004 (1:07 pm)
Yea, I noticed the same thing =(
#13
04/24/2004 (5:02 pm)
Note to all:

If you don't have:
Quote:
new Celestials(SunCycles) {
axistilt = "24.0";
yearlength = "100";
daylength = "60000";
date = "0";
time = "0";
longitude = "0.0";
latitude = "35.0";
};

or similar object defined in your mission, it will crash.

Otherwise it worked "out of the box"
#14
04/25/2004 (5:19 pm)
I think I got this to work in multiplayer. (Can't test it right now)

Change in Celestial.cc line 247
Sky* s=(Sky*)Sim::findObject("Sky");
to
Sky* s = gClientSceneGraph->getCurrentSky();
#15
04/26/2004 (10:03 pm)
Is it just me or does DTS shapes change color depending on the camera position after adding this resource?

If I look up and down a green tree, it will suddenly switch between yellowish and green.

Anyone else getting this?
#16
04/27/2004 (9:01 am)
Just adding to my comment above...

I've tested this on more than 1 computer with different graphic cards, it happens on all of them, i've also tested a build without this resource and the problem is then gone.

Any ideas?
#17
04/27/2004 (2:54 pm)
I am not seeing what you mention above after applying the patch, but I do have a couple of other things added beyond this patch.
#18
05/09/2004 (2:35 pm)
I'm having some problems with this patch. I added it manualy and the sky and terrain change colors correctly. However, my sun doesn't move at all and interiors/dts shapes don't change colors with the time of day. Was I supposed to add this ontop of the day night cycles?
#19
05/13/2004 (9:32 pm)
This seems to be the most up to date version of day/night, has anyone gotten it to work correctly yet? i.e all object lit correctly, and clientside synchronization? or has development been completely stopped/forgotten about/whatever
#20
07/25/2004 (2:46 am)
I played with this a little, as of this writting, although this does patch and compile, it crashes the HEAD when used in a client/server situation as soon as control is passed to the client.

I haven't gone too far into it as to find out why.

I don't know if it works in a single player environment since that is not applicable for my needs.
Page «Previous 1 2 3 4 5 6 7 Last »