Exemplo n.º 1
0
        //void ragdoll_WakeUp(object sender, EventArgs e)
        //{
        //    ragdoll._body.LinearDamping = slowDamping;
        //}



        public override void Update(SkeletonInfo info)
        {
            if (ragdoll.asleep)
            {
                return;
            }

            if (info.Tracking)
            {
                thrust = (((info.leftHand.Z + info.rightHand.Z) / 2) - info.torso.Z) * 3f;
            }
            else
            {
                thrust = 0;
            }


            if (thrust > 0)
            {
                if (!thrustOn)
                {
                    StartThrust();
                }

                ApplyThrustForce();
            }
            else if (thrustOn)
            {
                StopThrust();
            }
        }
Exemplo n.º 2
0
        public override void Update(SkeletonInfo info)
        {
            if (wakeTimer < WAKE_TIME)
            {
                base.Update(SkeletonInfo.StandardPose);
            }
            else
            {
                base.Update(info);
            }



            tick();

            //depthTexLoc = new Vector2(info.torso.X, info.torso.Y - .13f) * depthTex.Height * .5f + new Vector2(depthTex.Width / 2, depthTex.Height / 2); // this will need to be more complex
            //depthTexRot = _body.Rotation - info.Rotation;
            //depthTexScale = info.torso.Z * .035f;


            if (!asleep)
            {
                foreach (AbstractEquipment e in equipment)
                {
                    e.Update(info);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// ボーン情報のキャッシュを生成
        /// </summary>
        public ICollection <SkeletonInfo> GenerateCache()
        {
            // !!!!!!!_cache.GenerateCache();
            // 既にリストの存在しているボーンを探索しながらボーンをリストに追加する。

            var boneList = new Dictionary <Transform, SkeletonInfo>();

            // 一番の親ボーンを追加
            AddSkelton(_animator.transform, boneList);

            // 子から親を検索して次々にボーン情報を追加していく、
            // 既に追加しているボーンがあると検索を停止する。
            Enum.GetValues(typeof(HumanBodyBones)).Cast <HumanBodyBones>().
            Where(_ => _ != HumanBodyBones.LastBone).ToList().        // GetBoneTransformメソッドの引数にLastBoneを入れるとエラーになるため除外
            ForEach(_ => AddParentSkelton(_animator.GetBoneTransform(_), boneList));


            // 検索したボーンを配列化する
            var HumanSkeletonInfos = new SkeletonInfo[boneList.Count];
            int idx = 0;

            foreach (var item in boneList)
            {
                HumanSkeletonInfos[idx++] = item.Value;
            }
            return(HumanSkeletonInfos);
        }
Exemplo n.º 4
0
        //Gets a vector from the players shoulder to their hand
        private void _calculateVectors(ref Vector2 right, ref Vector2 left, SkeletonInfo info)
        {
            right.X = info.RightHand.X - info.DisplayPosition.X;
            right.Y = info.RightHand.Y - info.DisplayPosition.Y;
            right.Normalize();

            left.X = info.LeftHand.X - info.DisplayPosition.X;
            left.Y = info.LeftHand.Y - info.DisplayPosition.Y;
            left.Normalize();
        }
Exemplo n.º 5
0
        protected Vector2 GestureLocationToFarseerLocation(Vector3 gSpaceLocation, SkeletonInfo info)
        {
            // ragdollSpace is a coordinate system centered on and oriented to the ragdoll's body.
            // This calculation relies on the idea that info.torso and ragdoll.Body.Position should be superimposed.
            //Vector2 ragdollSpace = new Vector2(gSpace.X * RagdollBase.height, gSpace.Y * RagdollBase.height);
            Vector2 ragdollSpace = ragdoll.GestureVectorToRagdollVector(gSpaceLocation);


            // convert from ragdoll space to farseer space by rotating to the ragdoll's rotation and translating to the ragdoll's position.
            Vector2 farseerSpace = ragdoll.RagdollLocationToFarseerLocation(ragdollSpace);


            return(farseerSpace);
        }
Exemplo n.º 6
0
        //fills the skeleton info with infromation from the last skeleton frame
        private void _populateSkelInfo(int iter, GameState state)
        {
            SkeletonInfo tmp = new SkeletonInfo();

            tmp.TrackingID = _skeletonList[iter].TrackingId;
            tmp.Tracked    = _skeletonList[iter].TrackingState;

            var rightHand = _skeletonList[iter].Joints[JointType.HandRight];

            tmp.DisplayPosition = _coordMapper.MapSkeletonPointToColorPoint(_skeletonList[iter].Joints[JointType.ShoulderCenter].Position, ColorImageFormat.RgbResolution640x480Fps30);
            tmp.LeftHand        = _coordMapper.MapSkeletonPointToColorPoint(_skeletonList[iter].Joints[JointType.HandLeft].Position, ColorImageFormat.RgbResolution640x480Fps30);
            tmp.RightHand       = _coordMapper.MapSkeletonPointToColorPoint(rightHand.Position, ColorImageFormat.RgbResolution640x480Fps30);
            tmp.RightShoulder   = _coordMapper.MapSkeletonPointToColorPoint(_skeletonList[iter].Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30);

            if ((state ^ GameState.SinglePlayer) == GameState.Running ||
                (state ^ GameState.MultiPlayer) == GameState.Running)
            {
                _cursor.ToggleDisplay(false);
                var rightVec = new Vector2();
                var leftVec  = new Vector2();

                _calculateVectors(ref rightVec, ref leftVec, tmp);

                _selectNextColor(rightVec, leftVec, ref tmp);
                _getIndividualRot(rightVec, leftVec, ref tmp);
            }
            else if (iter < 1)
            {
                _cursor.ToggleDisplay(true);

                var world    = new Vector2(640, 480);
                var width    = world.X * .4f;
                var height   = world.Y * .4f;
                var bounding = new Rectangle(tmp.RightShoulder.X - (int)(width / 2),
                                             tmp.RightShoulder.Y - (int)(height / 2),
                                             (int)width, (int)height);

                var location = new ColorImagePoint();
                if (bounding.Contains(tmp.RightHand.X, tmp.RightHand.Y))
                {
                    location.X = tmp.RightHand.X - bounding.X;
                    location.Y = tmp.RightHand.Y - bounding.Y;
                    location   = location.BoundingToWorldSpace(new Vector2(width, height), world);
                }
                _cursor.Pos = new Vector2(location.X, location.Y);
                _cursor.Update(state);
            }

            AssignSkeletonInfo(tmp, iter);
        }
        /// <summary>
        /// スケルトンの追加
        /// </summary>
        private static void AddSkelton(Transform trans, Dictionary <string, SkeletonInfo> boneList)
        {
            string name = trans.name;

            if (!boneList.ContainsKey(name))
            {
                SkeletonInfo info = new SkeletonInfo(trans);
                boneList.Add(name, info);
            }
            else
            {
                Debug.Log(name + "は既に存在しています。");
            }
        }
Exemplo n.º 8
0
 public override void Update(SkeletonInfo info)
 {
     if (info.rightHand.X < .3f && info.leftHand.X > -.3f)
     {
         if (!bubbled)
         {
             Bubble();
         }
     }
     else
     {
         if (bubbled)
         {
             UnBubble();
         }
     }
 }
Exemplo n.º 9
0
        public void Update(SkeletonInfo info)
        {
            if (!playing)
            {
                return;
            }

            Vector3 rightHand = info.LocationToGestureSpace(info.rightHand);
            Vector3 lefthand  = info.LocationToGestureSpace(info.leftHand);

            //Vector3 rightFoot = info.LocationToGestureSpace(info.rightFoot);

            drumInstance.Volume   = MathHelper.Clamp(info.rightWristVel.Length() * .8f - .2f, 0, 1);
            drumInstance2.Volume  = MathHelper.Clamp(info.leftWristVel.Length() * .8f - .2f, 0, 1);
            guitarInstance.Volume = MathHelper.Clamp(rightHand.Y + lefthand.Y + .3f, 0, 1);
            //scratchInstance.Volume = MathHelper.Clamp((rightFoot.Y + .6f) * 2, 0, 1);
        }
        /// <summary>
        /// 指定のボーンにある子ボーンすべての変形情報を出力する。
        /// </summary>
        /// <param name="animatorRoot">この</param>
        /// <returns></returns>
        public static ICollection <SkeletonInfo> GenerateFromRootBone(Transform animatorRoot)
        {
            Dictionary <string, SkeletonInfo> boneList = new Dictionary <string, SkeletonInfo>();

            AddChildSkelton(animatorRoot, boneList);

            var ret = new SkeletonInfo[boneList.Count];

            int idx = 0;

            foreach (var item in boneList)
            {
                ret[idx++] = item.Value;
            }

            return(ret);
        }
Exemplo n.º 11
0
        public virtual void Update(SkeletonInfo info)
        {
            Vector3 vec    = info.rightHand - info.rightShoulder;
            Vector2 rSpace = KinectVectorToRagdollVector(vec, info);

            setShoulderToRightHand(rSpace);

            //float pracScaler = v2.X / vec.X;

            vec    = info.leftHand - info.leftShoulder;
            rSpace = KinectVectorToRagdollVector(vec, info);
            setShoulderToLeftHand(rSpace);

            vec    = info.rightFoot - info.rightHip;
            rSpace = KinectVectorToRagdollVector(vec, info);
            setHipToRightFoot(rSpace);

            vec    = info.leftFoot - info.leftHip;
            rSpace = KinectVectorToRagdollVector(vec, info);
            setHipToLeftFoot(rSpace);

            vec    = info.head - info.torso;
            rSpace = KinectVectorToRagdollVector(vec, info);
            setChestToHead(rSpace);

            if (!Possessed && info.Tracking)
            {
                Possessed = true;
                if (PossessedByPlayer != null)
                {
                    PossessedByPlayer(this, null);
                }
            }
            else if (Possessed && !info.Tracking)
            {
                Possessed = false;
                if (UnpossessedByPlayer != null)
                {
                    UnpossessedByPlayer(this, null);
                }
            }
        }
Exemplo n.º 12
0
 public void ConvertDumpToUnityAnimationFile()
 {
     if(animClip.IsEmpty()){
         Debug.Log ("Current dump is empty, nothing to bake!");
         return;
     }
     if(!bakingProperties.HasConstraint()){
         Debug.Log ("Can't bake animation file: no one property selected!");
         return;
     }
     if(!sourceSkeleton)
         sourceSkeleton = transform;
     curAnimationName = animClip.name;
     AnimationClip uAnimClip = new AnimationClip();
     uAnimClip.frameRate = animClip.samples;
     uAnimClip.name = curAnimationName;
     MethodInfo[] clipMethods = reflection.GetMethods ();
     foreach(MethodInfo mI in clipMethods){
         if(mI.Name == "set_legacy"){
             object[] arg = new object[1];
             arg[0] = isLegacyType;
             mI.Invoke(uAnimClip,arg);
         }
     }
     //uAnimClip.legacy = isLegacyType;
     skeletonInfo = new SkeletonInfo(new string[0],sourceSkeleton,0);
     skeletonInfo.UpdateSkeletonInfo(true);
     sampleStep = (float)1/animClip.samples;
     for(int i = 0;i<(skeletonInfo.bonesCount);i++){
         uAnimClip = WriteCurveToClip(uAnimClip,i);
     }
     string newAnimationFileFolderPath = animationFileFolderPath+sourceSkeleton.name+"/";
     BINS.CreateFolder(newAnimationFileFolderPath);
     //Debug.Log ("new animation folder path:"+newAnimationFolderPath);
     #if UNITY_EDITOR
         UnityEditor.AssetDatabase.CreateAsset(uAnimClip,newAnimationFileFolderPath+clipNamePrefix+uAnimClip.name+".anim");
         UnityEditor.AssetDatabase.SaveAssets();
     #endif
     //AssetDatabase.Refresh();
     Debug.Log ("animation file was created:"+uAnimClip.name+".anim");
 }
Exemplo n.º 13
0
        //gets the next background color based on the angle between the skeletons arms
        private void _selectNextColor(Vector2 rightVec, Vector2 leftVec, ref SkeletonInfo tmp)
        {
            float angle = (rightVec.X * leftVec.X) + (rightVec.Y * leftVec.Y);

            angle = (float)Math.Acos(angle);
            angle = angle * (180 / (float)Math.PI);

            //var lastScreenColor = tmp.ScreenColor;
            var color = "";

            if (angle >= 87 && angle <= 93)
            {
                tmp.ScreenColor = "Yellow";
                color           = "Yellow";
            }
            else if (angle >= 0 && angle <= 87)
            {
                tmp.ScreenColor = "Pink";
                color           = "Pink";
            }
            else if (angle > 175 && angle <= 182)
            {
                tmp.ScreenColor = "Violet";
                color           = "Dark Blue";
            }
            else if (angle >= 93 && angle <= 175)
            {
                tmp.ScreenColor = "Blue Green";
                color           = "Light Blue";
            }

            /*if (tmp.ScreenColor == lastScreenColor)
             * _message = "Angle," + color + "," + angle
             + "," + DateTime.Today.TimeOfDay.ToString() + ",";
             + else
             + _message = "Screen Color and Angle," + color + ","
             + angle + "," + DateTime.Today.TimeOfDay.ToString() + ",";*/
        }
Exemplo n.º 14
0
        //gets the individual rotation of each arm
        private void _getIndividualRot(Vector2 rightVec, Vector2 leftVec, ref SkeletonInfo tmp)
        {
            Vector2 zeroVector = new Vector2(1, 0);

            tmp.RightRotation = (float)Math.Acos((rightVec.X * zeroVector.X) + (rightVec.Y * zeroVector.Y));
            tmp.LeftRotation  = (float)Math.Acos((leftVec.X * zeroVector.X) + (leftVec.Y * zeroVector.Y));

            if (tmp.RightHand.Y < tmp.DisplayPosition.Y)
            {
                tmp.RightRotation *= -1;
            }

            if (tmp.LeftHand.Y < tmp.DisplayPosition.Y)
            {
                tmp.LeftRotation *= -1;
            }

            tmp.RotDiff = tmp.RightRotation - tmp.LeftRotation;

            /*var tmpLeft = tmp.LeftRotation * (180 / Math.PI);
             * var tmpRight = tmp.RightRotation * (180 / Math.PI);*/

            //_message += tmpLeft + "," + tmpRight + ",";
        }
Exemplo n.º 15
0
 /// <summary>
 /// Converts a relative vector (not a location) from kinect space to ragdoll space.
 /// Kinect space is the kinect cooridinate system.
 /// Ragdoll space is the coordinate system centered on and rotated with the ragdoll's body.
 /// </summary>
 /// <param name="gestureSpaceVector">A vector pointing from one position in kinect space to another.</param>
 /// <returns>The equivalent vector in ragdoll space.</returns>
 public Vector2 KinectVectorToRagdollVector(Vector3 kinectVector, SkeletonInfo info)
 {
     return(GestureVectorToRagdollVector(info.VectorToGestureSpace(kinectVector)));
 }
Exemplo n.º 16
0
 public abstract void Update(SkeletonInfo info);
Exemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="kinectLocation">This should be the location of a body part in pure skeletoninfo coordinates</param>
        /// <param name="info"></param>
        /// <returns>The absolute location of the body part in farseer coordinates</returns>
        protected virtual Vector2  KinectLocationToFarseerLocation(Vector3 kinectLocation, SkeletonInfo info)
        {
            // gSpace is just kinect space scaled to accomodate the person's size
            //Vector3 gSpace = info.ToGestureSpace(kinectLocation - info.torso); // this is equivalent to ToGestureSpace(absolute) - ToGestureSpace(torso)
            Vector3 gSpaceLocation = info.LocationToGestureSpace(kinectLocation);

            return(GestureLocationToFarseerLocation(gSpaceLocation, info));
        }
Exemplo n.º 18
0
        public override void Update(SkeletonInfo info)
        {
            base.Update(info);

            bodySound.Update(info);
        }