Beispiel #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;
        }