Пример #1
0
        public void RenderFace(Shader Shader, FaceState State, bool IsDebugTouchMode = false)
        {
            Matrix4D modelMatrix     = State.Object.ModelMatrix * Camera.TranslationMatrix;
            Matrix4D modelViewMatrix = modelMatrix * CurrentViewMatrix;

            RenderFace(Shader, State.Object, State.Face, modelMatrix, modelViewMatrix, IsDebugTouchMode);
        }
Пример #2
0
        // Free up the resources upon leaving this screen
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            currFaceState = FaceState.None;
            if (_faceReader != null)
            {
                _faceReader.Dispose();
            }

            if (_bodyReader != null)
            {
                _bodyReader.Dispose();
            }

            if (_infraredReader != null)
            {
                _infraredReader.Dispose();
            }

            if (_sensor != null)
            {
                _sensor.Close();
            }

            GC.SuppressFinalize(this);
        }
Пример #3
0
        public FacePage()
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Play();

            InitializeComponent();

            currFaceState = FaceState.KinectWait;
            currBodyState = BodyState.KinectWait;
            faceSamples   = new double[NUM_SAMPLES];

            flagRuns = new int[Enum.GetNames(typeof(FlagType)).Length];

            _sensor = KinectSensor.GetDefault();

            if (_sensor != null)
            {
                currFaceState   = FaceState.FaceWait;
                currBodyState   = BodyState.BodyWait;
                _infraredSource = _sensor.InfraredFrameSource;
                _infraredReader = _infraredSource.OpenReader();
                _infraredReader.FrameArrived += InfraredReader_FrameArrived;

                _bodySource = _sensor.BodyFrameSource;
                _bodyReader = _bodySource.OpenReader();
                _bodyReader.FrameArrived += BodyReader_FrameArrived;

                _faceSource = new HighDefinitionFaceFrameSource(_sensor);
                _faceReader = _faceSource.OpenReader();
                _faceReader.FrameArrived += FaceReader_FrameArrived;

                _sensor.Open();
            }
        }
Пример #4
0
    FaceState GetNextRequiredFace(CubeState.RotationActions move)
    {
        FaceStates faceStates  = m_cubeOrientation.GetFaceStates();
        FaceState  returnValue = null;

        switch (move)
        {
        case CubeState.RotationActions.UP:
            returnValue = faceStates.GetFaceState(CubeState.Faces.BOTTOM);
            break;

        case CubeState.RotationActions.DOWN:
            returnValue = faceStates.GetFaceState(CubeState.Faces.TOP);
            break;

        case CubeState.RotationActions.LEFT:
            returnValue = faceStates.GetFaceState(CubeState.Faces.RIGHT);
            break;

        case CubeState.RotationActions.RIGHT:
            returnValue = faceStates.GetFaceState(CubeState.Faces.LEFT);
            break;
        }

        Debug.Log("GetNextRequiredFace = " + returnValue);

        return(returnValue);
    }
Пример #5
0
        public Picture GetPortrait(FaceState state = FaceState.Neutral)
        {
            if (_picture == null)
            {
                _picture = Resources.Instance.LoadPIC(_picFile);
            }

            Picture output = _picture.GetPart(181, 67, 139, 133);

            switch (state)
            {
            case FaceState.Smiling:
                output.AddLayer(_picture.GetPart(1, 51, 59, 49), _overlayX, _overlayY);
                break;

            case FaceState.Angry:
                output.AddLayer(_picture.GetPart(1, 151, 59, 49), _overlayX, _overlayY);
                break;

            default:
                // TODO: Add other states
                break;
            }
            return(output);
        }
Пример #6
0
        public void TestSaveAndLoadToFile()
        {
            FaceState originalFaceState = new FaceState();
            FaceState loadedFaceState;

            originalFaceState.IsHappy = true;

            originalFaceState.Points = new System.Drawing.PointF[]
            {
                new System.Drawing.PointF(1, 1),
                new System.Drawing.PointF(2, 2),
                new System.Drawing.PointF(3, 3)
            };

            FaceState.SaveToFile(originalFaceState, "backup.dat");

            Assert.IsTrue(FaceState.LoadFromFile("backup.dat", out loadedFaceState));

            Assert.IsTrue(loadedFaceState.IsHappy);
            Assert.IsFalse(loadedFaceState.IsLeftEyeClosed);
            Assert.IsFalse(loadedFaceState.IsRightEyeClosed);
            Assert.IsFalse(loadedFaceState.IsMouthMoved);
            Assert.IsFalse(loadedFaceState.IsMouthOpen);
            Assert.IsFalse(loadedFaceState.IsWearingGlasses);
            Assert.IsTrue(loadedFaceState.Points.Length == 3);
            Assert.IsTrue(loadedFaceState.Points[0] == originalFaceState.Points[0]);
            Assert.IsTrue(loadedFaceState.Points[1] == originalFaceState.Points[1]);
            Assert.IsTrue(loadedFaceState.Points[2] == originalFaceState.Points[2]);
        }
Пример #7
0
 public void PrintState()
 {
     for (int i = 0; i < (int)Faces.NUM_FACES; i++)
     {
         FaceState state = GetFaceState((Faces)i);
         Debug.Log("Face " + i + " = " + state.m_state);
     }
 }
Пример #8
0
 void Update()
 {
     if (currentState != facestate)
     {
         SetFace(facestate);
         currentState = facestate;
     }
 }
Пример #9
0
        public void TestDetermineBoundingBox_NoPoints()
        {
            System.Drawing.RectangleF boundingBox = FaceState.DetermineBoundingBox(new System.Drawing.PointF[] { });
            Assert.IsTrue(boundingBox == System.Drawing.RectangleF.Empty);

            boundingBox = FaceState.DetermineBoundingBox(null);
            Assert.IsTrue(boundingBox == System.Drawing.RectangleF.Empty);
        }
Пример #10
0
        public void Update()
        {
            //0 - Idle
            //1 - Happy
            //2 - Confused
            //3 - Sad
            //4 - Pog
            //5 - Angry
            if (faceTime <= 0)
            {
                faceState = (FaceState)Mathf.RoundToInt(Random.Range(-0.1f, 5.1f));
                if (faceState <= 0)
                {
                    faceState = FaceState.Idle;
                    faceTime  = Random.Range(15, 30);
                }
                else
                {
                    switch (faceState)
                    {
                    case FaceState.Happy:
                        faceTime = Random.Range(15, 30);
                        break;

                    case FaceState.Confused:
                        faceTime = Random.Range(10, 15);
                        break;

                    case FaceState.Sad:
                        faceTime = Random.Range(5, 15);
                        break;

                    case FaceState.Pog:
                        faceTime = Random.Range(1, 2);
                        break;

                    case FaceState.Angry:
                        faceTime = Random.Range(10, 15);
                        break;

                    default:
                        faceTime = Random.Range(1, 2);
                        break;
                    }
                }

                animator.SetInteger("State", (int)faceState);
            }
            else
            {
                faceTime -= Time.unscaledDeltaTime;
                if (animator.GetInteger("State") != (int)faceState)
                {
                    animator.SetInteger("State", (int)faceState);
                }
            }
        }
Пример #11
0
 public FaceStates(FaceState front, FaceState top, FaceState right, FaceState bottom, FaceState left, FaceState back)
 {
     m_faceStates[(int)CubeState.Faces.FRONT]  = front;
     m_faceStates[(int)CubeState.Faces.TOP]    = top;
     m_faceStates[(int)CubeState.Faces.RIGHT]  = right;
     m_faceStates[(int)CubeState.Faces.BOTTOM] = bottom;
     m_faceStates[(int)CubeState.Faces.LEFT]   = left;
     m_faceStates[(int)CubeState.Faces.BACK]   = back;
 }
Пример #12
0
        private void Okay_Click(object sender, RoutedEventArgs e)
        {
            // Record the setup parameters based on the samples
            double average = 0;

            foreach (double d in faceSamples)
            {
                average += d;
            }
            average /= NUM_SAMPLES;

            switch (currFaceState)
            {
            case FaceState.NeutralWait:
                yTilts[0]     = average;
                xTilts[0]     = average;
                currFaceState = FaceState.UpTiltWait;
                break;

            case FaceState.UpTiltWait:
                yTilts[1]     = average;
                currFaceState = FaceState.DownTiltWait;
                break;

            case FaceState.DownTiltWait:
                yTilts[2]     = average;
                currFaceState = FaceState.LeftTiltWait;
                break;

            case FaceState.LeftTiltWait:
                xTilts[1]     = average;
                currFaceState = FaceState.RightTiltWait;
                break;

            case FaceState.RightTiltWait:
                xTilts[2]     = average;
                currFaceState = FaceState.Presentation;
                // set start time of practice presentation
                startTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                break;

            case FaceState.Presentation:
                currFaceState = FaceState.Evaluation;
                string flagsText = "";
                foreach (PresentationFlag pf in _myFlags)
                {
                    flagsText += "" + pf.timestamp + '\n';
                    flagsText += pf.flag.ToString() + '\n';
                }
                System.IO.File.WriteAllText(RESULT_FILE_PATH, "" + startTime + '\n' + getCurrentTimeMillis() + '\n' + flagsText);
                break;
            }
        }
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //	* New Method: Continue To Next Face Animation
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 private void ContinueToNextFaceAnimation()
 {
     if (m_eFaceState == FaceState.MOUTH_OPENED)
     {
         m_eFaceState = FaceState.MOUTH_CLOSED;
         GetFaceSpriteScript().spriteName = GetClosedMouthSpriteName();
     }
     else
     {
         m_eFaceState = FaceState.MOUTH_OPENED;
         GetFaceSpriteScript().spriteName = GetOpenedMouthSpriteName();
     }
 }
Пример #14
0
        public void TestDefaultValues()
        {
            FaceState faceState = new FaceState();

            Assert.IsTrue(faceState.boundingBox == System.Drawing.RectangleF.Empty);

            Assert.IsTrue(faceState.IsHappy == false);
            Assert.IsTrue(faceState.IsLeftEyeClosed == false);
            Assert.IsTrue(faceState.IsRightEyeClosed == false);
            Assert.IsTrue(faceState.IsMouthMoved == false);
            Assert.IsTrue(faceState.IsMouthOpen == false);
            Assert.IsTrue(faceState.IsWearingGlasses == false);
            Assert.IsTrue(faceState.Points == null);
        }
Пример #15
0
    void calcInterpolation()
    {
        FaceState current = faces[currentFaceIndex];
        FaceState next    = faces[nextFaceIndex];

        if (distances == null)
        {
            distances = new Vector3[current.faceVertices.Length];
        }

        for (int i = 0; i < distances.Length; i++)
        {
            distances[i] = next.faceVertices[i] - current.faceVertices[i];
        }
    }
Пример #16
0
        public void TestGetBoundingBox()
        {
            System.Drawing.RectangleF boundingBox = FaceState.DetermineBoundingBox(new System.Drawing.PointF[]
            {
                new System.Drawing.PointF(0, 0),
                new System.Drawing.PointF(0, 500),
                new System.Drawing.PointF(200, 0),
                new System.Drawing.PointF(100, 100)
            });

            Assert.IsTrue(boundingBox.Width == 200.0F);
            Assert.IsTrue(boundingBox.Height == 500.0F);
            Assert.IsTrue(boundingBox.X == 0);
            Assert.IsTrue(boundingBox.Y == 0);
        }
Пример #17
0
    public void SetFace(FaceState state)
    {
        facestate = state;

        StopAllCoroutines();
        for (int i = 0; i < planetFace.sharedMesh.blendShapeCount; i++)
        {
            if ((int)facestate == i && i != (int)FaceState.IDLE)
            {
                StartCoroutine(FaceAnimation(i, 100));
            }
            else if (i != (int)FaceState.IDLE)
            {
                StartCoroutine(FaceAnimation(i, 0));
            }
        }
    }
Пример #18
0
        private void AlertFlag(string alertString, FlagType type)
        {
            // Play a warning sound and display feedback
            System.Media.SoundPlayer player = new System.Media.SoundPlayer(ALERT_WAV_PATH);
            player.Play();
            tblFeedback.Foreground = Brushes.Red;
            tblFeedback.Text       = alertString;
            tblFeedback.FontStyle  = FontStyles.Oblique;
            tblFeedback.FontWeight = FontWeights.ExtraBold;
            tblFeedback.FontSize   = 24.0;

            // Switch to alerted state, wait for a while before showing next alert
            currFaceState = FaceState.Alerted;
            long flagTime = getCurrentTimeMillis();

            // Add flag to list
            _myFlags.Add(new PresentationFlag(type, flagTime));
        }
Пример #19
0
        public void TestBoundingBox_Caching()
        {
            FaceState faceState = new FaceState();

            faceState.boundingBox = new System.Drawing.RectangleF(1, 2, 3, 4);
            faceState.Points      = new System.Drawing.PointF[]
            {
                new System.Drawing.PointF(20, 20),
                new System.Drawing.PointF(15, 15),
                new System.Drawing.PointF(0, 20),
                new System.Drawing.PointF(15, 40),
                new System.Drawing.PointF(10, 60),
                new System.Drawing.PointF(5, 40),
                new System.Drawing.PointF(10, 10),
                new System.Drawing.PointF(5, 15)
            };

            Assert.IsTrue(System.Drawing.RectangleF.Equals(new System.Drawing.RectangleF(1, 2, 3, 4), faceState.BoundingBox));
        }
Пример #20
0
    void CheckIfCorrect()
    {
        TutorialManager.Instance.ClearAllTutorialMessages();

        FaceStates faceStates = m_cubeOrientation.GetFaceStates();

        if (!m_cubeState.CheckState(faceStates))
        {
            Debug.LogError("ERROR!!!! difference in facestates");
        }

        int levelNum = 0;

        if (m_gameStateClass != null)
        {
            levelNum = m_gameStateClass.GetLevelNumber();
        }

        bool correctOrientation = (faceStates.GetFaceState(CubeState.Faces.FRONT).m_orientation == m_requiredFace.m_orientation);
        bool levelRequiresCorrectCubeOrientation = true;

        if (levelNum < m_levelRequiresCorrectCubeOrientation.Length)
        {
            levelRequiresCorrectCubeOrientation = m_levelRequiresCorrectCubeOrientation [levelNum];
        }

        if ((faceStates.GetFaceState(CubeState.Faces.FRONT).m_state == m_requiredFace.m_state) &&
            (correctOrientation || !levelRequiresCorrectCubeOrientation))
        {
            // correct
            //IncrementScore();
            m_hudController.AdvanceProgression(m_faceFoundCount);

            m_requiredFace = GetNextRequiredFace(GetNextMoveInSequence());
            //PickRandomRequiredFace();
            StartCoroutine(CorrectFaceSequence());
        }
        else
        {
            // wrong
            StartCoroutine(GotItWrongCoRoutine());
        }
    }
Пример #21
0
    IEnumerator WaitForRotateCubeToStartPosition()
    {
        yield return(new WaitForSeconds(0.75f));

        m_hudController.ScrollIn();
        yield return(new WaitForSeconds(0.75f));

        StartMoveSequence();
        m_requiredFace = GetNextRequiredFace(GetNextMoveInSequence());
        //PickRandomRequiredFace();
        yield return(ShowFirstFaceFaceCoroutine());

        if ((m_gameStateClass != null) && (m_gameStateClass.GetLevelNumber() == 0))          // && !m_gameStateClass.HasTutorialBeenShown (TutorialManager.MessageID.SWIPE_TO_ROTATE))
        {
            TutorialManager.Instance.ShowTutorialMessage(TutorialManager.MessageID.SWIPE_TO_ROTATE);
        }

        SwitchToState(GameState.FIND);
    }
Пример #22
0
    public void SetFaceState(FaceState faceState)
    {
        switch (faceState)
        {
        case FaceState.Neutral:
            StartCoroutine(SetFaceNeutral());
            break;

        case FaceState.Happy:
            StartCoroutine(SetFaceHappy());
            break;

        case FaceState.Angry:
            StartCoroutine(SetFaceAngry());
            break;

        default:
            break;
        }
    }
Пример #23
0
        public void TestBoundingBox()
        {
            FaceState faceState = new FaceState();

            faceState.Points = new System.Drawing.PointF[]
            {
                new System.Drawing.PointF(20, 20),
                new System.Drawing.PointF(15, 15),
                new System.Drawing.PointF(0, 20),
                new System.Drawing.PointF(15, 40),
                new System.Drawing.PointF(10, 60),
                new System.Drawing.PointF(5, 40),
                new System.Drawing.PointF(10, 10),
                new System.Drawing.PointF(5, 15)
            };

            Assert.IsTrue(20.0F == faceState.BoundingBox.Width);
            Assert.IsTrue(50.0F == faceState.BoundingBox.Height);
            Assert.IsTrue(faceState.BoundingBox.X == 0);
            Assert.IsTrue(faceState.BoundingBox.Y == 10);
        }
Пример #24
0
    void startMorphing()
    {
        interpolationTime = 0;


        //RECALCUL DES INDEXS
        currentFaceIndex++;
        currentFaceIndex %= faces.Count;

        int nextIndex = currentFaceIndex + 1;

        nextFaceIndex = nextIndex % faces.Count;

        print("currentFaceIndex is " + currentFaceIndex);
        print("nextFaceIndex is " + nextFaceIndex);


        FaceState current = faces[currentFaceIndex];
        FaceState next    = faces[nextFaceIndex];

        print(" Current Face name is " + current.faceFileName + " the frame number is " + current.frame);
        print(" Next Face name is " + next.faceFileName + " the frame number is " + next.frame);


        // Ranger les face states dans l'ordre
        // Calculer le temps au prochain cycle

        //CALCUL DU TEMPS DE L INTERPOLATION
        timeToNextStep = next.frame - current.frame;

        print("Time to Next Step is : " + timeToNextStep);
        if (timeToNextStep < 0)
        {
            timeToNextStep += nbFrames;
        }



        calcInterpolation();
    }
Пример #25
0
    IEnumerator GotItWrongCoRoutine()
    {
        m_audioSource.PlayOneShot(m_audioGotFaceWrong, 1f);

        m_cube.GetComponentInChildren <Rotator>().BlockRotationForTimePeriod(1.0f);
        m_cube.GetComponent <Cube>().PlayShakeHeadAnimation();
        yield return(new WaitForSeconds(0.5f));

        DecrementLivesLeft();
        yield return(new WaitForSeconds(0.5f));

        m_cube.GetComponent <Cube>().ResetAnimation();

        if (m_livesLeft == 0)
        {
            m_touchSwipeDetector.enabled = false;
            m_hudController.ScrollOut();
            m_gameOverText.SetActive(true);
            GameStateClass.Instance.RecordLastPlayedLevel();
            yield return(new WaitForSeconds(1.5f));

            m_gameOverButtons.SetActive(true);
        }
        else
        {
            if (CHOOSE_ANOTHER_FACE_AFTER_EACH_WRONG_ANSWER)
            {
                // you've chosen the wrong face. Now we choose another face to find that is adjacent to this one.
                m_requiredFace = GetNextRequiredFace(GetNextMoveInSequence());
                yield return(ChangeRequiredFaceCoroutine());
            }
            else
            {
                // go back to the face we were looking at before you got it wrong
                SwitchToState(GameState.ROTATE_BACK_TO_PREVIOUS);
                //yield return new WaitForSeconds(0.5f);
            }
        }
    }
Пример #26
0
        }   // end of Face DirectGaze()

        public void Update(Movement movement)
        {
            float deltaTime = Time.GameTimeFrameSeconds;

            // Decrement the timers and check for any state changes.
            reactiveDuration  -= deltaTime;
            emotionalDuration -= deltaTime;
            gazeDuration      -= deltaTime;

            if (reactiveDuration < 0.0f && reactiveState != FaceState.None)
            {
                reactiveState = FaceState.None;
                newState      = true;
            }

            if (emotionalDuration < 0.0f && emotionalState != FaceState.None)
            {
                emotionalState = FaceState.None;
                newState       = true;
            }

            if (gazeDuration < 0.0f)
            {
                gazeState = GazeState.Scanning;
            }

            if (reactiveState != FaceState.None)
            {
                SetState(reactiveState);
            }
            else
            {
                SetState(emotionalState);
            }

            SetGaze(movement);
        }   // end of Face Update()
Пример #27
0
 public Picture GetPortrait(FaceState state)
 {
     return(new Picture(139, 133, Common.GetPalette256));
 }
Пример #28
0
    // Update is called once per frame
    void Update()
    {
        // エスケープで終了
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene("Title");
        }

        GameData.Instance.eyeOpenThreshold = Mathf.Clamp(GameData.Instance.eyeOpenThreshold + Input.GetAxis("Horizontal") / 100.0f, slider.minValue, slider.maxValue);
        slider.value     = GameData.Instance.eyeOpenThreshold;
        sliderValue.text = GameData.Instance.eyeOpenThreshold.ToString("F2");

        interval++;
        if (interval >= 20)
        {
            timerText.text = "EyeSize  L : " + openChecker.GetOpenL().ToString("F2") + " R : " + openChecker.GetOpenL().ToString("F2");
            interval       = 0;
        }

        switch (state)
        {
        case FaceState.None:
            if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Z) || Input.GetButtonDown("Action1"))
            {
                transition.FadeOut();
                audioSource.Play();
                state = FaceState.Finish;
                Invoke("LoadScene", 1.0f);
            }
            break;

        //case FaceState.Close:
        //    timerText.text = timer.ToString("F1");

        //    if (openChecker.KEEP_EYE_OPEN == false)
        //    {
        //        timer = Mathf.Clamp(timer - Time.deltaTime, 0.0f, 3.0f);
        //        if (timer == 0.0f)
        //        {
        //            timer = 3.0f;
        //            close.SetTrigger("out");
        //            Invoke("Open", 3.0f);
        //            state = FaceState.None;
        //        }
        //    }
        //    else
        //    {
        //        timer = 3.0f;
        //        timerText.text = "";
        //    }
        //    break;
        //case FaceState.Open:

        //    timerText.text = timer.ToString("F1");

        //    timer = Mathf.Clamp(timer - Time.deltaTime, 0.0f, 3.0f);
        //    interval++;
        //    if (interval % 10 == 0)
        //    {
        //        eyesSizeL.Add(openChecker.GetOpenL());
        //        eyesSizeR.Add(openChecker.GetOpenR());
        //    }
        //    if (timer == 0.0f)
        //    {
        //        open.SetTrigger("out");
        //        state = FaceState.None;

        //        EyeSizeL = eyesSizeL.Average();
        //        EyeSizeR = eyesSizeR.Average();

        //        //EyesData.Instance.EyeSizeL = EyeSizeL;
        //        //EyesData.Instance.EyeSizeR = EyeSizeR;

        //        timerText.text = "EyeSize  L : " + EyeSizeL.ToString("F2") + " R : " + EyeSizeR.ToString("F2");
        //    }
        //    break;

        case FaceState.Finish:
            Zoom();

            break;
        }
    }
Пример #29
0
        public void Update(int time, Monster srcMonster)
        {
            if (state == FaceState.Armored)
            {
                if (salvoCooldown == 0)
                {
                    fireCooldown -= time;
                    if (fireCooldown < 0) fireCooldown = 0;
                }
                else
                {
                    salvoCooldown -= time;
                    if (salvoCooldown < 0) salvoCooldown = 0;
                }
            }
            if (fireCooldown == 0)
            {
                fireCooldown = fireCooldownMax;
                fireCount--;
                if (fireCount == 0)
                {
                    fireCount = fireCountMax;
                    salvoCooldown = salvoCooldownMax;
                }

                Vector3 center = Engine.player.currentRoom.center;
                Vector3 outDirection = Engine.player.center.position - center;
                Vector3 up = Engine.player.cameraUp;
                outDirection.Normalize();
                up.Normalize();
                Vector3 right = Vector3.Cross(up, outDirection);
                Vector3 eye1 = center + outDirection * 6 + 1.5f * right +.5f * up;
                Vector3 eye2 = center + outDirection * 6 - 1.5f * right + .5f * up;

                Vector3 eye1Dif = Engine.player.center.position - eye1;
                Vector3 eye2Dif = Engine.player.center.position - eye2;

                float eye1Depth = -Vector3.Dot(eye1Dif, Engine.player.center.normal);
                float eye2Depth = -Vector3.Dot(eye2Dif, Engine.player.center.normal);

                Vector3 eye1Pos = eye1 - eye1Depth * Engine.player.center.normal;
                Vector3 eye2Pos = eye2 - eye2Depth * Engine.player.center.normal;

                float eye1Time = (Engine.player.depth - eye1Depth) / Projectile.eyeLaserVel;
                float eye2Time = (Engine.player.depth - eye2Depth) / Projectile.eyeLaserVel;

                Vector3 eye1GameDistance = Engine.player.center.position - eye1Pos;
                Vector3 eye2GameDistance = Engine.player.center.position - eye2Pos;

                Vector3 eye1Vel = eye1GameDistance / eye1Time;
                Vector3 eye2Vel = eye2GameDistance / eye2Time;

                Engine.player.currentRoom.projectiles.Add(new Projectile(srcMonster, ProjectileType.EyeLaser, eye1Pos, eye1Vel, Engine.player.center.normal, Engine.player.center.direction, eye1Depth));
                Engine.player.currentRoom.projectiles.Add(new Projectile(srcMonster, ProjectileType.EyeLaser, eye2Pos, eye2Vel, Engine.player.center.normal, Engine.player.center.direction, eye2Depth));
                SoundFX.FireLaser(Engine.player.currentRoom.center);
            }

            if (dialogState == 0 && Engine.player.state == State.Normal && state == FaceState.Rebuilding && Engine.player.state != State.Tunnel)
            {
                DialogBox.SetDialog("FinalBoss1");
                dialogState++;
            }
            if (dialogState == 1 && srcMonster.baseHP != srcMonster.startingBaseHP && damageCooldown == 0 && Engine.player.state != State.Tunnel)
            {
                DialogBox.SetDialog("FinalBoss2");
                state = FaceState.Rebuilding;
                forceRebuild = true;
                dialogState++;
            }
            if (dialogState == 2 && srcMonster.baseHP ==0 && Engine.player.state != State.Tunnel)
            {
                DialogBox.SetDialog("FinalBoss3");
                dialogState++;
            }

            damageCooldown -= time;
            if (damageCooldown < 0)
                damageCooldown = 0;
            if (state == FaceState.Exploding)
            {
                armorExplodeTime += time;
                if (armorExplodeTime > armorExplodeMaxTime)
                {
                    armorExplodeTime = armorExplodeMaxTime;
                    state = FaceState.Angry;
                }
            }
            else if(state == FaceState.Rebuilding)
            {
                armorExplodeTime -= time;
                if (armorExplodeTime < 0)
                {
                    armorExplodeTime = 0;
                    state = FaceState.Armored;
                }
            }
            else if (state == FaceState.Angry || forceRebuild)
            {
                forceRebuild = false;
                timer -= time;
                if (dialogState < 3 && srcMonster.baseHP > 0)
                {
                    if (timer < 0)
                    {
                        timer = timerMax;
                        state = FaceState.Rebuilding;
                        foreach (Monster m in Engine.player.currentRoom.monsters)
                        {
                            if (m.id.Contains("Guardian") && m.state == MonsterState.Death)
                            {
                                m.baseHP = m.startingBaseHP;
                                m.dead = false;
                                m.state = MonsterState.Spawn;
                                m.spawnTime = 0;
                                m.deathTime = Monster.maxDeathTime;
                            }
                        }
                    }
                }

                if(damageCooldown == 0 && (Engine.player.state == State.Phase || Engine.player.state == State.PhaseFail) && (Engine.player.jumpPosition - Engine.player.currentRoom.center).Length() < 6f)
                {
                    srcMonster.impactVector = new Vector3(1, 0, 0);
                    srcMonster.lastHitType = ProjectileType.Plasma;
                    damageCooldown = damageCooldownMax;
                }

            }
            else if (state == FaceState.Armored)
            {
                bool explode = true;
                if (srcMonster.startingBaseHP != 0)
                {

                    foreach (Monster m in Engine.player.currentRoom.monsters)
                    {
                        if (m.dead == false && m.id.Contains("Guardian"))
                            explode = false;
                    }
                    if (explode == true)
                    {
                        state = FaceState.Exploding;
                    }
                }
            }
        }
Пример #30
0
        private void FaceReader_FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs args)
        {
            using (var frame = args.FrameReference.AcquireFrame())
            {
                string output = "";
                if (frame != null && frame.IsFaceTracked && currBodyState == BodyState.Ready)
                {
                    // Prepare to enter the setup chain in the state diagram
                    if (currFaceState == FaceState.FaceWait)
                    {
                        currFaceState = FaceState.NeutralWait;
                    }

                    // Display basic points only.
                    Face face = frame.Face();

                    Point pointEyeLeft    = face.EyeLeft.ToPoint(Visualization.Infrared);
                    Point pointEyeRight   = face.EyeRight.ToPoint(Visualization.Infrared);
                    Point pointCheekLeft  = face.CheekLeft.ToPoint(Visualization.Infrared);
                    Point pointCheekRight = face.CheekRight.ToPoint(Visualization.Infrared);
                    Point pointNose       = face.Nose.ToPoint(Visualization.Infrared);
                    Point pointMouth      = face.Mouth.ToPoint(Visualization.Infrared);
                    Point pointChin       = face.Chin.ToPoint(Visualization.Infrared);
                    Point pointForehead   = face.Forehead.ToPoint(Visualization.Infrared);

                    Canvas.SetLeft(eyeLeft, pointEyeLeft.X - eyeLeft.Width / 2.0);
                    Canvas.SetTop(eyeLeft, pointEyeLeft.Y - eyeLeft.Height / 2.0);

                    Canvas.SetLeft(eyeRight, pointEyeRight.X - eyeRight.Width / 2.0);
                    Canvas.SetTop(eyeRight, pointEyeRight.Y - eyeRight.Height / 2.0);

                    Canvas.SetLeft(cheekLeft, pointCheekLeft.X - cheekLeft.Width / 2.0);
                    Canvas.SetTop(cheekLeft, pointCheekLeft.Y - cheekLeft.Height / 2.0);

                    Canvas.SetLeft(cheekRight, pointCheekRight.X - cheekRight.Width / 2.0);
                    Canvas.SetTop(cheekRight, pointCheekRight.Y - cheekRight.Height / 2.0);

                    Canvas.SetLeft(nose, pointNose.X - nose.Width / 2.0);
                    Canvas.SetTop(nose, pointNose.Y - nose.Height / 2.0);

                    Canvas.SetLeft(mouth, pointMouth.X - mouth.Width / 2.0);
                    Canvas.SetTop(mouth, pointMouth.Y - mouth.Height / 2.0);

                    Canvas.SetLeft(chin, pointChin.X - chin.Width / 2.0);
                    Canvas.SetTop(chin, pointChin.Y - chin.Height / 2.0);

                    Canvas.SetLeft(forehead, pointForehead.X - forehead.Width / 2.0);
                    Canvas.SetTop(forehead, pointForehead.Y - forehead.Height / 2.0);

                    // State handling to determine what to print to message area
                    switch (currFaceState)
                    {
                    case FaceState.NeutralWait:
                        output += "Step 2/6: Position your head in neutral forward-facing position.\n"
                                  + "Hold for at least " + RECOMMEND_TIME + " seconds, then press OK.\n";
                        faceSamples[sampleInd] = Math.Round(face.Chin.Z - face.Forehead.Z, 4);
                        break;

                    case FaceState.UpTiltWait:
                        output += "Step 3/6: Now tilt your head about 45 degress upwards.\n"
                                  + "Hold for at least " + RECOMMEND_TIME + " seconds, then press OK.\n";
                        faceSamples[sampleInd] = Math.Round(face.Chin.Z - face.Forehead.Z, 4);
                        break;

                    case FaceState.DownTiltWait:
                        output += "Step 4/6: Now tilt your head about 45 degress downwards.\n"
                                  + "Hold for at least " + RECOMMEND_TIME + " seconds, then press OK.\n";
                        faceSamples[sampleInd] = Math.Round(face.Chin.Z - face.Forehead.Z, 4);
                        break;

                    case FaceState.LeftTiltWait:
                        output += "Step 5/6: Turn your head slightly to the left.\n"
                                  + "Hold for at least " + RECOMMEND_TIME + " seconds, then press OK.\n";
                        faceSamples[sampleInd] = Math.Round(face.CheekRight.Z - face.CheekLeft.Z, 4);
                        break;

                    case FaceState.RightTiltWait:
                        output += "Step 6/6: Now turn your head slightly to to the right.\n"
                                  + "Hold for at least " + RECOMMEND_TIME + " seconds, then press OK.\n";
                        faceSamples[sampleInd] = Math.Round(face.CheekRight.Z - face.CheekLeft.Z, 4);
                        break;

                    case FaceState.Alerted:

                        // Waited long enough: switch back!
                        delayFrames++;
                        if (delayFrames >= ALERT_DELAY_FRAMES)
                        {
                            delayFrames   = 0;
                            currFaceState = FaceState.Presentation;
                        }
                        break;

                    case FaceState.Presentation:
                        output += "You're all set - start speaking right now! When you're done, press OK.\n";
                        // The BIG "check if these flags are activated" chunk of code

                        // Display timer
                        long   currentTime   = getCurrentTimeMillis();
                        int    numMinutes    = (int)(currentTime - startTime) / 60000;
                        int    numSeconds    = ((int)(currentTime - startTime) / 1000) % 60;
                        string numSecondsStr = "" + numSeconds;

                        output += "Time elapsed: " + numMinutes + ":" + numSecondsStr.PadLeft(2, '0');

                        int  enumInd;
                        bool alerted = false;
                        currYTilt = Math.Round(face.Chin.Z - face.Forehead.Z, 4);
                        if (Math.Abs(currYTilt - yTilts[0]) > Math.Abs(currYTilt - yTilts[1]))
                        {
                            enumInd = Convert.ToInt32(FlagType.HeadUp);
                            flagRuns[enumInd]++;
                            if (flagRuns[enumInd] >= RUN_THRESHOLD)
                            {
                                flagRuns[enumInd] = 0;
                                AlertFlag("Reminder: Tilt head lower!", FlagType.HeadUp);
                                alerted = true;
                            }
                        }
                        else if (Math.Abs(currYTilt - yTilts[0]) > Math.Abs(currYTilt - yTilts[2]))
                        {
                            enumInd = Convert.ToInt32(FlagType.HeadDown);
                            flagRuns[enumInd]++;
                            if (flagRuns[enumInd] >= RUN_THRESHOLD)
                            {
                                flagRuns[enumInd] = 0;
                                AlertFlag("Reminder: Tilt head higher!", FlagType.HeadDown);
                                alerted = true;
                            }
                        }

                        // track which way speaker is facing now
                        currXTilt = Math.Round(face.CheekRight.Z - face.CheekLeft.Z, 4);
                        FaceOrientation newOrientation = getFaceOrientation(currXTilt);
                        if (newOrientation == currFaceOrientation)
                        {
                            currZoneFrames++;
                        }
                        else
                        {
                            currZoneFrames      = 0;
                            currFaceOrientation = newOrientation;
                        }

                        if (currZoneFrames >= CURR_ZONE_THRESHOLD)
                        {
                            currZoneFrames = 0;
                            enumInd        = Convert.ToInt32(FlagType.HeadStatic);
                            AlertFlag("Reminder: Face different parts of the audience more often!", FlagType.HeadStatic);
                            alerted = true;
                        }

                        if (currRotation > FRONT_FACING_THRESHOLD)
                        {
                            enumInd = Convert.ToInt32(FlagType.Shoulders);
                            flagRuns[enumInd]++;
                            if (flagRuns[enumInd] >= RUN_THRESHOLD)
                            {
                                flagRuns[enumInd] = 0;
                                AlertFlag("Reminder: Straighten your shoulders!", FlagType.Shoulders);
                                alerted = true;
                            }
                        }
                        if (!alerted)
                        {
                            tblFeedback.Foreground = Brushes.Black;
                            tblFeedback.Text       = "READY";
                            tblFeedback.FontSize   = 15.0;
                            tblFeedback.FontStyle  = FontStyles.Oblique;
                            tblFeedback.FontWeight = FontWeights.ExtraBold;
                        }

                        break;

                    case FaceState.Evaluation:
                        output += "Practice session over! Return to main screen and check your feedback";
                        break;
                    }
                    // Record samples for the setup parameters
                    sampleInd = (sampleInd + 1) % NUM_SAMPLES;
                    // output += sampleInd; // for testing
                }
                else
                {
                    output = "Step 1/6: Stand up, face as squarely with the Kinect as you can, then wait for camera to find your face.";
                }

                tblFaceStatus.Text = output; // Show message in window
            }
        }
Пример #31
0
        /// <summary>
        /// Takes the current state and set the parameters to control the facial features.
        /// </summary>
        protected virtual void SetState(FaceState state)
        {
            float pupilSizeLeftTarget  = 1.0f;
            float pupilSizeRightTarget = 1.0f;
            int   milliseconds         = (int)(Time.GameTimeTotalSeconds * 1000.0);

            switch (state)
            {
            case FaceState.Crazy:
                eyeShapeLeft         = EyeShape.Open;
                eyeShapeRight        = EyeShape.Squint;
                pupilSizeLeftTarget  = 0.3f;
                pupilSizeRightTarget = 1.2f;
                browPositionLeft     = BrowPosition.Up;
                browPositionRight    = BrowPosition.Down;
                int brow = ((int)(Time.GameTimeTotalSeconds * 1000.0)) % 400 / 100;
                switch (brow)
                {
                case 0:
                    browPositionRight = BrowPosition.Normal;
                    break;

                case 1:
                    browPositionRight = BrowPosition.Down;
                    break;

                case 2:
                    browPositionRight = BrowPosition.Normal;
                    break;

                case 3:
                    browPositionRight = BrowPosition.Up;
                    break;
                }
                break;

            case FaceState.Happy:
                eyeShapeLeft        = eyeShapeRight = EyeShape.Open;
                pupilSizeLeftTarget = pupilSizeRightTarget = 1.2f;
                // Wiggle the brows.
                if ((milliseconds % 200) > 100)
                {
                    browPositionLeft = BrowPosition.Normal;
                }
                else
                {
                    browPositionLeft = BrowPosition.Up;
                }
                if ((milliseconds % 200) > 120)
                {
                    browPositionRight = BrowPosition.Normal;
                }
                else
                {
                    browPositionRight = BrowPosition.Up;
                }
                break;

            case FaceState.Mad:
                eyeShapeLeft        = eyeShapeRight = EyeShape.Squint;
                pupilSizeLeftTarget = pupilSizeRightTarget = 0.4f;
                browPositionLeft    = browPositionRight = BrowPosition.Down;
                break;

            case FaceState.Sad:
                eyeShapeLeft        = eyeShapeRight = EyeShape.Open;
                pupilSizeLeftTarget = pupilSizeRightTarget = 1.6f;
                browPositionLeft    = browPositionRight = BrowPosition.Up;
                break;

            case FaceState.Remember:
                // Boku looks up and to the left like he's remembering.
                eyeShapeLeft        = eyeShapeRight = EyeShape.Open;
                pupilSizeLeftTarget = pupilSizeRightTarget = 0.9f;
                browPositionLeft    = browPositionRight = BrowPosition.Up;
                gazeState           = GazeState.Fixed;
                gazeDuration        = 0.01f;
                pupilOffsetLeft     = new Vector2(-0.10f, 0.15f);
                pupilOffsetRight    = pupilOffsetLeft;
                break;

            case FaceState.Squint:
                eyeShapeLeft        = eyeShapeRight = EyeShape.Squint;
                pupilSizeLeftTarget = pupilSizeRightTarget = 0.9f;
                browPositionLeft    = browPositionRight = BrowPosition.Up;
                break;

            case FaceState.Dead:
                eyeShapeLeft         = EyeShape.Open;
                eyeShapeRight        = EyeShape.Squint;
                pupilSizeLeftTarget  = 0.5f;
                pupilSizeRightTarget = 0.5f;
                browPositionLeft     = BrowPosition.Normal;
                browPositionRight    = BrowPosition.Normal;
                pupilOffsetLeft      = pupilOffsetRight = new Vector2();
                gazeState            = GazeState.Fixed;
                gazeDuration         = float.MaxValue;
                break;

            default:
                eyeShapeLeft        = eyeShapeRight = EyeShape.Open;
                pupilSizeLeftTarget = pupilSizeRightTarget = 1.0f;
                browPositionLeft    = browPositionRight = BrowPosition.Normal;
                break;
            }

            // fire the change event so others can react
            if (newState && FaceChange != null)
            {
                FaceChange(state);
            }

            // A change of state may change the size of the pupils.  If so,
            // launch a twitch to smoothly change the size.
            if (newState)
            {
                newState = false;
                if (pupilSizeLeft != pupilSizeLeftTarget)
                {
                    TwitchManager.Set <float> set = delegate(float val, Object param) { pupilSizeLeft = val; };
                    TwitchManager.CreateTwitch <float>(pupilSizeLeft, pupilSizeLeftTarget, set, 0.2f, TwitchCurve.Shape.EaseInOut, null, null, true);
                }
                if (pupilSizeRight != pupilSizeRightTarget)
                {
                    TwitchManager.Set <float> set = delegate(float val, Object param) { pupilSizeRight = val; };
                    TwitchManager.CreateTwitch <float>(pupilSizeRight, pupilSizeRightTarget, set, 0.2f, TwitchCurve.Shape.EaseInOut, null, null, true);
                }
            }
        }   // end of Face SetState()