Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help with some camera code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Hyrules   Members   -  Reputation: 114

Like
0Likes
Like

Posted 29 July 2012 - 05:35 PM

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]

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS