2011-09-25 136 views
0

我有一個覆蓋在MKMapView之上的OpenGL視圖。我的目標是讓glView的座標在地圖上具有相同的MKMapPoints值。爲此,我在地圖的左上角和右下角找到了MKMapPoint的值。OpenGL Ortho座標

CLLocationCoordinate2D coordinateTopLeft = [mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:mapView]; 
MKMapPoint pointTopLeft = MKMapPointForCoordinate(coordinateTopLeft); 

CLLocationCoordinate2D coordinateBottomRight = [mapView convertPoint:CGPointMake(mapView.frame.size.width, mapView.frame.size.width) toCoordinateFromView:mapView]; 
MKMapPoint pointBottomRight = MKMapPointForCoordinate(coordinateBottomRight); 

然後我設置glView的右,左,下和頂部座標以相應地匹配這些點。

glOrthof(pointTopLeft.x, pointBottomRight.x, pointBottomRight.y, pointTopLeft.y, -1, 1); 

不幸的是,這並沒有奏效。我試圖繪製的三角形不起作用。我進行了測試,並且我試圖繪製的點數爲分別是位於正確域中的

我只是誤解了glOrthof方法是如何工作的?

+0

不是你的問題的答案(因此是評論),但是你假設你的地圖視圖上的座標系統是均勻間隔的,但由於地球曲率的原因,這並不是實際情況。對於某些應用來說,這可能不是問題,但對於那些要求高準確度的應用來說,它可能是。 – lxt

+0

MKMappoints實際上均勻間隔。它們表示地圖的2D投影上具有平行經線的點。 –

回答

0

你有沒有嘗試翻轉pointBottomRight.y和pointTopLeft.y? OpenGL y座標系與大多數常用的約定相反。