/// <summary> /// Constructor. /// Initializes default values for various materials. The default /// values are from http://wiki.secondlife.com/wiki/PRIM_MATERIAL /// <summary> public RemotePhysicsMaterialLibrary(RemotePhysicsConfiguration config) { float defaultDensity; // Retrieve the default density for objects defaultDensity = config.DefaultDensity; // Initialize each of the default material attributes using the // values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL m_attributes[(int)Material.Stone] = new RemotePhysicsMaterialAttributes("Stone", defaultDensity, 0.8f, 0.4f); m_attributes[(int)Material.Metal] = new RemotePhysicsMaterialAttributes("Metal", defaultDensity, 0.3f, 0.4f); m_attributes[(int)Material.Glass] = new RemotePhysicsMaterialAttributes("Glass", defaultDensity, 0.2f, 0.7f); m_attributes[(int)Material.Wood] = new RemotePhysicsMaterialAttributes("Wood", defaultDensity, 0.6f, 0.5f); m_attributes[(int)Material.Flesh] = new RemotePhysicsMaterialAttributes("Flesh", defaultDensity, 0.9f, 0.3f); m_attributes[(int)Material.Plastic] = new RemotePhysicsMaterialAttributes("Plastic", defaultDensity, 0.4f, 0.7f); m_attributes[(int)Material.Rubber] = new RemotePhysicsMaterialAttributes("Rubber", defaultDensity, 0.9f, 0.9f); m_attributes[(int)Material.Light] = new RemotePhysicsMaterialAttributes("Light", defaultDensity, config.DefaultFriction, config.DefaultRestitution); }
/// <summary> /// Constructor of the UDP packet manager. /// </summary> public RemotePhysicsUDPPacketManager(RemotePhysicsConfiguration config) { IPAddress remoteAddress; // Configure the connection point using configuration address // and port remoteAddress = IPAddress.Parse(config.RemoteAddress); m_remoteHost = new IPEndPoint(remoteAddress, config.RemotePort); // Create the UDP client that will be used to communicate with the // remote physics engine m_udpClient = new UdpClient(); // Check to see if the configuration states whether this packet // manager should use its own internal update thread m_useInternalThread = config.PacketManagerInternalThread; if (m_useInternalThread) { // Create the thread that will send and receive messages from // the remote physics engine m_updateThread = new Thread(new ThreadStart(RunUpdate)); m_updateThread.Priority = ThreadPriority.AboveNormal; m_updateThread.Start(); } }
/// <summary> /// Constructor of the TCP packet manager. /// </summary> /// <param name="config">The configuration which is used to /// initialize the packet manager</param> public RemotePhysicsTCPPacketManager(RemotePhysicsConfiguration config) { IPAddress remoteAddress; IPEndPoint remoteEP; // Create the incoming/outgoing packet threads and locks m_incomingPackets = new Queue <byte[]>(); m_outgoingPackets = new Queue <byte[]>(); m_outgoingMutex = new Mutex(); m_incomingMutex = new Mutex(); // Configure the connection point using the configuration address // and port remoteAddress = IPAddress.Parse(config.RemoteAddress); remoteEP = new IPEndPoint(remoteAddress, config.RemotePort); // Create the socket that will allow for communication with the // remote physics engine m_remoteSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Initialize the synchronization event used to block this // thread during the connection process connectDone = new ManualResetEvent(false); // Start the connection to the remote physics engine m_remoteSocket.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), m_remoteSocket); // Block the thread until the connection is complete connectDone.WaitOne(); // Initialize the buffer that will be used for reading messages // from the remote physics engine m_readBuffer = new byte[m_receiveBufferLength]; // Initialize the buffer that will be used to hold messages whose // data overflow the read buffer m_overflowBuffer = new byte[m_receiveBufferLength]; // Check to see if the configuration states that this packet // manager should use its own internal thread m_useInternalThread = config.PacketManagerInternalThread; if (m_useInternalThread) { // Create thread that will send and receive messages from the // remote server m_updateThread = new Thread(new ThreadStart(RunUpdate)); m_updateThread.Start(); } // Initialize the header length and packet length offset to // their defaults m_headerSize = m_defaultHeaderSize; m_packetLengthOffset = m_defaultPacketLengthOffset; }
/// <summary> /// Constructor. /// </summary> /// <param name="parentScene">The scene to which this object /// belongs</param> /// <param name="localID">The unique identifier of the object</param> /// <param name="name">The name of the object</param> /// <param name="typeName">The type of the object</param> /// <param name="config">The configuration used to initialize this /// object</param> protected RemotePhysicsObject(RemotePhysicsScene parentScene, uint localID, String name, String typeName, RemotePhysicsConfiguration config) { // Initialize the parent physics scene ParentScene = parentScene; // Indicate that this object has not been fully initialized IsInitialized = false; // Initialize the handle to the configuration that will be used // initialize other properties ParentConfiguration = config; // Initialize the local ID of this object LocalID = localID; // Initialize the name of this physics object // Usually this is the same name as the OpenSim object Name = name; // Initialize the type of this object in string form TypeName = typeName; // Initialize the gravity modifier to be 1.0, so that the // gravity of the scene will be unmodified when it affects // this object GravModifier = 1.0f; // Initialize the gravity vector Gravity = new OpenMetaverse.Vector3(0.0f, 0.0f, config.Gravity); // Indicate that the object is not hovering HoverActive = false; // Create the list of pending and sent collisions Collisions = new CollisionEventUpdate(); CollisionsLastReported = Collisions; // Initialize the collision steps to be invalid steps, since no // collision has occurred yet GroundCollisionStep = RemotePhysicsScene.InvalidStep; ObjectCollisionStep = RemotePhysicsScene.InvalidStep; LastCollisionStep = RemotePhysicsScene.InvalidStep; // No collisions have occurred, so start the collision count at 0 NumCollisions = 0; // Initialize the object that will ensure the thread safety of the // collision step data m_collisionStepLock = new Object(); }
/// <summary> /// Constructor. /// </summary> /// <param name="identifier">The name of this scene</param> public RemotePhysicsScene(string identifier) { // Indicate that the scene has yet to be initialized m_initialized = false; // Store the name of the region that will be represented by this // physics scene RegionName = identifier; // Create the configuration with the default values RemoteConfiguration = new RemotePhysicsConfiguration(); // Create the list that will hold the delegates of tainted actors m_taintCallbacks = new List <ActorTaintCallback>(); // Create the mutex object that will keep the taint callback list // thread-safe m_taintListLock = new Object(); // Create the material library that will track various material // archetypes MaterialLibrary = new RemotePhysicsMaterialLibrary( RemoteConfiguration); }
/// <summary> /// Constructor. /// </summary> /// <param name="localID">The unique identifier of the avatar</param> /// <param name="avatarName">The name of the avatar</param> /// <param name="parentScene">The physics scene to which the avatar /// belongs</param> /// <param name="position">The initial position of the avatar</param> /// <param name="velocity">The initial linear velocity of the /// avatar</param> /// <param name="size">The size of the avatar</param> /// <param name="isFlying">Whether the avatar is flying or not</param> /// <param name="config">The configuration used to initialize the /// avatar</param> public RemotePhysicsAvatar(uint localID, String avatarName, RemotePhysicsScene parentScene, OpenMetaverse.Vector3 position, OpenMetaverse.Vector3 velocity, OpenMetaverse.Vector3 size, bool isFlying, RemotePhysicsConfiguration config) : base(parentScene, localID, avatarName, "RemotePhysicsCharacter", config) { OpenMetaverse.Quaternion localPoseQuat; // Initialize the unique ID of this avatar m_actorID = localID; // Indicate that this object is an avatar m_actorType = (int)ActorTypes.Agent; // Initialize the position to what's given Position = position; // Initialize the orientation to the default value Orientation = OpenMetaverse.Quaternion.Identity; // Initialize the velocity based on what's given m_velocity = velocity; // Initialize the friction values based on the parent scene's // friction coefficient for avatars Friction = ParentConfiguration.AvatarKineticFriction; m_kineticFriction = ParentConfiguration.AvatarKineticFriction; m_staticFriction = ParentConfiguration.AvatarStaticFriction; // Initialize the density based on the parent scene's density // value for avatars Density = ParentConfiguration.AvatarDensity; // Initialize the size of this avatar using the given size m_size = size; // Check to see if any of the dimensions are zero // If they are, use the default sizes if (m_size.X == 0.0f) { m_size.X = ParentConfiguration.AvatarShapeDepth; } if (m_size.Y == 0.0f) { m_size.Y = ParentConfiguration.AvatarShapeWidth; } if (m_size.Z == 0.0f) { m_size.Z = ParentConfiguration.AvatarShapeHeight; } // Compute the mass of the avatar, so that it can be referenced // for later computations ComputeAvatarMass(); // Send out a message to the remote physics engine to create an // actor ParentScene.RemoteMessenger.CreateDynamicActor(m_actorID, Position, Orientation, 1.0f, m_velocity, new OpenMetaverse.Vector3(0.0f, 0.0f, 0.0f), true); // Fetch a unique identifier for this avatar's shape m_avatarShapeID = ParentScene.GetNewShapeID(); // Build the avatar's shape in the remote physics engine BuildAvatarShape(); // Add a constraint between the new actor and ground plane such // that the actor doesn't fall over on its side due to gravity // Use an unused actor ID to denote that this joint is between the // avatar and the world frame m_fallJointID = ParentScene.GetNewJointID(); ParentScene.RemoteMessenger.AddJoint(m_fallJointID, m_actorID, OpenMetaverse.Vector3.Zero, OpenMetaverse.Quaternion.Identity, ParentScene.GetNewActorID(), OpenMetaverse.Vector3.Zero, OpenMetaverse.Quaternion.Identity, new OpenMetaverse.Vector3(1.0f, 1.0f, 1.0f), new OpenMetaverse.Vector3(0.0f, 0.0f, 0.0f), new OpenMetaverse.Vector3(0.0f, 0.0f, 0.0f), new OpenMetaverse.Vector3(0.0f, 0.0f, 0.0f)); // Indicate that this object is now initialized IsInitialized = true; }