Exemplo n.º 1
0
    public void SendHeading(Heading heading)
    {
        Hashtable data = new Hashtable();
        data.Add("x", heading.GetPosition().x);
        data.Add("y", heading.GetPosition().y);
        data.Add("z", heading.GetPosition().z);
        data.Add("a", heading.GetAngle());
        data.Add("t", Convert.ToDouble(heading.GetTime()));
        data.Add("s", heading.GetSpeed().magnitude);
        if (heading.IsAccelerating())
        {
            data.Add("at", Convert.ToDouble(heading.GetAccelerationTime()));
            data.Add("es", heading.GetEndSpeed().magnitude);
        }
        else
        {
            data.Add("at", -1);
        }

        //send heading to server
        SmartFoxClient client = NetworkController.GetClient();
        string extensionName = NetworkController.GetExtensionName();
        client.SendXtMessage(extensionName, "h", data);
    }
Exemplo n.º 2
0
    public bool IsFutureOf(Heading old)
    {
        if(old == null)
            return false;
        //time elapsed between this heading and the old one
        float elapsed = (float)(GetTime() - old.GetTime())/1000.0f;
        float elapsed2 = 0;
        if(old.IsAccelerating())
        {
            //time elasped while accelerating from old.speed to old.endSpeed
            elapsed = Math.Min(elapsed, (float)old.GetAccelerationTime()/1000.0f);
            //time elapsed while moving at constant speed with magnitude equal to endSpeed
            elapsed2 = Math.Max(elapsed - (float)old.GetAccelerationTime()/1000.0f, 0);
        }

        //compute the expected future state of the old heading
        Vector3 expectedPosition = old.GetPosition() + old.GetSpeed() * elapsed + 0.5f * old.GetAcceleration() * Convert.ToSingle(Math.Pow(elapsed, 2));
        expectedPosition += (elapsed2 * old.GetEndSpeed());
        Vector3 expectedSpeed = old.GetSpeed()+ old.GetAcceleration() * elapsed;
        float expectedAngle = old.GetAngle();

        float dp= Vector3.Distance(expectedPosition, position);
        float ds = Vector3.Distance(expectedSpeed, GetSpeed());
        float da =  AngleDistance(expectedAngle, angle);

        if(dp <  0.05 && ds < 0.05 && da < 0.05)
            return true;
        /*Debug.Log("NOT FUTURE");
        Debug.Log("PAST->EXP. FUTURE: -- pos:"+old.GetPosition()+"->"+expectedPosition+", s:"+old.GetSpeed()+"->"+expectedSpeed+", a:"+old.GetAngle()+"->"+expectedAngle+";old is accel?"+old.IsAccelerating());
        Debug.Log("REAL FUTURE: -- pos:"+"  "+"->"+position+", s:"+"  "+"->"+GetSpeed()+", a:"+"  "+"->"+GetAngle()+", accel?"+IsAccelerating());
        Debug.Log("|---> :dpos,ds,da= "+dp+", "+ds+", "+da+".");
        Debug.Log("expectedSpeed = "+expectedSpeed+" = s_0+a*t_a = "+old.GetSpeed()+"+"+old.GetAcceleration()+"*"+elapsed);
        Debug.Log("accelTime = "+old.GetAccelerationTime()+", s= "+ GetSpeed()+", ds= "+ds);
        */
        return false;
    }
Exemplo n.º 3
0
    private void UpdateView(Heading heading)
    {
        //amount of time since starting this heading
        float elapsed = (float)(ServerClock.Instance.GetTime() - heading.GetTime())/1000.0f;
        if (elapsed <0)
            return;
        //x, z position
        float x = heading.GetPosition().x + heading.GetSpeed().x * elapsed + 0.5f * heading.GetAcceleration().x * Convert.ToSingle(Math.Pow(elapsed, 2));
        float z = heading.GetPosition().z + heading.GetSpeed().z * elapsed + 0.5f * heading.GetAcceleration().z * Convert.ToSingle(Math.Pow(elapsed, 2));

        float angle = heading.GetAngle();
        if(heading == interceptor && softAngleVariation)
            angle = view.GetAngle();

        float speed = heading.GetSpeed().magnitude;
        if (heading.IsAccelerating()) {
            int sign  = (Vector3.Dot(heading.GetAcceleration(), heading.GetSpeed())) > 0 ? 1 : -1;
            speed += sign*heading.GetAcceleration().magnitude * elapsed;
        }

        //copy properties to the view heading
        view.InitFromValues(new Vector3(x, 0, z), angle, ServerClock.Instance.GetTime(), speed);
    }