Responsible for the transfer the information to draw.
예제 #1
0
        /// <summary>
        /// Update
        /// </summary>
        protected override void Update(GameTime gameTime)
        {
            // Update game engine
            base.Update(gameTime);

            var controller = XboxController.RetrieveController(0);
            controller.UpdateState();

            if (controller.IsBackPressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            var elapsedGameTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            var input = new PlayerInput();
            HandleInput(ref input, controller);
           
            game.Input(input);
            game.Update(elapsedGameTime);
            frame = game.getPosition();

            CameraPos = new Vector3(frame.Position.X, -frame.Position.Y, CameraPos.Z);

            ViewMatrix = Matrix.CreateLookAt(CameraPos, new Vector3(CameraPos.X, CameraPos.Y, 0), Vector3.Up);

            Window.Title = "GTA2.NET - " + WindowTitle + Fps.ToString(CultureInfo.InvariantCulture) + " fps X: " + CameraPos.X.ToString() + "Y: " + CameraPos.Y.ToString() + "Z: " +CameraPos.Z;
        }
예제 #2
0
파일: GTA2Game.cs 프로젝트: jpires/gta2net
        /// <summary>
        /// Gets the 3D data from map centered in pos.
        /// </summary>
        /// <param name="pos">The center of square</param>
        /// <param name="size">The size of the square</param>
        /// <returns></returns>
        public Frame getPosition(Vector2 pos, uint size = 10)
        {
            Contract.Requires(map.ValidPosition(new Vector3(pos, 2)));

            //ToDo: work the case when some blocks don't exist because they are outside the map. In that case the frontier blocks should be repeated.
            List<VertexPositionNormalTexture> VertexPosList = new List<VertexPositionNormalTexture>();
            List<int> IndexBufferList = new List<int>();

            for (uint i = (uint)pos.X - size; i < pos.X + size; i++)
            {
                for (uint j = (uint)(pos.Y) - size; j < pos.Y + size; j++)
                {
                    for (uint k = 0; k < map.Height; k++)
                    {
                        Block block = map.GetBlock(new Vector3(i, j, k));
                        int idx = 0;
                        foreach (VertexPositionNormalTexture vx in block.Coors)
                        {
                            VertexPosList.Add(vx);
                            idx++;
                        }
                        int c = VertexPosList.Count - idx;
                        foreach (int ib in block.IndexBufferCollection)
                        {
                            IndexBufferList.Add(c + ib);
                        }
                    }
                }
            }

            List<VertexPositionNormalTexture> objectsVertexPosList = new List<VertexPositionNormalTexture>();
            List<int> objectsIndexBufferList = new List<int>();

            foreach (Pedestrian ped in pedList)
            {
                Frame md = ped.Draw();
                int idx = 0;
                foreach (VertexPositionNormalTexture vx in md.ObjectVertexList)
                {
                    objectsVertexPosList.Add(vx);
                    idx++;
                }
                int c = objectsVertexPosList.Count - idx;
                foreach (int ib in md.ObjectIndexList)
                {
                    objectsIndexBufferList.Add(c + ib);
                }

            }

            Frame frame = new Frame(VertexPosList, IndexBufferList, objectsVertexPosList, objectsIndexBufferList, pos);
            if(debugDraw)
            {
                drawer = new DebugDrawer();
                foreach (RigidBody body in _physics.RigidBodiesList)
                {
                    body.DebugDraw(drawer);
                    body.AllowDeactivation = false;
                    body.EnableDebugDraw = true;
                }

                frame.TriangleDebug = drawer.DrawInfo.TriangleDebug;
                frame.LineDebug = drawer.DrawInfo.LineDebug;
            }

            return frame;
        }