void skeletonCapbility_CalibrationEnd(ProductionNode node, uint id, bool success) { if (success) { Debug.Log("callibration ended successfully"); this.skeletonCapbility.StartTracking(id); this.joints.Add(id, new Dictionary <SkeletonJoint, SkeletonJointPosition>()); } else { this.poseDetectionCapability.StartPoseDetection(calibPose, id); } }
void gestures_GestureRecognized(ProductionNode node, string strGesture, ref Point3D idPosition, ref Point3D endPosition) { Debug.Log("gestures_GestureRecognized(): Here"); switch (strGesture) { case "Wave": this.hands.StartTracking(ref idPosition); break; default: break; } }
/// @brief Initialize the hand control /// /// This method provides the initialization for the hands control initializing all internal objects. /// It assumes the context is already valid (otherwise we fail). /// @note - Since we use a singleton pattern, multiple initializations will simply delete the old /// objects and create new ones! /// @note - It is the responsibility of the initializer to call @ref Dispose. /// @param context the context to use /// @param focusGesture the gesture used for focusing (i.e. this is aimed to set the hand which we will follow) /// @param refocusGesture the gesture used for refocus (when we lose focus temporarily) /// @param logger the logger object we will enter logs into /// @return true on success, false on failure. public bool Init(NIEventLogger logger, NIContext context, string focusGesture, string refocusGesture) { Dispose(); // to make sure we are not initialized if (InitWithContext(logger, context) == false) { return(false); } // we will create the user gestures and hands which are needed for the session manager // but are not needed externally (as we never access them directly). ProductionNode node = context.CreateNode(NodeType.Gesture); if (node == null) { Dispose(); return(false); } m_internalNodes.Add(node); node = context.CreateNode(NodeType.Hands) as HandsGenerator; if (node == null) { Dispose(); return(false); } m_internalNodes.Add(node); try { NINITECheckVersion.Instance.ValidatePrerequisite(); m_sessionManager = new SessionManager(context.BasicContext, focusGesture, refocusGesture); if (refocusGesture.CompareTo("") == 0) { m_sessionManager.QuickRefocusTimeout = 0; } else { m_sessionManager.QuickRefocusTimeout = 15000; } m_sessionManager.SessionStart += new System.EventHandler <PositionEventArgs>(HandsControlSessionStart); m_sessionManager.SessionEnd += new System.EventHandler(HandsControlSessionEnd); m_pointControl = new PointControl(); m_sessionManager.AddListener(m_pointControl); m_pointControl.PrimaryPointDestroy += new System.EventHandler <IdEventArgs>(SessionLostFocus); } catch (System.Exception ex) { Log("failed to create session manager with error " + ex.Message, NIEventLogger.Categories.Errors, NIEventLogger.Sources.Hands); Dispose(); return(false); } return(true); }
void skeletonCapbility_CalibrationEnd(ProductionNode node, uint id, bool success) { if (success) { App.ViewModel.Status = "Tracking user"; this.skeletonCapbility.StartTracking(id); App.ViewModel.Tracking = true; } else { App.ViewModel.Status = "Waiting for pose..."; this.poseDetectionCapability.StartPoseDetection(calibPose, id); } }
private void SpawnPlanet(int planetNumber, int maxPlanets) { // Get a random position for the planet. // Note that the distance from the star is set based on how many planets have been generated already // and the planet seperation distance. Vector2 pos = Random.insideUnitCircle; pos.Normalize(); pos *= (planetSeperationDistance * (planetNumber + 1)); // Create the planet from the prefab template and set its position GameObject newPlanet = Instantiate(planetTemplate, transform); newPlanet.transform.parent = gameObject.transform; newPlanet.transform.Translate(pos); // Give the planet a sprite and a name GiveSprite(newPlanet); newPlanet.name = name + " " + (planetNumber + 1); // Create resource, storage and production nodes to be added to the planet StorageNode newSNode = Instantiate(storageNodeTemplate, newPlanet.transform).GetComponent <StorageNode>(); ResourceNode newRNode = Instantiate(resourceNodeTemplates[Random.Range(0, resourceNodeTemplates.Length)], newPlanet.transform).GetComponent <ResourceNode>(); ProductionNode newPNode = Instantiate(factoryTemplates[Random.Range(0, factoryTemplates.Length)], newPlanet.transform).GetComponent <ProductionNode>(); // Connect the industry nodes to the storage node. newRNode.connectedStorageNode = newSNode; newPNode.connectedStorageNode = newSNode; // Give the company ownership of the nodes productionCompany.AddEmployee(newSNode.gameObject.GetComponent <Employee>()); productionCompany.AddEmployee(newRNode.gameObject.GetComponent <Employee>()); productionCompany.AddEmployee(newPNode.gameObject.GetComponent <Employee>()); // Add the industry nodes to the planet Planet planetScript = newPlanet.GetComponent <Planet> () as Planet; planetScript.industryNodes.Add(newRNode); planetScript.industryNodes.Add(newPNode); planetScript.industryNodes.Add(newSNode); planets.Add(planetScript); // Spawn a moon if our random number is 0 if (Random.Range(0, 5) == 0) { SpawnMoon(newPlanet); } }
void skeletonCapbility_CalibrationEnd(ProductionNode node, uint id, bool success) { if (success) { App.ViewModel.Status = "Tracking user"; this.skeletonCapbility.StartTracking(id); App.ViewModel.Tracking = true; this.leftSwipe.Initialize(); this.rightSwipe.Initialize(); } else { App.ViewModel.Status = "Calibration failed... Waiting for another pose..."; this.poseDetectionCapability.StartPoseDetection(calibPose, id); } }
/// @brief Used to add a new node to the context /// /// This will find a new node. If it is already there it will be found and if not /// it will be created. /// @note - It is the responsibility of the caller to call this only after @ref Init has been /// called successfully (if valid is false this will return null). /// @note - It is the responsibility of the caller to call @ref ReleaseNode on every node created BEFORE /// calling @ref Dispose. /// /// @param nt The type of node /// @return the node created as a ProductionNode. It is the responsibility of the caller to cast it /// into the appropriate type. public ProductionNode CreateNode(NodeType nt) { Log("Creating type=" + nt, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects); if (!Valid) { Log("Failed to create a node of type " + nt + " because the context is not initialized", NIEventLogger.Categories.Errors, NIEventLogger.Sources.BaseObjects); return(null); } ProductionNode ret = null; // this will hold the node try { // first we will try to find an existing one if it was already created by some means // (such as loading it from xml when inheriting this class). ret = m_context.FindExistingNode(nt); } catch { // if we are here then there is no node of the relevant type, we should // instead create a new one. Query queryToUse = null; if (m_query != null) { queryToUse = m_query.UsedQuery; } try { ret = m_context.CreateAnyProductionTree(nt, queryToUse); } catch (System.Exception ex) { m_Logger.Log(ex.Message, NIEventLogger.Categories.Errors, NIEventLogger.Sources.BaseObjects); return(null); } // Since generators need to start generating, we will check if the // new node is a Generator and if so start generating... Generator g = ret as Generator; if (g != null) { g.StartGenerating(); } } return(ret); }
private ProductionNode openNode(NodeType nt) { ProductionNode ret = null; try { ret = context.FindExistingNode(nt); } catch { ret = context.CreateAnyProductionTree(nt, null); Generator g = ret as Generator; if (null != g) { g.StartGenerating(); } } return(ret); }
private void SpawnMoon(GameObject parentPlanet) { Vector2 pos = Random.insideUnitCircle; pos.Normalize(); pos *= moonDistance; GameObject newMoon = Instantiate(planetTemplate, parentPlanet.transform); newMoon.transform.parent = parentPlanet.transform; newMoon.transform.Translate(pos); newMoon.GetComponent <SpriteRenderer>().sprite = _assets.planetSprites["planet_35"]; newMoon.transform.localScale /= 2; newMoon.name = parentPlanet.gameObject.name + " moon"; // Add resource and production nodes to the new moon. StorageNode newSNode = Instantiate(storageNodeTemplate, newMoon.transform).GetComponent <StorageNode>(); ResourceNode newRNode = Instantiate(resourceNodeTemplates[Random.Range(0, resourceNodeTemplates.Length)], newMoon.transform).GetComponent <ResourceNode>(); ProductionNode newPNode = Instantiate(factoryTemplates[Random.Range(0, factoryTemplates.Length)], newMoon.transform).GetComponent <ProductionNode>(); // Connect the industry nodes to the storage node. newRNode.connectedStorageNode = newSNode; newPNode.connectedStorageNode = newSNode; // Give the company ownership of the nodes productionCompany.AddEmployee(newSNode.gameObject.GetComponent <Employee>()); productionCompany.AddEmployee(newRNode.gameObject.GetComponent <Employee>()); productionCompany.AddEmployee(newPNode.gameObject.GetComponent <Employee>()); Planet planetScript = newMoon.GetComponent <Planet> () as Planet; planetScript.industryNodes.Add(newRNode); planetScript.industryNodes.Add(newPNode); planetScript.industryNodes.Add(newSNode); planets.Add(newMoon.GetComponent <Planet>()); }
void Update() { for (int i = 0; i < buildRates.Length; i++) { int activeBuildings = productionNodeCount[i]; if (baseNodes.First(baseNode => baseNode.Team == i).CurrentState == BaseNodeState.Researching) { activeBuildings++; } buildRates[i] = resourceRate[i] / activeBuildings; float[] resourcesGained = uiController.Store["ResourcesGained"]; resourcesGained[i] += resourceRate[i] * Time.deltaTime; uiController.SetValue("ResourcesGained", resourcesGained); } for (int i = 0; i < productionNodes.Length; i++) { ProductionNode currentNode = productionNodes[i]; if (currentNode.Team < 2) { currentNode.Build(buildRates[currentNode.Team] * Time.deltaTime, buildRates[currentNode.Team]); } } for (int i = 0; i < baseNodes.Length; i++) { if (baseNodes[i].CurrentState == BaseNodeState.Researching) { baseNodes[i].Research(buildRates[i] * Time.deltaTime); } } }
private ContextfreeGrammar TestGetCGGrammar() { var grammar = new ContextfreeGrammar(); grammar.Namespace = "bitzhuwei.CGCompiler"; grammar.GrammarName = "CG"; var Start = new ProductionNode("Start", EnumProductionNodePosition.NonLeave); var PList = new ProductionNode("PList", EnumProductionNodePosition.NonLeave); var VList = new ProductionNode("VList", EnumProductionNodePosition.NonLeave); var V = new ProductionNode("V", EnumProductionNodePosition.NonLeave); var VOpt = new ProductionNode("VOpt", EnumProductionNodePosition.NonLeave); var Vn = new ProductionNode("Vn", EnumProductionNodePosition.NonLeave); var Vt = new ProductionNode("Vt", EnumProductionNodePosition.NonLeave); var colon_Colon_Equality_ = new ProductionNode("\"::=\"", EnumProductionNodePosition.Leave); var semicolon_ = new ProductionNode("\";\"", EnumProductionNodePosition.Leave); var or_ = new ProductionNode("\"|\"", EnumProductionNodePosition.Leave); var lessThan_ = new ProductionNode("\"<\"", EnumProductionNodePosition.Leave); var greaterThan_ = new ProductionNode("\">\"", EnumProductionNodePosition.Leave); var token_null = new ProductionNode("\"null\"", EnumProductionNodePosition.Leave); var token_identifier = new ProductionNode("\"identifier\"", EnumProductionNodePosition.Leave); var token_number = new ProductionNode("\"number\"", EnumProductionNodePosition.Leave); var token_constString = new ProductionNode("\"constString\"", EnumProductionNodePosition.Leave); { var startProd = new ContextfreeProduction(); startProd.Left = Start; var candidate = new ProductionNodeList(); candidate.Add(Vn); candidate.Add(colon_Colon_Equality_); candidate.Add(VList); candidate.Add(semicolon_); candidate.Add(PList); startProd.RightCollection.Add(candidate); grammar.ProductionCollection.Add(startProd); } { var PListProd = new ContextfreeProduction(); PListProd.Left = PList; var candidate = new ProductionNodeList(); candidate.Add(Vn); candidate.Add(colon_Colon_Equality_); candidate.Add(VList); candidate.Add(semicolon_); candidate.Add(PList); PListProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(ProductionNode.tail_null); PListProd.RightCollection.Add(candidate); grammar.ProductionCollection.Add(PListProd); } { var VListProd = new ContextfreeProduction(); VListProd.Left = VList; var candidate = new ProductionNodeList(); candidate.Add(V); candidate.Add(VOpt); VListProd.RightCollection.Add(candidate); grammar.ProductionCollection.Add(VListProd); } { var VProd = new ContextfreeProduction(); VProd.Left = V; var candidate = new ProductionNodeList(); candidate.Add(Vn); VProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(Vt); VProd.RightCollection.Add(candidate); grammar.ProductionCollection.Add(VProd); } { var VOptProd = new ContextfreeProduction(); VOptProd.Left = VOpt; var candidate = new ProductionNodeList(); candidate.Add(V); candidate.Add(VOpt); VOptProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(or_); candidate.Add(V); candidate.Add(VOpt); VOptProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(ProductionNode.tail_null); VOptProd.RightCollection.Add(candidate); grammar.ProductionCollection.Add(VOptProd); } { var VnProd = new ContextfreeProduction(); VnProd.Left = Vn; var candidate = new ProductionNodeList(); candidate.Add(lessThan_); candidate.Add(ProductionNode.tail_identifier); candidate.Add(greaterThan_); VnProd.RightCollection.Add(candidate); grammar.ProductionCollection.Add(VnProd); } { var VtProd = new ContextfreeProduction(); VtProd.Left = Vt; var candidate = new ProductionNodeList(); candidate.Add(token_null); VtProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(token_identifier); VtProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(token_number); VtProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(token_constString); VtProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(ProductionNode.tail_identifier); VtProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(ProductionNode.tail_number); VtProd.RightCollection.Add(candidate); candidate = new ProductionNodeList(); candidate.Add(ProductionNode.tail_constString); VtProd.RightCollection.Add(candidate); grammar.ProductionCollection.Add(VtProd); } return(grammar); }
void userGenerator_NewUser(ProductionNode node, uint id) { Debug.Log("New User Found"); this.poseDetectionCapability.StartPoseDetection(this.calibPose, id); }
void userGenerator_LostUser(ProductionNode node, uint id) { Debug.Log("lost user"); this.joints.Remove(id); }
void hands_HandDestroy(ProductionNode node, uint id, float fTime) { Debug.Log("hands_HandDestroy(): Here"); }
void poseDetectionCapability_PoseDetected(ProductionNode node, string pose, uint id) { this.poseDetectionCapability.StopPoseDetection(id); this.skeletonCapbility.RequestCalibration(id, true); }
/// <summary> /// Called when [P node] is visited. /// </summary> /// <param name="node">The node.</param> public virtual void OnPNode(ProductionNode node) { }
/// <summary> /// Called when [P node] is visited. /// </summary> /// <param name="node">The node.</param> public override void OnPNode(ProductionNode node) { _sb.Append(_indentString).AppendLine(string.Format("P-Node: {0}", node)); _sb.Append(_indentString).AppendLine(""); _sb.Append(_indentString).AppendLine(" ====== Inferred Facts ======"); foreach (Activation activation in node.Production.InferredFacts) { _sb.Append(_indentString).AppendLine(string.Format(" {0}", activation.InferredFact)); } }
void userGenerator_NewUser(ProductionNode node, uint id) { this.poseDetectionCapability.StartPoseDetection(this.calibPose, id); }
void userGenerator_LostUser(ProductionNode node, uint id) { this.joints.Remove(id); }
/// @brief Used to release an added node /// /// This will release an added node from the context. /// @note - It is the responsibility of the caller to call this only on nodes created using the @ref CreateNode /// method and only when the context is valid! This method should be called on every node created BEFORE /// calling @ref Dispose. /// /// @param node The node to release public void ReleaseNode(ProductionNode node) { Log("disposing type=" + node.GetType(), NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Verbose); // note no need to stop generating a generator because disposing will do it for us. node.Dispose(); }
void poseDetectionCapability_PoseDetected(ProductionNode node, string pose, uint id) { App.ViewModel.Status = "Pose detected"; this.poseDetectionCapability.StopPoseDetection(id); this.skeletonCapbility.RequestCalibration(id, true); }
/// <summary> /// Called when [P node] is visited. /// </summary> /// <param name="node">The node.</param> public virtual void OnPNode(ProductionNode node) { }
void userGenerator_LostUser(ProductionNode node, uint id) { App.ViewModel.Status = "Lost user."; App.ViewModel.Tracking = false; this.ResetPoints(); }
void userGenerator_NewUser(ProductionNode node, uint id) { App.ViewModel.Status = "Waiting for pose..."; App.ViewModel.User.UserId = id; this.poseDetectionCapability.StartPoseDetection(this.calibPose, id); }