protected virtual void OnBodyMotionDetected(BodyMotion motion)
 {
     if (bodyMotionDetected != null)
     {
         BodyMotionDetectedEventArgs e = new BodyMotionDetectedEventArgs();
         e.motion = motion;
         bodyMotionDetected(this, e);
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        // get useful classes
        tF = GetComponent <Transform>();
        dS = GameObject.Find("Setting").GetComponent <DisplaySetting>();
        bP = GetComponent <BodyProperty>();
        bO = GetComponent <BodyOrbit>();
        if (bO.centralBody != null)
        {
            cBM = bO.centralBody.GetComponent <BodyMotion>();
        }

        // set display size of body
        float d = (float)(bP.D * dS.scaleD);

        tF.localScale = new Vector3(d, d, d);
        MeshRenderer mr = GetComponent <MeshRenderer>();

        mr.material.color = Color.white;

        InitOrbit();

        /*
         * // set the initial position of body,
         * // initial position is relative to the central body
         * pos[0] = bO.R;
         * SetPosition();
         *
         * // set the initial velocity of revolution
         * // initial velocity if relative to the central body
         * double pi = Math.PI;
         * vel[1] = Math.Sin(pi * bO.angle / 180) * bO.V;
         * vel[2] = Math.Cos(pi * bO.angle / 180) * bO.V;
         */

        t0   = Time.time;
        minZ = bO.R;

        // init trajectory and line drawing setting
        if (trajEnable)
        {
            AddTrajectory();
            line               = gameObject.GetComponent <LineRenderer>();
            line.material      = new Material(Shader.Find("Sprites/Default"));
            line.positionCount = 0;
            line.startWidth    = (float)(dS.scaleD * bP.D * 1.05); // self 1.05 times;
            //line.startWidth = (float)(cBM.bP.D * dS.scaleD * 0.1); // 1/10 of central body size;
            line.endWidth      = 0.01f;
            line.startColor    = Color.red;
            line.endColor      = Color.red;
            line.useWorldSpace = true;
        }

        Debug.Log(this.name + " size=" + tF.localScale + " pos=" + tF.position);
    }
Exemple #3
0
 // Start is called before the first frame update
 void Start()
 {
     tF                   = GetComponent <Transform>();
     chaseTF              = chaseObject.GetComponent <Transform>();
     chaseBM              = chaseObject.GetComponent <BodyMotion>();
     referTF              = referObject.GetComponent <Transform>();
     camera               = GetComponent <Camera>();
     camera.fieldOfView   = (float)(2 * Math.Atan(0.1 * field) * 180 / Math.PI); // for offset = 5D = 10R
     camera.nearClipPlane = 0.01f;
     camera.farClipPlane  = 1000;
 }
    // Update is called once per frame
    void Update()
    {
        if (sw.pollSkeleton())
        {
            float currentTime = Time.time;
            this.rightFootPos = sw.bonePos[PlayerId, 19];
            this.leftFootPos  = sw.bonePos[PlayerId, 15];
            this.spinePos     = sw.bonePos[PlayerId, 1];

            if (this.firstTime)
            {
                this.rightFootPosPre = this.rightFootPos;
                this.leftFootPosPre  = this.leftFootPos;
                this.spinePosPre     = this.spinePos;
                this.firstTime       = false;
            }

            this.rightFootVelo = this.rightFootPos - this.rightFootPosPre;
            this.leftFootVelo  = this.leftFootPos - this.leftFootPosPre;
            this.spineVelo     = this.spinePos - this.spinePosPre;

            if (this.rightFootVelo.y > accuracy && Math.Abs(this.rightFootVelo.y) > Math.Abs(this.rightFootVelo.x))
            {
                if (currentRightFootMotion != BodyMotion.RIGHT_FOOT_UP)
                {
                    currentRightFootMotion   = BodyMotion.RIGHT_FOOT_UP;
                    motionRightFootStartTime = currentTime;
                    motionStartRightFootPos  = leftFootPos;
                }
            }
            else
            {
                currentRightFootMotion = BodyMotion.NON;
            }

            if (this.leftFootVelo.y > accuracy && Math.Abs(this.leftFootVelo.y) > Math.Abs(this.leftFootVelo.x))
            {
                if (currentLeftFootMotion != BodyMotion.LEFT_FOOT_UP)
                {
                    currentLeftFootMotion   = BodyMotion.LEFT_FOOT_UP;
                    motionLeftFootStartTime = currentTime;
                    motionStartLeftFootPos  = leftFootPos;
                }
            }
            else
            {
                currentLeftFootMotion = BodyMotion.NON;
            }

            if (this.spineVelo.y > accuracy && Math.Abs(this.spineVelo.y) > Math.Abs(this.spineVelo.x))
            {
                if (currentLeftFootMotion != BodyMotion.LEFT_FOOT_UP)
                {
                    currentSpineMotion     = BodyMotion.BODY_UP;
                    motionSpineStartTime   = currentTime;
                    motionStartLeftFootPos = spinePos;
                }
            }
            else
            {
                currentSpineMotion = BodyMotion.NON;
            }
//			currentRightHandMotion == HandMotion.RIGHT_HAND_WAVE_OUT
//				&& currentTime - motionRightHandStartTime <= detectMotionDuration
//					&& rightHandPos.x - motionStartRightHandPos.x >= detectMotionDistance

            if (currentLeftFootMotion == BodyMotion.LEFT_FOOT_UP &&
                currentRightFootMotion == BodyMotion.RIGHT_FOOT_UP &&
                currentSpineMotion == BodyMotion.BODY_UP &&
                currentTime - motionRightFootStartTime <= detectMotionDuration &&
                currentTime - motionLeftFootStartTime <= detectMotionDuration &&
                currentTime - motionSpineStartTime <= detectMotionDuration &&
                rightFootPos.y - motionStartRightFootPos.y >= detectMotionDistance &&
                leftFootPos.y - motionStartLeftFootPos.y >= detectMotionDistance &&
                spinePos.y - motionStartSpineSPos.y >= detectMotionDistance)
            {
                if (rightFootVelo.y - spineVelo.y >= detectMotionDistance &&
                    leftFootVelo.y - spineVelo.y >= detectMotionDistance)
                {
                    OnBodyMotionDetected(BodyMotion.SUPER_JUMP);
                }
                else
                {
                    OnBodyMotionDetected(BodyMotion.JUMP);
                }

                motionLeftFootStartTime  = currentTime;
                motionRightFootStartTime = currentTime;
                motionSpineStartTime     = currentTime;
                motionStartLeftFootPos   = leftFootPos;
                motionStartRightFootPos  = rightFootPos;
                motionStartSpineSPos     = spinePos;
            }

            rightFootPosPre = rightFootPos;
            leftFootPosPre  = leftFootPos;
            spinePosPre     = spinePos;
        }
    }