Primitive.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using OpenSim.types;
  5. using libsecondlife;
  6. using libsecondlife.Packets;
  7. using OpenSim.Framework.Interfaces;
  8. using OpenSim.Physics.Manager;
  9. using OpenSim.Framework.Types;
  10. namespace OpenSim.world
  11. {
  12. public class Primitive : Entity
  13. {
  14. protected float mesh_cutbegin;
  15. protected float mesh_cutend;
  16. protected PrimData primData;
  17. protected bool newPrimFlag = false;
  18. protected bool updateFlag = false;
  19. protected bool dirtyFlag = false;
  20. private ObjectUpdatePacket OurPacket;
  21. private bool physicsEnabled = false;
  22. private bool physicstest = false;
  23. private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
  24. private Dictionary<uint, SimClient> m_clientThreads;
  25. private ulong m_regionHandle;
  26. private const uint FULL_MASK_PERMISSIONS = 2147483647;
  27. public bool PhysicsEnabled
  28. {
  29. get
  30. {
  31. return physicsEnabled;
  32. }
  33. set
  34. {
  35. physicsEnabled = value;
  36. }
  37. }
  38. public bool UpdateFlag
  39. {
  40. get
  41. {
  42. return updateFlag;
  43. }
  44. set
  45. {
  46. updateFlag = value;
  47. }
  48. }
  49. public LLVector3 Scale
  50. {
  51. set
  52. {
  53. LLVector3 offset = (value - primData.Scale);
  54. offset.X /= 2;
  55. offset.Y /= 2;
  56. offset.Z /= 2;
  57. this.primData.Position += offset;
  58. this.primData.Scale = value;
  59. this.dirtyFlag = true;
  60. }
  61. get
  62. {
  63. return this.primData.Scale;
  64. }
  65. }
  66. public PhysicsActor PhysActor
  67. {
  68. set
  69. {
  70. this._physActor = value;
  71. }
  72. }
  73. public Primitive(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, World world)
  74. {
  75. mesh_cutbegin = 0.0f;
  76. mesh_cutend = 1.0f;
  77. m_clientThreads = clientThreads;
  78. m_regionHandle = regionHandle;
  79. m_world = world;
  80. }
  81. public override Mesh getMesh()
  82. {
  83. Mesh mesh = new Mesh();
  84. Triangle tri = new Triangle(
  85. new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f),
  86. new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f),
  87. new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f));
  88. mesh.AddTri(tri);
  89. mesh += base.getMesh();
  90. return mesh;
  91. }
  92. public byte[] GetByteArray()
  93. {
  94. return this.primData.ToBytes();
  95. }
  96. public void GetProperites(SimClient client)
  97. {
  98. ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
  99. proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
  100. proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
  101. proper.ObjectData[0].ItemID = LLUUID.Zero; // this.uuid;
  102. proper.ObjectData[0].CreationDate = (ulong) this.primData.CreationDate;
  103. proper.ObjectData[0].CreatorID = this.primData.OwnerID;
  104. proper.ObjectData[0].FolderID = LLUUID.Zero;
  105. proper.ObjectData[0].FromTaskID = LLUUID.Zero;
  106. proper.ObjectData[0].GroupID = LLUUID.Zero;
  107. proper.ObjectData[0].InventorySerial = 0;
  108. proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
  109. proper.ObjectData[0].ObjectID = this.uuid;
  110. proper.ObjectData[0].OwnerID = primData.OwnerID;
  111. proper.ObjectData[0].TouchName = new byte[0];
  112. proper.ObjectData[0].TextureID = new byte[0];
  113. proper.ObjectData[0].SitName = new byte[0];
  114. proper.ObjectData[0].Name = new byte[0];
  115. proper.ObjectData[0].Description = new byte[0];
  116. proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
  117. proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
  118. proper.ObjectData[0].GroupMask = this.primData.GroupMask;
  119. proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
  120. proper.ObjectData[0].BaseMask = this.primData.BaseMask;
  121. client.OutPacket(proper);
  122. }
  123. public void UpdatePosition(LLVector3 pos)
  124. {
  125. this.Pos = pos;
  126. if (this._physActor != null) // && this.physicsEnabled)
  127. {
  128. try
  129. {
  130. lock (m_world.LockPhysicsEngine)
  131. {
  132. this._physActor.Position = new PhysicsVector(pos.X, pos.Y, pos.Z);
  133. }
  134. }
  135. catch (Exception e)
  136. {
  137. Console.WriteLine(e.Message);
  138. }
  139. }
  140. this.updateFlag = true;
  141. }
  142. public override void update()
  143. {
  144. LLVector3 pos2 = new LLVector3(0, 0, 0);
  145. if (this._physActor != null && this.physicsEnabled)
  146. {
  147. PhysicsVector pPos = this._physActor.Position;
  148. pos2 = new LLVector3(pPos.X, pPos.Y, pPos.Z);
  149. }
  150. if (this.newPrimFlag)
  151. {
  152. foreach (SimClient client in m_clientThreads.Values)
  153. {
  154. client.OutPacket(OurPacket);
  155. }
  156. this.newPrimFlag = false;
  157. }
  158. else if (this.updateFlag)
  159. {
  160. ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
  161. terse.RegionData.RegionHandle = m_regionHandle; // FIXME
  162. terse.RegionData.TimeDilation = 64096;
  163. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  164. terse.ObjectData[0] = this.CreateImprovedBlock();
  165. foreach (SimClient client in m_clientThreads.Values)
  166. {
  167. client.OutPacket(terse);
  168. }
  169. this.updateFlag = false;
  170. }
  171. else if (this.dirtyFlag)
  172. {
  173. foreach (SimClient client in m_clientThreads.Values)
  174. {
  175. UpdateClient(client);
  176. }
  177. this.dirtyFlag = false;
  178. }
  179. else
  180. {
  181. if (this._physActor != null && this.physicsEnabled)
  182. {
  183. if (pos2 != this.positionLastFrame)
  184. {
  185. ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
  186. terse.RegionData.RegionHandle = m_regionHandle; // FIXME
  187. terse.RegionData.TimeDilation = 64096;
  188. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  189. terse.ObjectData[0] = this.CreateImprovedBlock();
  190. foreach (SimClient client in m_clientThreads.Values)
  191. {
  192. client.OutPacket(terse);
  193. }
  194. }
  195. this.positionLastFrame = pos2;
  196. }
  197. }
  198. if (this.physicstest)
  199. {
  200. LLVector3 pos = this.Pos;
  201. pos.Z += 0.0001f;
  202. this.UpdatePosition(pos);
  203. this.physicstest = false;
  204. }
  205. }
  206. public void UpdateClient(SimClient RemoteClient)
  207. {
  208. LLVector3 lPos;
  209. if (this._physActor != null && this.physicsEnabled)
  210. {
  211. PhysicsVector pPos = this._physActor.Position;
  212. lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
  213. }
  214. else
  215. {
  216. lPos = this.Pos;
  217. }
  218. byte[] pb = lPos.GetBytes();
  219. Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length);
  220. // OurPacket should be update with the follwing in updateShape() rather than having to do it here
  221. OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID;
  222. OurPacket.ObjectData[0].PCode = this.primData.PCode;
  223. OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin;
  224. OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd;
  225. OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX;
  226. OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY;
  227. OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX;
  228. OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY;
  229. OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew;
  230. OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
  231. OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
  232. OurPacket.ObjectData[0].Scale = this.primData.Scale;
  233. OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve;
  234. OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
  235. OurPacket.ObjectData[0].ParentID = this.primData.ParentID ;
  236. OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
  237. //finish off copying rest of shape data
  238. OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
  239. OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
  240. OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX;
  241. OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY;
  242. OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist;
  243. OurPacket.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
  244. RemoteClient.OutPacket(OurPacket);
  245. }
  246. public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
  247. {
  248. this.primData.PathBegin = addPacket.PathBegin;
  249. this.primData.PathEnd = addPacket.PathEnd;
  250. this.primData.PathScaleX = addPacket.PathScaleX;
  251. this.primData.PathScaleY = addPacket.PathScaleY;
  252. this.primData.PathShearX = addPacket.PathShearX;
  253. this.primData.PathShearY = addPacket.PathShearY;
  254. this.primData.PathSkew = addPacket.PathSkew;
  255. this.primData.ProfileBegin = addPacket.ProfileBegin;
  256. this.primData.ProfileEnd = addPacket.ProfileEnd;
  257. this.primData.PathCurve = addPacket.PathCurve;
  258. this.primData.ProfileCurve = addPacket.ProfileCurve;
  259. this.primData.ProfileHollow = addPacket.ProfileHollow;
  260. this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
  261. this.primData.PathRevolutions = addPacket.PathRevolutions;
  262. this.primData.PathTaperX = addPacket.PathTaperX;
  263. this.primData.PathTaperY = addPacket.PathTaperY;
  264. this.primData.PathTwist = addPacket.PathTwist;
  265. this.primData.PathTwistBegin = addPacket.PathTwistBegin;
  266. this.dirtyFlag = true;
  267. }
  268. public void UpdateTexture(byte[] tex)
  269. {
  270. this.OurPacket.ObjectData[0].TextureEntry = tex;
  271. this.primData.Texture = tex;
  272. this.dirtyFlag = true;
  273. }
  274. public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
  275. {
  276. if (this._physActor != null)
  277. {
  278. if (this._physActor.Kinematic == pack.AgentData.UsePhysics)
  279. {
  280. this._physActor.Kinematic = !pack.AgentData.UsePhysics; //if Usephysics = true, then Kinematic should = false
  281. }
  282. this.physicsEnabled = pack.AgentData.UsePhysics;
  283. if (this._physActor.Kinematic == false)
  284. {
  285. LLVector3 pos = this.Pos;
  286. this.UpdatePosition(pos);
  287. pos.Z += 0.000001f;
  288. this.UpdatePosition(pos);
  289. this.physicstest = true;
  290. }
  291. else
  292. {
  293. PhysicsVector vec = this._physActor.Position;
  294. LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z);
  295. this.Pos = pos;
  296. this.updateFlag = true;
  297. }
  298. }
  299. }
  300. public void MakeParent(Primitive prim)
  301. {
  302. this.primData.ParentID = prim.localid;
  303. this.Pos -= prim.Pos;
  304. this.dirtyFlag = true;
  305. }
  306. public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
  307. {
  308. ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
  309. objupdate.RegionData.RegionHandle = m_regionHandle;
  310. objupdate.RegionData.TimeDilation = 64096;
  311. objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
  312. PrimData PData = new PrimData();
  313. this.primData = PData;
  314. this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  315. objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
  316. objupdate.ObjectData[0].PSBlock = new byte[0];
  317. objupdate.ObjectData[0].ExtraParams = new byte[1];
  318. objupdate.ObjectData[0].MediaURL = new byte[0];
  319. objupdate.ObjectData[0].NameValue = new byte[0];
  320. objupdate.ObjectData[0].Text = new byte[0];
  321. objupdate.ObjectData[0].TextColor = new byte[4];
  322. objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
  323. objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
  324. objupdate.ObjectData[0].Material = 3;
  325. objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
  326. objupdate.ObjectData[0].TextureAnim = new byte[0];
  327. objupdate.ObjectData[0].Sound = LLUUID.Zero;
  328. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
  329. this.primData.Texture = objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
  330. objupdate.ObjectData[0].State = 0;
  331. objupdate.ObjectData[0].Data = new byte[0];
  332. PData.OwnerID = objupdate.ObjectData[0].OwnerID = agentID;
  333. PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode;
  334. PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin;
  335. PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd;
  336. PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX;
  337. PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY;
  338. PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX;
  339. PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY;
  340. PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew;
  341. PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin;
  342. PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd;
  343. PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale;
  344. PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve;
  345. PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve;
  346. PData.ParentID = objupdate.ObjectData[0].ParentID = 0;
  347. PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow;
  348. PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
  349. PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions;
  350. PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX;
  351. PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY;
  352. PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist;
  353. PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
  354. objupdate.ObjectData[0].ID = (uint)(localID);
  355. objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000"));
  356. objupdate.ObjectData[0].ObjectData = new byte[60];
  357. objupdate.ObjectData[0].ObjectData[46] = 128;
  358. objupdate.ObjectData[0].ObjectData[47] = 63;
  359. LLVector3 pos1 = addPacket.ObjectData.RayEnd;
  360. //update position
  361. byte[] pb = pos1.GetBytes();
  362. Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
  363. this.newPrimFlag = true;
  364. this.primData.FullID = this.uuid = objupdate.ObjectData[0].FullID;
  365. this.localid = objupdate.ObjectData[0].ID;
  366. this.primData.Position = this.Pos = pos1;
  367. this.OurPacket = objupdate;
  368. }
  369. public void CreateFromStorage(PrimData store)
  370. {
  371. this.CreateFromStorage(store, store.Position, store.LocalID, false);
  372. }
  373. public void CreateFromStorage(PrimData store, LLVector3 posi, uint localID, bool newprim)
  374. {
  375. //need to clean this up as it shares a lot of code with CreateFromPacket()
  376. ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
  377. objupdate.RegionData.RegionHandle = m_regionHandle;
  378. objupdate.RegionData.TimeDilation = 64096;
  379. objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
  380. this.primData = store;
  381. objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
  382. objupdate.ObjectData[0].PSBlock = new byte[0];
  383. objupdate.ObjectData[0].ExtraParams = new byte[1];
  384. objupdate.ObjectData[0].MediaURL = new byte[0];
  385. objupdate.ObjectData[0].NameValue = new byte[0];
  386. objupdate.ObjectData[0].Text = new byte[0];
  387. objupdate.ObjectData[0].TextColor = new byte[4];
  388. objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
  389. objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
  390. objupdate.ObjectData[0].Material = 3;
  391. objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
  392. objupdate.ObjectData[0].TextureAnim = new byte[0];
  393. objupdate.ObjectData[0].Sound = LLUUID.Zero;
  394. if (store.Texture == null)
  395. {
  396. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
  397. objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
  398. }
  399. else
  400. {
  401. objupdate.ObjectData[0].TextureEntry = store.Texture;
  402. }
  403. objupdate.ObjectData[0].State = 0;
  404. objupdate.ObjectData[0].Data = new byte[0];
  405. objupdate.ObjectData[0].OwnerID = this.primData.OwnerID;
  406. objupdate.ObjectData[0].PCode = this.primData.PCode;
  407. objupdate.ObjectData[0].PathBegin = this.primData.PathBegin;
  408. objupdate.ObjectData[0].PathEnd = this.primData.PathEnd;
  409. objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX;
  410. objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY;
  411. objupdate.ObjectData[0].PathShearX = this.primData.PathShearX;
  412. objupdate.ObjectData[0].PathShearY = this.primData.PathShearY;
  413. objupdate.ObjectData[0].PathSkew = this.primData.PathSkew;
  414. objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
  415. objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
  416. objupdate.ObjectData[0].Scale = this.primData.Scale;
  417. objupdate.ObjectData[0].PathCurve = this.primData.PathCurve;
  418. objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
  419. objupdate.ObjectData[0].ParentID = 0;
  420. objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
  421. //finish off copying rest of shape data
  422. objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
  423. objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
  424. objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX;
  425. objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY;
  426. objupdate.ObjectData[0].PathTwist = this.primData.PathTwist;
  427. objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
  428. objupdate.ObjectData[0].ID = localID; // (uint)store.LocalID;
  429. objupdate.ObjectData[0].FullID = store.FullID;
  430. objupdate.ObjectData[0].ObjectData = new byte[60];
  431. objupdate.ObjectData[0].ObjectData[46] = 128;
  432. objupdate.ObjectData[0].ObjectData[47] = 63;
  433. LLVector3 pos1 = posi; // store.Position;
  434. //update position
  435. byte[] pb = pos1.GetBytes();
  436. Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
  437. this.uuid = objupdate.ObjectData[0].FullID;
  438. this.localid = objupdate.ObjectData[0].ID;
  439. this.Pos = pos1;
  440. this.OurPacket = objupdate;
  441. if (newprim)
  442. {
  443. this.newPrimFlag = true;
  444. }
  445. }
  446. public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
  447. {
  448. uint ID = this.localid;
  449. byte[] bytes = new byte[60];
  450. int i = 0;
  451. ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
  452. //dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry;
  453. dat.TextureEntry = new byte[0];
  454. //Console.WriteLine("texture-entry length in improvedterse block is " + this.OurPacket.ObjectData[0].TextureEntry.Length);
  455. bytes[i++] = (byte)(ID % 256);
  456. bytes[i++] = (byte)((ID >> 8) % 256);
  457. bytes[i++] = (byte)((ID >> 16) % 256);
  458. bytes[i++] = (byte)((ID >> 24) % 256);
  459. bytes[i++] = 0;
  460. bytes[i++] = 0;
  461. LLVector3 lPos;
  462. Axiom.MathLib.Quaternion lRot;
  463. if (this._physActor != null && this.physicsEnabled)
  464. {
  465. PhysicsVector pPos = this._physActor.Position;
  466. lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
  467. lRot = this._physActor.Orientation;
  468. }
  469. else
  470. {
  471. lPos = this.Pos;
  472. lRot = this.rotation;
  473. }
  474. byte[] pb = lPos.GetBytes();
  475. Array.Copy(pb, 0, bytes, i, pb.Length);
  476. i += 12;
  477. ushort ac = 32767;
  478. //vel
  479. bytes[i++] = (byte)(ac % 256);
  480. bytes[i++] = (byte)((ac >> 8) % 256);
  481. bytes[i++] = (byte)(ac % 256);
  482. bytes[i++] = (byte)((ac >> 8) % 256);
  483. bytes[i++] = (byte)(ac % 256);
  484. bytes[i++] = (byte)((ac >> 8) % 256);
  485. //accel
  486. bytes[i++] = (byte)(ac % 256);
  487. bytes[i++] = (byte)((ac >> 8) % 256);
  488. bytes[i++] = (byte)(ac % 256);
  489. bytes[i++] = (byte)((ac >> 8) % 256);
  490. bytes[i++] = (byte)(ac % 256);
  491. bytes[i++] = (byte)((ac >> 8) % 256);
  492. ushort rw, rx, ry, rz;
  493. rw = (ushort)(32768 * (lRot.w + 1));
  494. rx = (ushort)(32768 * (lRot.x + 1));
  495. ry = (ushort)(32768 * (lRot.y + 1));
  496. rz = (ushort)(32768 * (lRot.z + 1));
  497. //rot
  498. bytes[i++] = (byte)(rx % 256);
  499. bytes[i++] = (byte)((rx >> 8) % 256);
  500. bytes[i++] = (byte)(ry % 256);
  501. bytes[i++] = (byte)((ry >> 8) % 256);
  502. bytes[i++] = (byte)(rz % 256);
  503. bytes[i++] = (byte)((rz >> 8) % 256);
  504. bytes[i++] = (byte)(rw % 256);
  505. bytes[i++] = (byte)((rw >> 8) % 256);
  506. //rotation vel
  507. bytes[i++] = (byte)(ac % 256);
  508. bytes[i++] = (byte)((ac >> 8) % 256);
  509. bytes[i++] = (byte)(ac % 256);
  510. bytes[i++] = (byte)((ac >> 8) % 256);
  511. bytes[i++] = (byte)(ac % 256);
  512. bytes[i++] = (byte)((ac >> 8) % 256);
  513. dat.Data = bytes;
  514. return dat;
  515. }
  516. public override void BackUp()
  517. {
  518. this.primData.FullID = this.uuid;
  519. this.primData.LocalID = this.localid;
  520. this.primData.Position = this.Pos;
  521. this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w);
  522. this.m_world.localStorage.StorePrim(this.primData);
  523. }
  524. }
  525. }