CollisionSystem. Used by the world class to detect all collisions. Can be used seperatly from the physics.
コード例 #1
0
ファイル: Game1.cs プロジェクト: scy7he/Pong
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            collisionSystem = new CollisionSystemPersistentSAP();
            collisionSystem.CollisionDetected += new CollisionDetectedHandler(CollisionDetected);

            world = new World(collisionSystem);

            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();
        }
コード例 #2
0
ファイル: JDBaconTheGame.cs プロジェクト: jmdjr/jd-bacon
        /// <summary>
        /// The main game constructor.
        /// </summary>
        public JDBaconTheGame()
        {
            Content.RootDirectory = "Content";
            this.IsFixedTimeStep = false;
            this.Window.AllowUserResizing = true;

            graphics = new GraphicsDeviceManager(this);
            graphics.GraphicsProfile = GraphicsProfile.HiDef;
            graphics.SynchronizeWithVerticalRetrace = false;
            graphics.PreferMultiSampling = true;
            graphics.PreferredBackBufferWidth = 840;
            graphics.PreferredBackBufferHeight = 480;

            // Establishing JDBTG object instances.
            JDBTG.MusicManager = new EasyXnaAudioComponent(this, "Assets/Audio");
            // Create the screen manager component.
            screenManager = new ScreenManager(this);

            // Activate the first screens.
            screenManager.AddScreen(new BackgroundScreen(), null);
            screenManager.AddScreen(new MainMenuScreen(), null);

            Collision = new CollisionSystemPersistentSAP();

            World = new World(Collision);
            World.AllowDeactivation = true;
            World.Gravity = new JVector(0, -10, 0);

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

            normal = new RasterizerState();

            Components.Add(screenManager);
        }
コード例 #3
0
ファイル: PhysicsManager.cs プロジェクト: AreonDev/NoWayOut
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Core.PhysicsManager"/> class.
        /// </summary>
        /// <param name="collisionSystem">Collision system.</param>
        public PhysicsManager(MessageProvider prov, CollisionSystem collisionSystem = CollisionSystem.SweepAndPrune)
        {
            this.collisionSystem = collisionSystem;

            MessageProvider = prov;

            Jitter.Collision.CollisionSystem system;
            switch (collisionSystem)
            {
                case CollisionSystem.Brute:
                    system = new CollisionSystemBrute();
                    break;
                case CollisionSystem.PersistentSweepAndPrune:
                    system = new CollisionSystemPersistentSAP();
                    break;
                default:
                    system = new CollisionSystemSAP();
                    break;
            }

            MessageProvider += this;

            World = new World(system);

            World.CollisionSystem.CollisionDetected += (Jitter.Dynamics.RigidBody body1, Jitter.Dynamics.RigidBody body2,
                Jitter.LinearMath.JVector point1, Jitter.LinearMath.JVector point2, Jitter.LinearMath.JVector normal, float penetration) => 
            {
                if(MessageCreated != null)
                    MessageCreated(new CollisionDetectedMessage(body1, body2));
            };

            Start();
        }
コード例 #4
0
ファイル: RaycastResult.cs プロジェクト: whztt07/DeltaEngine
		public JitterRaycastResult(CollisionSystem collisionSystem, Ray ray)
		{
			float fraction;
			JVector rayOrigin = JitterDatatypesMapping.Convert(ref ray.Origin);
			JVector rayDirection = JitterDatatypesMapping.Convert(ref ray.Direction);
			Found = collisionSystem.Raycast(rayOrigin, rayDirection, null, out RigidBody,
				out JVectorNormal, out fraction);
			Vector3D surfaceNormal = Vector3D.Zero;
			JitterDatatypesMapping.Convert(ref JVectorNormal, ref surfaceNormal);
			SurfaceNormal = surfaceNormal;
		}
コード例 #5
0
ファイル: SceneGraph.cs プロジェクト: kkestell/nyx-1.0
        /// <summary>
        /// Initializes a new instance of the <see cref="SceneGraph" /> class.
        /// </summary>
        public SceneGraph()
        {
            this.root = new SceneNode();

            this.collisionSystem = new CollisionSystemSAP();
            this.world = new World(this.collisionSystem);
            this.world.Gravity = new JVector(0f, -12f, 0f);

            this.directionalLights = new List<DirectionalLight>();
            this.spotLights = new List<SpotLight>();
            this.pointLights = new List<PointLight>();
            this.renderableObjects = new List<RenderableObject>();

            this.camera = new Camera(this.engine);
        }
コード例 #6
0
ファイル: World.cs プロジェクト: ajmd17/apexengine-sharp
        /// <summary>
        /// Create a new instance of the <see cref="World"/> class.
        /// </summary>
        /// <param name="collision">The collisionSystem which is used to detect
        /// collisions. See for example: <see cref="CollisionSystemSAP"/>
        /// or <see cref="CollisionSystemBrute"/>.
        /// </param>
        public World(CollisionSystem collision)
        {
            if (collision == null)
                throw new ArgumentNullException("The CollisionSystem can't be null.", "collision");

            arbiterCallback = new Action<object>(ArbiterCallback);
            integrateCallback = new Action<object>(IntegrateCallback);

            // Create the readonly wrappers
            this.RigidBodies = new ReadOnlyHashset<RigidBody>(rigidBodies);
            this.Constraints = new ReadOnlyHashset<Constraint>(constraints);
            this.SoftBodies = new ReadOnlyHashset<SoftBody>(softbodies);

            this.CollisionSystem = collision;

            collisionDetectionHandler = new CollisionDetectedHandler(CollisionDetected);

            this.CollisionSystem.CollisionDetected += collisionDetectionHandler;

            this.arbiterMap = new ArbiterMap();

            AllowDeactivation = true;
        }
コード例 #7
0
ファイル: PhysicsSystem.cs プロジェクト: coryleeio/SPShared
 public PhysicsSystem()
     : base(TimeSpan.FromSeconds(TICKS_PER_SECOND), Aspect.All(typeof(ECS.Components.PhysicsBody)))
 {
     collisionSystem = new CollisionSystemSAP();
     world = new World(collisionSystem);
 }