예제 #1
0
파일: Atom.cs 프로젝트: SeijiEmery/chem-vr
    public void SetAtomType(AtomicTemplate template)
    {
        this.atomicNumber = template.atomicNumber;
        this.atomicMass   = template.mass;
        this.color        = template.color;
        this.atomicGroup  = 0;

        transform.localScale = Vector3.one * 0.1f * template.radius;

        // calculate electron groups...
        if (atomicNumber <= 0)
        {
            return;
        }

        freeElectrons = atomicNumber;
        var activeShellSize = 0;

        while (freeElectrons > 0)
        {
            ++atomicGroup;
            activeShellSize = 2;
            if (freeElectrons <= 2)
            {
                missingElectrons = 2 - freeElectrons;  break;
            }
            else
            {
                freeElectrons -= 2;
            }
            if (atomicGroup >= 4)
            {
                activeShellSize = 5; if (freeElectrons <= 10)
                {
                    missingElectrons = 10 - freeElectrons; break;
                }
                else
                {
                    freeElectrons -= 10;
                }
            }
            if (atomicGroup >= 2)
            {
                activeShellSize = 4; if (freeElectrons <= 6)
                {
                    missingElectrons = 8 - freeElectrons; break;
                }
                else
                {
                    freeElectrons -= 6;
                }
            }
        }
        maxBondingGroups = currentBondingGroups = activeShellSize;
        bondingGroups    = new AtomicBond[activeShellSize];

        ShowByColor();
        SetupDefaultElectronGroups();
    }
예제 #2
0
    GameObject SpawnAtom(HandTrackedInfo info, AtomicTemplate template)
    {
        var atom = GameObject.Instantiate(atomPrefab.gameObject, info.transform.position, info.transform.rotation, transform);

        atom.transform.position = info.transform.position;
        atom.GetComponent <Atom>().SetAtomType(template);
        atom.transform.localScale = Vector3.one * template.radius * 0.1f;
        atom.GetComponent <Renderer>().material.color = template.color;
        atom.GetComponent <Rigidbody>().mass          = template.mass;
        return(atom);
    }
예제 #3
0
    public override void OnTriggerPressed(HandTrackedInfo info)
    {
        switch (editMode)
        {
        case EditMode.Draw:
        {
            switch (focusType)
            {
            case FocusType.None:
            {
                SpawnAndEditAtom(info);
                break;
            }

            case FocusType.AtomicTemplate:
            {
                template = focusObject.GetComponent <AtomicTemplate>();
                SpawnAndEditAtom(info);
                break;
            }

            case FocusType.Atom:
            {
                drawnAtom = focusObject;
                connectAtomToHandControllerJoint = drawnAtom.AddComponent <FixedJoint>();
                connectAtomToHandControllerJoint.connectedBody = info.rigidbody;
                break;
            }

            case FocusType.Bond:
            {
                break;
            }
            }
        }
        break;

        case EditMode.AddBonds:
            switch (focusType)
            {
            case FocusType.None:
            {
                break;
            }

            case FocusType.AtomicTemplate:
            {
                break;
            }

            case FocusType.Atom:
            {
                startBoundsFrom = focusObject;
                break;
            }

            case FocusType.Bond:
            {
                break;
            }
            }
            break;

        case EditMode.Delete:
            switch (focusType)
            {
            case FocusType.None:
            {
                break;
            }

            case FocusType.AtomicTemplate:
            {
                template = focusObject.GetComponent <AtomicTemplate>();
                SpawnAndEditAtom(info);
                break;
            }

            case FocusType.Atom:
            {
                GameObject.DestroyImmediate(focusObject);
                break;
            }

            case FocusType.Bond:
            {
                GameObject.DestroyImmediate(focusObject);
                break;
            }
            }
            break;
        }
    }