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); }
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; }