internal GameLoop(GraphicsDevice gd, StuffKeeper sk, string gameRootDir) { mGD = gd; mSK = sk; mResX = gd.RendForm.ClientRectangle.Width; mResY = gd.RendForm.ClientRectangle.Height; mFontMats = new MatLib(gd, sk); mFontMats.CreateMaterial("Text"); mFontMats.SetMaterialEffect("Text", "2D.fx"); mFontMats.SetMaterialTechnique("Text", "Text"); mFonts = sk.GetFontList(); mST = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000); mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f); Vector4 color = Vector4.UnitY + (Vector4.UnitW * 0.15f); //string indicators for various statusy things mST.AddString(mFonts[0], "Stuffs", "PosStatus", color, Vector2.UnitX * 20f + Vector2.UnitY * 580f, Vector2.One); mST.AddString(mFonts[0], "Thread Status...", "ThreadStatus", color, Vector2.UnitX * 20f + Vector2.UnitY * 560f, Vector2.One); mTerMats = new MatLib(mGD, sk); Vector3 lightDir = Mathery.RandomDirection(mRand); Vector4 lightColor2 = Vector4.One * 0.4f; Vector4 lightColor3 = Vector4.One * 0.1f; lightColor2.W = lightColor3.W = 1f; mTerMats.CreateMaterial("Terrain"); mTerMats.SetMaterialEffect("Terrain", "Terrain.fx"); mTerMats.SetMaterialTechnique("Terrain", "TriTerrain"); mTerMats.SetMaterialParameter("Terrain", "mLightColor0", Vector4.One); mTerMats.SetMaterialParameter("Terrain", "mLightColor1", lightColor2); mTerMats.SetMaterialParameter("Terrain", "mLightColor2", lightColor3); mTerMats.SetMaterialParameter("Terrain", "mLightDirection", lightDir); mTerMats.SetMaterialParameter("Terrain", "mSolidColour", Vector4.One); mTerMats.SetMaterialParameter("Terrain", "mSpecPower", 1); mTerMats.SetMaterialParameter("Terrain", "mSpecColor", Vector4.One); mTerMats.SetMaterialParameter("Terrain", "mWorld", Matrix.Identity); mTerMats.CreateMaterial("Sky"); mTerMats.SetMaterialEffect("Sky", "Terrain.fx"); mTerMats.SetMaterialTechnique("Sky", "SkyGradient"); mTerMats.InitCelShading(1); mTerMats.GenerateCelTexturePreset(mGD.GD, mGD.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0); mTerMats.SetCelTexture(0); mSkyCube = PrimFactory.CreateCube(gd.GD, -5f); //debug draw mDebugMats = new MatLib(gd, sk); Vector4 redColor = Vector4.One; Vector4 greenColor = Vector4.One; Vector4 blueColor = Vector4.One; redColor.Y = redColor.Z = greenColor.X = greenColor.Z = blueColor.X = blueColor.Y = 0f; mDebugMats.CreateMaterial("DebugBoxes"); mDebugMats.SetMaterialEffect("DebugBoxes", "Static.fx"); mDebugMats.SetMaterialTechnique("DebugBoxes", "TriSolidSpec"); mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor0", Vector4.One); mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor1", lightColor2); mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor2", lightColor3); mDebugMats.SetMaterialParameter("DebugBoxes", "mSolidColour", blueColor); mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecPower", 1); mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecColor", Vector4.One); }
internal TerrainLoop(GraphicsDevice gd, StuffKeeper sk, string gameRootDir) { mGD = gd; mSK = sk; mResX = gd.RendForm.ClientRectangle.Width; mResY = gd.RendForm.ClientRectangle.Height; mFontMats = new MatLib(gd, sk); mFontMats.CreateMaterial("Text"); mFontMats.SetMaterialEffect("Text", "2D.fx"); mFontMats.SetMaterialTechnique("Text", "Text"); mFonts = sk.GetFontList(); mST = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000); mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f); string path = gameRootDir + "\\Levels\\Testa.Terrain"; mTerrain = new Terrain(path); //build model for raycasts/collisions mTModel = mTerrain.ConstructModel(); mTModel.FixBoxHeights(); // Vector4 color =Vector4.UnitY + (Vector4.UnitW * 0.15f); Vector4 color = Vector4.UnitX * 0.25f + Vector4.UnitZ * 0.25f + (Vector4.UnitW * 0.55f); //string indicators for various statusy things mST.AddString(mFonts[0], "Stuffs", "PosStatus", color, Vector2.UnitX * 20f + Vector2.UnitY * 610f, Vector2.One); mST.AddString(mFonts[0], "Stuffs", "ColStatus", color, Vector2.UnitX * 20f + Vector2.UnitY * 630f, Vector2.One); mST.AddString(mFonts[0], "Thread Status...", "ThreadStatus", color, Vector2.UnitX * 20f + Vector2.UnitY * 650f, Vector2.One); mTerMats = new MatLib(mGD, sk); Vector3 lightDir = Mathery.RandomDirection(mRand); Vector4 lightColor2 = Vector4.One * 0.4f; Vector4 lightColor3 = Vector4.One * 0.1f; lightColor2.W = lightColor3.W = 1f; mTerMats.CreateMaterial("Terrain"); mTerMats.SetMaterialEffect("Terrain", "Terrain.fx"); mTerMats.SetMaterialTechnique("Terrain", "TriTerrain"); mTerMats.SetMaterialParameter("Terrain", "mLightColor0", Vector4.One); mTerMats.SetMaterialParameter("Terrain", "mLightColor1", lightColor2); mTerMats.SetMaterialParameter("Terrain", "mLightColor2", lightColor3); mTerMats.SetMaterialParameter("Terrain", "mLightDirection", lightDir); mTerMats.SetMaterialParameter("Terrain", "mSolidColour", Vector4.One); mTerMats.SetMaterialParameter("Terrain", "mSpecPower", 1); mTerMats.SetMaterialParameter("Terrain", "mSpecColor", Vector4.One); mTerMats.SetMaterialParameter("Terrain", "mWorld", Matrix.Identity); mTerMats.CreateMaterial("Sky"); mTerMats.SetMaterialEffect("Sky", "Terrain.fx"); mTerMats.SetMaterialTechnique("Sky", "SkyGradient"); LoadShading(path); mTerMats.InitCelShading(1); mTerMats.GenerateCelTexturePreset(mGD.GD, mGD.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0); mTerMats.SetCelTexture(0); mSkyCube = PrimFactory.CreateCube(gd.GD, -5f); LoadTerrainTextureStuff(path); //debug draw mDebugMats = new MatLib(gd, sk); Vector4 redColor = Vector4.One; Vector4 greenColor = Vector4.One; Vector4 blueColor = Vector4.One; redColor.Y = redColor.Z = greenColor.X = greenColor.Z = blueColor.X = blueColor.Y = 0f; mDebugMats.CreateMaterial("DebugBoxes"); mDebugMats.SetMaterialEffect("DebugBoxes", "Static.fx"); mDebugMats.SetMaterialTechnique("DebugBoxes", "TriSolidSpec"); mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor0", Vector4.One); mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor1", lightColor2); mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor2", lightColor3); mDebugMats.SetMaterialParameter("DebugBoxes", "mSolidColour", blueColor); mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecPower", 1); mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecColor", Vector4.One); mNumStreamThreads = 2; mGroundPos.Y = 3000f; //start above mCellGridMax = mTerrain.GetCellGridMax(); mBoundary = mTerrain.GetBoundary(); Viewport vp = mGD.GetScreenViewPort(); mGD.GCam.Projection = Matrix.PerspectiveFovLH( MathUtil.DegreesToRadians(45f), vp.Width / (float)vp.Height, 0.1f, FogEnd); mGD.SetClip(0.1f, FogEnd); mDrawRays = new DrawRays(mGD, mSK); mOtherCam = new GameCamera(vp.Width, vp.Height, vp.Width / (float)vp.Height, 0.1f, FogEnd); }
public DrawStuff(GraphicsDevice gd, MaterialLib.StuffKeeper sk) { mMatLib = new MatLib(gd, sk); mLightDir = Mathery.RandomDirection(mRand); Vector4 lightColor2 = Vector4.One * 0.8f; Vector4 lightColor3 = Vector4.One * 0.6f; lightColor2.W = lightColor3.W = 1f; mMatLib.CreateMaterial("FacePoints"); mMatLib.SetMaterialEffect("FacePoints", "Static.fx"); mMatLib.SetMaterialTechnique("FacePoints", "TriVColorSolidSpec"); mMatLib.SetMaterialParameter("FacePoints", "mLightColor0", Vector4.One); mMatLib.SetMaterialParameter("FacePoints", "mLightColor1", lightColor2); mMatLib.SetMaterialParameter("FacePoints", "mLightColor2", lightColor3); mMatLib.SetMaterialParameter("FacePoints", "mSolidColour", Vector4.One); mMatLib.SetMaterialParameter("FacePoints", "mSpecPower", 1); mMatLib.SetMaterialParameter("FacePoints", "mSpecColor", Vector4.One); mMatLib.SetMaterialParameter("FacePoints", "mWorld", Matrix.Identity); mMatLib.CreateMaterial("LMPlane"); mMatLib.SetMaterialEffect("LMPlane", "Static.fx"); mMatLib.SetMaterialTechnique("LMPlane", "TriTex0"); mMatLib.SetMaterialParameter("LMPlane", "mLightColor0", Vector4.One); mMatLib.SetMaterialParameter("LMPlane", "mLightColor1", lightColor2); mMatLib.SetMaterialParameter("LMPlane", "mLightColor2", lightColor3); mPlaneProj = Matrix.OrthoOffCenterLH(0, gd.RendForm.Width, gd.RendForm.Height, 0, 0.1f, 5f); mPlaneWorld = Matrix.RotationY(MathF.PI); mPlaneWorld *= Matrix.Translation(Vector3.ForwardLH + Vector3.UnitX * 105f + Vector3.UnitY * 530f); mLMPlane = PrimFactory.CreatePlane(gd.GD, 200f); //axis boxes BoundingBox xBox = Misc.MakeBox(AxisSize, 1f, 1f); BoundingBox yBox = Misc.MakeBox(1f, AxisSize, 1f); BoundingBox zBox = Misc.MakeBox(1f, 1f, AxisSize); xBox.Minimum.X = 0; yBox.Minimum.Y = 0; mTexU = PrimFactory.CreateCube(gd.GD, xBox); mTexV = PrimFactory.CreateCube(gd.GD, yBox); Vector4 redColor = Vector4.One; Vector4 greenColor = Vector4.One; Vector4 blueColor = Vector4.One; redColor.Y = redColor.Z = greenColor.X = greenColor.Z = blueColor.X = blueColor.Y = 0f; //materials for axis mMatLib.CreateMaterial("RedAxis"); mMatLib.SetMaterialEffect("RedAxis", "Static.fx"); mMatLib.SetMaterialTechnique("RedAxis", "TriSolidSpec"); mMatLib.SetMaterialParameter("RedAxis", "mLightColor0", Vector4.One); mMatLib.SetMaterialParameter("RedAxis", "mLightColor1", lightColor2); mMatLib.SetMaterialParameter("RedAxis", "mLightColor2", lightColor3); mMatLib.SetMaterialParameter("RedAxis", "mSolidColour", redColor); mMatLib.SetMaterialParameter("RedAxis", "mSpecPower", 1); mMatLib.SetMaterialParameter("RedAxis", "mSpecColor", Vector4.One); mMatLib.CloneMaterial("RedAxis", "GreenAxis"); mMatLib.CloneMaterial("RedAxis", "BlueAxis"); mMatLib.SetMaterialParameter("GreenAxis", "mSolidColour", blueColor); mMatLib.SetMaterialParameter("BlueAxis", "mSolidColour", greenColor); }