Original Post
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]
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]