febriano's picture

camera look at a

hello am loading a .obj model but i cant see the model coz the first vertex is to coordinate x a value of 40.6737, so i thought i should move to coordinates (0,0,500) since am looking at (0,0,0) but i cant seem to see anything

  Matrix4 LookAt = Matrix4.LookAt( Vector3.UnitZ, Vector3.Zero, Vector3.UnitY*500);
            GL.LoadMatrix(ref LookAt);

even if i made a vector3 at the place of unit z and gave it (0,0,500); still nothing could some one help me ? thanks for your time


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
winterhell's picture

First from your LookAt construction it seems that the cameraPos is at (0,0,1) and you are looking at (0,0,0), i.e. you are looking down the Z axis. The things in front of the camera would have Z between 1 and -00.

Also when you push your perspective matrix( GL.MatrixMode(MatrixMode.Projection), Matrix.CreatePerspectiveFieldOfView etc) you want to put the zNear and zFar parameters such that your models is between them. Like 501 units in front of the camera is between zNear 0.1f and zFar 1000f.

You dont need Vector3.UnitY*500 as the camera Up, just a normalized vector Vector3.UnitY is enough.

febriano's picture

thanks for your reply man
   Matrix4 perspective = Matrix4.CreatePerspectiveFieldOfView((float)(System.Math.PI / 4f), aspectRatio, 0.01f, 2000f);
yea i have the znear and zfar as you can see in the line above , still cant move the cam

winterhell's picture

Can you see the model though? If not you'd want to verify your viewport as it may not be rendering all 4 unit quadrants from (-1,-1) to (1,1) but instead only one quadrant or its dimensions being as much as the resolution.
One way would be to render a large triangle like (-500, -500),(+500,-500),(0,+500) and if it shows figure out the rest incrementally.

As for camera movement you need to change the Modelview matrix every frame. Have a global camPos vector that you alter according to the keyboard input, and then have Matrix4.LookAt(camPos, camPos+cameraDirection, Vector3.UnitY);

febriano's picture

thanks for your reply man this is my viewport

    private void SetupViewport()
            float aspectRatio = (float)glControl1.Width / (float)glControl1.Height;
            GL.Viewport(0, 0, glControl1.Width, glControl1.Height);
            Matrix4 perspective = Matrix4.CreatePerspectiveFieldOfView((float)(System.Math.PI / 4f), aspectRatio, 0.01f, 2000f);
            GL.MultMatrix(ref perspective);

i rendered the triangle had to move the z to Matrix4 LookAt = Matrix4.LookAt( new Vector3(0f,0f,1500f), Vector3.Zero, Vector3.UnitY);
until i was ble to see it , but i still cant see the model am located at (0,0,0) want to move to (0,0,500) to be outside of the sphere