protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); cube = Content.Load <Model>("Box2"); sphere = Content.Load <Model>("Sphere"); torus = Content.Load <Model>("Torus"); terrain = new TerrainRenderer(Content.Load <Texture2D>("mazeH2"), Vector2.One * 100, Vector2.One * 200); terrain.NormalMap = Content.Load <Texture2D>("mazeN2"); terrain.Transform = new Transform(); terrain.Transform.LocalScale *= new Vector3(1, 5, 1); effect = Content.Load <Effect>("TerrainShader"); effect.Parameters["AmbientColor"].SetValue(new Vector3(0.1f, 0.1f, 0.1f)); effect.Parameters["DiffuseColor"].SetValue(new Vector3(0.3f, 0.1f, 0.1f)); effect.Parameters["SpecularColor"].SetValue(new Vector3(0, 0, 0.2f)); effect.Parameters["Shininess"].SetValue(20f); camera = new Camera(); camera.Transform = new Transform(); camera.Transform.LocalPosition = Vector3.Up * 50; camera.Transform.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Right, -MathHelper.PiOver2); player = new Player(terrain, Content, GraphicsDevice, camera, Light.Current); player.Transform.LocalPosition = new Vector3(0, 0, 0); player.Transform.LocalScale = new Vector3(10, 10, 10); }
protected override void OnLoad(EventArgs e) { multisampling = new Multisampling(4); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.ClearColor(State.ClearColor); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.MinSampleShading(1.0f); Map.New(2048); debug = new ObjectRenderer(); camera = new Camera(); terrain = new TerrainRenderer(camera); water = new WaterRenderer(); light = new Light(); assets = new AssetRenderer(); ui = new Ui(); sky = new SkyRenderer(); shadows = new ShadowBox(); }
public void UpdateQuadTree(TerrainRenderer terrain) { foreach (var node in Nodes) { node.UpdateQuadTree(terrain); } }
void SendObjectOverNetwork(GameObject obj) { if (obj.tag == "Platform") { PhotonNetwork.RaiseEvent((int)NetworkEventCode.SpawnPlatform, (Vector2)obj.transform.position, true, null); } else if (obj.tag == "Terrain") { TerrainRenderer renderer = obj.GetComponent <TerrainRenderer>(); if (renderer.ColliderConfigured) { BoxCollider2D bc = renderer.GetComponent <BoxCollider2D>(); //1 tile per unit, so we can use size directly TerrainBlock block = new TerrainBlock(obj.transform.position, (int)bc.size.x, (int)bc.size.y); PhotonNetwork.RaiseEvent((int)NetworkEventCode.SpawnTerrain, block, true, null); } } else if (obj.tag == "Obstacle") { PhotonNetwork.RaiseEvent((int)NetworkEventCode.SpawnObstacle, (Vector2)obj.transform.position, true, null); } else if (obj.tag == "Item") { PhotonNetwork.RaiseEvent((int)NetworkEventCode.SpawnItem, (Vector2)obj.transform.position, true, null); } }
private void refresh(Model model, TerrainRenderer terrain) { var placedAssets = assetsInNode.Where(a => a.Model == model.ModelName).ToList(); var positions = new Vector3[placedAssets.Count]; var rotations = new float[placedAssets.Count]; var scales = new float[placedAssets.Count]; for (var i = 0; i < placedAssets.Count; i++) { positions[i] = new Vector3(placedAssets[i].Position.X, (float)terrain.HeightMap.GetElevationAtPoint(placedAssets[i].Position), placedAssets[i].Position.Y); rotations[i] = placedAssets[i].Rotation; scales[i] = placedAssets[i].Scale; } foreach (var mesh in model.Meshes) { GL.BindBuffer(BufferTarget.ArrayBuffer, positionBuffer); GL.BufferData <Vector3>(BufferTarget.ArrayBuffer, positions.Length * Vector3.SizeInBytes, positions, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, rotationBuffer); GL.BufferData <float>(BufferTarget.ArrayBuffer, rotations.Length * sizeof(float), rotations, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, scaleBuffer); GL.BufferData <float>(BufferTarget.ArrayBuffer, scales.Length * sizeof(float), scales, BufferUsageHint.StaticDraw); } }
void SpawnTerrain() { // Spawn terrain int numSegments = Random.Range(minContiguousTerrainSegments, maxContiguousTerrainSegments); int totalWidth = 0; // measured in # tiles int currentSequenceWidth = 0; int heightOfCurrentSequence = 0; TerrainRenderer firstSegment = null; for (int x = 0; x < numSegments; x++) { int segmentWidth = Random.Range(minTerrainSegmentWidth, maxTerrainSegmentWidth); int segmentHeight = Random.Range(minTerrainSegmentHeight, maxTerrainSegmentHeight); float terrainSegmentX = transform.position.x + totalWidth; float terrainSegmentY = cameraLowerEdge; TerrainRenderer currentSegment = base.SpawnTerrain(terrainSegmentX, terrainSegmentY, segmentWidth, segmentHeight); if (x == 0) { firstSegment = currentSegment; } else if (segmentHeight != heightOfCurrentSequence) { firstSegment.ConfigureCollider(currentSequenceWidth, heightOfCurrentSequence); firstSegment = currentSegment; currentSequenceWidth = 0; } if (x == numSegments - 1) { if (segmentHeight == heightOfCurrentSequence) { firstSegment.ConfigureCollider(currentSequenceWidth + segmentWidth, heightOfCurrentSequence); } else { currentSegment.ConfigureCollider(segmentWidth, segmentHeight); } } currentSequenceWidth += segmentWidth; heightOfCurrentSequence = segmentHeight; // Spawn obstacle in random location on top of terrain segment float minObstacleX = terrainSegmentX; float maxObstacleX = terrainSegmentX + segmentWidth; float minObstacleY = terrainSegmentY + segmentHeight + 0.5f; SpawnObject(minObstacleX, maxObstacleX, minObstacleY); totalWidth += segmentWidth; } // Schedule next spawn Invoke("SpawnNext", (totalWidth * TerrainRenderer.TerrainTileUnit) / GameSettings.Instance.GameSpeed + Random.Range(minSpawnWaitTime, maxSpawnWaitTime)); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ClearColor(1, 1, 1, 1); FontDrawing = new QFontDrawing(); MainFont = new QFont("Tahoma", 16, new QFontBuilderConfiguration()); // load the rooms var rooms = Directory.GetFiles(@"Content\Rooms", "*.txt", SearchOption.AllDirectories) .Select(path => RoomLoader.Load(path)) .ToList(); var items = Directory.GetFiles(@"Content\Items", "*.txt", SearchOption.AllDirectories) .SelectMany(path => ItemLoader.Load(path).Select(w => w.itemtemplate)) .ToList(); // build the map const int mapw = 75, maph = 25; Map = new Map(mapw, maph, rooms, new Random()); // and the terrain renderer TerrainRenderer = new TerrainRenderer(Map) { ViewMatrix = Matrix4.CreateTranslation(2, 2, 0) * Matrix4.CreateScale(.1f) }; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { StandardLightingMaterial.effect = Content.Load <Effect>("Standard"); text = new SpriteBatch(GraphicsDevice); // *** ScreenManager *********************** ScreenManager.Setup(false, 1080, 720); camera.Transform.LocalPosition = Vector3.Up * 20; camera.Transform.Rotate(camera.Transform.Left, (float)Math.PI / 2); camera.FieldOfView = 2.6f; mapCam.orthographic = true; mapCam.Transform.LocalPosition = Vector3.Up * 100; mapCam.Transform.Rotate(mapCam.Transform.Left, (float)Math.PI / 2); mapCam.Size = Vector2.One * 100; mapCam.Position = new Vector2(0.9f, 0.01f); //*************************************** // F*****g around backgrounds = new SpriteBatch(GraphicsDevice); background = Content.Load <Texture2D>("DOGGIE"); offset = Content.Load <Effect>("offset"); Enemy.enemyModel = Content.Load <Model>("sphere"); terrain = new TerrainRenderer( Content.Load <Texture2D>("HeightMap"), Vector2.One * 100, Vector2.One * 200); terrain.NormalMap = Content.Load <Texture2D>("NormalMap"); terrainObject = GameObject3d.Initialize(); terrain.ourObject = terrainObject; terrainObject.material = terrain; terrainObject.transform.LocalScale *= new Vector3(1, 5, 1); font = Content.Load <SpriteFont>("font"); TerrainRenderer.effect = Content.Load <Effect>("TerrainShader"); Enemy.terrain = terrain; // Create Player playerObject = GameObject3d.Initialize(); playerObject.addBehavior(new PlayerBehav(terrain)); playerObject.mesh = Content.Load <Model>("sphere"); Enemy.createEnemy(playerObject); Enemy.createEnemy(playerObject); Enemy.createEnemy(playerObject); foreach (GameObject3d gameObject in GameObject3d.activeGameObjects) { gameObject.Start(); } GameObject.gameStarted = true; }
public MasterRenderer() { GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); createProjectionMatrix(); renderer = new EntityRenderer(shader,projectionMatrix); terrainRenderer = new TerrainRenderer(terrainShader, projectionMatrix); }
public TerrainRendererInitSystem(ICommonSessionObjects commonSession, ClientSessionObjectsComponent clientSession) { _commonSession = commonSession; _clientSession = clientSession; _renderer = new TerrainRenderer(); _clientSession.TerrainRenderer = _renderer; }
public void Render() { TerrainRenderer terrainRenderer = GetComponent <TerrainRenderer>(); terrainRenderer.terrainMap = currentMap; terrainRenderer.ClearImmediate(); terrainRenderer.Render(); }
public virtual TerrainRenderer SpawnTerrain(float posX, float posY, int width, int height) { TerrainRenderer terrainRenderer = terrainPool.Pop().GetComponent <TerrainRenderer>(); terrainRenderer.transform.position = new Vector2(posX, posY); terrainRenderer.gameObject.SetActive(true); terrainRenderer.Generate(width, height); return(terrainRenderer); }
public void Remove(Vector2 position, TerrainRenderer terrain) { foreach (var assetType in Map.MapData.Assets) { assetType.Value.RemoveAll(x => Vector2.Distance(position, x.Position) <= State.ToolRadius); } assetQuadTree.UpdateQuadTree(terrain); }
private void Initialize() { graphicsDevice = ScreenManager.GraphicsDevice; content = ScreenManager.Content; spriteBatch = ScreenManager.SpriteBatch; font = ScreenManager.Font; MeshManager.InitializeManager(graphicsDevice, content); screenWidth = graphicsDevice.Viewport.Width; screenHeight = graphicsDevice.Viewport.Height; clearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); // Create Render Targets mainRT = new RenderTarget2D(graphicsDevice, screenWidth, screenHeight, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); reflectionRT = new RenderTarget2D(graphicsDevice, screenWidth / 2, screenHeight / 2, true, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); occlusionRT = new RenderTarget2D(graphicsDevice, screenWidth / 8, screenHeight / 8, false, SurfaceFormat.Color, DepthFormat.None); bloomRT = new RenderTarget2D(graphicsDevice, screenWidth / 8, screenHeight / 8, false, SurfaceFormat.Color, DepthFormat.None); postEffects = new PostProcessingEffects(graphicsDevice, content.Load <Effect>(@"Effects\PostProcessingEffects")); // Create renderers lightRenderer = new LightRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Light")); terrainRenderer = new TerrainRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Terrain")); surfaceRenderer = new SurfaceRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Surface")); waterRenderer = new WaterRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Water")); billboardRenderer = new BillboardRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Billboard")); meshRenderer = new MeshRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Mesh")); // Create camera camera = new FirstPersonCamera(); camera.AspectRatio = graphicsDevice.Viewport.AspectRatio; camera.AABBSize = new Vector2(1.0f, 8.0f); camera.DrawDistance = 10000.0f; camera.MoveSpeed = 25.0f; camera.FreeFlyEnabled = false; camera.PitchMinDegrees = -75.0f; camera.PitchMaxDegrees = 60.0f; camera.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), camera.AspectRatio, 0.1f, 10000.0f); secretSFX = content.Load <SoundEffect>(@"SoundEffects\shotgun_pump"); // Load level data LoadLevel(@"Levels\" + levelFileName); }
// Start is called before the first frame update void Start() { int width = 64, height = 64; world = new World(width, height); GameObject terrainRendererGO = new GameObject("Terrain Renderer"); TerrainRenderer terrainRenderer = terrainRendererGO.AddComponent <TerrainRenderer>(); terrainRenderer.world = world; }
public static void Save(string name, TerrainRenderer terrain) { var path = getMapPath(name); MapData.Name = name; MapData.TerrainElevations = terrain.HeightMap.Heights; using (var stream = File.Open(path, FileMode.Create)) using (var compressedStream = new GZipStream(stream, CompressionMode.Compress)) { var binarySerializer = Binary.Create(); binarySerializer.Write(MapData, compressedStream); } }
//====== override: GameModule public override void Initialize(GameTime gameTime) { gameLogic = new GameLogic(new Size(100 - 30 - 3, 30 - 2), gameTime); gameLogic.AppleConsumed += () => trgAppleConsumeSound.Set(); terrainRenderer = new TerrainRenderer(); terrainRenderer.Register <AppleEntity>(new AppleLookProvider()); terrainRenderer.Register <SnakeBodyPartEntity>(new SnakeBodyPartLookProvider()); scoreTransitionUI = new ScoreTransitionUI(gameLogic.ScoreStatus, gameTime); bigDigitsScoreUI = new BigDigitsScoreUI(scoreTransitionUI); }
/// <summary> /// Implementation of user interface. /// </summary> private void OnGUI() { int offset = 0; LoadDataArea = new Rect(3, offset += 0, position.width - 6, 120); RenderDataArea = new Rect(3, offset += 120, position.width - 6, 130); // fixed window size GUILayout.ExpandHeight(false); GUILayout.ExpandWidth(false); #region Load Data GUILayout.BeginArea(LoadDataArea); apiKey = EditorGUILayout.TextField("Api Key", apiKey); lat = EditorGUILayout.FloatField("Latitude", lat); lon = EditorGUILayout.FloatField("Longitude", lon); rad = EditorGUILayout.IntSlider("Radius", rad, 1000, 60000); level = EditorGUILayout.IntSlider("Level", level, 7, 15); if (GUILayout.Button("Load Data")) { generator = new TerrainLoader(apiKey); generator.Init(lat, lon, rad, level); generator.Generate(); } if (generator != null) { Progress = generator.GetProgressStatus(); } else { Progress = 0; } GUILayout.EndArea(); #endregion #region Render Data GUILayout.BeginArea(RenderDataArea); minIndex = EditorGUILayout.Vector2IntField("MinIndex", minIndex); maxIndex = EditorGUILayout.Vector2IntField("MaxIndex", maxIndex); Resolution = EditorGUILayout.IntSlider("Resolution", Resolution, 32, 1024); Height = EditorGUILayout.IntSlider("Height", Height, 1, 100); if (GUILayout.Button("Render Data")) { renderer = new TerrainRenderer(); renderer.Init(minIndex.x, minIndex.y, maxIndex.x, maxIndex.y, resolution, Height); renderer.Run(); } GUILayout.EndArea(); #endregion EditorGUI.ProgressBar(new Rect(3, position.height - 24, position.width - 6, 20), Progress, (Progress * 100).ToString()); }
// Use this for initialization void Start() { cam = GetComponent <Camera>(); focus_point = transform.position; selection_renderer = selection_graphic.GetComponent <MeshRenderer>(); tile = new Assets.Scripts.Tiles.Castle(); reqRenderer = new RequirementRenderer(tile.Requirements); renderer = new TerrainRenderer(selection_graphic, reqRenderer, falseMaterial); default_layer = (LayerMask.NameToLayer("Default") + 1) << 8; }
void Start() { PhotonNetwork.OnEventCall += this.OnEvent; if (GameSettings.Instance.MultiplayerMode) { Vector2 lowerLeftCorner = Camera.main.ViewportToWorldPoint(new Vector3(0, 0)); // Camera width = orthographicSize * aspect * 2. Add 4 to account for helper's spawner offset. int width = (int)(Camera.main.orthographicSize * Camera.main.aspect * 2 + distanceOffset + 4); TerrainRenderer terrain = base.SpawnTerrain(lowerLeftCorner.x, lowerLeftCorner.y, width, startingTerrainHeight); terrain.ConfigureCollider(width, startingTerrainHeight); } }
private void addChildren(TerrainRenderer terrain) { for (var x = 0; x < 2; x++) { for (var z = 0; z < 2; z++) { var pos = position + new Vector2(x * (size / 2.0f), z * (size / 2.0f)); var node = new AssetNode(model, pos, level + 1); node.UpdateQuadTree(terrain); children[z * 2 + x] = node; } } }
public Agent(TerrainRenderer terrain, ContentManager Content, Camera camera, GraphicsDevice graphicsDevice, Light light) : base() { Terrain = terrain; this.Content = Content; path = null; //... Potentially need to add more here // *** Adding GameObject Elements *** Rigidbody rigidbody = new Rigidbody(); rigidbody.Transform = Transform; rigidbody.Mass = 1; rigidbody.Transform.LocalScale = new Vector3(3.0f, 3.0f, 3.0f); Add <Rigidbody>(rigidbody); model = Content.Load <Model>("Box"); (model.Meshes[0].Effects[0] as BasicEffect).DiffuseColor = Color.Black.ToVector3(); Renderer renderer = new Renderer(model, rigidbody.Transform, camera, Content, graphicsDevice, light, 1, null, 20f, null); Add <Renderer>(renderer); SphereCollider sphereCollider = new SphereCollider(); sphereCollider.Radius = renderer.ObjectModel.Meshes[0].BoundingSphere.Radius; sphereCollider.Transform = Transform; Add <Collider>(sphereCollider); search = new AStarSearch(gridSize, gridSize); float gridW = Terrain.size.X / gridSize; float gridH = Terrain.size.Y / gridSize; for (int i = 0; i < gridSize; i++) { for (int j = 0; j < gridSize; j++) { Vector3 pos = new Vector3(gridW * j + gridW / 2 - terrain.size.X / 2, 0.0f, gridH * i + gridH / 2 - terrain.size.Y / 2f); if (Terrain.GetAltitude(pos) > 1.0) { search.Nodes[i, j].Passable = false; } } } //Sets first path node RandomPathFinding(); rigidbody.Transform.LocalPosition = GetGridPosition(path[0]); }
public void RenderShadowMap(ShadowBox shadows, TerrainRenderer terrain, ClipPlane clip = ClipPlane.None) { GL.UseProgram(shadowShader.Program); GL.UniformMatrix4(shadowShader.ViewMatrix, false, ref shadows.ViewMatrix); GL.UniformMatrix4(shadowShader.ProjectionMatrix, false, ref shadows.ProjectionMatrix); GL.Uniform1(shadowShader.ClipPlane, (int)clip); assetQuadTree.Render(shadows.ShadowFrustumPlanes, shader); GL.DisableVertexAttribArray(4); GL.DisableVertexAttribArray(5); GL.DisableVertexAttribArray(6); }
// Start is called before the first frame update void Start() { instance = this; chunks = new TerrainChunk[World.instance.width / 100, World.instance.height / 100]; oldCurrentPosition = viewer.transform.position; playerXFloor = (int)Mathf.Round(oldCurrentPosition.x / 100) * 100; playerYFloor = (int)Mathf.Round(oldCurrentPosition.y / 100) * 100; StartCoroutine(CreateTerrain()); StartCoroutine(CheckChange()); StartCoroutine(UnloadTerrain()); // LoadStartingChunks(); }
protected override void LoadContent() { transforms = new List <Transform>(); cameras = new List <Camera>(); spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load <SpriteFont>("Font"); terrain = new TerrainRenderer(Content.Load <Texture2D>("mazeH2"), Vector2.One * 100, Vector2.One * 200); terrain.NormalMap = Content.Load <Texture2D>("mazeN2"); terrain.Transform = new Transform(); terrain.Transform.LocalScale *= new Vector3(1, 5, 1); effect = Content.Load <Effect>("TerrainShader"); effect.Parameters["AmbientColor"].SetValue(new Vector3(0.2f, 0.2f, 0.2f)); effect.Parameters["DiffuseColor"].SetValue(new Vector3(0.1f, 0.1f, 0.1f)); effect.Parameters["SpecularColor"].SetValue(new Vector3(0.2f, 0.2f, 0.2f)); effect.Parameters["Shininess"].SetValue(20f); camera = new Camera(); camera.Transform = new Transform(); camera.Transform.LocalPosition += Vector3.Up * 50; camera.Transform.Rotate(Vector3.Right, -MathHelper.PiOver2); camera.Position = new Vector2(-0.10f, 0f); camera.Size = new Vector2(1f, 1f); camera.AspectRatio = camera.Viewport.AspectRatio; light = new Light(); light.Transform = new Transform(); light.Transform.LocalPosition = Vector3.Backward * 5 + Vector3.Right * 5 + Vector3.Up * 5; random = new Random(); player = new Player(terrain, Content, camera, GraphicsDevice, light); agent = new Agent(terrain, Content, camera, GraphicsDevice, light, random); agent1 = new Agent(terrain, Content, camera, GraphicsDevice, light, random); agent2 = new Agent(terrain, Content, camera, GraphicsDevice, light, random); box = new Box(Content, camera, GraphicsDevice, light); topDownCamera = new Camera(); topDownCamera.Transform = new Transform(); topDownCamera.Transform.LocalPosition += Vector3.Up * 60; topDownCamera.Transform.Rotate(Vector3.Right, -MathHelper.PiOver2); topDownCamera.Position = new Vector2(0.75f, 0f); topDownCamera.Size = new Vector2(0.3f, 0.3f); topDownCamera.AspectRatio = topDownCamera.Viewport.AspectRatio; cameras.Add(topDownCamera); cameras.Add(camera); }
void Start() { w = new World(gameObject, 200, 200, new Classic(0.03f, 30f, 0.005f, 20)); renderer = new TerrainRenderer( this.gameObject, new Assets.Scripts.RenderPipeline.WorldPallette( w, new Color32[] { new Color32(120, 72, 0, 255), new Color32(1, 142, 14, 255), new Color32(194, 178, 128, 255) }), world_material); v = w.GetVertex(0, 0); }
public void UpdateQuadTree(TerrainRenderer terrain) { assetsInNode = getAssetsInNode(model.ModelName); if (!assetsInNode.Any()) { return; } if (assetsInNode.Count > AssetConfig.SplitCount) { addChildren(terrain); return; } refresh(model, terrain); }
public void Render(Camera camera, Light light, ShadowBox shadows, TerrainRenderer terrain, ClipPlane clip = ClipPlane.None) { GL.UseProgram(shader.Program); shader.ApplyCamera(camera); shader.ApplyLight(light); shader.ApplyShadows(shadows); GL.Uniform1(shader.ClipPlane, (int)clip); GL.Uniform4(shader.FogColor, State.ClearColor); GL.Uniform1(shader.FarPlane, State.Far); assetQuadTree.Render(camera.FrustumPlanes, shader); GL.DisableVertexAttribArray(4); GL.DisableVertexAttribArray(5); GL.DisableVertexAttribArray(6); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); GameObject terrainObject = new GameObject(); terrainObject.Transform.LocalScale *= new Vector3(1, 5, 1); terrain = terrainObject.Add <TerrainRenderer>(); terrain.Initialize( Content.Load <Texture2D>("Textures/Heightmap"), Vector2.One * 100, Vector2.One * 200); terrain.NormalMap = Content.Load <Texture2D>("Textures/Normalmap"); effect = Content.Load <Effect>("Effects/TerrainShader"); GameObject cameraObject = new GameObject(); cameraObject.Transform.LocalPosition = Vector3.Backward * 5 + Vector3.Right * 5 + Vector3.Up * 5; camera = cameraObject.Add <Camera>(); }
public void Start() { renderer = GetComponent <TerrainRenderer>(); noiseKernel = FindKernel(terrain3DNoiseShader, KernelIds.perlinNoise3DKernel, out noiseKernelGroupSize); marchingCubeKernel = FindKernel(isoSurfaceShader, KernelIds.marchingCubeKernel, out marchingCubeKernelGroupSize); computeNormalKernel = FindKernel(normalFromNoiseShader, KernelIds.computeNormalKernel, out computeNormalGroupSize); copyMeshBufferKernel = FindKernel(copyMeshBuffersShader, KernelIds.copyMeshBuffers, out copyMeshBufferGroupSize); // We add 1 so we can generate seamless normals at the cost of chunkSize * chunkSize * 3 cells GenerateBuffers(terrainChunkSize + 1); BindBuffers(chunkPosition, terrainChunkSize + 1); foreach (var unused in GenerateStep()) { ; } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load <SpriteFont>("Font"); terrain = new TerrainRenderer(Content.Load <Texture2D>("mazeH2"), Vector2.One * 100, Vector2.One * 200); terrain.Transform = new Transform(); terrain.Transform.LocalScale = new Vector3(1, 5, 1); terrain.NormalMap = Content.Load <Texture2D>("mazeN2"); effect = Content.Load <Effect>("TerrainShader"); effect.Parameters["AmbientColor"].SetValue(new Vector3(0.2f, 0.2f, 0.2f)); effect.Parameters["DiffuseColor"].SetValue(new Vector3(0.2f, 0.2f, 0.2f)); effect.Parameters["SpecularColor"].SetValue(new Vector3(0.2f, 0.2f, 0.2f)); effect.Parameters["Shininess"].SetValue(20f); camera = new Camera(); camera.Transform = new Transform(); camera.Transform.LocalPosition = Vector3.Up * 60; camera.Transform.Rotation = new Quaternion(-0.707f, 0, 0, 0.707f); light = new Light(); light.Transform = new Transform(); light.Transform.LocalPosition = Vector3.Backward * 5 + Vector3.Right * 5 + Vector3.Up * 5; random = new Random(); hits = 0; player = new Player(terrain, Content, camera, GraphicsDevice, light, random); agent1 = new Agent(terrain, Content, camera, GraphicsDevice, light, random); agent2 = new Agent(terrain, Content, camera, GraphicsDevice, light, random); agent3 = new Agent(terrain, Content, camera, GraphicsDevice, light, random); /* * t1 = new Treasure(terrain, Content, camera, GraphicsDevice, light, random); * t2 = new Treasure(terrain, Content, camera, GraphicsDevice, light, random); * t3 = new Treasure(terrain, Content, camera, GraphicsDevice, light, random); * t4 = new Treasure(terrain, Content, camera, GraphicsDevice, light, random); * t5 = new Treasure(terrain, Content, camera, GraphicsDevice, light, random); */ }
private void MakeGame(bool singleplayer) { var gamedata = new GameDataTilesMinecraft(); INetworkClient network; if (singleplayer) { network = new NetworkClientDummy(); } else { network = new NetworkClientMinecraft(); } clientgame = new GameMinecraft(); /* fix for crash */ //w.fpshistorygraphrenderer = new FpsHistoryGraphRenderer() { draw = w, viewportsize = w }; var mapstorage = clientgame; var getfile = new GetFilePath(new[] { "mine", "minecraft" }); var config3d = new Config3d(); var mapManipulator = new MapManipulator(); var terrainDrawer = new TerrainRenderer(); var the3d = w; var exit = w; var localplayerposition = w; var worldfeatures = new WorldFeaturesDrawer(); var physics = new CharacterPhysics(); var mapgenerator = new MapGeneratorPlain(); var internetgamefactory = this; if (singleplayer) { var n = (NetworkClientDummy)network; n.player = localplayerposition; n.Gui = w; n.Map1 = w; n.Map = mapstorage; n.Data = gamedata; n.Gen = new fCraft.MapGenerator(); n.Gen.data = gamedata; n.Gen.log = new fCraft.FLogDummy(); n.Gen.map = new MyFCraftMap() { data = gamedata, map = mapstorage, mapManipulator = mapManipulator }; n.Gen.rand = new GetRandomDummy(); n.DEFAULTMAP = "mountains"; } else { var n = (NetworkClientMinecraft)network; n.Map = w; n.Clients = clientgame; n.Chatlines = w; n.Position = localplayerposition; n.gameworld = new GameWorldTodoDummy(); } terrainDrawer.the3d = the3d; terrainDrawer.getfile = getfile; terrainDrawer.config3d = config3d; terrainDrawer.mapstorage = clientgame; terrainDrawer.data = gamedata; terrainDrawer.exit = exit; terrainDrawer.localplayerposition = localplayerposition; terrainDrawer.worldfeatures = worldfeatures; terrainDrawer.OnCrash += (a, b) => { CrashReporter.Crash(b.exception); }; var terrainChunkDrawer = new TerrainChunkRenderer(); terrainChunkDrawer.config3d = config3d; terrainChunkDrawer.data = gamedata; terrainChunkDrawer.mapstorage = clientgame; terrainDrawer.terrainchunkdrawer = terrainChunkDrawer; terrainChunkDrawer.terrainrenderer = terrainDrawer; worldfeatures.getfile = getfile; worldfeatures.localplayerposition = localplayerposition; worldfeatures.mapstorage = mapstorage; worldfeatures.the3d = the3d; mapManipulator.getfile = getfile; mapManipulator.mapgenerator = mapgenerator; w.map = clientgame; w.physics = physics; w.clients = clientgame; w.network = network; w.data = gamedata; w.getfile = getfile; w.config3d = config3d; w.mapManipulator = mapManipulator; w.terrain = terrainDrawer; bool IsMono = Type.GetType("Mono.Runtime") != null; terrainDrawer.textureatlasconverter = new TextureAtlasConverter(); if (IsMono) { terrainDrawer.textureatlasconverter.fastbitmapfactory = () => { return new FastBitmapDummy(); }; } else { terrainDrawer.textureatlasconverter.fastbitmapfactory = () => { return new FastBitmap(); }; } weapon = new WeaponBlockInfo() { data = gamedata, terrain = terrainDrawer, viewport = w, map = clientgame, shadows = shadowssimple }; w.weapon = new WeaponRenderer() { info = weapon, playerpos = w }; //no torch in mine mode var playerdrawer = new CharacterRendererMonsterCode(); playerdrawer.Load(new List<string>(File.ReadAllLines(getfile.GetFile("player.mdc")))); w.characterdrawer = playerdrawer; w.particleEffectBlockBreak = new ParticleEffectBlockBreak() { d_Data = gamedata, d_Map = clientgame, d_Terrain = terrainDrawer, d_Shadows = shadowsfull}; clientgame.terrain = terrainDrawer; clientgame.network = network; clientgame.viewport = w; clientgame.data = gamedata; w.game = clientgame; w.login = new LoginClientMinecraft(); w.internetgamefactory = internetgamefactory; PlayerSkinDownloader playerskindownloader = new PlayerSkinDownloader(); playerskindownloader.exit = w; playerskindownloader.the3d = the3d; playerskindownloader.skinserver = "http://minecraft.net/skin/"; w.playerskindownloader = playerskindownloader; physics.map = clientgame; physics.data = gamedata; mapgenerator.data = gamedata; audio.getfile = getfile; audio.gameexit = w; shadowsfull = new Shadows() { data = gamedata, map = clientgame, terrain = terrainDrawer, localplayerposition = localplayerposition, config3d = config3d }; shadowssimple = new ShadowsSimple() { data = gamedata, map = clientgame}; UseShadowsSimple(); w.currentshadows = this; var frustumculling = new FrustumCulling() { the3d = the3d }; terrainDrawer.frustumculling = frustumculling; terrainDrawer.batcher = new MeshBatcher() { frustumculling = frustumculling }; terrainDrawer.frustumculling = frustumculling; w.RenderFrame += (a, b) => { frustumculling.CalcFrustumEquations(); }; var dirtychunks = new DirtyChunks() { mapstorage = clientgame }; terrainDrawer.ischunkready = dirtychunks; terrainDrawer.ischunkready.frustum = frustumculling; terrainDrawer.ischunkready.Start(); //clientgame.ischunkready = dirtychunks; if (Debugger.IsAttached) { new DependencyChecker(typeof(InjectAttribute)).CheckDependencies( w, audio, gamedata, clientgame, network, mapstorage, getfile, config3d, mapManipulator, terrainDrawer, the3d, exit, localplayerposition, worldfeatures, physics, mapgenerator, internetgamefactory, playerdrawer, mapManipulator, w.login, shadowsfull, shadowssimple, terrainChunkDrawer); } }
private void MakeGame(bool singleplayer) { var gamedata = new GameDataTilesManicDigger(); var clientgame = new GMFortressLogic(); ICurrentSeason currentseason = clientgame; gamedata.CurrentSeason = currentseason; INetworkClientFortress network; if (singleplayer) { network = new NetworkClientDummyInfinite() { gameworld = clientgame }; clientgame.Players[0] = new Player() { Name = "gamer1" }; } else { network = new NetworkClientFortress(); } var mapstorage = clientgame; var getfile = new GetFilePath(new[] { "mine", "minecraft" }); var config3d = new Config3d(); var mapManipulator = new MapManipulator(); var terrainDrawer = new TerrainRenderer(); var the3d = w; var exit = w; var localplayerposition = w; var worldfeatures = new WorldFeaturesDrawerDummy(); var physics = new CharacterPhysics(); var mapgenerator = new MapGeneratorPlain(); var internetgamefactory = this; if (singleplayer) { var n = (NetworkClientDummyInfinite)network; n.players = clientgame; n.localplayerposition = localplayerposition; } else { var n = (NetworkClientFortress)network; n.Map = w; n.Clients = clientgame; n.Chatlines = w; n.Position = localplayerposition; n.ENABLE_FORTRESS = true; n.NetworkPacketReceived = clientgame; } terrainDrawer.the3d = the3d; terrainDrawer.getfile = getfile; terrainDrawer.config3d = config3d; terrainDrawer.mapstorage = clientgame; terrainDrawer.data = gamedata; terrainDrawer.exit = exit; terrainDrawer.localplayerposition = localplayerposition; terrainDrawer.worldfeatures = worldfeatures; terrainDrawer.OnCrash += (a, b) => { CrashReporter.Crash(b.exception); }; var blockdrawertorch = new BlockDrawerTorch(); blockdrawertorch.terraindrawer = terrainDrawer; blockdrawertorch.data = gamedata; var terrainChunkDrawer = new TerrainChunkRenderer(); terrainChunkDrawer.config3d = config3d; terrainChunkDrawer.data = gamedata; terrainChunkDrawer.mapstorage = clientgame; terrainDrawer.terrainchunkdrawer = terrainChunkDrawer; terrainChunkDrawer.blockdrawertorch = blockdrawertorch; terrainChunkDrawer.terrainrenderer = terrainDrawer; mapManipulator.getfile = getfile; mapManipulator.mapgenerator = mapgenerator; w.map = clientgame.mapforphysics; w.physics = physics; w.clients = clientgame; w.network = network; w.data = gamedata; w.getfile = getfile; w.config3d = config3d; w.mapManipulator = mapManipulator; w.terrain = terrainDrawer; w.PickDistance = 4.5f; weapon = new WeaponBlockInfo() { data = gamedata, terrain = terrainDrawer, viewport = w, map = clientgame, shadows = shadowssimple }; w.weapon = new WeaponRenderer() { info = weapon, blockdrawertorch = blockdrawertorch, playerpos = w }; var playerdrawer = new CharacterRendererMonsterCode(); playerdrawer.Load(new List<string>(File.ReadAllLines(getfile.GetFile("player.mdc")))); w.characterdrawer = playerdrawer; w.particleEffectBlockBreak = new ParticleEffectBlockBreak() { data = gamedata, map = clientgame, terrain = terrainDrawer }; w.ENABLE_FINITEINVENTORY = false; clientgame.terrain = terrainDrawer; clientgame.viewport = w; clientgame.data = gamedata; clientgame.network = network; clientgame.craftingtabletool = new CraftingTableTool() { map = mapstorage }; InfiniteMapChunked map = new InfiniteMapChunked() { generator = new WorldGeneratorDummy() }; map.Reset(10 * 1000, 10 * 1000, 128); clientgame.map = map; terrainDrawer.ischunkready = map; w.game = clientgame; w.login = new LoginClientDummy(); w.internetgamefactory = internetgamefactory; PlayerSkinDownloader playerskindownloader = new PlayerSkinDownloader(); playerskindownloader.exit = w; playerskindownloader.the3d = the3d; playerskindownloader.skinserver = "http://fragmer.net/md/skins/"; w.playerskindownloader = playerskindownloader; w.fpshistorygraphrenderer = new FpsHistoryGraphRenderer() { draw = w, viewportsize = w }; physics.map = clientgame.mapforphysics; physics.data = gamedata; mapgenerator.data = gamedata; audio.getfile = getfile; audio.gameexit = w; this.clientgame = clientgame; this.map = map; w.currentshadows = this; shadowsfull = new Shadows() { data = gamedata, map = clientgame, terrain = terrainDrawer, localplayerposition = localplayerposition, config3d = config3d, ischunkready = map }; shadowssimple = new ShadowsSimple() { data = gamedata, map = clientgame }; if (fullshadows) { UseShadowsFull(); } else { UseShadowsSimple(); } if (Debugger.IsAttached) { new DependencyChecker(typeof(InjectAttribute)).CheckDependencies( w, audio, gamedata, clientgame, network, mapstorage, getfile, config3d, mapManipulator, terrainDrawer, the3d, exit, localplayerposition, worldfeatures, physics, mapgenerator, internetgamefactory, blockdrawertorch, playerdrawer, map, w.login, shadowsfull, shadowssimple, terrainChunkDrawer); } }
protected override void LoadContent() { if (_shouldExit) return; _camera.SetAspectRatio(GraphicsDevice.BackBuffer.Width / (float)GraphicsDevice.BackBuffer.Height); // create all needed components _terrainRenderer = ToDisposeContent(new TerrainRenderer(_graphicsDeviceManager, Content)); _samplingRenderer = ToDisposeContent(new SamplingRenderer(_graphicsDeviceManager, Content)); _residencyManager = ToDisposeContent(new ResidencyManager(_graphicsDeviceManager, Content)); // schedule the loading of the structures that needs to be used right now var createTexturesTask = _terrainRenderer.CreateTexturesAsync(); var loadStructuresTask = _residencyManager.LoadStructuresAsync(); // schedule the loading of other data var terrainRendererTask = _terrainRenderer.LoadStructuresAsync(); var samplingRendererTask = _samplingRenderer.LoadStructuresAsync(); // wait for loading of critical structures that will be used below Task.WaitAll(createTexturesTask, loadStructuresTask); // prepare the tiled textures _terrainRenderer.DiffuseResidencyMap = _residencyManager.ManageTexture(_terrainRenderer.DiffuseTexture, Path.Combine(SampleSettings.DataPath, SampleSettings.DiffuseTextureFile)); _terrainRenderer.NormalResidencyMap = _residencyManager.ManageTexture(_terrainRenderer.NormalTexture, Path.Combine(SampleSettings.DataPath, SampleSettings.NormalTextureFile)); var initializeManagedResourcesTask = _residencyManager.InitializeManagedResourcesAsync(); // wait for all content to load Task.WaitAll(terrainRendererTask, samplingRendererTask, initializeManagedResourcesTask); base.LoadContent(); }