// Heatmap renderer credit: https://community.esri.com/thread/188830-heatmap-presenting-data-in-runtime-10000 public static Renderer GetHeatmapRenderer(byte opacity = 255, long blurRadius = 14, long minPixelIntensity = 0, long maxPixelIntensity = 100, DataUtils.ColorPalletteType type = DataUtils.ColorPalletteType.Heat) { // Create a new HeatMapRenderer with info provided by the user. HeatMapRenderer heatMapRendererInfo = new HeatMapRenderer { BlurRadius = blurRadius, MinPixelIntensity = minPixelIntensity, MaxPixelIntensity = maxPixelIntensity, }; // Add the chosen color stops (plus transparent for empty areas). var colorStops = GetColorStops(type); //defaultColorStops; foreach (var(ratio, color) in colorStops) { var colorWithAlpha = color; if (ratio != 0) { colorWithAlpha.A = opacity; } heatMapRendererInfo.AddColorStop(ratio, colorWithAlpha); } // Get the JSON representation of the renderer class. string heatMapJson = heatMapRendererInfo.ToJson(); // Use the static Renderer.FromJson method to create a new renderer from the JSON string. return(Renderer.FromJson(heatMapJson)); }
// Update is called once per frame private void Update() { movex = Input.GetAxis("Horizontal"); movez = Input.GetAxis("Vertical"); /* Senza WASD * if(Input.GetKeyDown(KeyCode.UpArrow)) * { * movex = -1 * speed; * } * if (Input.GetKeyDown(KeyCode.DownArrow)) * { * movex = 1 * speed; * } * if (Input.GetKeyDown(KeyCode.LeftArrow)) * { * movez = -1 * speed; * } * if (Input.GetKeyDown(KeyCode.LeftArrow)) * { * movez = +1 * speed; * }*/ Vector3 v = (transform.forward * -movez); this.transform.Rotate(0, movex, 0); rb.AddForce(v * speed); if ((this.transform.GetChild(0).position.x - stored_position.x) < 1f && (this.transform.GetChild(0).position.x - stored_position.x) > -1f && (this.transform.GetChild(0).position.z - stored_position.z) < 1f && (this.transform.GetChild(0).position.z - stored_position.z) > -1f) { isMoving = false; } else { isMoving = true; HeatMapRenderer hm_render = hm_obj.GetComponent <HeatMapRenderer>(); hm_render.hm.AddPoint((int)((49 - rb.transform.position.x)), (int)((21 - rb.transform.position.z))); /*Test for group of pixel * hm_render.hm.AddPoint((int)((49-rb.transform.position.x)/2), (int)((21-rb.transform.position.z)/2)); */ hm_render.toUpdate = true; stored_position.Set(this.transform.GetChild(0).position.x, 0, this.transform.GetChild(0).position.z); } // Debug.Log("Offset X:" + (this.transform.GetChild(0).position.x, stored_position.x)); // Debug.Log("Offset Z:" + (this.transform.GetChild(0).position.z, stored_position.z)); }
/* First Definition Part of the Agent*/ public override void Initialize() { rb = this.GetComponent <Rigidbody>(); m_resetParams = Academy.Instance.EnvironmentParameters; hm_render = hm_obj.GetComponent <HeatMapRenderer>(); rb.velocity = new Vector3(2, 0, 2); house_script = new HouseScript(); for (int i = 0; i < 3; i++) { if (i + 1 == active_display) { cameras[i].enabled = true; } else { cameras[i].enabled = false; } } }
// Update is called once per frame private void FixedUpdate() { if (rb.velocity.magnitude > maxSpeed) { rb.velocity = rb.velocity.normalized * maxSpeed; } if ((this.transform.GetChild(0).position.x - stored_position.x) < 1f && (this.transform.GetChild(0).position.x - stored_position.x) > -1f && (this.transform.GetChild(0).position.z - stored_position.z) < 1f && (this.transform.GetChild(0).position.z - stored_position.z) > -1f) { isMoving = false; } else { isMoving = true; //Getting the map actual value for getting the reward HeatMapRenderer hm_render = hm_obj.GetComponent <HeatMapRenderer>(); float reward = hm_render.hm.GetPoint((int)rb.transform.position.x, (int)rb.transform.position.z); Debug.Log(reward); hm_render.hm.AddPoint((int)rb.transform.position.x, (int)rb.transform.position.z); /*Test for group of pixel * hm_render.hm.AddPoint((int)((49-rb.transform.position.x)/2), (int)((21-rb.transform.position.z)/2)); */ hm_render.toUpdate = true; stored_position.Set(this.transform.GetChild(0).position.x, 0, this.transform.GetChild(0).position.z); if (reward < 1f) { } else { AddReward(-(1 / 1000)); //0.1,0.5,1 //0.0001,0.0005,0.001 } } // Debug.Log("Offset X:" + (this.transform.GetChild(0).position.x, stored_position.x)); // Debug.Log("Offset Z:" + (this.transform.GetChild(0).position.z, stored_position.z)); }