Jump to content

  • Log In with Google      Sign In   
  • Create Account


Draging a map in directx


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
6 replies to this topic

#1 Hyrules   Members   -  Reputation: 114

Like
0Likes
Like

Posted 25 July 2012 - 04:29 PM

Hi everyone ,

i'm in the process of making a gis with directx and i have to drag the mouse around the map see different part of it (like google map). The main problem with this is the speed of the drag when zooming in and out. Setting the scroll speed to a static number when zoom out and draging the map is easy but when I zoom in i have to slow the speed of the dragging in order to give the gis a proper smooth movement. I wonder if anyone has any experience with this and if someone has any idea of a mathematical formula to do this smoothly. The way I do this right now is the following and static but is working well. thanks in advance.

[source lang="csharp"] public void UpdateScene(float x , float y, float z) { float currentX; float currentY; float currentZ; currentX = x * 0.00014f; currentY = y * 0.00314f; currentZ = z * 0.0005f; camPosition.X += currentX; camPosition.Y += -currentY; // Console.Write("CamPosition Z: " + camPosition.Z +"\r"); if (camPosition.Z + currentZ < 1.1f && camPosition.Z + currentZ > -1.5) { camPosition.Z += currentZ; } else { currentZ = 0; } camView = camView * Matrix.Translation(new Vector3(currentX, -currentY, -currentZ)); 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); }[/source]

Sponsor:

#2 Rene Z   Members   -  Reputation: 483

Like
1Likes
Like

Posted 25 July 2012 - 05:49 PM

If you're using an orthographic projection, the area the camera can see has a width height, and depth. Transform the mouse position data to normalized coordinates (a range from zero to one) if you're currently using pixels or something else. Then multiply the size of the camera view with delta mouse position, negate, and use the result to translate the camera.

If you're using a perspective projection this won't work, so let me know if that's the case.

#3 Rene Z   Members   -  Reputation: 483

Like
0Likes
Like

Posted 25 July 2012 - 05:53 PM

For some reason the edit button doesn't work. Read 'Then multiply the size of the camera view' in the post above as 'Then multiply the width and height of the camera view'.

#4 Hyrules   Members   -  Reputation: 114

Like
0Likes
Like

Posted 25 July 2012 - 06:05 PM

Here is the camera and world setup i'm not sure if it's othorgraphic... thanks for your help.

[source lang="csharp"] private void SetWorldAndCam() { // Set Constant Buffer cbPerObjectBufferDesc = new BufferDescription(); cbPerObjectBufferDesc.SizeInBytes = Marshal.SizeOf(typeof(cbPerObject)); cbPerObjectBufferDesc.Usage = ResourceUsage.Default; cbPerObjectBufferDesc.BindFlags = BindFlags.ConstantBuffer; cbPerObjectBufferDesc.CpuAccessFlags = CpuAccessFlags.None; cbPerObjectBufferDesc.OptionFlags = ResourceOptionFlags.None; cbPerObjectBufferDesc.StructureByteStride = Marshal.SizeOf(typeof(cbPerObject)); // Set Camera camPosition = new Vector3(0.0f, 0.0f, -1.0f); camTarget = new Vector3(0.0f, 0.0f, 0.0f); camUp = new Vector3(0.0f, 1.0f, 0.0f); camView = Matrix.LookAtLH(camPosition, camTarget, camUp); camProj = Matrix.PerspectiveFovLH(0.4f * 3.14f, (float)ptd.Height / ptd.Width, 0.00001f, 1000.0f); World = Matrix.Identity; 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); }[/source]

#5 Hyrules   Members   -  Reputation: 114

Like
0Likes
Like

Posted 25 July 2012 - 06:19 PM

duh stupid me i answered my own question... it's Perspective : camProj = Matrix.PerspectiveFovLH(0.4f * 3.14f, (float)ptd.Height / ptd.Width, 0.00001f, 1000.0f);

#6 Hyrules   Members   -  Reputation: 114

Like
0Likes
Like

Posted 25 July 2012 - 06:44 PM

well without knowing it you answered another of my questions i didnt want an perpective projection but an orthgraphic one. you help is much appreciated.

#7 Hyrules   Members   -  Reputation: 114

Like
0Likes
Like

Posted 28 July 2012 - 01:26 PM

I'm still confused about this. My dragging is working except that it's rather a challenge to drag at close zoom because the movement is going to fast.

My camera is a perspective :

[source lang="csharp"] private void SetWorldAndCam() { // Set Constant Buffer cbPerObjectBufferDesc = new BufferDescription(); cbPerObjectBufferDesc.SizeInBytes = Marshal.SizeOf(typeof(cbPerObject)); cbPerObjectBufferDesc.Usage = ResourceUsage.Default; cbPerObjectBufferDesc.BindFlags = BindFlags.ConstantBuffer; cbPerObjectBufferDesc.CpuAccessFlags = CpuAccessFlags.None; cbPerObjectBufferDesc.OptionFlags = ResourceOptionFlags.None; cbPerObjectBufferDesc.StructureByteStride = Marshal.SizeOf(typeof(cbPerObject)); // Set Camera camPos = 0.42; camPosition = new Vector3(0.0f, 0.0f, -100.0f); camTarget = new Vector3(0.0f, 0.0f, 0.0f); camUp = new Vector3(0.0f, 1.0f, 0.0f); camView = Matrix.LookAtLH(camPosition, camTarget, camUp); camProj = Matrix.PerspectiveFovLH(0.4f * 3.14f, (float)ptd.Width / ptd.Height, 0.00001f, float.MaxValue); World = Matrix.Identity * 10000; 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); }[/source]
and here is wher I do my dragging :

[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 ; Ray mr = PanelToWordSpace(); Console.WriteLine(mr.Position); #region Zoom if (z != 0) { if (z > 0 && camPos > 0.09 ) { camPos = camPos - 0.07; } else { if (z < 0 && camPos < 0.98) { camPos = camPos + 0.07; } } Console.WriteLine(camPos); } #endregion camView = camView * Matrix.Translation(currentX,-currentY,0.00f); camProj = Matrix.PerspectiveFovLH((float)camPos * 3.14f, (float)ptd.Width/ ptd.Height, 0.00001f, float.MaxValue); 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); }[/source]

The main problem I have is having the mouse cursor stick to the place I am dragging and give the drag a proper speed. Any help would be appreciated.




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