Exemple #1
0
 public void Calculate()
 {
     try
     {//parse strings into floating point numbers
         float v_x = Single.Parse(vect_inputs[0].text);
         float v_y = Single.Parse(vect_inputs[1].text);
         float v_z = Single.Parse(vect_inputs[2].text);
         float p_x = Single.Parse(point_inputs[0].text);
         float p_y = Single.Parse(point_inputs[1].text);
         float p_z = Single.Parse(point_inputs[2].text);
         float d_x = Single.Parse(direction_inputs[0].text);
         float d_y = Single.Parse(direction_inputs[1].text);
         float d_z = Single.Parse(direction_inputs[2].text);
         if (d_x == 0 && d_y == 0 && d_z == 0)
         {
             throw new Exception("The direction cannot be be zero!");
         }
         float num = Single.Parse(scalar_input.text);
         if (num < 0)
         {
             throw new Exception("Only positive tolerance allowed!");
         }
         vector    = new MyVector3(v_x, v_y, v_z);
         line      = new Line(new MyVector3(d_x, d_y, d_z), new MyVector3(p_x, p_y, p_z));
         tolerance = num;
     }
     catch (Exception e)
     {//parsing failed
         Debug.LogError(e.Message);
         vect_inputs[0].text      = "";
         vect_inputs[1].text      = "";
         vect_inputs[2].text      = "";
         point_inputs[0].text     = "";
         point_inputs[1].text     = "";
         point_inputs[2].text     = "";
         direction_inputs[0].text = "";
         direction_inputs[1].text = "";
         direction_inputs[2].text = "";
         scalar_input.text        = "";
         return;
     }
     //printe vectors to the scene
     distanceFromLine.text = vector.DistanceFromLine(line).ToString("0.000");
     isOnLine.text         = vector.IsOnLine(line, tolerance).ToString();
 }