//Spawn a rigid body object, and allow it to live for 10 seconds
    void SpawnPrimitive(PrimitiveType type)
    {
        Vector3    spawnPosition = MouseUtils.GetMouseWorldPositionAtDepth(10);
        GameObject go            = GameObject.CreatePrimitive(type);

        go.transform.position = spawnPosition;
        go.AddComponent <Rigidbody>();

        GameObject.Destroy(go, 10);
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.O))
        {
            for (int item = 0; item < itemsPerAdd; item++)
            {
                AddItem();
            }
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            AddItem(MouseUtils.GetMouseWorldPositionAtDepth(10));
        }

        if (Input.GetMouseButtonDown((int)MouseUtils.Button.Left))                                                      //have to input transformations here
        {
            quadTree.ClearSearch();                                                                                     //Dmax, Dmin and angle have to be public variables

            /*calculate Dopt from projection size(public variable if mouse input)
             * for Dopt dist from mouse clicked wall, create quad tree localising without increment in cost
             *
             *
             * private ones feasibilityBonus[rows,columns];
             * private ones optimalBonus[rows,columns];
             * mouse input values converted into a node on the grid "input" containing input.x and input.y
             *
             * for(i = input.x-Dmax;i<input.x+Dmax;i++){
             *      for(j = input.y-Dmax;j<input.y+Dmax;i++){
             *
             *              if (Dmin<dist(i,j)<Dmax){
             *                      feasibilityBonus(i,j) = 10;
             *                      if (dist(i,j) == Dopt){
             *                              optimalBonus(i,j) = 100;
             *                      }
             *              }
             *              if (envCost(node) less than envThreshold){
             *                      generateProjectionAngle();
             *                      projectionCost[i,j] = Sum(cost of all nodes in projection angle);
             *              }
             *              cost[i,j] = envCost(node)/(optimalBonus[i,j]*feasibilityBonus[i,j]) * projectionCost[i,j];
             *      }
             * }
             */

            Vector3    clickPos = MouseUtils.GetMouseWorldPositionAtDepth(10);
            GameObject nearest  = quadTree.FindNearest(clickPos.x, clickPos.y, clickPos.z);
            if (nearest != null)
            {
                Debug.DrawLine(clickPos, nearest.transform.position, Color.green, 5);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            ApplyMesh(triangleVertices);
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            ApplyMesh(quadVertices);
        }

        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            AddPointToScene(MouseUtils.GetMouseWorldPositionAtDepth(10));
        }

        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            foreach (GameObject point in customShape)
            {
                GameObject.Destroy(point);
            }
            customShape.Clear();
            regenerateCustom = true;
        }

        if (Input.GetMouseButton((int)MouseUtils.Button.Left))
        {
            regenerateCustom = true;
        }

        if (regenerateCustom)
        {
            List <Vector3> customPoints = new List <Vector3>();
            foreach (GameObject go in customShape)
            {
                customPoints.Add(go.transform.position);
            }
            ApplyMesh(customPoints);
            regenerateCustom = false;
        }
    }
 void MoveToMouseAtSpecifiedDepth(float depth)
 {
     this.transform.position = MouseUtils.GetMouseWorldPositionAtDepth(depth);
 }