2011-07-15 23 views
0

所以我基本上有一堆路線(想想3D位置),我想在視圖中繪製它們。XCode Design - 如何製作地圖?

我之前並沒有真正做過什麼w/graphics,並且很好奇,我甚至應該開始考慮在XCode w /我的Cocoa應用程序中這麼做。

任何人有任何建議嗎?

我應該繼承NSView嗎?我應該使用OpenGL嗎?

謝謝!

編輯:所以我能夠繼承的NSView,在這裏看到:http://groovyape.com/map.png

這是最好的辦法嗎? (我意識到它只是2D,我害怕嘗試3D嘿)。如果我想讓人們點擊圈子怎麼辦?我該怎麼做?

回答

1

在你的NSView子類可以覆蓋各種鼠標事件處理程序做任何你想要的:

- (void)mouseDown:(NSEvent *)event; 
- (void)mouseDragged:(NSEvent *)event; 
- (void)mouseUp:(NSEvent *)event; 

然後,你需要一種方法來知道在哪裏圈是這樣,你就會知道,當他們」已經被點擊了。如果你有一個圓作爲NSPoint和半徑,那麼類似這樣的事情會起作用

- (BOOL)isPoint:(NSPoint)click inCircleAtPoint:(NSPoint)centre withRadius:(float)r 
{ 
    float dx = click.x - centre.x; 
    float dy = click.y - centre.y; 

    // Get the distance from the click to the centre of the circle 
    float h = hypot (dx, dy); 

    // is the distance less than the radius? 
    return (h < r); 
} 

- (void)mouseDown:(NSEvent *)event 
{ 
    NSPoint clickPoint = [event locationInWindow]; 

    if ([self isPoint:clickPoint inCircleAtPoint:mapPoint withRadius:5.0]) { 
     // Click was in point 
    } 
}