Hi everyone,
I'm currently using slimdx to make a GIS and i'm having some kind of problem with the camera which i'm not quite sure how to fix. I`ve been able to make the cursor follow the place i'm dragging but when I drag the camera the second time it is reset to the original position. Any help would be appreciated. i'm using an orthographic projection. The PanelToWorldSpace convert the view to a 1 to -1 coordinates system.
[source lang="csharp"] public void UpdateScene(float x , float y, float z) { float currentX; float currentY; float currentIH = ptd.Height; float currentIW = ptd.Width; currentX = x; currentY = y; mouseX = x; mouseY = y; Ray mr = PanelToWordSpace(x,y); #region Zoom if (z != 0) { if (z > 0 && camPos > 0.09 ) { camPos = camPos - 0.07; } else { if (z < 0 && camPos < 1.4) { camPos = camPos + 0.07; } } camProj = Matrix.OrthoLH(ptd.Width*3, ptd.Height*3, 0.00001f, float.MaxValue); } #endregion mouseNormalX = mr.Position.X; mouseNormalY = mr.Position.Y; float mouseNormalDeltaX = oldMouseNormalX - mouseNormalX; float mouseNormalDeltaY = oldMouseNormalY - mouseNormalY; float mouseDeltaX = oldMouseX - mouseX; float mouseDeltaY = oldMouseY - mouseY; camProj = camProj * Matrix.Translation(new Vector3(-mouseNormalDeltaX, -mouseNormalDeltaY, 0.0f)); WVP = World * camView * camProj ; cbPerObj.WVP = Matrix.Transpose(WVP); DataStream cbData = new DataStream(Marshal.SizeOf(typeof(cbPerObject)), true, true); cbData.Write(cbPerObj); cbData.Position = 0; cbPerObjectBuffer = new Buffer(device, cbData, cbPerObjectBufferDesc); context.VertexShader.SetConstantBuffer(cbPerObjectBuffer, 0); oldMouseNormalX = mouseNormalX; oldMouseNormalY = mouseNormalY; oldMouseX = mouseX; oldMouseY = mouseY; }[/source]
[source lang="csharp"] private Ray PanelToWordSpace(float x , float y) { Vector3 near = new Vector3(x,y,0.00001f); Vector3 far = new Vector3(x,y,float.MaxValue); Vector3 vNearW = Vector3.Unproject(near,0,0,ptd.Width,ptd.Height,0,1,World ); Vector3 vFarW = Vector3.Unproject(far, 0, 0, ptd.Width, ptd.Height, 0, 1, World); Vector3 vDirect = vFarW - vNearW; vDirect = Vector3.Normalize(vDirect); return new Ray(vNearW, vDirect); }[/source]
No replies to this topic






