//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace ElementalGame.GameObjects
{
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Xml;
#endregion
using DarkWynterEngine.Globals;
using DarkWynterEngine.ObjectLib;
using DarkWynterEngine.GameObjects;
///
/// Large sphere surrounding the game world.
/// Like a sky-box, except spherical to simulate true atmospheric visibility.
///
public class SkySphere : GameObject
{
private string skyTexture;
private string skyTextureBump;
private float rotationScale = 10.0f;
private float[] materialDiffuse = { 0.7f, 0.7f, 0.7f, 1.0f };
// Specular factor
private float[] materialSpecular = { 0.0f, 0.0f, 0.0f, 1.0f };
///
/// Skysphere contrustor.
///
public SkySphere()
{
mass.gameObjectPointer = this;
mass.objectType = Enums.ObjectType.SKYSPHERE;
}
///
/// Override loading configurations for skysphere.
///
/// Contains skyphere data
/// The object library
/// True if load was successful
public override bool Load(XmlNode node, ObjectLibrary objectLibrary)
{
//base.Load(node, objectLibrary);
try
{
skyTexture = node.Attributes["texture"].Value;
skyTextureBump = node.Attributes["bumpTexture"].Value;
}
catch { System.Diagnostics.Debug.WriteLine("Error reading sky texture filename"); return false; }
textureList.Clear();
textureList.Add(Statics.SystemSettings.content.Load(skyTexture));
textureList.Add(Statics.SystemSettings.content.Load(skyTextureBump));
model = Statics.SystemSettings.content.Load("Content/_models/skySphere");
// Apply our own advanced Effect to the Model
foreach (ModelMesh mesh in model.Meshes)
{
for (int i = 0; i < mesh.MeshParts.Count; i++)
{
// Add effect to mesh
mesh.MeshParts[i].Effect = ShaderParameters.effect_draw;
}
}
mass.SetPosition(new Vector3(Statics.TerrainSettings.collisionMapSize / 2, 500, Statics.TerrainSettings.collisionMapSize / 2), new Vector3(Statics.TerrainSettings.collisionMapSize / 2, 500, Statics.TerrainSettings.collisionMapSize / 2 + 1));
mass.scale = new Vector3(1200);
//mass.scale = new Vector3(Statics.TerrainSettings.vertexMapSize * 8);
//skySphere.mass.scale = Statics.TerrainSettings.terrainScaleFactor * 32;
return true;
}
///
/// Update rotation on the skysphere.
///
/// The object library
public override void Update(ref ObjectLibrary objectLibrary)
{
Random rand = new Random();
//// Increment Rotation With dt
mass.Rotate(0.00f, 0.01f);
mass.SetPosition( Statics.PlayerSettings.playerPosition, Statics.PlayerSettings.playerPosition + Vector3.Forward);
mass.scale = new Vector3(2000);
//mass.scale = new Vector3(1300);
}
///
/// Override draw for skysphere.
///
/// Contains model info.
/// Shader technique used to draw skysphere
public override void Draw(ModelManager modelManager, string technique)
{
// HACK ==========================================
//return;
matrix = Matrix.CreateScale(mass.scale) *
Matrix.CreateFromQuaternion(mass.currentRotation) *
Matrix.CreateTranslation(mass.currentPosition);
ShaderParameters.World.SetValue(matrix);
// Lighting
ShaderParameters.materialDiffuse.SetValue(materialDiffuse);
ShaderParameters.materialSpecular.SetValue(materialSpecular);
ShaderParameters.modelTexture1.SetValue(textureList[0]);
ShaderParameters.bumpTexture1.SetValue(textureList[1]);
// Draw the model
base.DrawTriStrips(model, technique);
}
}
}