Example #1
0
    private void MoveSelectionToCylinder(ICylinder s)
    {
        /* Set new position */
        transform.position = CalculateCylinderMiddle(s);
        s.ResetColor();

        /* Clear cylinders object */
        ClearHighlightedAndResetColor();
        cylinders_.Clear();

        /* Set info displayed */
        center_cylinder_ = s;

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

            AddCylinder(cylinder);
        }
    }
Example #2
0
    public void ChangeModeToBondAngles()
    {
        /*
         * If the previous state is not bond angles, and an atom was selected, then find the closest bond
         * and move the selection there
         */
        if (state != STATE.BOND_ANGLES)
        {
            ISphere currently_selected_sphere = null;
            if (selection_plane_previous_ != null)
            {
                currently_selected_sphere = selection_plane_previous_.GetComponent <SelectionPlaneSpheres>().center_sphere_;
            }
            ResetState(true);

            if (currently_selected_sphere != null)
            {
                ICylinder nearest_bond = GetNearestBond(currently_selected_sphere.transform.position, 2 * AtomicRadii.GetCovalentRadius(currently_selected_sphere.atom_.element_));
                if (nearest_bond != null)
                {
                    selected_bond_ = nearest_bond;
                    SpawnSelectionPlaneCylinders();
                }
            }
        }
        else
        {
            ResetState(false);
        }

        state = STATE.BOND_ANGLES;
        transform.GetChild(1).GetComponent <ModePanel>().SetState(state);
        info_ui_.ResetInfo();
    }
Example #3
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 cylinders within the previous radius */
        for (int i = 0; i < cylinders_.Count; i++)
        {
            ICylinder cylinder = cylinders_[i];
            cylinder.SetHighlighted(0);
            cylinder.ResetColor();
        }
        cylinders_.Clear();

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

            AddCylinder(cylinder);
        }
    }
Example #4
0
    public void ChangeModeToTorsionAngles()
    {
        /*
         * If the previous state is bond angles, and a bond was selected, then find the closest atom
         * and move the selection there
         */
        if (state == STATE.BOND_ANGLES)
        {
            ICylinder currently_selected_cylinder = null;
            if (selection_plane_previous_ != null)
            {
                currently_selected_cylinder = selection_plane_previous_.GetComponent <SelectionPlaneCylinders>().center_cylinder_;
            }
            ResetState(true);

            if (currently_selected_cylinder != null)
            {
                ISphere nearest_atom = GetNearestAtom(currently_selected_cylinder.transform.position, 2 * AtomicRadii.ball_and_stick_radius);
                if (nearest_atom != null)
                {
                    selected_atom_ = nearest_atom;
                    SpawnSelectionPlaneSpheres();
                }
            }
        }
        else
        {
            ResetState(false);
        }

        state = STATE.TORSION_ANGLE;
        transform.GetChild(1).GetComponent <ModePanel>().SetState(state);
    }
Example #5
0
    /* Get nearest bond given a position and a radius */
    private ICylinder GetNearestBond(Vector3 position, float radius)
    {
        Collider[] hitColliders = Physics.OverlapSphere(position, radius);

        ICylinder current_nearest  = null;
        float     nearest_distance = radius;

        foreach (Collider c in hitColliders)
        {
            ICylinder s = c.gameObject.GetComponent <ICylinder>();
            if (s == null)
            {
                continue;
            }

            float distance = Vector3.Distance(position, s.transform.position);
            if (distance < nearest_distance)
            {
                nearest_distance = distance;
                current_nearest  = s;
            }
        }

        return(current_nearest);
    }
Example #6
0
    /* Spawn a selection sphere for 2D navigation for the currently selected bond */
    private void SpawnSelectionPlaneCylinders()
    {
        if (selection_plane_previous_ != null)
        {
            Destroy(selection_plane_previous_);
        }

        selection_plane_previous_ = Instantiate(prefab_selection_plane_cylinders_, SelectionPlaneCylinders.CalculateCylinderMiddle(selected_bond_), Quaternion.identity);
        selection_plane_previous_.transform.parent = transform;
        SelectionPlaneCylinders plane = selection_plane_previous_.GetComponent <SelectionPlaneCylinders>();

        plane.visualization    = selection_visualization_;
        plane.center_cylinder_ = selected_bond_;

        /* Get and set the bonds within the selection radius */
        ClearHighlighted();
        Collider[] hitColliders = Physics.OverlapSphere(selected_bond_.transform.position, SELECTION_MODE_SPHERE_RADIUS);
        foreach (Collider c in hitColliders)
        {
            ICylinder s = c.gameObject.GetComponent <ICylinder>();
            if (s == null || s == selected_bond_)
            {
                continue;
            }

            plane.AddCylinder(s);
        }
    }
Example #7
0
        int CreateCylinder(CObjectInfo objInfo, CCylinderData data, int objIndex, out ICylinder pCylinder)
        {
            int iResult = SUCCESS;

            data.Time = m_DataManager.SystemData_Cylinder.CylinderTimer[objIndex];
            pCylinder = new MCylinder(objInfo, m_IO, data);

            return(iResult);
        }
Example #8
0
    private void SpawnArc(ICylinder a, ICylinder b)
    {
        /* Spawn an arc between two cylinders
         * Calculate the origin and the direction by taking into consideration
         * all possible cylinder directions
         */

        Vector3 position1 = a.transform.position;
        Vector3 position2 = b.transform.position;
        Vector3 position3 = position1 + a.transform.up * a.height_;
        Vector3 position4 = position2 + b.transform.up * b.height_;

        Vector3 arc_origin;
        Vector3 arc_dir1;
        Vector3 arc_dir2;

        if (position1 == position2)
        {
            arc_origin = position1;
            arc_dir1   = a.transform.up;
            arc_dir2   = b.transform.up;
        }
        else if (position1 == position4)
        {
            arc_origin = position1;
            arc_dir1   = a.transform.up;
            arc_dir2   = -b.transform.up;
        }
        else if (position2 == position3)
        {
            arc_origin = position2;
            arc_dir1   = -a.transform.up;
            arc_dir2   = b.transform.up;
        }
        else if (position4 == position3)
        {
            arc_origin = position3;
            arc_dir1   = -a.transform.up;
            arc_dir2   = -b.transform.up;
        }
        else
        {
            /* The two vectors don't form an angle */
            return;
        }

        arc_previous_ = Instantiate(prefab_arc_, arc_origin, Quaternion.identity);
        arc_previous_.transform.parent = transform;

        ArcRenderer arc = arc_previous_.GetComponent <ArcRenderer>();

        arc.X_      = arc_dir1;
        arc.W_      = arc_dir2;
        arc.Radius_ = (a.height_ + b.height_) / 4;
    }
Example #9
0
        /// <summary>
        /// Gets this thing's cylinder hierarchy.
        /// </summary>
        /// <returns>The ordered collection of <see cref="ICylinder"/>s in this thing's cylinder hierarchy.</returns>
        public IEnumerable <ICylinder> GetCylinderHierarchy()
        {
            ICylinder current = (this is ICylinder thisAsCylinder) ? thisAsCylinder : this.ParentCylinder;

            while (current != null)
            {
                yield return(current);

                current = current.ParentCylinder;
            }
        }
Example #10
0
    /* Clear the highlighted objects */
    private void ClearHighlighted()
    {
        foreach (ISphere s in highlighted_spheres_)
        {
            s.SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
        }
        highlighted_spheres_.Clear();

        if (previously_highlighted_bond_ != null)
        {
            previously_highlighted_bond_.SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
        }
        previously_highlighted_bond_ = null;
    }
Example #11
0
    void Start()
    {
        List <Atom>        atoms;
        List <List <int> > connections;
        string             model_name;

        try {
            model_name = ParseInputModelFile();
            PDBParser.ParseAtomsAndConnections(@"Assets/MModels/" + model_name, out atoms, out connections);
        }
        catch (System.IO.IOException) {
            print("Parsing input error");
            return;
        }


        /*  Spawn the objects */
        foreach (Atom atom in atoms)
        {
            /* Units in Nano meters */
            Vector3 atom_position = new Vector3(atom.x_, atom.y_, atom.z_);
            atoms_bounding_box_.AddPoint(atom_position);

            /* Instantiate the atom */
            GameObject temp = Instantiate(prefab_atom, atom_position, Quaternion.identity);
            temp.transform.parent = transform;
            temp.isStatic         = this.gameObject.isStatic;

            /* Find ISphere component, and set the atom information */
            ISphere isphere = temp.GetComponent <ISphere>();
            isphere.atom_ = atom;
            ispheres_.Add(isphere);

            /* Insert to the dictionaries used */
            InsertToAtomsDictionary(isphere);
            InsertToResiudesDictionary(isphere);
            InsertToChainsDictionary(isphere);
        }

        /* Parse connections, currently the application does not do something with these connections */
        foreach (List <int> c in connections)
        {
            int atom_id = c[0];
            for (int i = 1; i < c.Count; i++)
            {
                ISphere connection_isphere = ispheres_[c[i]];
                ispheres_[atom_id].connections_.Add(connection_isphere);
            }
        }

        /* Spawn bonds */
        Transform bonds_transform = transform.GetChild(0);
        int       bonds           = 0;

        /* For all resisudes */
        foreach (KeyValuePair <int, List <ISphere> > value in residue_dictionary)
        {
            /* Get combinations of two atoms */
            List <ISphere> resiude_atoms = value.Value;
            for (int ia = 0; ia < resiude_atoms.Count; ia++)
            {
                ISphere a                 = resiude_atoms[ia];
                Vector3 a_position        = a.transform.position;
                float   a_covalent_radius = AtomicRadii.GetCovalentRadius(a.atom_.element_);
                for (int ib = 0; ib < resiude_atoms.Count; ib++)
                {
                    if (!(ia > ib))
                    {
                        continue;
                    }
                    ISphere b = resiude_atoms[ib];

                    Vector3 b_position        = b.transform.position;
                    float   b_covalent_radius = AtomicRadii.radii_covalent[b.atom_.element_];

                    /* If their distance is smaller then the sume of radius + plus a bias, then spawn a bond */
                    float distance = Vector3.Distance(a_position, b_position);
                    if (distance <= a_covalent_radius + b_covalent_radius + 0.015)
                    {
                        bonds++;
                        GameObject temp = Instantiate(prefab_bond, a_position, Quaternion.identity);
                        temp.transform.parent = bonds_transform;
                        temp.isStatic         = this.gameObject.isStatic;

                        /* Rotate it accordingly */
                        Vector3    direction  = b_position - a_position;
                        Quaternion toRotation = Quaternion.FromToRotation(new Vector3(0, 1, 0), direction);
                        temp.transform.rotation = toRotation;

                        /* Set size and radius */
                        ICylinder icylinder = temp.GetComponent <ICylinder>();
                        icylinder.radius_ = AtomicRadii.ball_and_stick_bond_radius;
                        icylinder.height_ = distance;
                    }
                }
            }
        }
        Debug.Log("Spawned: " + bonds + " bonds");

        /* Position the model and the camera in the world */
        SetCameraAndPanelBoxPosition(atoms_bounding_box_);

        bonds_selected_[0] = null;
        bonds_selected_[1] = null;

        /* Set some default info on the world panel */
        SELECTION_MODE_SPHERE_RADIUS = AtomicRadii.ball_and_stick_radius * 5.0f;
        transform.GetChild(1).GetComponent <ModePanel>().SetRadius(SELECTION_MODE_SPHERE_RADIUS);

        info_ui_ = Camera.main.transform.Find("AtomInfoBox").GetComponent <AtomInfoBox>();
    }
Example #12
0
    /* FPS counter */
    //void OnGUI() {
    //    GUI.Label(new Rect(0, 0, 100, 100), (1.0f / Time.smoothDeltaTime).ToString());
    //}

    void Update()
    {
        /* If the bring forward the panel button is hit, the ray cast only in UI layer */
        if (Input.GetKey(KeyCode.Space))
        {
            bool ui_hit = RayCastUIlayer();
            if (ui_hit)
            {
                return;
            }
        }

        RaycastHit hit;

        /*
         * Perform ray casting towards the camera direction, move the ray origin slightly forward to avoid intersections with spheres that
         * we are currently inside
         */
        bool ray_cast_hit = Physics.Raycast(Camera.main.transform.position + Camera.main.transform.forward * AtomicRadii.ball_and_stick_radius, Camera.main.transform.forward, out hit, 100.0f);

        /* Process model movement input */
        if (Input.GetKey(KeyCode.Keypad1))
        {
            MoveTowardsSelectedObject(speed_object_towards_move);
        }

        if (Input.GetKey(KeyCode.Keypad7))
        {
            MoveTowardsSelectedObject(-speed_object_towards_move);
        }

        if (Input.GetKey(KeyCode.Keypad4))
        {
            transform.position = transform.position - Camera.main.transform.right * speed_object_vertical_move;
        }

        if (Input.GetKey(KeyCode.Keypad6))
        {
            transform.position = transform.position + Camera.main.transform.right * speed_object_vertical_move;
        }

        if (Input.GetKey(KeyCode.Keypad8))
        {
            transform.position = transform.position + Camera.main.transform.up * speed_object_vertical_move;
        }

        if (Input.GetKey(KeyCode.Keypad5))
        {
            transform.position = transform.position - Camera.main.transform.up * speed_object_vertical_move;
        }

        /* Check ray cast against UI */
        if (ray_cast_hit)
        {
            Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * hit.distance, Color.white);

            ButtonEvent button = hit.transform.GetComponent <ButtonEvent>();
            if (button != null)
            {
                ProcessRayCastUIHit(hit);
            }
        }

        /* Process state machine */
        if (state == STATE.EXPLORING_ATOMS)
        {
            /* If there is a selected atom, and the discard button is pressed, then destory selection */
            if (selected_atom_ != null)
            {
                if (Input.GetKeyDown(KeyCode.Escape) == true)
                {
                    ClearHighlighted();
                    selected_atom_ = null;
                    Destroy(selection_plane_previous_);
                    return;
                }

                return;
            }

            /* Else process ray cast hit */
            if (ray_cast_hit)
            {
                ProcessRayCastHit(hit);
            }
            else
            {
                /* If ray cast failed, clear highlighting */
                ClearHighlighted();
                if (exploring_method_ != ExploringMethod.CHAINS)
                {
                    ClearColored();
                }

                //Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * 1000, Color.white);
            }
        }
        else if (state == STATE.ATOM_DISTANCES)
        {
            /* If discard button, then reset state */
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                ResetState(true);
                return;
            }

            /* if we have selected an atom, process distances */
            if (selected_atom_ != null)
            {
                SelectionPlaneSpheres plane = selection_plane_previous_.GetComponent <SelectionPlaneSpheres>();

                /*
                 * Get the current selected atom, and if it's different than the previous, and the marked button is pressed
                 * mark atom, and calculate distance
                 */
                int     current_index    = atom_selected_id_ % 4;
                ISphere previously_added = ((current_index == 0) ? atoms_selected_[3] : atoms_selected_[current_index - 1]);
                if (Input.GetKeyDown(KeyCode.E) && previously_added != plane.center_sphere_)
                {
                    atoms_selected_[current_index] = plane.center_sphere_;

                    atom_selected_id_++;

                    /* If marked atom object is null, spawn it */
                    if (marked_atom_object_ == null)
                    {
                        marked_atom_object_ = Instantiate(prefab_marked_atom_, plane.center_sphere_.transform.position, Quaternion.identity);
                        marked_atom_object_.transform.parent = this.transform;
                    }
                    /* Calculate radius of the atom based on the viusalization method, and move marked atom object */
                    float selected_atom_radius;
                    if (GetVisualizationMethod() == VisualizationMethod.BALL_AND_STICK)
                    {
                        selected_atom_radius = AtomicRadii.ball_and_stick_radius;
                    }
                    else
                    {
                        selected_atom_radius = AtomicRadii.GetCovalentRadius(plane.center_sphere_.atom_.element_);
                    }
                    marked_atom_object_.transform.position = plane.center_sphere_.transform.position + 1.4f * Vector3.up * selected_atom_radius;
                    marked_sphere_ = plane.center_sphere_.gameObject;

                    /* If the previously marked atom is not null, then calculate distance */
                    if (previously_added != null)
                    {
                        Vector3 middle = (previously_added.transform.position + plane.center_sphere_.transform.position) / 2;

                        /* Destroy the previous atom distance object from the world */
                        if (atom_distance_previous_ != null)
                        {
                            Destroy(atom_distance_previous_);
                        }
                        /* and spawn the new in the middle of the distance */
                        atom_distance_previous_ = Instantiate(prefab_atom_distance_, middle, Quaternion.identity);
                        atom_distance_previous_.transform.parent = transform;
                        AtomDistance temp = atom_distance_previous_.GetComponent <AtomDistance>();
                        temp.atom1_ = previously_added;
                        temp.atom2_ = plane.center_sphere_;
                    }
                }
                return;
            }

            /* If there is not selected atom, process ray casting as usual */
            if (ray_cast_hit)
            {
                ProcessRayCastHit(hit);
            }
            else
            {
                ClearHighlighted();
                if (exploring_method_ != ExploringMethod.CHAINS)
                {
                    ClearColored();
                }
            }
        }
        else if (state == STATE.BOND_ANGLES)
        {
            /* If discard button is hit, reset state */
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                ResetState(true);
                return;
            }

            /* If selection is spawned, process selected bonds */
            if (selected_bond_ != null)
            {
                SelectionPlaneCylinders plane = selection_plane_previous_.GetComponent <SelectionPlaneCylinders>();

                int       current_index    = bonds_selected_id_ % 2;
                ICylinder previously_added = ((current_index == 0) ? bonds_selected_[1] : bonds_selected_[current_index - 1]);
                /* if the precious is different than the currently selected, select bond, and the arc */
                if (previously_added != plane.center_cylinder_)
                {
                    bonds_selected_[current_index] = plane.center_cylinder_;

                    bonds_selected_id_++;

                    if (previously_added != null)
                    {
                        if (arc_previous_ != null)
                        {
                            Destroy(arc_previous_);
                        }
                        SpawnArc(bonds_selected_[0], bonds_selected_[1]);
                    }
                }
                return;
            }

            /* Else, process ray casting for bonds */
            if (ray_cast_hit)
            {
                ClearHighlighted();

                ICylinder icylinder = hit.transform.GetComponent <ICylinder>();

                if (icylinder != null)
                {
                    icylinder.SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.WHITE);
                    previously_highlighted_bond_ = icylinder;

                    /* If bond seleted, spawn selection object */
                    if (Input.GetMouseButtonDown(0) == true)
                    {
                        selected_bond_ = icylinder;
                        SpawnSelectionPlaneCylinders();
                    }
                }
            }
            else
            {
                ClearHighlighted();
            }
        }
        else if (state == STATE.TORSION_ANGLE)
        {
            /* if the torsion planed has been spawned, highlight the atoms that participate in it */
            if (torsion_plane_spawned_)
            {
                atoms_selected_[0].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.GREEN);
                atoms_selected_[1].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.GREEN);
                atoms_selected_[2].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.GREEN);
                atoms_selected_[3].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.GREEN);
            }

            /* If discard is pushed, and the torsion planed is spawned, go back to atom selection
             * else reset and destroy selection
             */
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (torsion_plane_spawned_)
                {
                    ISphere last_added_sphere = ((atom_selected_id_ == 0) ? atoms_selected_[3] : atoms_selected_[atom_selected_id_ - 1]);
                    ResetState(false);
                    selected_atom_ = last_added_sphere;
                    SpawnSelectionPlaneSpheres();
                    info_ui_.SetAtom(last_added_sphere);
                }
                else
                {
                    ResetState(true);
                }

                return;
            }

            /* If selection is spawned, then process the currently selected atom */
            if (selected_atom_ != null)
            {
                SelectionPlaneSpheres plane = selection_plane_previous_.GetComponent <SelectionPlaneSpheres>();

                ISphere previously_added = ((atom_selected_id_ == 0) ? atoms_selected_[3] : atoms_selected_[atom_selected_id_ - 1]);
                if (Input.GetKeyDown(KeyCode.E) && atom_selected_id_ < 4 && previously_added != plane.center_sphere_)
                {
                    atoms_selected_[atom_selected_id_ % 4] = plane.center_sphere_;
                    info_ui_.SetTorsionAtom(atom_selected_id_, plane.center_sphere_.atom_.name_);

                    atom_selected_id_++;

                    /* If reached 4 selected atoms, spawn the torsion plane object */
                    if (atom_selected_id_ == 4)
                    {
                        SpawnTorsionAngle();
                        selected_atom_ = null;
                        Destroy(selection_plane_previous_);
                        torsion_plane_spawned_ = true;
                    }
                }
                return;
            }

            /* Else ray cast as usual */
            if (ray_cast_hit && !torsion_plane_spawned_)
            {
                ProcessRayCastHit(hit);
            }
            else
            {
                ClearHighlighted();
                if (exploring_method_ != ExploringMethod.CHAINS)
                {
                    ClearColored();
                }
            }
        } /* End of torsion angle state */
    }
Example #13
0
 public SparkPlug(ICylinder cylinder)
 {
     _cylinder = cylinder;
 }
Example #14
0
    /* Reset the current state
     * @param destroy_selection If true, destroy the 2D selection object
     */
    private void ResetState(bool destroy_selection)
    {
        switch (state)
        {
        case STATE.EXPLORING_ATOMS:
            if (selection_plane_previous_ != null)
            {
                if (destroy_selection)
                {
                    Destroy(selection_plane_previous_);
                    selected_atom_ = null;
                    info_ui_.ResetInfo();
                }
            }

            break;

        case STATE.ATOM_DISTANCES:
            if (selection_plane_previous_ != null)
            {
                if (destroy_selection)
                {
                    Destroy(selection_plane_previous_);
                    selected_atom_ = null;
                    info_ui_.ResetInfo();
                }
            }
            if (atom_distance_previous_ != null)
            {
                Destroy(atom_distance_previous_);
            }
            if (marked_atom_object_ != null)
            {
                Destroy(marked_atom_object_);
            }
            marked_sphere_     = null;
            atoms_selected_[0] = null;
            atoms_selected_[1] = null;
            atoms_selected_[2] = null;
            atoms_selected_[3] = null;
            atom_selected_id_  = 0;

            break;

        case STATE.BOND_ANGLES:
            if (selection_plane_previous_ != null)
            {
                if (destroy_selection)
                {
                    Destroy(selection_plane_previous_);
                    selected_bond_ = null;
                }
            }
            if (arc_previous_ != null)
            {
                Destroy(arc_previous_);
            }
            if (bonds_selected_[0] != null)
            {
                bonds_selected_[0].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
            }
            if (bonds_selected_[1] != null)
            {
                bonds_selected_[1].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
            }
            bonds_selected_[0] = null;
            bonds_selected_[1] = null;
            bonds_selected_id_ = 0;

            break;

        case STATE.TORSION_ANGLE:
            if (selection_plane_previous_ != null)
            {
                if (destroy_selection)
                {
                    Destroy(selection_plane_previous_);
                    selected_atom_ = null;
                    info_ui_.ResetInfo();
                }
            }
            if (torsion_angle_previous_ != null)
            {
                Destroy(torsion_angle_previous_);
            }
            if (atoms_selected_[0] != null)
            {
                atoms_selected_[0].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
            }
            if (atoms_selected_[1] != null)
            {
                atoms_selected_[1].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
            }
            if (atoms_selected_[2] != null)
            {
                atoms_selected_[2].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
            }
            if (atoms_selected_[3] != null)
            {
                atoms_selected_[3].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.NO_HIGHLIGHT);
            }
            atoms_selected_[0]     = null;
            atoms_selected_[1]     = null;
            atoms_selected_[2]     = null;
            atoms_selected_[3]     = null;
            atom_selected_id_      = 0;
            torsion_plane_spawned_ = false;
            info_ui_.ClearTorsionAtoms();

            break;

        default:
            break;
        }

        ClearColored();
        ClearHighlighted();
    }
Example #15
0
 public static Vector3 CalculateCylinderMiddle(ICylinder s)
 {
     return(s.transform.position + s.transform.up * s.height_ / 2);
 }
Example #16
0
    void Update()
    {
        /* Calculate the coordiinate system transformation matrix */
        CalculateInverseTransform();

        /* highlight and color center cylinder */
        center_cylinder_.SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.GREEN);
        center_cylinder_.ResetColor();

        /* Calculate positions and reset colors and highlighting for cylinders within the radius */
        plane_positions_ = new List <Vector3>(cylinders_.Count);
        for (int i = 0; i < cylinders_.Count; i++)
        {
            ICylinder s = cylinders_[i];
            Vector3   cylinder_middle         = CalculateCylinderMiddle(s);
            Vector4   cylinder_world_position = new Vector4(cylinder_middle.x, cylinder_middle.y, cylinder_middle.z, 1);
            Vector4   cylinder_plane_position = ITM_ * cylinder_world_position;
            plane_positions_.Add(cylinder_plane_position);
            s.SetHighlighted(0);
            s.ResetColor();
        }

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

        /* Highlight the cylinders 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 cylinder mapped in this direction, skip */
                if (s == -1)
                {
                    continue;
                }
                cylinders_[s].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.WHITE);

                if (visualization == SelectionVisualizationMethod.COLOR_CIRCLE)
                {
                    cylinders_[s].SetColor(colors_[j, i]);
                }
                else
                {
                    /* If arrows navigation used, calculate atomic radius used based on the atoms viusalization method */
                    float atom_radius = AtomicRadii.ball_and_stick_radius;

                    /* and set the arrow objects in front of the atom */
                    arrows_[j, i].SetActive(true);
                    Vector3 cylinder_middle = CalculateCylinderMiddle(cylinders_[s]);
                    arrows_[j, i].transform.position = cylinder_middle +
                                                       Vector3.Normalize(Camera.main.transform.position - cylinder_middle) * 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 cylinder based on the control input */
        int cylinder_index = GetDirectionInput();

        if (cylinder_index != -1)
        {
            ICylinder s = cylinders_[cylinder_index];

            /* If clicked as well, move the selection */
            if (Input.GetMouseButtonDown(0))
            {
                MoveSelectionToCylinder(s);
            }
            else
            {
                /* Make input selected cylinder white */
                s.SetColor(Color.white);
            }
        }
    }
Example #17
0
 public void AddCylinder(ICylinder s)
 {
     cylinders_.Add(s);
 }
Example #18
0
 public VEngine(ICylinder cylinder, ISparkPlug sparkPlug)
 {
     Cylinder  = cylinder;
     SparkPlug = sparkPlug;
 }