
Matrix.LookAt doesn't work!
Posted Thursday, 7 October, 2010 - 13:48 by jp-sdt inHi,
I tried simply to change the eye/target position. But the Final-view is ever the same position. What I forgot?
using System; using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using System.Drawing; using System.Reflection; using OpenTK.Input; using Riv3D_Editor; using Riv3D_Editor.ModelClasses; namespace Nehe_Tutorials { class Game : GameWindow { #region Main static void Main() { using (Game game = new Game()) { game.Run(60.0); } } public Game() : base(1024, 768, new GraphicsMode(new ColorFormat()), "Test") { VSync = VSyncMode.On; } #endregion #region Defenitions bool fullscreen; Matrix4d Cam; #endregion #region OnLoad protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ShadeModel(ShadingModel.Smooth); GL.ClearColor(0.5f, 0.8f, 0.9f, 0); GL.ClearDepth(1.0); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); } #endregion #region OnResize protected override void OnResize(EventArgs e) { base.OnResize(e); GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height); Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 0.1f, 2000.0f); GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref projection); } #endregion #region Update protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); if (Keyboard[Key.Escape]) Exit(); if (Keyboard[Key.F1]) { fullscreen = !fullscreen; if (fullscreen) WindowState = WindowState.Fullscreen; else WindowState = WindowState.Normal; } } #endregion #region Draw protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Cam = Matrix4d.LookAt(100.0, 0, 0, 100.0, 20.0, 0, 0, 1.0, 0); //silly example to transform the view GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref Cam); GL.LoadIdentity(); Grid grid = new Grid(); SwapBuffers(); } #endregion } }


Comments
Re: Matrix.LookAt doesn't work!
GL.LoadMatrix(ref Cam);
GL.LoadIdentity();
The second call overwrites your Cam matrix.
Re: Matrix.LookAt doesn't work!
Hi,
I deledet it but the problem is the same.
thank you for your try^^
best reguards
jp-sdt
Re: Matrix.LookAt doesn't work!
Hi,
I deledet it but the problem is the same.
thank you for your try^^
best reguards
jp-sdt
Re: Matrix.LookAt doesn't work!
And you're sure that Grid doesn't overwrite again your modelview matrix? As it's hard to guess that code.
Re: Matrix.LookAt doesn't work!
Sorry ^^"
but Im Sure there aren't any overwrites for matrixes.
Maybe I forgot somewhat important here?
Re: Matrix.LookAt doesn't work!
Ok.
When I posted the code I saw the problem ^^"
I just forgot to use GL.PopMatrix() and GL.PushMatrix()
But thank you c2woody :)