protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); ///Create the Terrain Object ///Controls how the heigh map is loaded TerrainObject to = new TerrainObject(factory, "..\\Content\\Textures\\Untitled", Vector3.Zero, Matrix.Identity, MaterialDescription.DefaultBepuMaterial(), 1, 1,10); ///Create the Model using the Terrain Object. Here we pass the textures used, in our case we are using MultiTextured Terrain so we pass lots of textures TerrainModel stm = new TerrainModel(factory, to, "TerrainName", "..\\Content\\Textures\\Terraingrass"); stm.SetTexture(factory.CreateTexture2DColor(1,1,Color.Green), TextureType.DIFFUSE); ///Create the shader ///In this sample we passed lots of textures, each one describe a level in the terrain, the ground is the sand and grass. the hills are rocks and the "mountains" are snow ///They are interpolated in the shader, you can control how using the shader parameters exposed in the DeferredTerrainShader ForwardXNABasicShader shader = new ForwardXNABasicShader(); ///Deferred material ForwardMaterial fmaterial = new ForwardMaterial(shader); ///The object itself IObject obj = new IObject(fmaterial, stm, to); ///Add to the world this.World.AddObject(obj); shader.BasicEffect.EnableDefaultLighting(); CameraFirstPerson cam = new CameraFirstPerson(GraphicInfo.Viewport); this.World.CameraManager.AddCamera(cam); }
void createterrain(int height = 5) { ///Create the Terrain Object ///Controls how the heigh map is loaded TerrainObject to = new TerrainObject(GraphicFactory, "..\\Content\\Textures\\hmap", new Vector3(0, -30, 0), Matrix.Identity, MaterialDescription.DefaultBepuMaterial(), 3, 3, height); ///Create the Model using the Terrain Object. Here we pass the textures used TerrainModel stm = new TerrainModel(GraphicFactory, to, "TerrainName", "..\\Content\\Textures\\Terraingrass"); stm.SetTexture("..\\Content\\Textures\\Terraingrass", TextureType.DIFFUSE); ForwardXNABasicShader shader = new ForwardXNABasicShader(); ForwardMaterial fmaterial = new ForwardMaterial(shader); ///The object itself obj = new IObject(fmaterial, stm, to); ///Add to the world this.World.AddObject(obj); ///light =p shader.BasicEffect.EnableDefaultLighting(); shader.BasicEffect.SpecularPower = 250; shader.BasicEffect.PreferPerPixelLighting = true; //Fog =P shader.BasicEffect.FogEnabled = true; shader.BasicEffect.FogColor = new Vector3(0.1f, 0.1f, 0.1f); // Dark grey shader.BasicEffect.FogStart = 30; shader.BasicEffect.FogEnd = 300; }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(true, GraphicInfo); Texture2D tMap = factory.GetTexture2D("Textures//hmap_10243"); QuadTerrain q = new PloobsEngine.Material.QuadTerrain(factory, tMap, 33, 513, 10, 3f); DeferredTerrainMaterial mat = new DeferredTerrainMaterial(q); //Set various terrain stats. mat.diffuseScale = q.flatScale / 4; mat.detailScale = q.flatScale / 100; mat.detailMapStrength = 2; mat.textureBlend = factory.GetTexture2D("Textures//hmap_256blend"); mat.textureDetail = factory.GetTexture2D("Textures//coolgrass2DOT3"); mat.textureRed = factory.GetTexture2D("Textures//TexR"); mat.textureGreen = factory.GetTexture2D("Textures//TexG"); mat.textureBlue = factory.GetTexture2D("Textures//TexB"); mat.textureBlack = factory.GetTexture2D("Textures//TexBase"); TerrainObject to = new TerrainObject(factory,Vector3.Zero, Matrix.Identity, q.getHeightMap() ,MaterialDescription.DefaultBepuMaterial()); IObject obj3 = new IObject(mat, null, to); this.World.AddObject(obj3); LightThrowBepu lt = new LightThrowBepu(this.World, factory); #region NormalLight DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); float li = 0.5f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); #endregion this.World.CameraManager.AddCamera(CameraFirstPerson); CameraFirstPerson.FarPlane = 20000; SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); }
public TerrainModel(GraphicFactory factory, TerrainObject terrainObject, String TerrainName, String BaseTexture, String NivelBaixo = null, String NivelMedio = null, String NivelAlto = null) : base(factory, TerrainName,false) { this.terrainObject = terrainObject; LoadModelo(factory); TextureInformations[0][0].SetTexture(BaseTexture, TextureType.MULTITEX1); TextureInformations[0][0].SetTexture(NivelBaixo, TextureType.MULTITEX2); TextureInformations[0][0].SetTexture(NivelMedio, TextureType.MULTITEX3); TextureInformations[0][0].SetTexture(NivelAlto, TextureType.MULTITEX4); TextureInformations[0][0].SetTexture(terrainObject.HeightMap, TextureType.HEIGHTMAP); }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager) { base.LoadContent(GraphicInfo,factory, contentManager); Picking picking = new Picking(this); this.AddScreenUpdateable(picking); perlim = factory.CreateTexture2DPerlinNoise(512, 512, 0.03f, 3f, 0.5f, 1); to = new TerrainObject(factory,perlim, Vector3.Zero, Matrix.Identity, MaterialDescription.DefaultBepuMaterial(), 2, 2); //TerrainObject to = new TerrainObject(factory,"..\\Content\\Textures\\Untitled",Vector3.Zero,Matrix.Identity,MaterialDescription.DefaultBepuMaterial(),2,1); TerrainModel stm = new TerrainModel(factory, to,"TerrainName","..\\Content\\Textures\\Terraingrass", "..\\Content\\Textures\\rock", "..\\Content\\Textures\\sand", "..\\Content\\Textures\\snow"); DeferredTerrainShader shader = new DeferredTerrainShader(TerrainType.MULTITEXTURE); DeferredMaterial mat = new DeferredMaterial(shader); IObject obj3 = new IObject(mat, stm, to); this.World.AddObject(obj3); #region NormalLight DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); float li = 0.5f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); #endregion this.World.CameraManager.AddCamera(new CameraFirstPerson(true,GraphicInfo)); SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); ///O PICKING FUNCIONA APENAS COM OBJETOS QUE TENHAM CORPO FISICO REAL !!! ///OS GHOST E OS DUMMY NUNCA SERAO SELECIONADOS ///Para ser informado a todo frame sobre as colisoes do raio, basta utilizar o outro construtor picking.OnPickedLeftButton += new OnPicked(onPick); }
/// <summary> /// Load content for the screen. /// </summary> /// <param name="GraphicInfo"></param> /// <param name="factory"></param> /// <param name="contentManager"></param> protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); RasterizerState = new RasterizerState(); RasterizerState.FillMode = FillMode.WireFrame; ///Forward Shader (look at this shader construction for more info) TerrainMaterial material = new TerrainMaterial(factory, "Terrain//HeightMap"); ///The object itself TerrainObject to = new TerrainObject(factory, Vector3.Zero, Matrix.Identity, material.Model.GetHeights(), MaterialDescription.DefaultBepuMaterial()); IObject obj = new IObject(material, null, to); ///Add to the world this.World.AddObject(obj); ///add a camera RotatingCamera cam = new RotatingCamera(this, new Vector3(-200, -100, -300)); this.World.CameraManager.AddCamera(cam); SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubeMap"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); { Texture2D t = factory.CreateTexture2DColor(1, 1, Color.Red); SimpleModel simpleModel = new SimpleModel(factory, "Model/block"); simpleModel.SetTexture(t); ///Forward Shader (look at this shader construction for more info) ForwardXNABasicShader shader = new ForwardXNABasicShader(); ///Forward material ForwardMaterial fmaterial = new ForwardMaterial(shader); for (int i = 0; i < 10; i++) { for (int j = 0; j < 5; j++) { ///Physic info (position, rotation and scale are set here) BoxObject tmesh = new BoxObject(new Vector3(j * 10 + 200, 100, i * 10 + 200), 1, 1, 1, 10, Vector3.One * 2, Matrix.Identity, MaterialDescription.DefaultBepuMaterial()); ///The object itself obj = new IObject(fmaterial, simpleModel, tmesh); ///Add to the world this.World.AddObject(obj); objs.Add(obj); tmesh.isMotionLess = true; } } shader.BasicEffect.EnableDefaultLighting(); } }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager) { base.LoadContent(GraphicInfo,factory, contentManager); ///Create the Terrain Object ///Controls how the heigh map is loaded TerrainObject to = new TerrainObject(factory,"..\\Content\\Textures\\Untitled",Vector3.Zero,Matrix.Identity,MaterialDescription.DefaultBepuMaterial(),2,1); ///Create the Model using the Terrain Object. Here we pass the textures used, in our case we are using MultiTextured Terrain so we pass lots of textures TerrainModel stm = new TerrainModel(factory, to,"TerrainName","..\\Content\\Textures\\Terraingrass", "..\\Content\\Textures\\rock", "..\\Content\\Textures\\sand", "..\\Content\\Textures\\snow"); ///Create the shader ///In this sample we passed lots of textures, each one describe a level in the terrain, the ground is the sand and grass. the hills are rocks and the "mountains" are snow ///They are interpolated in the shader, you can control how using the shader parameters exposed in the DeferredTerrainShader DeferredTerrainShader shader = new DeferredTerrainShader(TerrainType.MULTITEXTURE); ///the classic material DeferredMaterial mat = new DeferredMaterial(shader); IObject obj3 = new IObject(mat, stm, to); this.World.AddObject(obj3); lt = new LightThrowBepu(this.World, factory); #region NormalLight DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); float li = 0.5f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); #endregion CameraFirstPerson cam = new CameraFirstPerson(MathHelper.ToRadians(30), MathHelper.ToRadians(-10), new Vector3(200, 150, 250), GraphicInfo); this.World.CameraManager.AddCamera(cam); SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//grassCube"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); this.RenderTechnic.AddPostEffect(new AntiAliasingPostEffectStalker()); }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(true, GraphicInfo); Texture2D tMap = factory.GetTexture2D("Textures//hmap_10243"); QuadTerrain q = new PloobsEngine.Material.QuadTerrain(factory, tMap, 33, 513, 10, 3f); ForwardTerrainMaterial mat = new ForwardTerrainMaterial(q); //Set various terrain stats. mat.diffuseScale = q.flatScale / 4; mat.detailScale = q.flatScale / 100; mat.detailMapStrength = 2; mat.textureBlend = factory.GetTexture2D("Textures//hmap_256blend"); mat.textureDetail = factory.GetTexture2D("Textures//coolgrass2DOT3"); mat.textureRed = factory.GetTexture2D("Textures//TexR"); mat.textureGreen = factory.GetTexture2D("Textures//TexG"); mat.textureBlue = factory.GetTexture2D("Textures//TexB"); mat.textureBlack = factory.GetTexture2D("Textures//TexBase"); mat.sunlightVector = Vector3.Normalize(new Vector3(.5f, .5f, .8f)); mat.sunlightColour = new Vector3(2.3f, 2f, 1.8f); TerrainObject to = new TerrainObject(factory,Vector3.Zero, Matrix.Identity, q.getHeightMap() ,MaterialDescription.DefaultBepuMaterial()); IObject obj3 = new IObject(mat, null, to); this.World.AddObject(obj3); LightThrowBepu lt = new LightThrowBepu(this.World, factory); this.World.CameraManager.AddCamera(CameraFirstPerson); CameraFirstPerson.FarPlane = 20000; SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); }
/// <summary> /// Load content for the screen. /// </summary> /// <param name="GraphicInfo"></param> /// <param name="factory"></param> /// <param name="contentManager"></param> protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); ///Forward Shader (look at this shader construction for more info) TerrainMaterial material = new TerrainMaterial(factory, "Terrain//HeightMap"); ///The object itself TerrainObject to = new TerrainObject(factory, Vector3.Zero, Matrix.Identity, material.Model.GetHeights(), MaterialDescription.DefaultBepuMaterial()); IObject obj = new IObject(material, null, to); ///Add to the world this.World.AddObject(obj); ///add a camera this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); Texture2D t = factory.CreateTexture2DColor(1,1,Color.Red); for (int i = 0; i < 10; i++) { for (int j = 0; j < 5; j++) { SimpleModel simpleModel = new SimpleModel(factory, "Model/block"); simpleModel.SetTexture(t); ///Physic info (position, rotation and scale are set here) BoxObject tmesh = new BoxObject(new Vector3(j * 10 + 200,100,i * 10 + 200), 1, 1, 1, 10, Vector3.One * 2, Matrix.Identity, MaterialDescription.DefaultBepuMaterial()); ///Forward Shader (look at this shader construction for more info) ForwardXNABasicShader shader = new ForwardXNABasicShader(); ///Forward material ForwardMaterial fmaterial = new ForwardMaterial(shader); ///The object itself obj = new IObject(fmaterial, simpleModel, tmesh); ///Add to the world this.World.AddObject(obj); } } }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager) { base.LoadContent(GraphicInfo,factory, contentManager); TerrainObject to = new TerrainObject(factory,"..\\Content\\Textures\\Untitled",Vector3.Zero,Matrix.Identity,MaterialDescription.DefaultBepuMaterial(),2,1); TerrainModel stm = new TerrainModel(factory, to,"TerrainName","..\\Content\\Textures\\Terraingrass", "..\\Content\\Textures\\rock", "..\\Content\\Textures\\sand", "..\\Content\\Textures\\snow"); DeferredTerrainShader shader = new DeferredTerrainShader(TerrainType.MULTITEXTURE); DeferredMaterial mat = new DeferredMaterial(shader); IObject obj3 = new IObject(mat, stm, to); this.World.AddObject(obj3); LightThrowBepu lt = new LightThrowBepu(this.World, factory); #region NormalLight DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); float li = 0.5f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); #endregion this.World.CameraManager.AddCamera(new CameraFirstPerson(true,GraphicInfo)); SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); }
private void GetVertexData(List<VertexPositionNormalTexture> vertices, List<int> indices, TerrainObject to) { Terrain DisplayedObject = to.Terrain; int numColumns = DisplayedObject.Shape.Heights.GetLength(0); int numRows = DisplayedObject.Shape.Heights.GetLength(1); TerrainShape shape = DisplayedObject.Shape; //The terrain can be transformed arbitrarily. However, the collision against the triangles is always oriented such that the transformed local //up vector points in the same direction as the collidable surfaces. //To make sure the graphics match the terrain collision, see if a triangle normal faces in the same direction as the local up vector. //If not, construct the graphics with reversed winding. Vector3 a, b, c; DisplayedObject.GetPosition(0, 0, out a); DisplayedObject.GetPosition(1, 0, out b); DisplayedObject.GetPosition(0, 1, out c); Vector3 normal = Vector3.Cross(c - a, b - a); Vector3 terrainUp = new Vector3(DisplayedObject.WorldTransform.LinearTransform.M21, DisplayedObject.WorldTransform.LinearTransform.M22, DisplayedObject.WorldTransform.LinearTransform.M23); float dot; Vector3.Dot(ref normal, ref terrainUp, out dot); bool reverseWinding = dot < 0; for (int j = 0; j < numRows; j++) { for (int i = 0; i < numColumns; i++) { VertexPositionNormalTexture v; DisplayedObject.GetPosition(i, j, out v.Position); DisplayedObject.GetNormal(i, j, out v.Normal); if (reverseWinding) Vector3.Negate(ref v.Normal, out v.Normal); v.TextureCoordinate = new Vector2(i, j); vertices.Add(v); if (i < numColumns - 1 && j < numRows - 1) if (shape.QuadTriangleOrganization == QuadTriangleOrganization.BottomLeftUpperRight) { //v3 v4 //v1 v2 //v1 v2 v3 indices.Add((int)(numColumns * j + i)); if (reverseWinding) { indices.Add((int)(numColumns * (j + 1) + i)); indices.Add((int)(numColumns * j + i + 1)); } else { indices.Add((int)(numColumns * j + i + 1)); indices.Add((int)(numColumns * (j + 1) + i)); } //v2 v4 v3 indices.Add((int)(numColumns * j + i + 1)); if (reverseWinding) { indices.Add((int)(numColumns * (j + 1) + i)); indices.Add((int)(numColumns * (j + 1) + i + 1)); } else { indices.Add((int)(numColumns * (j + 1) + i + 1)); indices.Add((int)(numColumns * (j + 1) + i)); } } else if (shape.QuadTriangleOrganization == QuadTriangleOrganization.BottomRightUpperLeft) { //v1 v2 v4 indices.Add((int)(numColumns * j + i)); if (reverseWinding) { indices.Add((int)(numColumns * j + i + 1)); indices.Add((int)(numColumns * (j + 1) + i + 1)); } else { indices.Add((int)(numColumns * (j + 1) + i + 1)); indices.Add((int)(numColumns * j + i + 1)); } //v1 v4 v3 indices.Add((int)(numColumns * j + i)); if (reverseWinding) { indices.Add((int)(numColumns * (j + 1) + i)); indices.Add((int)(numColumns * (j + 1) + i + 1)); } else { indices.Add((int)(numColumns * (j + 1) + i + 1)); indices.Add((int)(numColumns * (j + 1) + i)); } } } } }