这几天试着将它改成控件,不过go button
private void buttonGo_Click(object sender,System.EventArgs e)
{
try{
double lat = double.Parse(this.textBoxLatitude.Text);
double lon=double.Parse(this.textBoxLongitude.Text);
double alt =(double)this.numericUpDownAltitude.Value);
m_WorldWindow.GotoLatLonAltitude(lat,lon,alt);
}
}
这个消息无法进入,让人有点郁闷的摸不着头脑.部分的鼠标响应消息也失灵了.奇怪的事.有时候还是可以看到效果.
通过追踪,device 的初始有点问题.
在worldwindow 里面的
public void GotoLatLonAltitude(double latitude, double longitude, double altitude)
{
this.drawArgs.WorldCamera.SetPosition(latitude, longitude,
this.drawArgs.WorldCamera.Heading.Degrees,altitude,this.drawArgs.WorldCamera.Tilt.Degrees);
}
此处的drawArgs.worldcamera,好象也有点问题.
期待完全处理之中
public virtual void SetPosition(double lat, double lon, double heading, double _altitude, double tilt, double bank)
{
if(double.IsNaN(lat)) lat = this._latitude.Degrees;
if(double.IsNaN(lon)) lon = this._longitude.Degrees;
if(double.IsNaN(heading)) heading = this._heading.Degrees;
if(double.IsNaN(bank)) bank = this._bank.Degrees;
m_Orientation = Quaternion4d.EulerToQuaternion(
MathEngine.DegreesToRadians(lon),
MathEngine.DegreesToRadians(lat),
MathEngine.DegreesToRadians(heading));
Point3d p = Quaternion4d.QuaternionToEuler(m_Orientation);
_latitude.Radians = p.Y;
_longitude.Radians = p.X;
_heading.Radians = p.Z;
if(!double.IsNaN(tilt))
Tilt = Angle.FromDegrees(tilt);
if(!double.IsNaN(_altitude))
this.Altitude = _altitude;
this.Bank = Angle.FromDegrees(bank);
}
Matrix m_absoluteViewMatrix = Matrix.Identity;
Matrix m_absoluteWorldMatrix = Matrix.Identity;
Matrix m_absoluteProjectionMatrix = Matrix.Identity;
public Matrix AbsoluteViewMatrix
{
get{ return m_absoluteViewMatrix; }
}
public Matrix AbsoluteWorldMatrix
{
get{ return m_absoluteWorldMatrix; }
}
public Matrix AbsoluteProjectionMatrix
{
get{ return m_absoluteProjectionMatrix; }
}
/// <summary>
/// Calculates latitude/longitude for given screen coordinate.
/// </summary>
public virtual void PickingRayIntersection(
int screenX,
int screenY,
out Angle latitude,
out Angle longitude)
{
Vector3 v1 = new Vector3();
v1.X = screenX;
v1.Y = screenY;
v1.Z = viewPort.MinZ;
v1.Unproject(viewPort, m_absoluteProjectionMatrix, m_absoluteViewMatrix, m_absoluteWorldMatrix);
Vector3 v2 = new Vector3();
v2.X = screenX;
v2.Y = screenY;
v2.Z = viewPort.MaxZ;
v2.Unproject(viewPort, m_absoluteProjectionMatrix, m_absoluteViewMatrix, m_absoluteWorldMatrix);
Point3d p1 = new Point3d(v1.X, v1.Y, v1.Z);
Point3d p2 = new Point3d(v2.X, v2.Y, v2.Z);
double a = (p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y) + (p2.Z - p1.Z) * (p2.Z - p1.Z);
double b = 2.0*((p2.X - p1.X)*(p1.X) + (p2.Y - p1.Y)*(p1.Y) + (p2.Z - p1.Z)*(p1.Z));
double c = p1.X*p1.X + p1.Y*p1.Y + p1.Z*p1.Z - _worldRadius * _worldRadius;
double discriminant = b*b - 4 * a * c;
if(discriminant <= 0)
{
latitude = Angle.NaN;
longitude = Angle.NaN;
return;
}
// float t0 = ((-1.0f) * b + (float)Math.Sqrt(b*b - 4 * a * c)) / (2*a);
double t1 = ((-1.0) * b - Math.Sqrt(b*b - 4 * a * c)) / (2*a);
// Vector3 i0 = new Vector3(p1.X + t0*(p2.X - p1.X), p1.Y + t0*(p2.Y - p1.Y), p1.Z + t0 *(p2.Z - p1.Z));
Point3d i1 = new Point3d(p1.X + t1*(p2.X - p1.X), p1.Y + t1*(p2.Y - p1.Y), p1.Z + t1 *(p2.Z - p1.Z));
// Vector3 i0t = MathEngine.CartesianToSpherical(i0.X, i0.Y, i0.Z);
Point3d i1t = MathEngine.CartesianToSphericalD(i1.X, i1.Y, i1.Z);
Point3d mousePointer = i1t;
latitude = Angle.FromRadians(mousePointer.Y);
longitude = Angle.FromRadians(mousePointer.Z);
}