gpt4 book ai didi

XCode 设计 - 如何创建 map ?

转载 作者:行者123 更新时间:2023-12-03 18:00:47 25 4
gpt4 key购买 nike

所以我基本上有一堆路线(想想 3D 位置),我想在 View 中绘制它们。

我之前实际上没有用图形做过任何事情,并且很好奇我应该如何开始考虑在 XCode 中用我的 Cocoa 应用程序来做这件事。

大家有什么建议吗?

我应该继承 NSView 吗?我应该使用 OpenGL 吗?

谢谢!

编辑:所以我能够子类化 NSView,请参见此处:http://groovyape.com/map.png

这是最好的方法吗? (我意识到这只是 2D,我不敢尝试 3D 嘿)。如果我想让人们点击圆圈怎么办 - 我该怎么做?

最佳答案

在你的 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
}
}

关于XCode 设计 - 如何创建 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6711039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com