예제 #1
0
        public void Initialize(asgCameraMode mode, asgPlayerActor player, float cameraForce, Vector2 targetOffset)
        {
            cameraMode = mode;
            this.cameraForce = cameraForce;
            if (gxtDisplayManager.SingletonIsInitialized)
            {
                gxtDisplayManager.Singleton.resolutionChanged += OnResolutionChanged;
            }

            gxtOBB tmp = Camera.GetViewOBB();
            cameraSafeZone = new gxtOBB(tmp.Position, tmp.Extents * 0.8f, tmp.Rotation);
            if (gxtDisplayManager.SingletonIsInitialized)
            {
                gxtDisplayManager.Singleton.resolutionChanged += OnResolutionChanged;
            }

            // cameraSpeed is in screen space
            cameraSpeed = 3.0f;
            cameraBody = new gxtRigidBody();
            cameraBody.MotionType = gxtRigidyBodyMotion.DYNAMIC;
            cameraBody.AngularDamping = 1.0f;
            cameraBody.Damping = 1.0f;
            cameraBody.IgnoreGravity = true;
            cameraBody.Mass = 2.0f;
            cameraBody.CanSleep = false;
            cameraBody.Awake = true;
            player.World.AddRigidBody(cameraBody);

            this.player = player;
            this.offset = targetOffset;
        }
예제 #2
0
        public override void Initialize(bool setupDebugDrawing = true)
        {
            base.Initialize();
            world = new gxtWorld();
            world.Initialize(true, "ASG Prototype");
            gxtDisplayManager.Singleton.WindowTitle = "ASG Prototype";
            if (setupDebugDrawing)
            {
                if (gxtDebugDrawer.SingletonIsInitialized)
                {
                    debugDrawId = gxtDebugDrawer.Singleton.GetNewId();
                    gxtDebugDrawer.Singleton.AddSceneGraph(debugDrawId, world.SceneGraph);
                    gxtDebugDrawer.Singleton.DebugFont = gxtResourceManager.Singleton.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>("Fonts\\debug_font");
                }
                else
                {
                    gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "Cannot Set Up Debug Drawing For The Gameplay Screen Because the Debug Drawer Has Not Been Initialized");
                }
            }

            gxtLog.WriteLineV(gxtVerbosityLevel.SUCCESS, "Initialized GXT World \"{0}\"", world.Name);

            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Populating world...");
            world.PhysicsWorld.AddCollisionGroupName("player", gxtCollisionGroup.GROUP1);
            world.PhysicsWorld.AddCollisionGroupName("traversable_world_geometry", gxtCollisionGroup.GROUP2);

            // setup player
            asgPlayerActor player = new asgPlayerActor(world);
            player.Initialize(Vector2.Zero, 6.5f);
            world.AddActor(player);

            // player controller
            asgPlayerController playerController = new asgPlayerController();
            playerController.Initialize(player);
            world.AddController(playerController);

            // camera controller
            asgCameraController cameraController = new asgCameraController(world.Camera);
            cameraController.Initialize(asgCameraMode.AUTONOMOUS, player, 1.0f, new Vector2(0.0f, -3.5f));
            world.AddController(cameraController);

            // geoms (platforms and walls)
            gxtPolygon platformPolygon = gxtGeometry.CreateRectanglePolygon(15.0f, 2.0f);
            CreatePlatformGeom(platformPolygon, new Vector2(0.0f, 8.5f));

            // dynamic box
            gxtRigidBody boxBody = new gxtRigidBody();
            boxBody.Mass = 1.0f;
            boxBody.CanSleep = false;
            boxBody.Awake = true;

            gxtPolygon box = gxtGeometry.CreateRectanglePolygon(1.5f, 1.5f);
            gxtGeom boxGeom = new gxtGeom(box, true);
            boxGeom.RigidBody = boxBody;
            boxBody.Inertia = gxtRigidBody.GetInertiaForRectangle(1.5f, 1.5f, boxBody.Mass);
            boxBody.Position = new Vector2(-3.5f, -3.5f);
            world.AddGeom(boxGeom);
            world.AddRigidBody(boxBody);

            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Done populating world...");
        }
예제 #3
0
 private gxtGeom CreatePlatformGeom(gxtPolygon polygon, Vector2 position)
 {
     gxtGeom platGeom = new gxtGeom(polygon, true);
     gxtRigidBody platBody = new gxtRigidBody();
     platBody.MotionType = gxtRigidyBodyMotion.FIXED;
     platBody.CanSleep = false;
     platBody.Awake = true;
     platGeom.RigidBody = platBody;
     gxtPhysicsMaterial mat = new gxtPhysicsMaterial(0.6f, 0.3f);
     platGeom.CollisionGroups = world.PhysicsWorld.GetCollisionGroup("traversable_world_geometry");
     platGeom.CollidesWithGroups = world.PhysicsWorld.GetCollisionGroup("player");
     platGeom.Material = mat;
     platGeom.SetPosition(new Vector2(0.0f, 8.5f));
     world.AddGeom(platGeom);
     return platGeom;
 }
예제 #4
0
        private void InitBodies()
        {
            bodyA = new gxtRigidBody();
            bodyA.CanSleep = false;
            bodyA.Awake = true;
            bodyA.IgnoreGravity = false;
            bodyA.MotionType = gxtRigidyBodyMotion.DYNAMIC;
            bodyA.Mass = 5.15f;
            bodyA.Inertia = gxtRigidBody.GetInertiaForPolygon(geomA.Polygon, bodyA.Mass);//gxtRigidBody.GetInertiaForRectangle(geomA.LocalAABB.Width, geomA.LocalAABB.Height, bodyA.Mass) + gxtRigidBody.GetInertiaForRectangle(geomB.LocalAABB.Width, geomB.LocalAABB.Height, bodyA.Mass); //gxtRigidBody.GetInertiaForPolygon(geomA.Polygon, bodyA.Mass);
            geomA.RigidBody = bodyA;
            //geomB.RigidBody = bodyA;
            bodyA.Position = new Vector2(0, 0);
            bodyA.Damping = 0.999815f;
            bodyA.AngularDamping = 0.99615f;
            //bodyA.Material = material;

            bodyF = new gxtRigidBody();
            bodyF.CanSleep = false;
            bodyF.Awake = true;
            bodyF.IgnoreGravity = true;
            bodyF.MotionType = gxtRigidyBodyMotion.DYNAMIC;
            bodyF.Mass = 1.0f;
            float inertiaRect = gxtRigidBody.GetInertiaForRectangle(geomF.LocalAABB.Width, geomF.LocalAABB.Height, bodyF.Mass); //gxtRigidBody.GetInertiaForPolygon(geomA.Polygon, bodyA.Mass);
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Rectangle Inertia: {0}", inertiaRect);
            float polyInertia = gxtRigidBody.GetInertiaForPolygon(geomF.Polygon, bodyF.Mass);
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Polygon Inertia: {0}", polyInertia);
            float circleInertia = gxtRigidBody.GetInertiaForCircle(2.0f, bodyF.Mass);
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Circle Inertia: {0}", circleInertia);
            bodyF.Inertia = polyInertia;
            bodyF.FixedRotation = true;
            //bodyF.Inertia = 0.0f;
            geomF.RigidBody = bodyF;
            bodyF.Position = new Vector2(-7.5f, -3.15f);
            bodyF.Damping = 0.999815f;
            bodyF.AngularDamping = 0.99615f;
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Body F I: {0}, invI: {1}", bodyF.Inertia, bodyF.InverseInertia);
            //bodyF.Material = material;

            floorRB = new gxtRigidBody();
            floorRB.MotionType = gxtRigidyBodyMotion.FIXED;
            floorRB.CanSleep = false;
            floorRB.Awake = true;
            floorRB.IgnoreGravity = true;
            floorRB.Mass = 2.0f;
            floorRB.Position = new Vector2(0.0f, 10.25f);
            //floorRB.Material = material;
            floorRB.Inertia = gxtRigidBody.GetInertiaForRectangle(20, 4.5f, 2.0f);
            //floorG.RigidBody = floorRB;

            /*
            bodyB = new gxtRigidBody();
            bodyB.CanSleep = false;
            bodyB.Awake = true;
            bodyB.IgnoreGravity = true;
            bodyB.MotionType = gxtRigidyBodyMotion.FIXED;
            bodyB.Mass = 5.0f;
            geomB.RigidBody = bodyB;
            bodyB.Position = new Vector2(0, 250);
            bodyB.Material = material;
            */

            bodyC = new gxtRigidBody();
            bodyC.CanSleep = false;
            bodyC.Awake = true;
            bodyC.IgnoreGravity = true;
            bodyC.MotionType = gxtRigidyBodyMotion.FIXED;
            bodyC.Mass = 5.0f;
            bodyC.FixedRotation = true;
            geomC.RigidBody = bodyC;
            bodyC.Position = new Vector2(4.5f, 2.85f);

            bodyD = new gxtRigidBody();
            bodyD.CanSleep = false;
            bodyD.Awake = true;
            bodyD.IgnoreGravity = false;
            bodyD.MotionType = gxtRigidyBodyMotion.DYNAMIC;
            bodyD.Mass = 2.0f;
            geomD.RigidBody = bodyD;
            bodyD.Inertia = gxtRigidBody.GetInertiaForRectangle(2.0f, 2.0f, 2.0f);
            bodyD.Position = new Vector2(0.0f, 4.65f);
            //bodyD.Material = material;

            /*
            bodyE = new gxtRigidBody();
            bodyE.CanSleep = false;
            bodyE.Awake = true;
            bodyE.IgnoreGravity = true;
            bodyE.MotionType = gxtRigidyBodyMotion.FIXED;
            bodyE.Mass = 5.0f;
            geomE.RigidBody = bodyE;
            bodyE.Position = new Vector2(110, -175);
            bodyE.Material = material;
            */
            world.AddRigidBody(bodyA);
            world.AddRigidBody(floorRB);

            /*
            world.AddRigidBody(bodyB);
            world.AddRigidBody(bodyC);
            */
            world.AddRigidBody(bodyD);
            //world.AddRigidBody(bodyE);

            world.AddRigidBody(bodyF);
        }
예제 #5
0
파일: asgPlayerActor.cs 프로젝트: Loko/GXT
        public void Initialize(Vector2 initPos, float speed = 3.0f, float maxSpeed = 500.0f)
        {
            hashedString = new gxtHashedString("player_actor");
            this.position = initPos;
            this.rotation = 0.0f; // if we were to take a rotation be sure to use gxtMath.WrapAngle(initRot)
            MoveSpeed = speed;
            MaxSpeed = maxSpeed;

            this.clipMode = asgClipMode.NORMAL;
            // in physics world units
            // setup body
            playerBody = new gxtRigidBody();
            playerBody.Mass = 2.0f;
            playerBody.CanSleep = false;    // should NEVER go to sleep
            playerBody.Awake = true;
            playerBody.FixedRotation = true;
            playerBody.IgnoreGravity = false;
            playerBody.Position = position;
            playerBody.Rotation = rotation;
            world.AddRigidBody(playerBody);

            // setup geom
            //playerPolygon = gxtGeometry.CreateRectanglePolygon(2, 3.5f);
            playerPolygon = gxtGeometry.CreateRoundedRectanglePolygon(2.0f, 3.5f, 0.45f, 0.05f);
            //playerPolygon = gxtGeometry.CreateEllipsePolygon(1.0f, 1.75f, 20);
            //playerPolygon = gxtGeometry.CreateCapsulePolygon(3.0f, 1.0f, 8);
            //playerPolygon = gxtGeometry.CreateCirclePolygon(3.0f, 3);
            playerGeom = new gxtGeom(playerPolygon, position, rotation);
            playerGeom.Tag = this;
            playerGeom.CollidesWithGroups = world.PhysicsWorld.GetCollisionGroup("traversable_world_geometry");
            playerGeom.CollisionGroups = world.PhysicsWorld.GetCollisionGroup("player");
            playerGeom.RigidBody = playerBody;
            playerGeom.OnCollision += OnCollision;
            playerGeom.OnSeperation += OnSeperation;
            world.PhysicsWorld.AddGeom(playerGeom);

            // setup scene node
            // for now we'll just use a line loop but programming it
            // this way makes it easy to swap out for something like a skeleton
            // or a texture later down the road
            scenePoly = gxtPolygon.Copy(playerPolygon);
            scenePoly.Scale(gxtPhysicsWorld.PHYSICS_SCALE);
            //playerEntity = new gxtLineLoop(scenePoly.v);

            // setup drawable
            //playerDrawable = new gxtDrawable(playerEntity, Color.Yellow, true, 0.1f);
            playerSceneNode = new gxtSceneNode();
            playerSceneNode.Position = playerBody.Position;
            //playerSceneNode.AttachDrawable(playerDrawable);
            //world.AddSceneNode(playerSceneNode);

            // setup raycatsing logic
            rayCastTimer = new gxtStopWatch(true);
            world.AddProcess(rayCastTimer);
            raycasts = new List<gxtRayHit>();

            clipMode = asgClipMode.NORMAL;
            this.halfHeight = playerGeom.LocalAABB.Height * 0.5f;
        }
예제 #6
0
        private void InitBodies()
        {
            bodies = new List<gxtRigidBody>();

            playerBody = new gxtRigidBody();
            playerBody.CanSleep = true;
            playerBody.Awake = true;
            playerBody.IgnoreGravity = false;
            playerBody.MotionType = gxtRigidyBodyMotion.DYNAMIC;
            playerBody.Mass = 3.0f;
            playerBody.Inertia = gxtRigidBody.GetInertiaForRectangle(playerGeom.LocalAABB.Width, playerGeom.LocalAABB.Height, playerBody.Mass);
            playerGeom.RigidBody = playerBody;
            playerBody.Position = new Vector2(150, -100);
            playerBody.Damping = 1.0f;

            gxtRigidBody floorBody = new gxtRigidBody();
            floorBody.CanSleep = true;
            floorBody.Awake = false;
            floorBody.IgnoreGravity = true;
            floorBody.MotionType = gxtRigidyBodyMotion.FIXED;
            floorBody.Mass = 20.0f;
            floorBody.Inertia = gxtRigidBody.GetInertiaForRectangle(playerGeom.LocalAABB.Width, playerGeom.LocalAABB.Height, playerBody.Mass);
            geoms[0].RigidBody = floorBody;
            floorBody.Position = new Vector2(0, 200);
            floorBody.Damping = 1.0f;
            //floorBody.Material = new gxtPhysicsMaterial(0.65f, 0.1f);

            world.AddRigidBody(playerBody);
            world.AddRigidBody(floorBody);
            bodies.Add(floorBody);
        }
예제 #7
0
        private void CreateGeom(Vector2 min, Vector2 max, float density)
        {
            gxtGeom g = new gxtGeom();
            g.CollidesWithGroups = gxtCollisionGroup.ALL;
            g.CollisionEnabled = true;
            g.CollisionGroups = gxtCollisionGroup.ALL;
            g.CollisionResponseEnabled = true;
            g.Polygon = gxtGeometry.CreateRectanglePolygon(max.X - min.X, max.Y - min.Y);
            g.Material = new gxtPhysicsMaterial(0.85f, 0.45f);

            gxtRigidBody b = new gxtRigidBody();
            b.IgnoreGravity = false;
            b.Mass = density * g.Polygon.GetArea();
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "mass: {0}", b.Mass);
            b.Inertia = gxtRigidBody.GetInertiaForRectangle(max.X - min.X, max.Y - min.Y, b.Mass);
            b.MotionType = gxtRigidyBodyMotion.DYNAMIC;
            //b.Material = new gxtPhysicsMaterial(0.85f, 0.45f);
            b.Position = ((min + max) * 0.5f);
            b.Damping = 0.9995f;

            g.RigidBody = b;

            geoms.Add(g);
            bodies.Add(b);
            world.AddGeom(g);
            world.AddRigidBody(b);
        }
예제 #8
0
파일: RayTestGame.cs 프로젝트: Loko/GXT
        private void InitBodies()
        {
            bodyA = new gxtRigidBody();
            bodyA.CanSleep = true;
            bodyA.Awake = true;
            bodyA.IgnoreGravity = true;
            bodyA.MotionType = gxtRigidyBodyMotion.DYNAMIC;
            bodyA.Mass = 1.0f;
            bodyA.Inertia = gxtRigidBody.GetInertiaForRectangle(geomA.LocalAABB.Width, geomA.LocalAABB.Height, bodyA.Mass);
            geomA.RigidBody = bodyA;
            bodyA.Position = new Vector2(150, -100);


            bodyB = new gxtRigidBody();
            bodyB.CanSleep = false;
            bodyB.Awake = true;
            bodyB.IgnoreGravity = true;
            bodyB.MotionType = gxtRigidyBodyMotion.FIXED;
            bodyB.Mass = 5.0f;
            geomB.RigidBody = bodyB;
            bodyB.Position = new Vector2(0, 250);

            world.AddRigidBody(bodyA);
            world.AddRigidBody(bodyB);
        }
예제 #9
0
파일: gxtWorld.cs 프로젝트: Loko/GXT
 public void RemoveRigidBody(gxtRigidBody body)
 {
     physicsWorld.RemoveBody(body);
 }
예제 #10
0
파일: gxtWorld.cs 프로젝트: Loko/GXT
 public void AddRigidBody(gxtRigidBody body)
 {
     physicsWorld.AddBody(body);
 }
예제 #11
0
파일: gxtSolver.cs 프로젝트: Loko/GXT
 private static float GetCombinedRestitution(gxtRigidBody bodyA, gxtRigidBody bodyB)
 {
     if (frictionType == gxtFrictionType.AVERAGE)
         return gxtMath.Sqrt(bodyA.GetRestitution() * bodyB.GetRestitution());
     else
         return gxtMath.Min(bodyA.GetFriction(), bodyB.GetFriction());
 }
예제 #12
0
파일: gxtPhysicsWorld.cs 프로젝트: Loko/GXT
        public void RemoveBody(gxtRigidBody body)
        {
            gxtDebug.SlowAssert(!body_remove_list.Contains(body));

            if (!body_remove_list.Contains(body))
                body_remove_list.Add(body);
        }
예제 #13
0
파일: gxtPhysicsWorld.cs 프로젝트: Loko/GXT
        public void AddBody(gxtRigidBody body)
        {
            gxtDebug.SlowAssert(!body_add_list.Contains(body));

            if (!body_add_list.Contains(body))
                body_add_list.Add(body);
        }