Exemplo n.º 1
0
        /// <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;
        }