Exemplo n.º 1
0
        public Character(uint id)
            : base(id)
        {
            Sphere.Margin = COLLISION_MARGIN_DEFAULT;

            ClimbSensor = new SphereShape(ClimbR);
            ClimbSensor.Margin = COLLISION_MARGIN_DEFAULT;

            RayCb = new BtEngineClosestRayResultCallback(Self, true);
            RayCb.CollisionFilterMask = (short) (CollisionFilterGroups.StaticFilter | CollisionFilterGroups.KinematicFilter);
            HeightInfo.Cb = RayCb;

            ConvexCb = new BtEngineClosestConvexResultCallback(Self, true);
            ConvexCb.CollisionFilterMask = (short) (CollisionFilterGroups.StaticFilter | CollisionFilterGroups.KinematicFilter);
            HeightInfo.Ccb = ConvexCb;

            DirFlag = ENT_MOVE.Stay;
        }
Exemplo n.º 2
0
        public static bool lua_DropEntity(int id, float time, bool onlyRoom = false)
        {
            var ent = EngineWorld.GetEntityByID((uint)id);
            if (ent == null)
            {
                ConsoleInfo.Instance.Warning(SYSWARN_NO_ENTITY, id);
                return false;
            }

            var move = ent.ApplyGravity(time);

            var cb = new BtEngineClosestRayResultCallback(ent.Self);
            var from = ent.Transform * ent.Bf.Centre;
            from.Z = ent.Transform.Origin.Z;
            var to = from + move;
            //to.Z -= ent.Bf.BBMax.Z - ent.Bf.BBMin.Z;
            BtEngineDynamicsWorld.RayTest(from.ToBullet(), to.ToBullet(), cb);

            if (cb.HasHit)
            {
                var cont = (EngineContainer) cb.CollisionObject.UserObject;

                if (!onlyRoom || (onlyRoom && cont.ObjectType == OBJECT_TYPE.RoomBase))
                {
                    Helper.SetInterpolate3(out move, from, to, cb.ClosestHitFraction);
                    ent.Transform.Origin.Z = move.Z;

                    ent.UpdateRigidBody(true);
                    return true;
                }
                else
                {
                    ent.UpdateRigidBody(true);
                    return false;
                }
            }
            else
            {
                ent.Transform.Origin += move;
                ent.UpdateRigidBody(true);
                return false;
            }
        }
Exemplo n.º 3
0
        public static void SecondaryMouseDown()
        {
            var from = EngineCamera.Position;
            var to = from + EngineCamera.ViewDirection * 32768.0f;

            var camCont = new EngineContainer {Room = EngineCamera.CurrentRoom};

            var cbc = new BtEngineClosestRayResultCallback(camCont);
            //cbc.CollisionFilterMask = CollisionFilterGroups.StaticFilter | CollisionFilterGroups.KinematicFilter;
            BtEngineDynamicsWorld.RayTest(from.ToBullet(), to.ToBullet(), cbc);
            if(cbc.HasHit)
            {
                var castRay = new float[6];

                Vector3 place;
                Helper.SetInterpolate3(out place, from, to, cbc.ClosestHitFraction);
                place.CopyToArray(castRay, 0);
                (place + 100.0f * cbc.HitNormalWorld.ToOpenTK()).CopyToArray(castRay, 3);

                var c0 = (EngineContainer) cbc.CollisionObject.UserObject;
                if(c0 != null)
                {
                    if(c0.ObjectType == OBJECT_TYPE.BulletMisc)
                    {
                        var obj = cbc.CollisionObject;
                        var body = RigidBody.Upcast(obj);
                        body?.MotionState?.Dispose();
                        body?.CollisionShape?.Dispose();

                        if(body != null)
                        {
                            body.UserObject = null;
                        }
                        c0.Room = null;
                        c0 = null;

                        BtEngineDynamicsWorld.RemoveCollisionObject(obj);
                        obj.Dispose();
                    }
                    else
                    {
                        LastContainer = c0;
                    }
                }
            }
        }