Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        internal void BuildRayDrawInfo(List <Vector3> rays, List <Vector3> hits, float polySize)
        {
            if (mVBRays != null)
            {
                mVBRays.Dispose();
            }
            if (mIBRays != null)
            {
                mIBRays.Dispose();
            }

            if (mHits != null)
            {
                mHits.Free();
            }

            if (rays.Count < 2)
            {
                return;
            }

            VPosNormCol0    [] segVerts = new VPosNormCol0[rays.Count * 3];
            VPosNormCol0    [] hitVerts = new VPosNormCol0[hits.Count * 8];

            UInt32        index   = 0;
            List <UInt32> indexes = new List <UInt32>();

            for (int i = 0; i < rays.Count; i += 2)
            {
                Color col = Mathery.RandomColor(mRand);

                //endpoint
                segVerts[index].Position = rays[i + 1];

                Vector3 lineVec = rays[i + 1] - rays[i];

                //get a perpindicular axis to the a to b axis
                //so the back side of the connection can flare out a bit
                Vector3 crossVec = Vector3.Cross(lineVec, Vector3.UnitY);

                crossVec.Normalize();

                Vector3 normVec = Vector3.Cross(crossVec, lineVec);

                normVec.Normalize();

                //crossVec	*=.2f;

                segVerts[index + 1].Position = rays[i] - crossVec;
                segVerts[index + 2].Position = rays[i] + crossVec;


                //scale up to visible
                segVerts[index].Position.X     *= polySize;
                segVerts[index].Position.Z     *= polySize;
                segVerts[index + 1].Position.X *= polySize;
                segVerts[index + 1].Position.Z *= polySize;
                segVerts[index + 2].Position.X *= polySize;
                segVerts[index + 2].Position.Z *= polySize;

                //upside down tri
                segVerts[index + 3].Position = segVerts[index + 2].Position;
                segVerts[index + 4].Position = segVerts[index + 1].Position;
                segVerts[index + 5].Position = segVerts[index].Position;

                segVerts[index].Color0     = col;
                segVerts[index + 1].Color0 = col;
                segVerts[index + 2].Color0 = col;
                segVerts[index + 3].Color0 = col;
                segVerts[index + 4].Color0 = col;
                segVerts[index + 5].Color0 = col;

                Half4 norm;
                norm.X = normVec.X;
                norm.Y = normVec.Y;
                norm.Z = normVec.Z;
                norm.W = 1f;
                segVerts[index].Normal     = norm;
                segVerts[index + 1].Normal = norm;
                segVerts[index + 2].Normal = norm;

                norm.X = -normVec.X;
                norm.Y = -normVec.Y;
                norm.Z = -normVec.Z;
                segVerts[index + 3].Normal = norm;
                segVerts[index + 4].Normal = norm;
                segVerts[index + 5].Normal = norm;

                indexes.Add(index);
                indexes.Add(index + 1);
                indexes.Add(index + 2);
                indexes.Add(index + 3);
                indexes.Add(index + 4);
                indexes.Add(index + 5);

                index += 6;
            }

            mVBRays  = VertexTypes.BuildABuffer(mGD.GD, segVerts, VertexTypes.GetIndex(segVerts[0].GetType()));
            mIBRays  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBRays = VertexTypes.BuildAVBB(VertexTypes.GetIndex(segVerts[0].GetType()), mVBRays);

            mRaysIndexCount = indexes.Count;

            indexes.Clear();

            mHits = PrimFactory.CreateCubes(mGD.GD, hits, 5f);
        }