2.7.9. Complete source code
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using BetaCell.Debug;
using BetaCell.Util.GlobalInfo.Content;
using BetaCell.Environment.Camera;
using BetaCell.Util.GlobalInfo;
using BetaCell.Environment;
using BetaCell.Environment.Mesh.Visitors;
using BetaCell.Util.Procedural;
using BetaCell.Common.Vertex;
using BetaCell.Environment.Mesh;
using BetaCell.Environment.Texture;
using BetaCell.Environment.Texture.Feeder;
using BetaCell.Effects;
namespace Starter
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
//Game attributes
GraphicsDeviceManager
graphics;
GraphicsDevice device;
ContentManager content;
BCFirstPersonHumanCamera
camera;
//end game attributes
//This tutorial's attributes
BCMesh plane;
BCTimedTextureFeeder
timedTexFeeder;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
content = new ContentManager(Services);
#if(XBOX360)
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
#else
graphics.PreferredBackBufferWidth = 852;
graphics.PreferredBackBufferHeight = 480;
#endif
}
protected override void
Initialize()
{
//base initialization
device = graphics.GraphicsDevice;
BCLogger.instance.init(device, content);
BCInitializationManager.initialize(content);
OnActivated(null, null);
recreateScene();
base.Initialize();
}
private void recreateScene()
{
BCColorSet colorSet = new BCColorSet(Color.White);
BCDynamicEffectVisitor colorSetter =
new BCDynamicEffectVisitor(colorSet.getFunction("Shader.ColorSet"),
colorSet, 0);
//-------------
//plane
//-------------
plane = ProceduralModelers.PLANE_MODELER.createPlane(4, 4, 25, 25, new
Vector3(0, 0, 0),
new BCVertexPosNorTexContainer(), 1);
BCMeshGraphicUtil.init(plane, device);
//Setting texture
BCTextureVisitor cloud0 = new BCTextureVisitor(
"tex",
new
BCMemoryTextureStrategy(content.Load<Texture2D>("Content/gameAssets/cloud0"))
);
BCTextureVisitor cloud1 = new BCTextureVisitor(
"tex1",
new
BCMemoryTextureStrategy(content.Load<Texture2D>("Content/gameAssets/cloud1"))
);
timedTexFeeder = new BCTimedTextureFeeder();
timedTexFeeder.addSampler(
"tex",
new BCSampler(
"LINEAR", "LINEAR", "LINEAR", "4",
"WRAP", "WRAP", "0xffffffff"
)
);
timedTexFeeder.addSampler(
"tex1",
new BCSampler(
"LINEAR", "LINEAR", "LINEAR", "4",
"WRAP", "WRAP", "0xffffffff"
)
);
BCDynamicEffectVisitor textureEffectSetter =
new BCDynamicEffectVisitor(
timedTexFeeder.getFunction("Shader.Texture.Motion.ScrollTexture"),
timedTexFeeder,
BCDynamicEffect.MAX_FUNCTIONS
);
plane.visit(cloud0);
plane.visit(cloud1);
plane.visit(colorSetter);
plane.visit(textureEffectSetter);
}
protected override void
OnActivated(object sender, EventArgs args)
{
buildViewMatrix();
base.OnActivated(sender, args);
}
void buildViewMatrix()
{
Vector3 pos = new Vector3(-70, 40, -70);
Vector3 look = new Vector3(7, -4, 7);
look.Normalize();
camera = new BCFirstPersonHumanCamera(look, pos,
MathHelper.PiOver4,
(float)this.Window.ClientBounds.Width /
(float)this.Window.ClientBounds.Height,
1f, 200);
BCGlobalInfo.instance.setMatrix(
BCGlobalInfo.VIEW_INDEX,
camera.getViewMatrix(-1)
);
BCGlobalInfo.instance.setMatrix(
BCGlobalInfo.PROJECTION_INDEX,
camera.getProjectionMatrix(-1)
);
}
protected override void
Update(GameTime gameTime)
{
timedTexFeeder.gTime = (float)gameTime.TotalGameTime.TotalSeconds / 10;
}
protected override void
Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(ClearOptions.Target |
ClearOptions.DepthBuffer, Color.White, 1.0f, 0);
plane.Draw(gameTime);
BCLogger.instance.printFPS(gameTime);
BCLogger.instance.flush();
base.Draw(gameTime);
}
}
}