public static byte[] BuildObjectData(Vector3 position, Quaternion rotation, Vector3 velocity, Vector3 acceleration, Vector3 angularVelocity) { byte[] objectData = new byte[60]; int pos = 0; position.GetBytes().CopyTo(objectData, pos); pos += 12; velocity.GetBytes().CopyTo(objectData, pos); pos += 12; acceleration.GetBytes().CopyTo(objectData, pos); pos += 12; rotation.GetBytes().CopyTo(objectData, pos); pos += 12; angularVelocity.GetBytes().CopyTo(objectData, pos); return objectData; }
/// <summary> /// Send a Multiple Object Update packet to change the size, scale or rotation of a primitive /// </summary> /// <param name="simulator">A reference to the <seealso cref="OpenMetaverse.Simulator"/> object where the object resides</param> /// <param name="localID">The objects ID which is local to the simulator the object is in</param> /// <param name="data">The new rotation, size, or position of the target object</param> /// <param name="type">The flags from the <seealso cref="UpdateType"/> Enum</param> public void UpdateObject(Simulator simulator, uint localID, Vector3 data, UpdateType type) { MultipleObjectUpdatePacket multiObjectUpdate = new MultipleObjectUpdatePacket(); multiObjectUpdate.AgentData.AgentID = Client.Self.AgentID; multiObjectUpdate.AgentData.SessionID = Client.Self.SessionID; multiObjectUpdate.ObjectData = new MultipleObjectUpdatePacket.ObjectDataBlock[1]; multiObjectUpdate.ObjectData[0] = new MultipleObjectUpdatePacket.ObjectDataBlock(); multiObjectUpdate.ObjectData[0].Type = (byte)type; multiObjectUpdate.ObjectData[0].ObjectLocalID = localID; multiObjectUpdate.ObjectData[0].Data = data.GetBytes(); Client.Network.SendPacket(multiObjectUpdate, simulator); }
public AMeshKey GetMeshUniqueKey(PrimitiveBaseShape primShape, Vector3 size, byte lod, bool convex) { AMeshKey key = new AMeshKey(); Byte[] someBytes; key.hashB = 5181; key.hashC = 5181; ulong hash = 5381; if (primShape.SculptEntry) { key.uuid = primShape.SculptTexture; key.hashC = mdjb2(key.hashC, primShape.SculptType); key.hashC = mdjb2(key.hashC, primShape.PCode); } else { hash = mdjb2(hash, primShape.PathCurve); hash = mdjb2(hash, (byte)primShape.HollowShape); hash = mdjb2(hash, (byte)primShape.ProfileShape); hash = mdjb2(hash, primShape.PathBegin); hash = mdjb2(hash, primShape.PathEnd); hash = mdjb2(hash, primShape.PathScaleX); hash = mdjb2(hash, primShape.PathScaleY); hash = mdjb2(hash, primShape.PathShearX); key.hashA = hash; hash = key.hashB; hash = mdjb2(hash, primShape.PathShearY); hash = mdjb2(hash, (byte)primShape.PathTwist); hash = mdjb2(hash, (byte)primShape.PathTwistBegin); hash = mdjb2(hash, (byte)primShape.PathRadiusOffset); hash = mdjb2(hash, (byte)primShape.PathTaperX); hash = mdjb2(hash, (byte)primShape.PathTaperY); hash = mdjb2(hash, primShape.PathRevolutions); hash = mdjb2(hash, (byte)primShape.PathSkew); hash = mdjb2(hash, primShape.ProfileBegin); hash = mdjb2(hash, primShape.ProfileEnd); hash = mdjb2(hash, primShape.ProfileHollow); hash = mdjb2(hash, primShape.PCode); key.hashB = hash; } hash = key.hashC; hash = mdjb2(hash, lod); if (size == m_MeshUnitSize) { hash = hash << 8; hash |= 8; } else { someBytes = size.GetBytes(); for (int i = 0; i < someBytes.Length; i++) hash = mdjb2(hash, someBytes[i]); hash = hash << 8; } if (convex) hash |= 4; if (primShape.SculptEntry) { hash |= 1; if (primShape.SculptType == (byte)SculptType.Mesh) hash |= 2; } key.hashC = hash; return key; }
public byte[] GetFlexiBytes() { byte[] data = new byte[16]; int i = 0; // Softness is packed in the upper bits of tension and drag data[i] = (byte)((_flexiSoftness & 2) << 6); data[i + 1] = (byte)((_flexiSoftness & 1) << 7); data[i++] |= (byte)((byte)(_flexiTension * 10.01f) & 0x7F); data[i++] |= (byte)((byte)(_flexiDrag * 10.01f) & 0x7F); data[i++] = (byte)((_flexiGravity + 10.0f) * 10.01f); data[i++] = (byte)(_flexiWind * 10.01f); Vector3 lForce = new Vector3(_flexiForceX, _flexiForceY, _flexiForceZ); lForce.GetBytes().CopyTo(data, i); return data; }
/// <summary> /// Calculate a hash value over fields that can affect the underlying physics shape. /// Things like RenderMaterials and TextureEntry data are not included. /// </summary> /// <param name="size"></param> /// <param name="lod"></param> /// <returns>ulong - a calculated hash value</returns> public ulong GetMeshKey(Vector3 size, float lod) { ulong hash = 5381; hash = djb2(hash, this.PathCurve); hash = djb2(hash, (byte)((byte)this.HollowShape | (byte)this.ProfileShape)); hash = djb2(hash, this.PathBegin); hash = djb2(hash, this.PathEnd); hash = djb2(hash, this.PathScaleX); hash = djb2(hash, this.PathScaleY); hash = djb2(hash, this.PathShearX); hash = djb2(hash, this.PathShearY); hash = djb2(hash, (byte)this.PathTwist); hash = djb2(hash, (byte)this.PathTwistBegin); hash = djb2(hash, (byte)this.PathRadiusOffset); hash = djb2(hash, (byte)this.PathTaperX); hash = djb2(hash, (byte)this.PathTaperY); hash = djb2(hash, this.PathRevolutions); hash = djb2(hash, (byte)this.PathSkew); hash = djb2(hash, this.ProfileBegin); hash = djb2(hash, this.ProfileEnd); hash = djb2(hash, this.ProfileHollow); // TODO: Separate scale out from the primitive shape data (after // scaling is supported at the physics engine level) byte[] scaleBytes = size.GetBytes(); for (int i = 0; i < scaleBytes.Length; i++) hash = djb2(hash, scaleBytes[i]); // Include LOD in hash, accounting for endianness byte[] lodBytes = new byte[4]; Buffer.BlockCopy(BitConverter.GetBytes(lod), 0, lodBytes, 0, 4); if (!BitConverter.IsLittleEndian) { Array.Reverse(lodBytes, 0, 4); } for (int i = 0; i < lodBytes.Length; i++) hash = djb2(hash, lodBytes[i]); // include sculpt UUID if (this.SculptEntry) { scaleBytes = this.SculptTexture.GetBytes(); for (int i = 0; i < scaleBytes.Length; i++) hash = djb2(hash, scaleBytes[i]); hash = djb2(hash, this.SculptType); } return hash; }