public LODModelPacketOut(ModelEntity me)
 {
     UsageType = NetUsageType.ENTITIES;
     ID = ServerToClientPacket.LOD_MODEL;
     Data = new byte[24 + 4 + 16 + 8 + 24];
     me.GetPosition().ToDoubleBytes().CopyTo(Data, 0);
     int ind = me.TheServer.Networking.Strings.IndexForString(me.model);
     Utilities.IntToBytes(ind).CopyTo(Data, 24);
     Quaternion quat = me.GetOrientation();
     Utilities.FloatToBytes((float)quat.X).CopyTo(Data, 24 + 4);
     Utilities.FloatToBytes((float)quat.Y).CopyTo(Data, 24 + 4 + 4);
     Utilities.FloatToBytes((float)quat.Z).CopyTo(Data, 24 + 4 + 4 + 4);
     Utilities.FloatToBytes((float)quat.W).CopyTo(Data, 24 + 4 + 4 + 4 + 4);
     Utilities.LongToBytes(me.EID).CopyTo(Data, 24 + 4 + 16);
     me.scale.ToDoubleBytes().CopyTo(Data, 24 + 4 + 16 + 8);
 }
Exemple #2
0
 public void ApplyHook(PlayerEntity player, ItemStack item, Location Position, BEPUphysics.Entities.Entity HitEnt)
 {
     RemoveHook(player);
     PhysicsEntity pe;
     double len = (double)(Position - player.GetCenter()).Length();
     Location step = (player.GetCenter() - Position) / len;
     Location forw = Utilities.VectorToAngles(step);
     BEPUutilities.Quaternion quat = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (double)(forw.Pitch * Utilities.PI180)) *
         Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), (double)(forw.Yaw * Utilities.PI180));
     if (HitEnt == null)
     {
         ModelEntity mod = new ModelEntity("cube", player.TheRegion);
         mod.Mass = 0;
         mod.CanSave = false;
         mod.scale = new Location(0.023, 0.05, 0.05);
         mod.mode = ModelCollisionMode.AABB;
         mod.SetPosition(Position);
         mod.SetOrientation(quat);
         player.TheRegion.SpawnEntity(mod);
         pe = mod;
         player.Hooks.Add(new HookInfo() { Joint = null, Hit = pe, IsBar = true });
     }
     else
     {
         pe = (PhysicsEntity)HitEnt.Tag;
     }
     JointDistance jd;
     //jd = new JointDistance(player, pe, 0.01f, len + 0.01f, player.GetCenter(), Position);
     //player.TheRegion.AddJoint(jd);
     //player.Hooks.Add(new HookInfo() { Joint = jd, Hit = pe, IsBar = false });
     PhysicsEntity cent = pe;
     for (double f = 0; f < len - 1f; f += 0.5f)
     {
         Location cpos = Position + step * f;
         ModelEntity ce = new ModelEntity("cube", player.TheRegion);
         ce.Mass = 15;
         ce.CanSave = false;
         ce.scale = new Location(0.023, 0.05, 0.05);
         ce.mode = ModelCollisionMode.AABB;
         ce.SetPosition(cpos + step * 0.5);
         ce.SetOrientation(quat);
         player.TheRegion.SpawnEntity(ce);
         jd = new JointDistance(ce, cent, 0.01f, 0.5f, ce.GetPosition(), (ReferenceEquals(cent, pe) ? Position: cent.GetPosition()));
         CollisionRules.AddRule(player.Body, ce.Body, CollisionRule.NoBroadPhase);
         player.TheRegion.AddJoint(jd);
         player.Hooks.Add(new HookInfo() { Joint = jd, Hit = ce, IsBar = true });
         cent = ce;
     }
     jd = new JointDistance(cent, player, 0.01f, 0.5f, cent.GetPosition(), player.GetCenter());
     player.TheRegion.AddJoint(jd);
     player.Hooks.Add(new HookInfo() { Joint = jd, Hit = player, IsBar = false });
 }