Exemplo n.º 1
0
 public void Link(RobotLink link)
 {
     prev = link;
     Multiply(new float[4, 4] {
         { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { -link.t.position.x, -link.t.position.y, -link.t.position.z, 1 }
     });
 }
Exemplo n.º 2
0
    private void Rotate(RobotLink part, int deg)
    {
        float c = Mathf.Cos(deg * Mathf.PI / 180);
        float s = Mathf.Sin(deg * Mathf.PI / 180);

        part.Multiply(new float[4, 4] {
            { 1, 0, 0, 0 }, { 0, c, s, 0 }, { 0, -s, c, 0 }, { 0, 0, 0, 1 }
        });
        if (part == arm1)
        {
            Text text = (Text)GameObject.Find("TextArm1").GetComponent(typeof(Text));
            int  d    = int.Parse(text.text.Substring(0, text.text.Length - 1));
            d         = (d + deg + 360) % 360;
            d         = d > 180 ? d - 360 : d;
            text.text = d + "°";
        }
        else if (part == arm2)
        {
            Text text = (Text)GameObject.Find("TextArm2").GetComponent(typeof(Text));
            int  d    = int.Parse(text.text.Substring(0, text.text.Length - 1));
            d         = (d + deg + 360) % 360;
            d         = d > 180 ? d - 360 : d;
            text.text = d + "°";
        }
        else if (part == arm3)
        {
            Text text = (Text)GameObject.Find("TextArm3").GetComponent(typeof(Text));
            int  d    = int.Parse(text.text.Substring(0, text.text.Length - 1));
            d         = (d + deg + 360) % 360;
            d         = d > 180 ? d - 360 : d;
            text.text = d + "°";
        }
    }
Exemplo n.º 3
0
    void Start()
    {
        Transform t = transform.Find("Static Base");

        staticbase       = new RobotLink(t, t.position.x, t.position.y, t.position.z);
        t                = transform.Find("Dynamic Base");
        dynamicbase      = new RobotLink(t, t.position.x - staticbase.t.position.x, t.position.y - staticbase.t.position.y, t.position.z - staticbase.t.position.z);
        t                = transform.Find("Arm1");
        arm1             = new RobotLink(t, t.position.x - dynamicbase.t.position.x, t.position.y - dynamicbase.t.position.y, t.position.z - dynamicbase.t.position.z);
        t                = transform.Find("Arm2");
        arm2             = new RobotLink(t, t.position.x - arm1.t.position.x, t.position.y - arm1.t.position.y, t.position.z - arm1.t.position.z);
        t                = transform.Find("Arm3");
        arm3             = new RobotLink(t, t.position.x - arm2.t.position.x, t.position.y - arm2.t.position.y, t.position.z - arm2.t.position.z);
        arm3.prev        = arm2;
        arm2.prev        = arm1;
        arm1.prev        = dynamicbase;
        dynamicbase.prev = staticbase;
        // SIMPLE ROTATION ABOUT THE X AXIS BY X DEGREES
        //float x = 30;
        //float c = Mathf.Cos (x * Mathf.PI / 180);
        //float s = Mathf.Sin (x * Mathf.PI / 180);
        //arm1.Multiply (new float[4,4] {{1,0,0,0},{0,c,s,0},{0,-s,c,0},{0,0,0,1}});

        circleSprites = Resources.LoadAll <Sprite>("blue_circle");
    }
Exemplo n.º 4
0
 public void StopRotate()
 {
     if (client != null)
     {
         client.StopRotate(BitConverter.GetBytes(DateTime.UtcNow.Ticks));
     }
     part = null;
 }
Exemplo n.º 5
0
 public void RotatePointerR()
 {
     if (client != null)
     {
         client.RotatePointerR(BitConverter.GetBytes(DateTime.UtcNow.Ticks));
     }
     part = pointer;
     deg  = 1;
 }
Exemplo n.º 6
0
 public void RotateArm2R()
 {
     part = arm2;
     deg  = -1;
     if (client != null)
     {
         client.RotateArm2R(BitConverter.GetBytes(DateTime.UtcNow.Ticks));
     }
 }
Exemplo n.º 7
0
 public void RotateArm1R()
 {
     if (client != null)
     {
         client.RotateArm1R(BitConverter.GetBytes(DateTime.UtcNow.Ticks));
     }
     part = arm1;
     deg  = 1;
 }
Exemplo n.º 8
0
    /// <summary>
    /// SpawnJoint: Spawns a new joint object.
    /// </summary>
    public static GameObject SpawnLink()
    {
        Vector3 SpawnPosition = new Vector3(0.05f, 0f, -5.8f);

        GameObject newLink = GameObject.CreatePrimitive(PrimitiveType.Capsule);

        newLink.transform.position = SpawnPosition;
        RobotLink LinkComponent = newLink.AddComponent <RobotLink>();

        return(newLink);
    }
 /// <summary>
 /// Helps ConfigureRobot by adding into the dict and list, recurses onto the next child
 /// </summary>
 private static void addToList(RobotJoint[] listJoints, RobotLink theTree, string RobotType, List <RobotJoint> originalList = null)
 {
     foreach (RobotJoint joint in listJoints)
     {
         theTree.JointDict.Add(joint, theTree);
         originalList.Add(joint);
         if (joint.ChildGO != null)
         {
             ConfigureRobot(joint.ChildGO.gameObject, RobotType, false, theTree, originalList);
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Initializer
        /// </summary>
        public RobotLink(GameObject sObject, string typeBase, bool iRoot, RobotLink parent = null)
        {
            Rigidbody thisObjectRB = sObject.GetComponent <Rigidbody>();

            SelfObject    = sObject;
            BaseType      = typeBase;
            isRoot        = iRoot;
            Parent        = parent;
            localCOM      = thisObjectRB.centerOfMass;
            inertiaTensor = thisObjectRB.inertiaTensor;
            mass          = thisObjectRB.mass;

            // If it's a root and floating, then we need to store the position as well as the rotation
            if (isRoot && BaseType.ToLower() == "floating")
            {
                RootPosition = thisObjectRB.position;
                RootRotation = thisObjectRB.rotation;
            }
        }
Exemplo n.º 11
0
    /// <summary>
    /// GenerateJoint: Helper method to recreate links by:
    ///     1. Creating the appropriate GameObject
    ///     2. Setting its position properties.
    ///     3. Setting misc. properties as well as removing the collider.
    ///
    /// TODO: Need to set COM and inertiatensors upon initialization.
    /// TODO: See if link component is actually useful.
    ///
    /// <param name="linkConfig"> A protobuf object holding all of the necessary information to recreate a link. </param>
    ///
    /// <returns> A GameObject representing a link of a robot. </returns>
    /// </summary>
    public static GameObject GenerateLink(LinkStorage linkConfig)
    {
        GameObject newLink = GenerateShape(linkConfig.Shape);

        newLink.transform.localScale = new Vector3(linkConfig.Shape.ScaleParams[0], linkConfig.Shape.ScaleParams[1], linkConfig.Shape.ScaleParams[2]);
        newLink.transform.position   = new Vector3(linkConfig.PositionParams[0], linkConfig.PositionParams[1], linkConfig.PositionParams[2]);
        newLink.transform.rotation   = new Quaternion(linkConfig.RotationParams[0], linkConfig.RotationParams[1], linkConfig.RotationParams[2], linkConfig.RotationParams[3]);

        // There should be code here to set COM and inertiatensors.
        RobotLink newRobotLink = newLink.AddComponent <RobotLink>();

        Rigidbody newRigid = newLink.AddComponent <Rigidbody>();

        newRigid.isKinematic = true;
        newRigid.useGravity  = false;
        Destroy(newLink.GetComponent <Collider>());

        return(newLink);
    }
Exemplo n.º 12
0
    void Start()
    {
        staticbase  = new RobotLink(transform.Find("StaticBase"));
        dynamicbase = new RobotLink(transform.Find("DynamicBase"));
        arm1        = new RobotLink(transform.Find("Arm1"));
        arm2        = new RobotLink(transform.Find("Arm2"));
        pointer     = new RobotLink(transform.Find("Pointer"));
        pointer.Link(arm2);
        arm2.Link(arm1);
        arm1.Link(dynamicbase);
        dynamicbase.Link(staticbase);
        // SIMPLE ROTATION ABOUT THE X AXIS BY X DEGREES
        //float x = 30;
        //float c = Mathf.Cos (x * Mathf.PI / 180);
        //float s = Mathf.Sin (x * Mathf.PI / 180);
        //arm1.Multiply (new float[4,4] {{1,0,0,0},{0,c,s,0},{0,-s,c,0},{0,0,0,1}});

        circleSprites = Resources.LoadAll <Sprite>("blue_circle");
    }
Exemplo n.º 13
0
        /// <summary>
        /// Makes a new "RobotLink" instance given the root of a robot
        /// </summary>
        public static RobotLink ConfigureRobot(GameObject rootObject, string RobotType, bool _isTheRoot = true, RobotLink parentTree = null, List <RobotJoint> originalList = null)
        {
            RobotJoint[] robotJoints = rootObject.GetComponents <RobotJoint>();

            if (_isTheRoot)
            {
                RobotLink newRobotLink = new RobotLink(rootObject, RobotType, true);
                newRobotLink.BaseType = RobotType;
                addToList(robotJoints, newRobotLink, RobotType, newRobotLink.RobotJoints);
                return(newRobotLink);
            }
            else
            {
                RobotLink newRobotLink = new RobotLink(rootObject, RobotType, false);
                newRobotLink.BaseType = RobotType;
                newRobotLink.Parent   = parentTree;
                addToList(robotJoints, newRobotLink, RobotType, originalList);
                return(null);
            }
        }
Exemplo n.º 14
0
    /// <summary>
    /// Method to recreate a link
    /// </summary>
    public static GameObject GenerateLink(LinkStorage linkConfig)
    {
        GameObject newLink = GenerateShape(linkConfig.Shape);

        newLink.transform.localScale = new Vector3(linkConfig.Shape.ScaleParams[0], linkConfig.Shape.ScaleParams[1], linkConfig.Shape.ScaleParams[2]);
        newLink.transform.position   = new Vector3(linkConfig.PositionParams[0], linkConfig.PositionParams[1], linkConfig.PositionParams[2]);
        newLink.transform.rotation   = new Quaternion(linkConfig.RotationParams[0], linkConfig.RotationParams[1], linkConfig.RotationParams[2], linkConfig.RotationParams[3]);

        // There should be code here to set COM and inertiatensors, but will leave that for later.
        // Also will do more stuff with this link component... For now it's just... uh... kind of useless
        RobotLink newRobotLink = newLink.AddComponent <RobotLink>();

        Rigidbody newRigid = newLink.AddComponent <Rigidbody>();

        newRigid.isKinematic = true;
        newRigid.useGravity  = false;
        Destroy(newLink.GetComponent <Collider>());

        return(newLink);
    }
Exemplo n.º 15
0
        void Update()
        {
            if (_material != null)
            {
                // The target color for the Interaction object will be determined by various simple state checks.
                Color targetColor = defaultColor;

                if (_intObj.isHovered && useHover)
                {
                    float glow = _intObj.closestHoveringControllerDistance.Map(0F, 0.2F, 1F, 0.0F);
                    targetColor = Color.Lerp(defaultColor, hoverColor, glow);
                }

                // On press
                if (_intObj is InteractionButton && (_intObj as InteractionButton).isPressed)
                {
                    if (!_isPushed)
                    {
                        _isPushed = true;

                        switch (ButtonChoice)
                        {
                        case ButtonType.SpawnLink:
                            GameObject newLink  = RobotLink.SpawnLink();
                            GameObject Linktool = SpawnTransformTool(newLink);

                            LinkIDCount += 1;
                            newLink.GetComponent <RobotLink>().SelfID = LinkIDCount;

                            newLink.transform.localScale = spawnScale;
                            newLink.transform.position   = spawnLocation;

                            break;

                        case ButtonType.SpawnJoint:
                            GameObject newJoint  = ObjectJoint.SpawnJoint();
                            GameObject Jointtool = SpawnTransformTool(newJoint);

                            JointIDCount += 1;
                            newJoint.GetComponent <ObjectJoint>().SelfID = JointIDCount;

                            newJoint.transform.localScale = spawnScale;
                            newJoint.transform.position   = spawnLocation;

                            break;

                        case ButtonType.Attach:
                            AttachObjects();
                            break;

                        case ButtonType.Delete:
                            DeleteObject();
                            break;
                        }

                        targetColor = pressedColor;
                    }
                }

                // For the button cooldown
                if (_intObj is InteractionButton && !(_intObj as InteractionButton).isPressed)
                {
                    _isPushed = false;
                }

                // Lerp actual material color to the target color.
                _material.color = Color.Lerp(_material.color, targetColor, 30F * Time.deltaTime);
            }
        }
Exemplo n.º 16
0
    private void SpawnLink()
    {
        GameObject newLink = RobotLink.SpawnLink();

        newLink.AddComponent <ClickerTest>();
    }
Exemplo n.º 17
0
 void StopRotate()
 {
     part = null;
 }
Exemplo n.º 18
0
 void RotateArm3R()
 {
     part = arm3;
     deg  = 1;
 }
Exemplo n.º 19
0
 void RotateArm3L()
 {
     part = arm3;
     deg  = -1;
 }
Exemplo n.º 20
0
 void RotateArm2R()
 {
     part = arm2;
     deg  = -1;
 }
Exemplo n.º 21
0
 void RotateArm2L()
 {
     part = arm2;
     deg  = 1;
 }
Exemplo n.º 22
0
 void RotateArm1R()
 {
     part = arm1;
     deg  = 1;
 }
Exemplo n.º 23
0
 void RotateArm1L()
 {
     part = arm1;
     deg  = -1;
 }
Exemplo n.º 24
0
 void RotatePointerR()
 {
     part = pointer;
     deg  = 1;
 }
Exemplo n.º 25
0
 void RotatePointerL()
 {
     part = pointer;
     deg  = -1;
 }