コード例 #1
0
ファイル: GrabberService.cs プロジェクト: eyJhb/itx-flex
        private void GrabberSession_StateChanged(GrabberState newState)
        {
            switch (newState)
            {
            case GrabberState.Running:
            case GrabberState.Error:
                DispatcherHelper.CheckBeginInvokeOnUI((Action)(() =>
                {
                    foreach (ICaptureWindow captureWindow in this.captureWindows)
                    {
                        captureWindow.ShowOverlay();
                    }
                }));
                break;

            default:
                DispatcherHelper.CheckBeginInvokeOnUI((Action)(() =>
                {
                    foreach (ICaptureWindow captureWindow in this.captureWindows)
                    {
                        captureWindow.HideOverlay();
                    }
                }));
                break;
            }
        }
コード例 #2
0
 public void Release()
 {
     if (state == GrabberState.grabbingOtherObject)
     {
         currentlyHoveredGrabbable.transform.SetParent(null);
         state = GrabberState.worn;
     }
 }
コード例 #3
0
 public void StartSimulation(int stepsPerInstruction)
 {
     _stepsPerInstruction = stepsPerInstruction;
     _instructionCounter  = 0;
     _restartMark         = 0;
     _endStepState        = _startState;
     ClampOpen            = _startState.clampOpen;
 }
コード例 #4
0
 public void UnWear()
 {
     if (state == GrabberState.worn)
     {
         Destroy(grabberRiggidBody);
         transform.SetParent(null);
         state = GrabberState.free;
         CheckColliders();
     }
 }
コード例 #5
0
        protected void CheckIsGrabbable(GameObject other)
        {
            GrabbableBehaviour grabbable = other.gameObject.GetComponentInParent <GrabbableBehaviour>();

            if (grabbable != null)
            {
                currentlyHoveredGrabbable = grabbable;
                state = GrabberState.hoveringOtherObject;
            }
        }
コード例 #6
0
 public void Wear(Transform grabberPivot)
 {
     if (state == GrabberState.free)
     {
         grabberRiggidBody             = gameObject.AddComponent <Rigidbody>();
         grabberRiggidBody.isKinematic = true;
         grabberRiggidBody.useGravity  = false;
         state = GrabberState.worn;
         transform.SetParent(grabberPivot);
         transform.localPosition = Vector3.zero;
         transform.localRotation = Quaternion.identity;
         CheckColliders();
     }
 }
コード例 #7
0
        protected void TryGrabOtherObject()
        {
            if (state == GrabberState.hoveringOtherObject)
            {
                if (currentlyHoveredGrabbable != null && currentlyHoveredGrabbable.CanGrab() && state != GrabberState.grabbingOtherObject)
                {
                    state = GrabberState.grabbingOtherObject;
                    Transform handSnapPoint = isLeftHanded ? currentlyHoveredGrabbable.leftHandSnapPoint : currentlyHoveredGrabbable.rightHandSnapPoint;
                    currentlyHoveredGrabbable.transform.SetParent(snapPoint);

                    currentlyHoveredGrabbable.transform.rotation = snapPoint.rotation * Quaternion.Inverse(handSnapPoint.localRotation);
                    currentlyHoveredGrabbable.transform.position = snapPoint.position - currentlyHoveredGrabbable.transform.rotation * handSnapPoint.localPosition;
                }
            }
        }
コード例 #8
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            //Rotate robot axes
            upperArmTransform.Rotation.x += robotArmSpeed * DeltaTime * Keyboard.UpDownAxis;
            lowerArmTransform.Rotation.x += robotArmSpeed * DeltaTime * Keyboard.WSAxis;

            //Rotate camera with mouse
            if (Mouse.LeftButton)
            {
                _camAngle += -.01f * DeltaTime * Mouse.Velocity.x;
            }

            //Diagnostics.Debug(currentGrabberState);

            //Grabber movement
            if (Keyboard.IsKeyDown(KeyCodes.Space))
            {
                currentGrabberState = currentGrabberState == GrabberState.open || currentGrabberState == GrabberState.opening ? GrabberState.closing : GrabberState.opening;
                Diagnostics.Debug("Setting Grabber state to " + currentGrabberState);
            }

            if (currentGrabberState == GrabberState.closing)
            {
                grabber1Transform.Rotation.x += grabberSpeed * DeltaTime;
                grabber2Transform.Rotation.x -= grabberSpeed * DeltaTime;
                if (grabber1Transform.Rotation.x >= 0)
                {
                    Diagnostics.Debug("Setting Grabber state to closed");
                    currentGrabberState          = GrabberState.closed;
                    grabber1Transform.Rotation.x = 0;
                    grabber2Transform.Rotation.x = 0;
                }
            }
            else if (currentGrabberState == GrabberState.opening)
            {
                grabber1Transform.Rotation.x -= grabberSpeed * DeltaTime;
                grabber2Transform.Rotation.x += grabberSpeed * DeltaTime;
                if (grabber1Transform.Rotation.x <= grabber1Limit)
                {
                    Diagnostics.Debug("Setting Grabber state to open");
                    currentGrabberState          = GrabberState.open;
                    grabber1Transform.Rotation.x = grabber1Limit;
                    grabber2Transform.Rotation.x = grabber2Limit;
                }
            }


            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, -10, 50) * float4x4.CreateRotationY(_camAngle);

            // Render the scene on the current render context
            sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
コード例 #9
0
ファイル: Grabber.cs プロジェクト: Monster25/gmdprojectAC
 void SetState(GrabberState grabberState)
 {
     this.grabberState = grabberState;
 }
コード例 #10
0
	// returns true for succesful
	public void PerformInstruction ()
	{
//		if (instructions[_instructionCounter] == Instruction.None)
//		{
//			_instructionCounter = _restartMark; // will be 0 is no restart mark set
//		}
		
//		Debug.Log("Deregistering "+heldPart+" at "+LocationAtClampEnd().x+":"+LocationAtClampEnd().y);
		
//		Debug.Log ("PerformInstruction "+_currentInstruction+": "+instructions[_instructionCounter]);
		
		_startStepState.rotation = 0;
		_startStepState = _endStepState;
	
//		Debug.Break ();
//		Debug.Log ("before: "+_endStepState.direction);
		
//		Debug.Log ("instructionCounter "+_instructionCounter);
//		Debug.Log ("instruction = "+instructions[_instructionCounter]);
		
		if (instructions.Count == 0)
		{
			_currentInstruction = Instruction.None;
		}
		else
		{
			_currentInstruction = instructions[_instructionCounter];
		}
		_isMoveingInstruction = false;
//		_doAtEndOfInstruction = null;
		
		switch (_currentInstruction)
		{
			case Instruction.TurnClock:
			{
				_endStepState.direction += 1;
				_isMoveingInstruction = true;
			}
			break;
			case Instruction.TurnAnti:
			{
				_endStepState.direction += 5;
				_isMoveingInstruction = true;
			}
			break;
			case Instruction.Extend:
			{
				_endStepState.extention += 1;
				_isMoveingInstruction = true;
			}
			break;
			case Instruction.Retract:
			{
				_endStepState.extention -= 1;
				_isMoveingInstruction = true;
			}
			break;
			case Instruction.RotateClock:
			{
				_endStepState.rotation += 1;
				_isMoveingInstruction = true;
			}
			break;
			case Instruction.RotateAnti:
			{
				_endStepState.rotation -= 1;
				_isMoveingInstruction = true;
			}
			break;
			case Instruction.RestartMark:
			{
				_restartMark = _instructionCounter+1;
			}
			break;
			case Instruction.Grab:
			{
				// dealt with in another function
			}
			break;
			case Instruction.Drop:
			{
				GrabbablePart heldPart = GrabberManager.instance.GetPartHeldBy(this);
				if (heldPart != null)
				{
				
					IntVector2 locationAtClamp = LocationAtClamp();
					if (GridManager.instance.GetHexCell(locationAtClamp) == null)
					{
						// trying to drop into non grid location
						
						LevelManager.instance.gameState = LevelManager.State.SimulationFailed;
						heldPart.highlighted = true;
						break;
					}
					
					GrabberManager.instance.RegisterDrop(this, heldPart);
				}
//				else
//				{
//					Debug.Log ("No part to drop", this);
//				}
			}
			break;
		}
		
		
		_endStepState.direction = (HexMetrics.Direction)((int)_endStepState.direction % 6);
		_endStepState.extention = Mathf.Clamp(_endStepState.extention, 0, 2);
		
		
//		Debug.Log ("after: "+_endStepState.direction);
		
		_stepCounter = 0;
		_instructionCounter += 1;
		if (_instructionCounter == instructions.Count)
		{
			_instructionCounter = _restartMark;
			if (_instructionCounter == instructions.Count)
			{
				_instructionCounter = instructions.Count - 1;
			}
		}
		
	}
コード例 #11
0
	void MoveToState(GrabberState grabberState)
	{
		MoveToState(grabberState.extention, ((int)grabberState.direction)*-60f, 0f);
	}
コード例 #12
0
	public void StartSimulation(int stepsPerInstruction)
	{
		_stepsPerInstruction = stepsPerInstruction;
		_instructionCounter = 0;
		_restartMark = 0;
		_endStepState = _startState;
		ClampOpen = _startState.clampOpen;
	}
コード例 #13
0
    // returns true for succesful
    public void PerformInstruction()
    {
//		if (instructions[_instructionCounter] == Instruction.None)
//		{
//			_instructionCounter = _restartMark; // will be 0 is no restart mark set
//		}

//		Debug.Log("Deregistering "+heldPart+" at "+LocationAtClampEnd().x+":"+LocationAtClampEnd().y);

//		Debug.Log ("PerformInstruction "+_currentInstruction+": "+instructions[_instructionCounter]);

        _startStepState.rotation = 0;
        _startStepState          = _endStepState;

//		Debug.Break ();
//		Debug.Log ("before: "+_endStepState.direction);

//		Debug.Log ("instructionCounter "+_instructionCounter);
//		Debug.Log ("instruction = "+instructions[_instructionCounter]);

        if (instructions.Count == 0)
        {
            _currentInstruction = Instruction.None;
        }
        else
        {
            _currentInstruction = instructions[_instructionCounter];
        }
        _isMoveingInstruction = false;
//		_doAtEndOfInstruction = null;

        switch (_currentInstruction)
        {
        case Instruction.TurnClock:
        {
            _endStepState.direction += 1;
            _isMoveingInstruction    = true;
        }
        break;

        case Instruction.TurnAnti:
        {
            _endStepState.direction += 5;
            _isMoveingInstruction    = true;
        }
        break;

        case Instruction.Extend:
        {
            _endStepState.extention += 1;
            _isMoveingInstruction    = true;
        }
        break;

        case Instruction.Retract:
        {
            _endStepState.extention -= 1;
            _isMoveingInstruction    = true;
        }
        break;

        case Instruction.RotateClock:
        {
            _endStepState.rotation += 1;
            _isMoveingInstruction   = true;
        }
        break;

        case Instruction.RotateAnti:
        {
            _endStepState.rotation -= 1;
            _isMoveingInstruction   = true;
        }
        break;

        case Instruction.RestartMark:
        {
            _restartMark = _instructionCounter + 1;
        }
        break;

        case Instruction.Grab:
        {
            // dealt with in another function
        }
        break;

        case Instruction.Drop:
        {
            GrabbablePart heldPart = GrabberManager.instance.GetPartHeldBy(this);
            if (heldPart != null)
            {
                IntVector2 locationAtClamp = LocationAtClamp();
                if (GridManager.instance.GetHexCell(locationAtClamp) == null)
                {
                    // trying to drop into non grid location

                    LevelManager.instance.gameState = LevelManager.State.SimulationFailed;
                    heldPart.highlighted            = true;
                    break;
                }

                GrabberManager.instance.RegisterDrop(this, heldPart);
            }
//				else
//				{
//					Debug.Log ("No part to drop", this);
//				}
        }
        break;
        }


        _endStepState.direction = (HexMetrics.Direction)((int)_endStepState.direction % 6);
        _endStepState.extention = Mathf.Clamp(_endStepState.extention, 0, 2);


//		Debug.Log ("after: "+_endStepState.direction);

        _stepCounter         = 0;
        _instructionCounter += 1;
        if (_instructionCounter == instructions.Count)
        {
            _instructionCounter = _restartMark;
            if (_instructionCounter == instructions.Count)
            {
                _instructionCounter = instructions.Count - 1;
            }
        }
    }
コード例 #14
0
 void MoveToState(GrabberState grabberState)
 {
     MoveToState(grabberState.extention, ((int)grabberState.direction) * -60f, 0f);
 }