Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline bfox  
#1 Posted : Tuesday, November 29, 2011 8:48:18 PM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
Why
//if camera 0 -10 0 TranslationZ 10
if cam.UpdateProjectionMatrix();
//if camera 0 -10 0 TranslationZ 8.1818 ----
i need find point on z = 0 when i zoom unzoom camera;
Code:

        [Test]
        public static void Test2()
        {
            BaseCamera cam = new FreeCamera(new Vector(0, -10, 0));
            cam.Target=new Vector(0, 0, 0);
            cam.FieldOfView = MathHelper.DegreeToRadians(90);
            cam.NearPlane = 1; //work
            cam.FarPlane = 10; //work
            var halfSize = new Vector(3, 3, 3);

            string text;
            Application.Start(delegate
                                  {
                                      Grid.Draw();
                                      text = ScreenSpace.InternalViewProjection3D.Translation.ToString(); //Look after zoom (unzoom)  
                                      //if camera 0 -10 0         TranslationZ   10
                                      //ater
                                      //if camera 0 -10 0         TranslationZ   8.1818 ----
                                       
                                      var point = new Point(0f, 0.5f);
                                      text += "\n Position" + cam.Position;
                                      text += "\n FarPlane" + cam.FarPlane;
                                      text += "\n Point in" + point;
                                      Ray ray = ScreenSpace.GetRayFromScreenPoint(point);
                                      Vector end = ray.Direction + ray.Position;
                                      point = new Point(end.X, end.Z);
                                      text += "\n Point on grid" + point;

                                      Vector vector = ScreenSpace.Project(new Vector(point.X, 0,point.Y));
                                      text += "\n vector" + vector;
                                      
                                      ray = ScreenSpace.GetRayFromScreenPoint(new Point(vector.X, vector.Y));
                                      end = ray.Direction + ray.Position;
                                      point = new Point(end.X, end.Z);
                                      text += "\n 2 Point on grid" + point;

                                      vector = ScreenSpace.Project(new Vector(point.X, 0,point.Y));
                                      text += "\n vector" + vector;
                                    


                                      Font.Default.DrawCentered(text,
                                                                new Point(0.5f, 0.3f));


                                      if (Input.Keyboard.IsReleased(InputButton.A))
                                      {
                                          cam.Position -= new Vector(0, 0.01f, 0);
                                          cam.UpdateProjectionMatrix();
                                          cam.FarPlane = cam.Position.Y;
                                          cam.UpdateProjectionMatrix();
                                      }
                                      if (Input.Keyboard.IsReleased(InputButton.S))
                                      {
                                          cam.Position += new Vector(0,0.01f,0);
                                          cam.UpdateProjectionMatrix();
                                          cam.FarPlane = cam.Position.Y;
                                          cam.UpdateProjectionMatrix();
                                      }
                                  });
        }



Benjamin i need help ThumpUp


Test 2

Code:

        [Test]
        public static void Test3()
        {
            BaseCamera cam = new FreeCamera(new Vector(0, -10, 0));
            cam.Target = new Vector(0, 0, 0);
            cam.FieldOfView = MathHelper.DegreeToRadians(90);
            cam.NearPlane = 1; //work
            cam.FarPlane = 10; //work
            var halfSize = new Vector(3, 3, 3);

            string text = "";
            string text2 = "";
            string text3 = "";
            bool start = false;
            bool zoom = false;
            bool unzoom = false;
            Application.Start(delegate
                                  {
                                      Grid.Draw();
                                      if (!start)
                                      {
                                          text = ScreenSpace.InternalViewProjection3D.Translation.ToString();
                                          start = true;
                                          cam.UpdateProjectionMatrix();
                                          text2 = ScreenSpace.InternalViewProjection3D.Translation.ToString();
                                      }

                                      if (!zoom)
                                      {
                                          cam.Position += new Vector(0, 0.1f, 0);
                                          cam.UpdateProjectionMatrix();
                                          cam.FarPlane = cam.Position.Y;
                                          cam.UpdateProjectionMatrix();
                                          text3 = ScreenSpace.InternalViewProjection3D.Translation.ToString();
                                          zoom = true;
                                      }

                                      if (!unzoom)
                                      {
                                          cam.Position -= new Vector(0, 0.1f, 0);
                                          cam.UpdateProjectionMatrix();
                                          cam.FarPlane = cam.Position.Y;
                                          cam.UpdateProjectionMatrix();
                                          text3 = ScreenSpace.InternalViewProjection3D.Translation.ToString();
                                          unzoom = true;
                                      }

                                      Font.Default.DrawCentered(text + "\n" + text2 + "\n" + text3,
                                                                new Point(0.5f, 0.3f));
                                  });
        }




text "(0.0000, 0.0000, 9.5859)" string
text2 "(0.0000, 0.0000, 10.0000)" string
text3 "(0.0000, 0.0000, 8.1818)" string

Edited by user Tuesday, November 29, 2011 9:01:25 PM(UTC)  | Reason: Not specified

Russian game developer.
Давайте делать игры в команде. Идет набор.

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Benjamin  
#2 Posted : Tuesday, November 29, 2011 11:00:40 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Hey BFoX,

I have really no idea why you are using the FreeCamera for your 2D Camera, just write your own camera (derive from BaseCamera) and implement what you need. That should be a lot easier than what you are trying to do!

Your code is otherwise correct and a very good unit test, easy to play around with. You should do some more debugging yourself in the future. All you have to do is to set a breakpoint at the cam.FarPlane = cam.Position.Y line. You will see that FarPlane is +10 before you run over that line and then -10 after you read the Y value. This obviously causes all your trouble. The camera is looking at the origin from 10 units away (0, -10, 0) and the FarPlane is 10 units, so it makes all sense before pressing buttons. Then you set the camera position to (0, -10.01, 0), which is all fine, but you also set FarPlane to -10.01, which makes no sense and destroys your view projection matrix (funny thing is you still see in the correct direction ^^).

This "fixes" your code, but you should really try do write your own Camera2D class, I can help with that and include it in the next nightly release (which is coming Thursday because I am on a conference till tomorrow).
Code:

				if (Input.Keyboard.IsReleased(InputButton.A))
				{
					cam.Position -= new Vector(0, 0.01f, 0);
					cam.UpdateProjectionMatrix();
					cam.FarPlane = -cam.Position.Y;
					cam.UpdateProjectionMatrix();
				}
				if (Input.Keyboard.IsReleased(InputButton.S))
				{
					cam.Position += new Vector(0, 0.01f, 0);
					cam.UpdateProjectionMatrix();
					cam.FarPlane = -cam.Position.Y;
					cam.UpdateProjectionMatrix();
				}
Offline bfox  
#3 Posted : Wednesday, November 30, 2011 9:29:23 AM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: Benjamin Nitschke (DeltaEngine) Go to Quoted Post
Hey BFoX,

I have really no idea why you are using the FreeCamera for your 2D Camera, just write your own camera (derive from BaseCamera) and implement what you need. That should be a lot easier than what you are trying to do!

Your code is otherwise correct and a very good unit test, easy to play around with. You should do some more debugging yourself in the future. All you have to do is to set a breakpoint at the cam.FarPlane = cam.Position.Y line. You will see that FarPlane is +10 before you run over that line and then -10 after you read the Y value. This obviously causes all your trouble. The camera is looking at the origin from 10 units away (0, -10, 0) and the FarPlane is 10 units, so it makes all sense before pressing buttons. Then you set the camera position to (0, -10.01, 0), which is all fine, but you also set FarPlane to -10.01, which makes no sense and destroys your view projection matrix (funny thing is you still see in the correct direction ^^).

This "fixes" your code, but you should really try do write your own Camera2D class, I can help with that and include it in the next nightly release (which is coming Thursday because I am on a conference till tomorrow).
Code:

				if (Input.Keyboard.IsReleased(InputButton.A))
				{
					cam.Position -= new Vector(0, 0.01f, 0);
					cam.UpdateProjectionMatrix();
					cam.FarPlane = -cam.Position.Y;
					cam.UpdateProjectionMatrix();
				}
				if (Input.Keyboard.IsReleased(InputButton.S))
				{
					cam.Position += new Vector(0, 0.01f, 0);
					cam.UpdateProjectionMatrix();
					cam.FarPlane = -cam.Position.Y;
					cam.UpdateProjectionMatrix();
				}


Yes i am write my own Camera2D class, but for fast test i use free canera =). i wait help with that. and i can send my version of the camera2D.
Russian game developer.
Давайте делать игры в команде. Идет набор.
Rss Feed  Atom Feed
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.062 seconds.