예제 #1
0
        public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying)
        {
            base.BaseInitialize(parent_scene, localID, avName, "BSCharacter");
            _physicsActorType = (int)ActorTypes.Agent;
            _position         = pos;
            _size             = size;
            _flying           = isFlying;
            _orientation      = OMV.Quaternion.Identity;
            _velocity         = OMV.Vector3.Zero;
            _buoyancy         = ComputeBuoyancyFromFlying(isFlying);

            // The dimensions of the avatar capsule are kept in the scale.
            // Physics creates a unit capsule which is scaled by the physics engine.
            ComputeAvatarScale(_size);
            _avatarDensity = PhysicsScene.Params.avatarDensity;
            // set _avatarVolume and _mass based on capsule size, _density and _scale
            ComputeAvatarVolumeAndMass();

            ShapeData shapeData = new ShapeData();

            shapeData.ID          = LocalID;
            shapeData.Type        = ShapeData.PhysicsShapeType.SHAPE_AVATAR;
            shapeData.Position    = _position;
            shapeData.Rotation    = _orientation;
            shapeData.Velocity    = _velocity;
            shapeData.Scale       = _scale;
            shapeData.Mass        = _mass;
            shapeData.Buoyancy    = _buoyancy;
            shapeData.Static      = ShapeData.numericFalse;
            shapeData.Friction    = PhysicsScene.Params.avatarFriction;
            shapeData.Restitution = PhysicsScene.Params.avatarRestitution;

            // do actual create at taint time
            PhysicsScene.TaintedObject("BSCharacter.create", delegate()
            {
                DetailLog("{0},BSCharacter.create,taint", LocalID);
                BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData);

                // Set the buoyancy for flying. This will be refactored when all the settings happen in C#.
                // If not set at creation, the avatar will stop flying when created after crossing a region boundry.
                BulletSimAPI.SetObjectBuoyancy(PhysicsScene.WorldID, LocalID, _buoyancy);

                BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(PhysicsScene.World.ptr, LocalID));

                // This works here because CreateObject has already put the character into the physical world.
                BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr,
                                                     (uint)CollisionFilterGroups.AvatarFilter, (uint)CollisionFilterGroups.AvatarMask);
            });
            return;
        }
예제 #2
0
        public BSCharacter(uint localID, UUID avID, String avName, BSScene parent_scene, Vector3 pos,
                           Quaternion rotation, Vector3 size, bool isFlying)
        {
            _localID     = localID;
            _avID        = avID;
            _avName      = avName;
            _scene       = parent_scene;
            _position    = pos;
            _orientation = rotation;
            _size        = size;
            _orientation = Quaternion.Identity;
            _velocity    = Vector3.Zero;
            _buoyancy    = 0f; // characters return a buoyancy of zero
            _scale       = new Vector3(1f, 1f, 1f);
            float AVvolume =
                (float)(Math.PI * Math.Pow(_scene.Params.avatarCapsuleRadius, 2) * _scene.Params.avatarCapsuleHeight);

            _density    = _scene.Params.avatarDensity;
            _mass       = _density * AVvolume;
            _isPhysical = true;

            ShapeData shapeData = new ShapeData
            {
                ID          = _localID,
                Type        = ShapeData.PhysicsShapeType.SHAPE_AVATAR,
                Position    = _position,
                Rotation    = _orientation,
                Velocity    = _velocity,
                Scale       = _scale,
                Mass        = _mass,
                Buoyancy    = isFlying ? 1f : 0f,
                Static      = ShapeData.numericFalse,
                Friction    = _scene.Params.avatarFriction,
                Restitution = _scene.Params.defaultRestitution
            };

            // do actual create at taint time
#if (!ISWIN)
            _scene.TaintedObject(delegate()
            {
                BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData);
            });
#else
            _scene.TaintedObject(() => BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData));
#endif

            return;
        }
예제 #3
0
        public BSCharacter(uint localID, String avName, BSScene parent_scene, Vector3 pos, Vector3 size, bool isFlying)
        {
            _localID     = localID;
            _avName      = avName;
            _scene       = parent_scene;
            _position    = pos;
            _size        = size;
            _flying      = isFlying;
            _orientation = Quaternion.Identity;
            _velocity    = Vector3.Zero;
            _buoyancy    = isFlying ? 1f : 0f;
            _scale       = new Vector3(1f, 1f, 1f);
            _density     = _scene.Params.avatarDensity;
            ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale

            ShapeData shapeData = new ShapeData();

            shapeData.ID          = _localID;
            shapeData.Type        = ShapeData.PhysicsShapeType.SHAPE_AVATAR;
            shapeData.Position    = _position;
            shapeData.Rotation    = _orientation;
            shapeData.Velocity    = _velocity;
            shapeData.Scale       = _scale;
            shapeData.Mass        = _mass;
            shapeData.Buoyancy    = _buoyancy;
            shapeData.Static      = ShapeData.numericFalse;
            shapeData.Friction    = _scene.Params.avatarFriction;
            shapeData.Restitution = _scene.Params.defaultRestitution;

            // do actual create at taint time
            _scene.TaintedObject(delegate()
            {
                BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData);
            });

            return;
        }