// Use this for initialization
        public void Init()
        {
            ChecksumExtractor.Init(this);

            gameObjectMap = new Dictionary <IBody, GameObject>();
            collisionInfo = new Dictionary <RigidBody, Dictionary <RigidBody, TSCollision> >();

            CollisionSystemPersistentSAP collisionSystem = new CollisionSystemPersistentSAP();

            collisionSystem.EnableSpeculativeContacts = SpeculativeContacts;

            world = new World(collisionSystem);
            collisionSystem.world = world;

            world.physicsManager = this;
            world.Gravity        = Gravity;

            world.Events.BodiesBeginCollide += CollisionEnter;
            world.Events.BodiesStayCollide  += CollisionStay;
            world.Events.BodiesEndCollide   += CollisionExit;

            world.Events.TriggerBeginCollide += TriggerEnter;
            world.Events.TriggerStayCollide  += TriggerStay;
            world.Events.TriggerEndCollide   += TriggerExit;

            world.Events.RemovedRigidBody += OnRemovedRigidBody;

            instance = this;

            AddRigidBodies();
        }
Example #2
0
        //private bool debugDraw = false;

        public JitterDemo()
        {
            this.IsMouseVisible = true;
            graphics            = new GraphicsDeviceManager(this);

            graphics.PreferMultiSampling = true;

            Content.RootDirectory = "Content";

            // 720p
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth  = 1280;

            this.IsFixedTimeStep   = false;
            this.TargetElapsedTime = TimeSpan.FromSeconds(1.0 / 100.0);
            this.graphics.SynchronizeWithVerticalRetrace = false;

            CollisionSystem collision = new CollisionSystemPersistentSAP();

            collision.EnableSpeculativeContacts = false;
            World = new World(collision); World.AllowDeactivation = false;

            this.Window.AllowUserResizing = true;

            this.Window.Title = "Jitter 2D Physics Demo - Jitter 2D "
                                + Assembly.GetAssembly(typeof(Jitter2D.World)).GetName().Version.ToString();
        }
        public PhysicsShadowWorld(
            IEventEngine <IPhysicsEventContext> physicsEventEngine,
            IHierarchy hierarchy,
            IDebugRenderer debugRenderer,
            IConsoleHandle consoleHandle)
        {
            _physicsEventEngine = physicsEventEngine;
            _hierarchy          = hierarchy;
            _debugRenderer      = debugRenderer;
            _consoleHandle      = consoleHandle;

            var collisionSystem = new CollisionSystemPersistentSAP
            {
                EnableSpeculativeContacts = true
            };

            _physicsWorld = new JitterWorld(collisionSystem);
            _physicsWorld.ContactSettings.MaterialCoefficientMixing =
                ContactSettings.MaterialCoefficientMixingType.TakeMinimum;

            _physicsWorld.Gravity = new JVector(0, -10f, 0);

            _rigidBodyMappings = new List <RigidBodyMapping>();

            _lastFramePosition = new Dictionary <int, Vector3>();
            _lastFrameRotation = new Dictionary <int, Quaternion>();
            _transformCache    = new Dictionary <int, WeakReference <IHasTransform> >();

            _physicsWorld.Events.BodiesBeginCollide += EventsOnBodiesBeginCollide;
            _physicsWorld.Events.BodiesEndCollide   += EventsOnBodiesEndCollide;
        }
Example #4
0
        static public void loadWorld()
        {
            CollisionSystem collision = new CollisionSystemPersistentSAP();

            world = new World(collision);

            string mapName = Botv2.Utilities.GameHelper.getMapName();
            string mapPath = Path.GetDirectoryName(Bot.process.Modules[0].FileName) + "/csgo/maps/" + mapName;

            FileStream stream = File.OpenRead(mapPath);
            BSP        map    = new BSP(stream);

            List <Vector3>  vertices = map.getVertices();
            List <ushort[]> edges    = map.getEdges();
            List <Face>     faces    = map.getOriginalFaces();

            map.getFaces();
            int[] surfedges   = map.getSurfedges();
            int[] textureData = map.getTextureInfo();

            stream.Close();

            for (int i = 0; i < faces.Count; i++)
            {
                Face                       face      = faces[i];
                List <JVector>             jVertices = new List <JVector>();
                List <VertexPositionColor> temp      = new List <VertexPositionColor>();

                for (int b = 0; b <= face.numEdges; b++)
                {
                    if (surfedges[face.firstEdge + b] < 0)
                    {
                        temp.Add(new VertexPositionColor(vertices[(int)edges[Math.Abs(surfedges[face.firstEdge + b])][0]], Color.LightGray));
                        temp.Add(new VertexPositionColor(vertices[(int)edges[Math.Abs(surfedges[face.firstEdge + b])][1]], Color.LightGray));
                        continue;
                    }

                    int edgeIndex  = Math.Abs(surfedges[face.firstEdge + b]);
                    int verticeOne = edges[edgeIndex][1];
                    int verticeTwo = edges[edgeIndex][0];

                    temp.Add(new VertexPositionColor(vertices[verticeOne], Color.LightGray));
                    temp.Add(new VertexPositionColor(vertices[verticeTwo], Color.LightGray));
                }

                foreach (VertexPositionColor v in temp)
                {
                    jVertices.Add(new JVector(v.Position.X, v.Position.Y, v.Position.Z));
                }
                RigidBody rigBody = new RigidBody(new ConvexHullShape(jVertices));

                world.AddBody(rigBody);
            }
        }
Example #5
0
        //******************************************
        //physics***********************************
        //******************************************
        public virtual void IniPhysicsSystem()
        {
            DxPhysicsSystem();

            CollisionSystem collisionSystem = new CollisionSystemPersistentSAP();

            //collisionSystem.EnableSpeculativeContacts = true;//!*

            _physicsSystem = new World(collisionSystem);

            _physicsSystem.AllowDeactivation = true;
        }
Example #6
0
        public JitterDemo()
        {
            this.IsMouseVisible = true;
            graphics            = new GraphicsDeviceManager(this);

            graphics.GraphicsProfile     = GraphicsProfile.HiDef;
            graphics.PreferMultiSampling = true;

            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth  = 800;

            this.IsFixedTimeStep = false;
            this.graphics.SynchronizeWithVerticalRetrace = false;

            CollisionSystem collision = new CollisionSystemPersistentSAP();

            World = new World(collision); World.AllowDeactivation = true;

            //World.ContactSettings.


            this.Window.AllowUserResizing = true;

#if (WINDOWS)
            this.Window.Title = "Jitter Physics Demo - Jitter "
                                + Assembly.GetAssembly(typeof(Jitter.World)).GetName().Version.ToString();
#else
            this.Window.Title = "Jitter Physics Demo - Jitter";
#endif


            Random rr = new Random();
            rndColors = new Color[20];

            for (int i = 0; i < 20; i++)
            {
                rndColors[i] = new Color((float)rr.NextDouble(), (float)rr.NextDouble(), (float)rr.NextDouble());
            }


            wireframe          = new RasterizerState();
            wireframe.FillMode = FillMode.WireFrame;

            cullMode          = new RasterizerState();
            cullMode.CullMode = CullMode.None;


            normal = new RasterizerState();
        }
Example #7
0
        /// <summary>
        /// Loads the board's content-
        /// </summary>
        /// <param name="device">GraphicsDevice</param>
        /// <param name="content">ContentManager</param>
        public void LoadContent(GraphicsDevice device, ContentManager content)
        {
            //Load sounds
            rollEffect = content.Load <SoundEffect>("roll1");

            placeEffects = new SoundEffect[3];
            //placeEffects[0] = content.Load<SoundEffect>("place1");
            //placeEffects[1] = content.Load<SoundEffect>("place2");
            //placeEffects[2] = content.Load<SoundEffect>("place3");

            Texture2D[] dieTextures = new Texture2D[6]
            {
                Legacy.LoadTexture(device, "die1"),
                Legacy.LoadTexture(device, "die6"),
                Legacy.LoadTexture(device, "die3"),
                Legacy.LoadTexture(device, "die4"),
                Legacy.LoadTexture(device, "die5"),
                Legacy.LoadTexture(device, "die2")
            };


            CollisionSystem sap = new CollisionSystemPersistentSAP();

            world = new World(sap);
            world.SetDampingFactors(1.0f, 1.0f);
            sap.CollisionDetected += OnCollisionDetected;
            world.Gravity          = new JVector(0, -9.8f * 5, 0f);

            RigidBody board = new RigidBody(new BoxShape(new JVector(1000, 25, 1000)));

            board.Position = new JVector(0, -25, 0);
            board.IsStatic = true;
            world.AddBody(board);

            die1Body          = new RigidBody(new BoxShape(new JVector(1.5875f)));
            die1Body.Mass     = 5.8f;
            die1Body.IsStatic = true; //Temporary
            die1Body.Position = new JVector(-15, 60, 0);
            world.AddBody(die1Body);

            die2Body          = new RigidBody(new BoxShape(new JVector(1.5875f)));
            die2Body.Mass     = 5.8f;
            die2Body.IsStatic = true; //Temporary
            die2Body.Position = new JVector(15, 60, 0);
            world.AddBody(die2Body);

            die1Entity = new Prism(device, die1Body, dieTextures);
            die2Entity = new Prism(device, die2Body, dieTextures);
        }
Example #8
0
        /// <summary>
        /// Initialize the physics with the collision-setup
        /// </summary>
        private PhysicsManager()
        {
            CollisionSystem collision = new CollisionSystemPersistentSAP();

            // Initialization of physic-settings
            World = new World(collision)
            {
                AllowDeactivation = true,
                Gravity           = new JVector(0, -20, 0)
            };

            // Event-handling
            World.Events.BodiesBeginCollide += Events_BodiesBeginCollide;
            World.Events.BodiesEndCollide   += Events_BodiesEndCollide;
            World.Events.ContactCreated     += Events_ContactCreated;
        }
Example #9
0
        void CreateWorld()
        {
            CollisionSystem collision = null;

            switch (settings.CollisionSystem.CollisionSystem)
            {
            case JSettings.CollisionSystemEnum.SAP: collision = new CollisionSystemSAP(); break;

            case JSettings.CollisionSystemEnum.PersistentSAP: collision = new CollisionSystemPersistentSAP(); break;

            case JSettings.CollisionSystemEnum.Brute: collision = new CollisionSystemBrute(); break;
            }
            collision.EnableSpeculativeContacts = settings.CollisionSystem.EnableSpeculativeContacts;
            World = new World(collision);
            World.SetInactivityThreshold(settings.InactivityThreshold.MinAngularVelocity,
                                         settings.InactivityThreshold.MinLinearVelocity,
                                         settings.InactivityThreshold.MinSleepingTime);
            World.AllowDeactivation           = settings.World.AllowDeactivation;
            Multithread                       = settings.Multithread.Mode;
            ThreadManager.ThreadsPerProcessor = settings.Multithread.ThreadsPerProcessor;
            timestep = settings.World.Timestep;
            JRigidbody.LerpFactor = settings.Rigidbody.LerpFactor;
        }
Example #10
0
 void CreateWorld()
 {
     CollisionSystem collision = null;
     switch (settings.CollisionSystem.CollisionSystem)
     {
         case JSettings.CollisionSystemEnum.SAP: collision = new CollisionSystemSAP(); break;
         case JSettings.CollisionSystemEnum.PersistentSAP: collision = new CollisionSystemPersistentSAP(); break;
         case JSettings.CollisionSystemEnum.Brute: collision = new CollisionSystemBrute(); break;
     }
     collision.EnableSpeculativeContacts = settings.CollisionSystem.EnableSpeculativeContacts;
     World = new World(collision);
     World.SetInactivityThreshold(settings.InactivityThreshold.MinAngularVelocity,
                                     settings.InactivityThreshold.MinLinearVelocity,
                                             settings.InactivityThreshold.MinSleepingTime);
     World.AllowDeactivation = settings.World.AllowDeactivation;
     Multithread = settings.Multithread.Mode;
     ThreadManager.ThreadsPerProcessor = settings.Multithread.ThreadsPerProcessor;
     timestep = settings.World.Timestep;
     JRigidbody.LerpFactor = settings.Rigidbody.LerpFactor;
 }
        float far;         // = 100f; // the far clipping plane distance



        public JitterDemo()
        {
            this.IsMouseVisible = false;
            graphics            = new GraphicsDeviceManager(this);

            //graphics.PreferredBackBufferWidth = 800;
            //graphics.PreferredBackBufferHeight = 600;
            //graphics.GraphicsProfile = GraphicsProfile.HiDef;
            //graphics.SynchronizeWithVerticalRetrace = false;

            graphics.GraphicsProfile     = GraphicsProfile.HiDef;
            graphics.PreferMultiSampling = true;

            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth  = 800;

            this.IsFixedTimeStep = false;
            this.graphics.SynchronizeWithVerticalRetrace = false;

            CollisionSystem collision = new CollisionSystemPersistentSAP();

            World = new World(collision);
            World.AllowDeactivation = true;
            World.SetIterations(3, 3);
            World.Gravity = new JVector(0, -9.81f, 0);
            World.ContactSettings.AllowedPenetration = 0.01f;
            this.Window.AllowUserResizing            = true;

#if (WINDOWS)
            this.Window.Title = "Jitter Physics Demo - Jitter "
                                + Assembly.GetAssembly(typeof(Jitter.World)).GetName().Version.ToString();
#else
            this.Window.Title = "Jitter Physics Demo - Jitter";
#endif


            Random rr = new Random();
            rndColors = new Color[20];

            for (int i = 0; i < 20; i++)
            {
                rndColors[i] = new Color((float)rr.NextDouble(), (float)rr.NextDouble(), (float)rr.NextDouble());
            }


            wireframe          = new RasterizerState();
            wireframe.FillMode = FillMode.WireFrame;

            cullMode          = new RasterizerState();
            cullMode.CullMode = CullMode.None;


            normal = new RasterizerState();


            float rad = sc_maths.DegreeToRadian(180);

            Matrix playerRot = Matrix.CreateRotationY(rad);


            playerMatrix    *= playerRot;
            playerMatrix.M42 = 10;

            /*if (startOVRDrawThread == 0)
             * {
             *  Thread main_thread_update = new Thread(() =>
             *  {
             *      OculusRift rift = new OculusRift();
             *      RenderTarget2D[] renderTargetEye = new RenderTarget2D[2];
             *      // initialize the Rift
             *
             *  _thread_looper:
             *
             *      try
             *      {
             *          if (hasInit == 1)
             *          {
             *              int result = rift.Init(GraphicsDevice);
             *
             *              if (result != 0)
             *              {
             *                  throw new InvalidOperationException("rift.Init result: " + result);
             *              }
             *              for (int eye = 0; eye < 2; eye++)
             *              {
             *                  renderTargetEye[eye] = rift.CreateRenderTargetForEye(eye);
             *              }
             *
             *              hasInit = 2;
             *          }
             *
             *          if (hasInit == 2)
             *          {
             *
             *              for (int eye = 0; eye < 2; eye++)
             *              {
             *                  activeBodies = 0;
             *
             *                  /*GraphicsDevice.SetRenderTarget(renderTargetEye[eye]);
             *                  GraphicsDevice.Clear(Color.CornflowerBlue);
             *
             *                  GraphicsDevice.BlendState = BlendState.Opaque;
             *                  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
             *
             *              }
             *
             *              result = rift.SubmitRenderTargets(renderTargetEye[0], renderTargetEye[1]);
             *
             *          }
             *      }
             *      catch (Exception ex)
             *      {
             *
             *      }
             *      Thread.Sleep(0);
             *      goto _thread_looper;
             *
             *      //ShutDown();
             *      //ShutDownGraphics();
             *
             *  }, 0);
             *
             *  main_thread_update.IsBackground = true;
             *  main_thread_update.SetApartmentState(ApartmentState.STA);
             *  main_thread_update.Start();
             *  startOVRDrawThread = 1;
             * }*/
        }