예제 #1
0
    /* Change selection radius */
    public void ChangeRadius()
    {
        transform.localScale = 2 * new Vector3(Atoms.SELECTION_MODE_SPHERE_RADIUS, Atoms.SELECTION_MODE_SPHERE_RADIUS, Atoms.SELECTION_MODE_SPHERE_RADIUS);

        /* Set radius of the transparent sphere */
        ISphere s = GetComponent <ISphere>();

        s.SetRadius(Atoms.SELECTION_MODE_SPHERE_RADIUS);

        /* Reset spheres within the previous radius */
        for (int i = 0; i < spheres_.Count; i++)
        {
            ISphere sphere = spheres_[i];
            sphere.SetHighlighted(0);
            sphere.ResetColor();
        }
        spheres_.Clear();

        /* Get the new spheres within radius */
        Collider[] hitColliders = Physics.OverlapSphere(this.transform.position, Atoms.SELECTION_MODE_SPHERE_RADIUS);
        foreach (Collider c in hitColliders)
        {
            ISphere sphere = c.gameObject.GetComponent <ISphere>();
            if (sphere == null || sphere == center_sphere_)
            {
                continue;
            }

            AddSphere(sphere);
        }
    }
예제 #2
0
    void Update()
    {
        /* Calculate the coordiinate system transformation matrix */
        CalculateInverseTransform();

        /* highlight and color center sphere */
        center_sphere_.SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.GREEN);
        center_sphere_.SetCPKColor();

        /* Calculate positions and reset colors and highlighting for spheres within the radius */
        plane_positions_ = new List <Vector3>(spheres_.Count);
        for (int i = 0; i < spheres_.Count; i++)
        {
            ISphere s = spheres_[i];
            Vector4 sphere_world_position = new Vector4(s.transform.position.x, s.transform.position.y, s.transform.position.z, 1);
            Vector4 sphere_plane_position = ITM_ * sphere_world_position;
            plane_positions_.Add(sphere_plane_position);
            s.SetHighlighted(0);
            s.SetCPKColor();
        }

        /* Calculate spheres available for selection and their directions */
        FillArray();

        /* Highlight the spheres that can be navigated to, set the arrow directions based on the visualization used, or set the colors */
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                int s = array_[i, j];
                /* If no sphere mapped in this direction, skip */
                if (s == -1)
                {
                    continue;
                }
                spheres_[s].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.WHITE);

                if (visualization == SelectionVisualizationMethod.COLOR_CIRCLE)
                {
                    spheres_[s].SetColor(colors_[j, i]);
                }
                else
                {
                    /* If arrows navigation used, calculate atomic radius used based on the atoms viusalization method */
                    float atom_radius;
                    if (atoms_object_.GetVisualizationMethod() == Atoms.VisualizationMethod.BALL_AND_STICK)
                    {
                        atom_radius = AtomicRadii.ball_and_stick_radius;
                    }
                    else
                    {
                        atom_radius = AtomicRadii.GetCovalentRadius(spheres_[s].atom_.element_);
                    }

                    /* and set the arrow objects in front of the atom */
                    arrows_[j, i].SetActive(true);
                    arrows_[j, i].transform.position = spheres_[s].transform.position +
                                                       Vector3.Normalize(Camera.main.transform.position - spheres_[s].transform.position) * 1.2f * atom_radius;

                    /* make arrows face the camera */
                    arrows_[j, i].transform.rotation = Quaternion.LookRotation(arrows_[j, i].transform.position - Camera.main.transform.position, Camera.main.transform.up);
                }
            }
        }

        /* Get the index for the selected sphere based on the control input */
        int sphere_index = GetDirectionInput();

        if (sphere_index != -1)
        {
            ISphere s = spheres_[sphere_index];

            /* If clicked as well, move the selection */
            if (Input.GetMouseButtonDown(0))
            {
                MoveSelectionToSphere(s);
            }
            else
            {
                /* Make input selected sphere white */
                s.SetColor(Color.white);
            }
        }
    }