Page 1

XNA FPP/TPP Game Tutorial (2)Skybox & Sky Effects

By Justin P McConnell


Contents Chapter1

What you need to know

3

Some Things to ponder

Chapter2

Reaching for the sky

4-6

You need to know

6-7

Help on this

7-9

Into The Setup

Chapter3

The Code

10-18

Sky Mesh

18-25

Sky Sphere

26

The Atmosphere

27-31 Extra Code‌ 32 Resources 33 Disclamer


What you need to know There are a million ways to draw the sky and each way is different taking in consideration of what you expect and needs of your game as well what you want your game to look like Drawing your sky is possibly the second complex thing to do in your game because it involves some pretty advanced stuff depending on how good you want your sky to look and it can be really easy if your only doing something simple Your particle system in your game is possibly the hardest because of the natural motion you have to impart on it and the shier scale of the physics you will have to understand to make it work and depending on your game you might not even need this but all that is for another tutorial sometime in the future First of take a look at your game or what you want it to look like do you want to draw the atmosphere with the fog/mist as well the clouds give your world an atmospheric shield what are people going to notice do you need to get to technical Im going to show you three to four different ways to draw the sky First of you have the easiest witch is to render a mesh with a texture and set it as the sky Second you have a little harder way you can make a sphere mesh and cast the image from the previous mesh through the sphere Third you can render plains for the player and fallow them around Fourth and the hardest is where you draw everything ie(clouds, stars, sun/moon, etc)


Reaching for the sky A great programmer I am not but the basics are the basics and I will show you how to reach for the sky as it where you have to understand a few things Here is an example of the second type of sky I described

As you see here in the picture you have a sphere inside a box mesh and the sphere is acting like a projection matrix taking the bit of the box with holds your sky texture and apply that snap shot to a face of the sphere the disadvantage of this is that unless you know what you are doing and are conscious of how it is working your sky will be really distorted adversely if you go with the first way I described Like this


With your terrain and everything inside you wont get distortions but you will most likely end up with seams where the edge of the box is yet another way

is drawing a bell like this with the sky on it will give you a lot less seams and very little distortion but getting the texture of the sky on something like this can be a little hard depending on how you want it to look I am not going to even go over drawing a plain in front of your player because it is so simple and self explanatory and if you have looked at the cam tutorial you should be able to do it no problem just take the forward direction and multiply it and you have the position of your plane tah dah but being as it is so bland it will probably be something you will be willing to forget about Then now we come onto drawing everything‌ I made models of what this should all look like in general


You’ve got layers of stuff shown in the second picture first we start out with the terrain then we move on to the fog, haze, and or mist witch determines your viewing distance as well some of the color in your atmosphere this would be what you breath then next we have the first and second cloud plain two are used in this demonstration to give the clouds some depth next we move on to the shield and glow witch are the last two layers given your needs you may want more or less layers as well all these layers can overlap and envelope each other for instance the fog/haze layer can go from the ground layer up to the second to last layer to give more color to your atmosphere you can have the cloud layer higher or lower then the shield it all depends on how you want it to look unless your seeing it from space it really doesn’t matter though

If you should need further help on this eather cause it was to technical or you just need further explanation sadly there isn’t much but what is there happens to be only slightly helpful msdn is kind of sketchy of what it has and not many people on the internet seem to know though for the simple stuff there is a wealth of knowledge Here are a few sites you can visit they will give you a better understanding of what you have been presented with For the sky sphere you can take a look at http://msdn.microsoft.com/en-us/library/bb464016.aspx as well there is a sample for you to download if you really want to see what is going on and try to reverse engineer it’s functions into a program of your own design for the bell I have a tutorial for those of you who want to make your own and also to get into 3d modeling for your immediate needs check out http://www.youtube.com/watch?v=Dq_myIjb1_c there are a few good skybox textures on this site


http://forums.xna.com/forums/p/8241/43332.aspx for others check down at the bottom for references to these and more

so now on we go lets get the basic setup for this

so first with your content

Your content should be set up so you know where everything is and is called directly and is easy to find and reference With models in a folder and textures/effects they might use in sub folders if your making a model that is going to have your sky texture your going to need a model almost any model will do as long as works in your world from a box to a sphere hemi sphere slightly curved plain will do so long as you will be able to see it there are two to three ways to apply a texture to a mesh depending on your mesh and application or as far as the sky is concerned you can set the texture in the model file ie modifying these lines


Where it sais relative filename that would be the texture that is applied to the mesh and there is usually two of these in every .fbx model Next is to call a new texture for the mesh in the code Effect.Texture = Sky;

This is called every time you draw the mesh or at least normally you can set these when you load the model or when you update it dosnt matter Then the last way to set a texture is to use the method within the sphere model witch uses a texture cube .dds file to map a cube witch is the preferred rout for most game designers though the process varies slightly Now on to some more fun stuff

For a look at what we are going to be making


I am including a sophisticated clock for date and time changes should you want to change the environments of your game/program for different seasons or times of day as well I improved the format of the position calculator and will in the next tutorial add a FPS monitor should you want that function to get the clock go to my Post at PhStudios http://www.phstudios.com/forums/index.php?/topic/1574-extreammmorpg/page__st__20__gopid__10806&#entry10806 the clock has an optional 12hour 24 hour cycle the 12 hour cycle actually eats up more then the 24 hour but not by much

now if you have not done the cam tutorial this will seem really hard and you wont be able to do this tutorial because you will have no camera to view the world


The Code First of if you have not started up your project from the first tutorial go ahead and do so We are going to be adding one of three sky effects today and depending on witch one you want scroll down and find the one you want

Sky Mesh:

But I don’t know? Don’t worry it will all be clear in the end This is relatively easy and is about the same as drawing the terrain First of you will need a class called sky mesh right click objects and add a class Call the class SkyMesh

Actually you can call it what ever you want for me it was easiest to call it skymesh because that is pretty much what it is a single mesh that holds a texture that will be your sky Inside sky mesh put in


{ /// <summary> /// This is for a mesh that uses textures /// </summary> //do you want the sky to fallow the player or stay in one place //public enum SkyStatus //{ // Fallow, // Fixed //} class SkyMesh { #region Fields and Properties public bool IsThereTime = false; public int Hour, Minute, Second, MilliSecond; Model SkyBox; Texture2D Sky; public Vector3 Position; public Vector3 Rotation; public Vector3 LookAt; public public public public

Matrix Matrix Matrix Matrix

RotationMatrix; Projection; World; View;

public float Scale = 1.0f; #endregion #region Initialize public SkyMesh(ContentManager Content) { SkyBox = Content.Load<Model>("Models\\Sky75"); if (IsThereTime == true) { Sky = Content.Load<Texture2D>("Models\\Textures\\Texture.tga"); } } #endregion #region Update and Draw public void Update() { UpdateMatrices(); }


public virtual void UpdateMatrices() { RotationMatrix = Matrix.CreateRotationX(Rotation.X) * Matrix.CreateRotationY(Rotation.Y); LookAt = Position + Vector3.Transform(Vector3.Forward, RotationMatrix); World = Matrix.CreateFromYawPitchRoll( Rotation.Y, Rotation.X, Rotation.Z) * Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position); } public void GetTime(ContentManager Content) { switch (Hour) { case 0: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\0"); break; case 1: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\1"); break; case 2: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\2"); break; case 3: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\3"); break; case 4: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\4"); break; case 5: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\5"); break; case 6: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\6"); break; case 7: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\7"); break; case 8: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\8"); break; case 9:


Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\9"); break; case 10: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\10"); break; case 11: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\11"); break; case 12: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\12"); break; case 13: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\13"); break; case 14: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\14"); break; case 15: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\15"); break; case 16: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\16"); break; case 17: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\17"); break; case 18: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\18"); break; case 19: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\19"); break; case 20: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\20"); break; case 21: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\21"); break; case 22: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\22"); break; case 23:


Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\23"); break; case 24: Sky = Content.Load<Texture2D>("Models\\Textures\\Time\\24"); break; } } public void DrawSkybox() { foreach (ModelMesh mesh in SkyBox.Meshes) { foreach (BasicEffect Effect in mesh.Effects) { Effect.World = World; Effect.View = View; Effect.Projection = Projection; Effect.TextureEnabled = true; Effect.LightingEnabled = true; switch (mesh.Name) { case "": Effect.Texture = Sky; break; } Effect.DiffuseColor = Vector3.One; Effect.CommitChanges(); } mesh.Draw(); } } #endregion } }

Iâ&#x20AC;&#x2122;ve added in a calculator for the time so it will switch the textures as the time of the day changes all you have to do is set up the time to reflect the clockâ&#x20AC;&#x2122;s time witch I proved in one of my links and also may provide in a future part of my tutorials Also remember that this uses a model so you will have to make shure your model is in order and all your textures work with the selected model weather it will be a sphere/hemi sphere just a box or what ever you may chose As well I have added in a possible way to move the mesh with the player should you choose to well why would I want to do that may you ask Say you have only a limmeted viewing space what do you do (A) you scale everything down so it fits (B) you make the world move with the character/player so it only loads what is needed for the current situation


If say you have a near plane of .01 and far plane of 50 your not going to be able to see much but you cant incresse it if you make the sky fallow the player there is no reason to make it supper huge

Remember to update the usings (in the red) And get rid of the objects in the namespace(so the namespace matches the name of your program/game) Add in SkyMesh Sky;

To the top of Game1.cs below also if your going to use the clock add in Clock Time = new Clock();

Below that so that the top of Game1.cs looks something like this public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont font; List<string> Hud1 = new List<string>(); List<string> Hud2 = new List<string>(); Vector2 Hudposition = Vector2.Zero; int check = 0; PlayerObject player = new PlayerObject(); PlayerCam Cam = new PlayerCam(); SkyMesh Sky; Model terrain;


Vector3 terrainposition = Vector3.Zero; Clock Time = new Clock(); KeyboardInput keyboard; MouseInput mouse;

After a bit of finagling I figured out that there was a few things that I could take out of load content protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("Font"); keyboard = new KeyboardInput(); mouse = new MouseInput(); Sky = new SkyMesh(Content); Cam.aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; Cam.UpdateMatrices(); player.Model = Content.Load<Model>("Models\\missile"); terrain = Content.Load<Model>("Models\\terrain"); Sky.Projection = Cam.CameraProjectionMatrix; Sky.View = Cam.CameraViewMatrix; Sky.Update();

I have also took a look at the hud and updated that so it uses the clock as well changed the look of the position display So you will need to change a few things with the draw method protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here Sky.DrawSkybox();--------here base.Draw(gameTime); all of this\/\/\/-------------------------------------------spriteBatch.Begin(); for (int i = 0; i < Hud1.Count; i++) { spriteBatch.DrawString(font, Hud1[i], Hudposition, Color.White); Hudposition.Y += font.LineSpacing; } Hudposition = Vector2.Zero;


for (int i = 0; i < Hud2.Count; i++) { Hudposition.X = graphics.GraphicsDevice.Viewport.Width (font.MeasureString(Hud2[i]).X); spriteBatch.DrawString(font, Hud2[i], Hudposition, Color.White); Hudposition.Y += font.LineSpacing; } Hudposition = Vector2.Zero; Hud1.Clear(); Hud2.Clear(); UpdateHud(); spriteBatch.End(); } void UpdateHud() { Hud1.Add("CameraPosition"); Hud1.Add("X:" + Cam.CameraPosition.X); Hud1.Add("Y:" + Cam.CameraPosition.Y); Hud1.Add("Z:" + Cam.CameraPosition.Z); Hud1.Add("CameraRotation"); Hud1.Add("X:" + Cam.CameraRotation.X); Hud1.Add("Y:" + Cam.CameraRotation.Y); Hud1.Add("Z:" + Cam.CameraRotation.Z); Time.UpdateClock(); Hud2.Add("Time|" + Time.Hour + ":" + Time.Minute); Hud2.Add("" + Time.Second + ":" + Time.MilliSecond); Hud2.Add(Time.DayOfTheWeek); Hud2.Add(Time.Month + "|" + Time.Day + "|" + Time.Year); Hud2.Add("WOM|" + Time.Week); Hud2.Add("MOY|" + Time.MonthOfTheYear); Hud2.Add("WOY|" + Time.WeekOfTheYear); Hud2.Add("DOY|" + Time.DayOfTheYear); if (Time.MilitaryTime == true) { Hud2.Add("24 H"); } if (Time.MilitaryTime == false) { Hud2.Add("12 H"); } Down to here/\/\/\/\------------------------------------------}

Of corse if you should chose to use a different format for your hud that is purely up to you Next there is a few things we have to add to the update method Add


if (Sky.IsThereTime == true) { Sky.GetTime(Content); } Sky.Update();

Before Cam.Update(gameTime); base.Update(gameTime);

And Hudposition = Vector2.Zero;

Before mouse.Update(gameTime); keyboard.Update(gameTime);

So now you should be able to start it up and have a reasonable way to draw a sky texture

Sky Sphere:

This is a Good choice too Go ahead and add a Class to Objects Name that class SkySphere


Grabb the usings and erase the objects after the name using using using using using using using using using using using using using

System; System.Collections.Generic; System.Linq; System.Text; Microsoft.Xna.Framework; Microsoft.Xna.Framework.Audio; Microsoft.Xna.Framework.Content; Microsoft.Xna.Framework.GamerServices; Microsoft.Xna.Framework.Graphics; Microsoft.Xna.Framework.Input; Microsoft.Xna.Framework.Media; Microsoft.Xna.Framework.Net; Microsoft.Xna.Framework.Storage;

namespace SkySpheretest { public class SkySphere { #region Fields and Properties public Model Sphere = new Model(); public Vector3 Position = Vector3.Zero; public Vector3 Rotation = Vector3.Zero; public Vector3 LookAt; public public public public

Matrix Matrix Matrix Matrix

RotationMatrix; Projection; View; World;

public float Scale = 1.0f; public Effect SphereEffect; public TextureCube Cube;


public bool IsLoading = false; #endregion #region Initialization public SkySphere(){} #endregion #region Update and Draw public void Update() { UpdateMatrices(); SetEffects(); GetEffects(Sphere); } public void UpdateMatrices() { RotationMatrix = Matrix.CreateRotationX(Rotation.X) * Matrix.CreateRotationY(Rotation.Y); LookAt = Position + Vector3.Transform(Vector3.Forward, RotationMatrix); World = Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position); } //this is called when the sphere loads public void GetEffects(Model model) { foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = SphereEffect; } } } //this must be called before mesh.draw and before get effects public void SetEffects() { SphereEffect.Parameters["ViewMatrix"].SetValue(View); if (IsLoading == true) { SphereEffect.Parameters["SkyboxTexture"].SetValue(Cube); IsLoading = false; } SphereEffect.Parameters["ProjectionMatrix"].SetValue(Projection); } public void DrawCube()


{ } public void DrawSphere(Model model) { foreach (ModelMesh mesh in model.Meshes) { SetEffects(); mesh.Draw(); } } #endregion } }

Now we are going into Game1.cs to do a little work If you have done The Cam tutorial you are going to need to change some stuff Instead of public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont Font; List<string> HUD = new List<string>(); PlayerObject player = new PlayerObject(); PlayerCam Cam = new PlayerCam(); Vector2 hudposition; KeyboardInput keyboard; MouseInput mouse; int check = 0; Model terrain; Vector3 terrainposition = Vector3.Zero;

It should be public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont font; List<string> Hud1 = new List<string>(); List<string> Hud2 = new List<string>(); Vector2 Hudposition = Vector2.Zero; int check = 0; PlayerObject player = new PlayerObject(); PlayerCam Cam = new PlayerCam();


SkyMesh Sky; Model terrain; Vector3 terrainposition = Vector3.Zero; Clock Time = new Clock(); KeyboardInput keyboard; MouseInput mouse;

In LoadContent Below Cam.AspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; Cam.UpdateMatrices();

Put this Sky = new SkySphere(); Sky.IsLoading = true; Sky.Sphere = Content.Load<Model>("Models\\Sphere"); Sky.SphereEffect = Content.Load<Effect>("Models\\Effects\\SkySphere"); Sky.Cube = Content.Load<TextureCube>("Models\\Textures\\GK_CM_SK001_cm_rgba"); Sky.Projection = Cam.CameraProjectionMatrix; Sky.View = Cam.CameraViewMatrix; Sky.Scale = 2.0f; Sky.Update();

Now the update After mouse.Update(gameTime); keyboard.Update(gameTime);

Put in if (mouse.NewLeftMouseClick) { bool instance = true; if (Time.MilitaryTime == true) { if (instance == true) { Time.CalculateTime(); Time.MilitaryTime = false; instance = false; } }


if (Time.MilitaryTime == false) { if (instance == true) { Time.MilitaryTime = true; instance = false; } } }

This will change your time from military 24 hour to 12 hour standard time Then Before Cam.Update(gameTime); base.Update(gameTime);

Put in Time.UpdateClock();

Now the Draw Before DrawModel(terrain, terrainposition);

Put in Sky.Projection = Cam.CameraProjectionMatrix; Sky.View = Cam.CameraViewMatrix; Sky.DrawSphere(Sky.Sphere);

Now to handle the changes to the Hud We need to get rid of the old hud In updateHud() change HUD.Add("your position: " + player.Position.X + "X : " + player.Position.Y + "Y : " + player.Position.Z + "Z"); HUD.Add("Your Rotation: " + player.rotation.X + "X : " + player.rotation.Y + "Y : " + player.rotation.Z + "Z"); HUD.Add("Camera Position: " + cam.CameraPosition.X + "X : " + cam.CameraPosition.Y + "Y : " + cam.CameraPosition.Z + "Z"); HUD.Add("Camera Rotation: " + cam.CameraRotation.X + "X : " +


cam.CameraRotation.Y + "Y : " + cam.CameraRotation.Z + "Z"); HUD.Add("Camera LookAt : " + cam.LookAt.X + "X : " + cam.LookAt.Y + "Y : " + cam.LookAt.Z + "Z"); HUD.Add("Perspective:"+ cam.Perspective + ":" + cam.PerspectiveInt); HUD.Add("Speed: " + player.Speed); HUD.Add("Check:" + check);

To Hud1.Add("CameraPosition"); Hud1.Add("X:" + Cam.CameraPosition.X); Hud1.Add("Y:" + Cam.CameraPosition.Y); Hud1.Add("Z:" + Cam.CameraPosition.Z); Hud1.Add("CameraRotation"); Hud1.Add("X:" + Cam.CameraRotation.X); Hud1.Add("Y:" + Cam.CameraRotation.Y); Hud1.Add("Z:" + Cam.CameraRotation.Z); Time.UpdateClock(); Hud2.Add("Time|" + Time.Hour + ":" + Time.Minute); Hud2.Add("" + Time.Second + ":" + Time.MilliSecond); Hud2.Add(Time.DayOfTheWeek); Hud2.Add(Time.Month + "|" + Time.Day + "|" + Time.Year); Hud2.Add("WOM|" + Time.Week); Hud2.Add("MOY|" + Time.MonthOfTheYear); Hud2.Add("WOY|" + Time.WeekOfTheYear); Hud2.Add("DOY|" + Time.DayOfTheYear); if (Time.MilitaryTime == true) { Hud2.Add("24 H"); } if (Time.MilitaryTime == false) { Hud2.Add("12 H"); }

Then after base.Draw(gameTime); change spriteBatch.Begin(); for (int i = 0; i < HUD.Count; i++) { spriteBatch.DrawString(Font, HUD[i], hudposition, Color.White); hudposition.Y += Font.LineSpacing; }


HUD.Clear(); UpdateHUD(); spriteBatch.End();

To spriteBatch.Begin(); for (int i = 0; i < Hud1.Count; i++) { spriteBatch.DrawString(font, Hud1[i], Hudposition, Color.White); Hudposition.Y += font.LineSpacing; } Hudposition = Vector2.Zero; for (int i = 0; i < Hud2.Count; i++) { Hudposition.X = graphics.GraphicsDevice.Viewport.Width (font.MeasureString(Hud2[i]).X); spriteBatch.DrawString(font, Hud2[i], Hudposition, Color.White); Hudposition.Y += font.LineSpacing; } Hudposition = Vector2.Zero; Hud1.Clear(); Hud2.Clear(); UpdateHud(); spriteBatch.End();

Before base.Draw(gameTime); Put in GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; GraphicsDevice.RenderState.DepthBufferWriteEnable = true;


The Atmosphere:

You will still need a sphere not for the planet but for the black though you can just set the background color to black we want the stars as well Also latter on I will talk to you about reflections and it will help you with putting the stars in the sky Also you will need some way to add an alpha to your textures like the fog/haze, clouds, shield and the glow You can add it in 3 ways that I can think of off the top of my head You can add it in to the code setting up and alpha channel to be set up like this effect.Alpha = 0.9f;

also you can set it up in the texture of a mesh then the last way I can think of is to add an effect file with the scattering effect in it now there isnâ&#x20AC;&#x2122;t much I can show you here without going over Quadâ&#x20AC;&#x2122;s and this atmosphere will take up a whole tutorial by itself so latter on I will explain this in greater detail in another tutorial just keep reading and remember to leave me comments send me emails or message me at phstudios


Extra Code If you where wondering about the Clock and didnâ&#x20AC;&#x2122;t feel like downloading it Here it is using using using using using using using using using using using using using

System; System.Collections.Generic; System.Linq; System.Text; Microsoft.Xna.Framework; Microsoft.Xna.Framework.Audio; Microsoft.Xna.Framework.Content; Microsoft.Xna.Framework.GamerServices; Microsoft.Xna.Framework.Graphics; Microsoft.Xna.Framework.Input; Microsoft.Xna.Framework.Media; Microsoft.Xna.Framework.Net; Microsoft.Xna.Framework.Storage;

namespace SkySpheretest { class Clock { private TimeSpan time; DateTime today; public int Hour, Minute, Second, MilliSecond; public int Year, Month, Week, Day, DayOfTheYear, WeekOfTheYear; public string DayOfTheWeek, MonthOfTheYear, AmPm; GameTime thistime = new GameTime(); public bool MilitaryTime = true; public Vector2 Center; public Clock() { TimeZone ReagonalTime = TimeZone.CurrentTimeZone; time = ReagonalTime.GetUtcOffset(new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day)); today = DateTime.UtcNow; today = today.Add(time); Hour = today.Hour; Minute = today.Minute; Second = today.Second; MilliSecond = today.Millisecond; Year = today.Year; Month = today.Month; Week = today.Day / 7; Day = today.Day; //DayOfTheWeek = today.DayOfWeek; DayOfTheWeek = "" + today.DayOfWeek; }


public void UpdateClock() { TimeZone ReagonalTime = TimeZone.CurrentTimeZone; time = ReagonalTime.GetUtcOffset(new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day)); today = DateTime.UtcNow; today = today.Add(time); CalculateSpecifics(); if (MilitaryTime == true) { Hour = today.Hour; } Minute = today.Minute; Second = today.Second; MilliSecond = today.Millisecond; Year = today.Year; Month = today.Month; Week = today.Day / 7; Day = today.Day; //DayOfTheWeek = today.DayOfWeek; DayOfTheWeek = "" + today.DayOfWeek; WeekOfTheYear = (today.Month * 4) + Week; DayOfTheYear = today.DayOfYear; } //if you switch time to non military call this public void CalculateTime() { switch (today.Hour) { case 0: Hour = 12; break; case 1: Hour = 1; break; case 2: Hour = 2; break; case 3: Hour = 3; break; case 4: Hour = 4; break; case 5: Hour = 5; break; case 6: Hour = 6; break; case 7: Hour = 7; break; case 8: Hour = 8;


break; case 9: Hour = break; case 10: Hour = break; case 11: Hour = break; case 12: Hour = break; case 13: Hour = break; case 14: Hour = break; case 15: Hour = break; case 16: Hour = break; case 17: Hour = break; case 18: Hour = break; case 19: Hour = break; case 20: Hour = break; case 21: Hour = break; case 22: Hour = break; case 23: Hour = break;

9; 10; 11; 12; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11;

} } void CalculateSpecifics() { if (MilitaryTime == false) { if (today.Hour < 12) { AmPm = "AM"; } else


{ AmPm = "PM"; } if (today.Hour != Hour) { CalculateTime(); } } switch (today.Month) { case 1: MonthOfTheYear break; case 2: MonthOfTheYear break; case 3: MonthOfTheYear break; case 4: MonthOfTheYear break; case 5: MonthOfTheYear break; case 6: MonthOfTheYear break; case 7: MonthOfTheYear break; case 8: MonthOfTheYear break; case 9: MonthOfTheYear break; case 10: MonthOfTheYear break; case 11: MonthOfTheYear break; case 12: MonthOfTheYear break;

= "January"; = "February"; = "March"; = "April"; = "May"; = "June"; = "July"; = "August"; = "September"; = "October"; = "November"; = "December";

} } //For Analog time ie: wrist watch or grandfather clock void CalculateRadialTime() { ///<> /// /// For this you need to set a center then Rotate Arms around it /// ie center = image.width / 2, image.hight / 2 ///<>


} } }

Ive added in some special parts for extra functions like an analog clock you will however have to come up with the function for the movement of the hands and I might give you that latter in another tutorial


Resources

For the CubeMap Here is the CubeMap I used in the tutorial http://maxstudios.de/res/textures/Gregor_Koch_CubeMaps_V01.zip Just put them in Models\\Textures The Bell can be made in blender I have a tutorial for that up on youtube

As well for the sphere can be made in blender the same way just export the sphere as it is Also it can be downloaded at http://go.microsoft.com/fwlink/?LinkId=149792&clcid=0x409 you will have to take it from the project file inside the zip you might also want the skysphere effect coppy these two files the dot fbx goes inside your model folder and the dot fx file goes inside your effects folder

As well there are a few good sites where you can learn how to code with the format/language inside the dot fx file that is Here http://www.neatware.com/player/fx.html


For all of you out there who are having trouble with what I am doing weather it is my code my methods or any ethics I can be reached at http://www.youtube.com/user/jjppmm29 http://www.phstudios.com/forums/index.php?/user/601-jjppmm29/ myspace.com/justins3rdspace or http://www.facebook.com/home.php?#!/profile.php?id=100000514691553 not everything I have shown here is made by me and I do not take credit for any of it the purpose of these tutorials is to get your foot in the door when it comes to programming and developing skills to make your own game where you take this information and what you do with it is up to the individual

XNA FPPTPP Game Tutorial 2 Sky  

Showing you how to draw the sky in game

Advertisement