// RadarDisplay Class Definition // // Defines Radar device that can ping the environment for interesting targets Script.include(["pd_utils.js"]); RadarDisplay = function() { print("RadarDisplay - CONSTRUCTOR"); this.targetMarkerUrl = "http://nerdchallenge.com/hifi/props/radar_target.fbx"; this.targetMarkerDims = { x:1.12, y:0.02, z:1.12 }; this.pos = {x:20, y:100 }; this.range = 100.0; // Range of radar. this.targets = []; // Target entities found in latest ping. this.hitText = "Eco Targets Found: "; this.title = createOverlay("RADAR", {x:this.pos.x, y:this.pos.y}, 16, 0.8); this.main = createOverlay(this.hitText + "0", {x:this.pos.x, y:this.pos.y + 30}, 14, 0); }; RadarDisplay.prototype.showUI = function(isVisible) { isVisible = typeof isVisible !== 'undefined' ? isVisible : true; Overlays.editOverlay(this.title, {visible: isVisible}); Overlays.editOverlay(this.main, {visible: isVisible}); }; RadarDisplay.prototype.uiSetHits = function(numHits) { Overlays.editOverlay(this.main, {text: this.hitText + numHits}); }; RadarDisplay.prototype.getTargetsInRange = function() { foundEnts = Entities.findEntities(MyAvatar.position, this.range); this.showUI(); pdTargets = []; //print ("Found ents: " + foundEnts.length); for( i = 0; i < foundEnts.length; i++) { var entity = foundEnts[i]; var entityProps = Entities.getEntityProperties(entity); //print("Processing: " + entityProps.name); var userDataString = entityProps.userData; if (typeof(userDataString) == "undefined") continue; if (userDataString == "") continue; //print("USER DATA STRING:" + userDataString); var userData = JSON.parse(userDataString); print(userData.pdType); if (userData.pdType != "undefined") { this.targets.push(entityProps); print ("Found pd target: " + userData.pdType); } } }; RadarDisplay.prototype.showSceneMarkers = function() { for (i = 0; i < this.targets.length; i++) { print("Creating target marker"); var target = this.targets[i]; createModelEntity(this.targetMarkerUrl, target.position, "radar_target", this.targetMarkerDims, getRandomInt(3,5) ); } }; RadarDisplay.prototype.firePing = function() { this.targets = []; this.getTargetsInRange(); this.uiSetHits(this.targets.length); this.showSceneMarkers(); }; ////////////////////////// // Testing //var radarDisplay = new RadarDisplay(); // Controller.keyPressEvent.connect(keyPressEvent); // function keyPressEvent(event) { // var keyName = event.text; // // if (event.isShifted) { // keyName = "SHIFT+" + keyName; // } // // if (keyName == "r") // { // print("Radar pinging..."); // radarDisplay.firePing(); // } // // if (keyName == "-") // { // MyAvatar.goToLocation({x:0,y:0,z:0}); // MyAvatar.motorVelocity = {x:0,y:0,z:0}; // } // // if (keyName == ">") // { // // Scan mode // print("SCAN mode toggle"); // } // } // // Does a radar ping on enviro