コード例 #1
0
 public void AddToSpace(BEPUphysics.Space space)
 {
     space.Add(mesh);
     foreach (String key in models.Keys)
     {
         space.Add(models[key].Mesh);
     }
 }
コード例 #2
0
        public void InitializeWorld()
        {
            mGameObjects = new List <NetGameObject>();
            //mWorldMap = new WorldMap();

#if _USE_BEPU_PHYSICS
            space = new BEPUphysics.Space();
            space.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0);
#elif _USE_BULLET_SHARP
            Broadphase = new BulletSharp.AxisSweep3(new BulletSharp.Math.Vector3(-1000, -1000, -1000), new BulletSharp.Math.Vector3(1000, 1000, 1000));

            var conf       = new BulletSharp.DefaultCollisionConfiguration();
            var dispatcher = new BulletSharp.CollisionDispatcher(conf);
            world         = new BulletSharp.MultiBodyDynamicsWorld(dispatcher, Broadphase, new BulletSharp.MultiBodyConstraintSolver(), conf);
            world.Gravity = new BulletSharp.Math.Vector3(0, -9.81f, 0);

            var box = new BulletSharp.BoxShape(50f, 1f, 50f);
            //box.Margin = 0f;
            floor = new BulletSharp.RigidBody(new BulletSharp.RigidBodyConstructionInfo(0f, new BulletSharp.DefaultMotionState(), box, new BulletSharp.Math.Vector3(0, -2f, 0)));
            floor.CollisionFlags = BulletSharp.CollisionFlags.KinematicObject;


            BulletSharp.Math.Matrix worldTrans = new BulletSharp.Math.Matrix();
            worldTrans.M41       = 0f;
            worldTrans.M42       = -2f;
            worldTrans.M43       = 0;
            floor.WorldTransform = worldTrans;
            //floor.Friction = 0.5f;


            world.AddRigidBody(floor, BulletSharp.CollisionFilterGroups.DefaultFilter, //BulletSharp.CollisionFilterGroups.Everything);
                               (BulletSharp.CollisionFilterGroups.DefaultFilter
                                | BulletSharp.CollisionFilterGroups.StaticFilter
                                | BulletSharp.CollisionFilterGroups.KinematicFilter
                                | BulletSharp.CollisionFilterGroups.DebrisFilter
                                | BulletSharp.CollisionFilterGroups.SensorTrigger
                                | BulletSharp.CollisionFilterGroups.CharacterFilter
                               )
                               );
#elif _USE_BEPU_PHYSICS_V2
            characters = new BepuPhysics.CharacterControllers(BufferPool);
            Simulation = Simulation.Create(BufferPool, new BepuPhysics.CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0)));

            Simulation.Statics.Add(new StaticDescription(new System.Numerics.Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(50, 1, 50)), 0.1f)));
#endif
        }
コード例 #3
0
        public BEPUPhysicsWorld(Karen90MmoFramework.Quantum.Bounds bounds, Karen90MmoFramework.Quantum.Vector3 gravity, bool createBoundary = false)
        {
            var parallelLooper = new ParallelLooper();

            if (Environment.ProcessorCount > 1)
            {
                for (var i = 0; i < Environment.ProcessorCount; i++)
                {
                    parallelLooper.AddThread();
                }
            }

            this.space = new Space(parallelLooper)
            {
                ForceUpdater = { Gravity = new Vector3(gravity.X, gravity.Y, gravity.Z) }
            };
            this.bounds = bounds;

            this.frictionlessMaterial = new Material(0f, 0f, 0f);

            this.staticGroup    = new CollisionGroup();
            this.kinematicGroup = new CollisionGroup();
            this.dynamicGroup   = new CollisionGroup();
            this.avatarGroup    = new CollisionGroup();

            CollisionGroup.DefineCollisionRule(this.staticGroup, this.staticGroup, CollisionRule.NoBroadPhase);
            CollisionGroup.DefineCollisionRule(this.staticGroup, this.kinematicGroup, CollisionRule.NoBroadPhase);
            CollisionGroup.DefineCollisionRule(this.staticGroup, this.dynamicGroup, CollisionRule.NoBroadPhase);
            CollisionGroup.DefineCollisionRule(this.staticGroup, this.avatarGroup, CollisionRule.Defer);
            CollisionGroup.DefineCollisionRule(this.kinematicGroup, this.kinematicGroup, CollisionRule.NoBroadPhase);
            CollisionGroup.DefineCollisionRule(this.kinematicGroup, this.dynamicGroup, CollisionRule.NoBroadPhase);
            CollisionGroup.DefineCollisionRule(this.kinematicGroup, this.avatarGroup, CollisionRule.Defer);
            CollisionGroup.DefineCollisionRule(this.dynamicGroup, this.dynamicGroup, CollisionRule.NoBroadPhase);
            CollisionGroup.DefineCollisionRule(this.dynamicGroup, this.avatarGroup, CollisionRule.Defer);
            CollisionGroup.DefineCollisionRule(this.avatarGroup, this.avatarGroup, CollisionRule.NoBroadPhase);

            if (createBoundary)
            {
                this.CreateWorldBoundary();
            }
        }
コード例 #4
0
ファイル: World.cs プロジェクト: devforgood/engine
        private void InitializeWrold()
        {
            mGameObjects = new List <NetGameObject>();
            //mWorldMap = new WorldMap();

#if _USE_BEPU_PHYSICS
            space = new BEPUphysics.Space();


            // floor
            space.Add(new Box(new BEPUutilities.Vector3(0, -1.0f, 0), 30, 1, 30));
            // temp box
            space.Add(new Box(new BEPUutilities.Vector3(0, 0, -1.0f), 1, 1, 1));

            var vertices = new BEPUutilities.Vector3[]
            {
                new BEPUutilities.Vector3(-0.454f, 0.087f, -0.413f),
                new BEPUutilities.Vector3(-0.454f, 0.087f, 0.29f),
                new BEPUutilities.Vector3(-0.454f, 0.79f, -0.413f),
                new BEPUutilities.Vector3(0.454f, 0.79f, -0.413f),
                new BEPUutilities.Vector3(0.454f, 0.087f, 0.29f),
                new BEPUutilities.Vector3(0.454f, 0.087f, -0.413f),
                new BEPUutilities.Vector3(-0.333f, 1f, -0.5f),
                new BEPUutilities.Vector3(-0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.333f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(-0.333f, 1f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 0f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.5f, 0f, -0.5f),
                new BEPUutilities.Vector3(0.333f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(-0.474f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(-0.355f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 0f, -0.5f),
                new BEPUutilities.Vector3(-0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(-0.5f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.5f, 0f, -0.5f),
                new BEPUutilities.Vector3(0.5f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.355f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(0.474f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(0.355f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(0.474f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(-0.355f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(-0.474f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(-0.474f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(-0.355f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(0.333f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.474f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.355f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(0.474f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(0.5f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.474f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.5f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.474f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(0.355f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(0.355f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(0.355f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(0.333f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(-0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(-0.474f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(-0.5f, 0f, 0.5f),
                new BEPUutilities.Vector3(-0.355f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(-0.474f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(-0.474f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 0f, 0.5f),
                new BEPUutilities.Vector3(-0.355f, 0.058f, 0.5f),
                new BEPUutilities.Vector3(-0.333f, 0f, 0.5f),
                new BEPUutilities.Vector3(-0.333f, 1f, -0.5f),
                new BEPUutilities.Vector3(-0.355f, 1.058f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 0.049f, -0.451f),
                new BEPUutilities.Vector3(-0.454f, 0.79f, -0.413f),
                new BEPUutilities.Vector3(-0.5f, 0.882f, -0.451f),
                new BEPUutilities.Vector3(-0.454f, 0.087f, -0.413f),
                new BEPUutilities.Vector3(-0.5f, 0.049f, 0.382f),
                new BEPUutilities.Vector3(-0.5f, 0.882f, -0.451f),
                new BEPUutilities.Vector3(-0.454f, 0.79f, -0.413f),
                new BEPUutilities.Vector3(-0.454f, 0.087f, 0.29f),
                new BEPUutilities.Vector3(-0.5f, 0.049f, -0.451f),
                new BEPUutilities.Vector3(-0.5f, 0.049f, 0.382f),
                new BEPUutilities.Vector3(-0.454f, 0.087f, 0.29f),
                new BEPUutilities.Vector3(-0.454f, 0.087f, -0.413f),
                new BEPUutilities.Vector3(0.5f, 0.049f, -0.451f),
                new BEPUutilities.Vector3(0.5f, 0.882f, -0.451f),
                new BEPUutilities.Vector3(0.454f, 0.79f, -0.413f),
                new BEPUutilities.Vector3(0.454f, 0.087f, -0.413f),
                new BEPUutilities.Vector3(0.454f, 0.087f, 0.29f),
                new BEPUutilities.Vector3(0.5f, 0.049f, -0.451f),
                new BEPUutilities.Vector3(0.454f, 0.087f, -0.413f),
                new BEPUutilities.Vector3(0.5f, 0.049f, 0.382f),
                new BEPUutilities.Vector3(0.5f, 0.049f, 0.382f),
                new BEPUutilities.Vector3(0.454f, 0.79f, -0.413f),
                new BEPUutilities.Vector3(0.5f, 0.882f, -0.451f),
                new BEPUutilities.Vector3(0.454f, 0.087f, 0.29f),
                new BEPUutilities.Vector3(-0.5f, 0f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 0.049f, -0.451f),
                new BEPUutilities.Vector3(-0.5f, 0.882f, -0.451f),
                new BEPUutilities.Vector3(-0.5f, 0.049f, 0.382f),
                new BEPUutilities.Vector3(-0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(-0.5f, 0f, 0.5f),
                new BEPUutilities.Vector3(0.5f, 0.882f, -0.451f),
                new BEPUutilities.Vector3(0.5f, 0.049f, -0.451f),
                new BEPUutilities.Vector3(0.5f, 0f, -0.5f),
                new BEPUutilities.Vector3(0.5f, 0.049f, 0.382f),
                new BEPUutilities.Vector3(0.5f, 1f, -0.5f),
                new BEPUutilities.Vector3(0.5f, 0f, 0.5f),
            };

            int[] indices = new int[]
            {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 9, 10, 11, 12, 10, 13, 11, 10, 14, 13, 13, 14, 15, 10, 16, 17, 17, 18, 10, 19, 20, 21, 22, 20, 19, 19, 23, 22, 22, 23, 24, 25, 26, 27, 26, 25, 28, 29, 30, 31, 31, 32, 29, 33, 34, 35, 33, 36, 34, 37, 38, 39, 37, 39, 40, 41, 42, 43, 43, 44, 41, 45, 46, 47, 47, 48, 45, 49, 50, 51, 49, 52, 50, 53, 54, 55, 55, 56, 53, 57, 58, 59, 57, 59, 60, 61, 62, 63, 61, 64, 62, 65, 66, 67, 67, 68, 65, 69, 70, 71, 71, 72, 69, 73, 74, 75, 75, 76, 73, 77, 78, 79, 78, 77, 80, 81, 82, 83, 81, 84, 82, 85, 86, 87, 88, 86, 85, 85, 87, 89, 89, 87, 88, 85, 90, 88, 89, 88, 90, 91, 92, 93, 93, 92, 94, 93, 95, 91, 94, 91, 95, 93, 94, 96, 95, 96, 94
            };

            var stair = new BEPUphysics.BroadPhaseEntries.StaticMesh(vertices, indices, new BEPUutilities.AffineTransform(new BEPUutilities.Vector3(0.5f, 0.5f, 0.5f), BEPUutilities.Quaternion.Identity, new BEPUutilities.Vector3(0, 0, 0)));
            space.Add(stair);


            space.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0);
#endif
        }
コード例 #5
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            CurrentProject.GraphicsDevice = GraphicsDevice;
            CurrentProject.SkyboxShader.LoadShader(Content, GraphicsDevice);
            CurrentProject.TexturedMeshShader.LoadShader(Content, GraphicsDevice);
            CurrentProject.BasicColorShader.LoadShader(Content, GraphicsDevice);
            CurrentProject.Resolution = new Vector2(800, 600);

            CurrentProject.BasicColorShader.LoadShader(Content, GraphicsDevice);
            Skybox.Load(Content);

            Space = new BEPUphysics.Space();
            Space.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9f, 0);
            Space.ForceUpdater.Enabled = true;

            Map.Load(Content);
            MapVisible.Load(Content);
            SetDefaultSkinmeshLightning(MapVisible.Model);
            Map.PhysicsInitialize(Space);

            StairsVisible.Load(Content);
            SetDefaultSkinmeshLightning(StairsVisible.Model);
            Stairs.Load(Content);
            Stairs.PhysicsInitialize(Space);

            Teapot.Load(Content);
            Cup.Load(Content);

            Camera.PhysicsInitialize(Space);
            Skybox.LinkCamera(Camera);

            DefaultFont = Content.Load <SpriteFont>("Font");

            RenderTargetMap = new RenderTarget2D(GraphicsDevice, 800, 480, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);

            NonEuclideanRenders = new RenderTarget2D[10];
            for (int i = 0; i < 10; i++)
            {
                NonEuclideanRenders[i] = new RenderTarget2D(GraphicsDevice, 800, 480, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);
            }

            StairsCol2.Load(Content);

            illusion2plane = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 6, BufferUsage.None);
            illusion2plane.SetData(new VertexPositionColor[]
            {
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -13.46f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -15.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -13.46f), Color.Red),

                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -15.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -15.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -13.46f), Color.Red),
            });

            illusion3plane = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 6, BufferUsage.None);
            illusion3plane.SetData(new VertexPositionColor[]
            {
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -18.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -21.00f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -18.73f), Color.Red),

                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -21.00f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -21.00f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -18.73f), Color.Red),
            });

            RoomIllusion1.Load(Content);
            SetDefaultSkinmeshLightning(RoomIllusion1.Model);

            NonEuclideanRenderFunctions.LoadSepShader(Content);

            pblack = new Texture2D(GraphicsDevice, 1, 1);
            pblack.SetData(new Color[] { Color.Black });
        }
コード例 #6
0
ファイル: DecalQB.cs プロジェクト: scotttorgeson/HeroesOfRock
        public override void PreLoadInit(ParameterSet Parm)
        {
            decalsWorld = new BEPUphysics.Space();

            ActorQB actorQB = Stage.LoadingStage.GetQB<ActorQB>();
            actorQB.RegisterActorCreatedFunction(AddToDecalWorld);
        }
コード例 #7
0
ファイル: DecalQB.cs プロジェクト: scotttorgeson/HeroesOfRock
        public override void KillInstance()
        {
            if (decals != null)
            {
                decals.Clear();
                decals = null;
            }

            if (decalsWorld != null)
            {
                decalsWorld.Dispose();
                decalsWorld = null;
            }
        }
コード例 #8
0
 private void Awake()
 {
     m_space = new BEPUphysics.Space();
     m_space.ForceUpdater.gravity = m_gravity;
 }