- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的程序中有一个简单的矩形,我必须对其进行 HitTest 。我正在使用 openFrameworks,但我认为这里的问题也与 OpenGL 主题有关。
public class Shape : public class ofNode {
Shape() {
container.setFromCenter(getPosition(), 200,100);
setPosition(ofVec3f(365, 50, 0)); //set the position of the node
lookAt(ofVec3f(0,0,0));
}
virtual void draw() {
ofRect(container); //the 200/100 rectangle will be drawn as per the container position and dimensions
}
ofVec3f getTopLeft() const {
return getTopLeft() * ofNode::getGlobalTransformMatrix();
}
ofVec3f getTopRight() const {} //similar - getTopRight from container and multiply
ofVec3f getBottomLeft() const {} //similar
ofVec3f getBottomRight() const {} //similar
bool hitTest(int tx, int ty) {
// return true if mouse pointer is inside four vertices - hit test logic working fine
}
private:
ofRectagle container;
};
我在这里遇到的问题是我在我的程序中旋转和平移形状:
void draw() {
ofPushMatrix();
ofTranslate(600,300,0);
ofRotateY(rotate);
shape->draw();
ofCircle(shape->getTopLeft(), 10); //circle is drawn at the rectangle top left vertex on the screen but the coordinates while rotating and drawing do not change (as seen on cout)
ofCircle(shape->getTopRight(), 10); //similar
ofCircle(shape->getBottomLeft(), 10); //similar
ofCircle(shape->getBottomRight(), 10); //similar
ofPopmatrix();
}
在上面的 draw
函数中改变旋转时,点不会改变。因此,我没有合适的四个顶点用于 HitTest 来确定鼠标是否在里面。如何获取屏幕中可以根据鼠标位置检查 HitTest 的点的位置?
最佳答案
如果你想测试鼠标指针是否在矩形的范围内,我建议你先将它们转换到屏幕空间并在那里进行测试,按照我在 https://stackoverflow.com/a/14424267/524368 中给你的一般想法。
我还要说,是时候停止使用 OpenGL 的内置矩阵操作函数了。 使用它们绝对没有任何好处!有些人认为它们会进行 GPU 加速,但事实并非如此。一旦您在程序的其他位置需要这些矩阵,就不能为此滥用 OpenGL。 OpenGL 毕竟不是一个数学库。在以后的版本中,整个矩阵堆栈已从 OpenGL 中删除——很好的摆脱。
OpenFrameworks comes with a fully featured matrix math library .我强烈建议您使用 that。您可以使用 glLoadMatrix
(固定函数管道)或 glUniformMatrix
(着色器管道)将生成的矩阵提供给 OpenGL。
您可以使用它来实现我在其他答案中概述的投影功能。
要测试一个点是否位于由边定义的边界内,您可以使用称为“半边”的概念。假设你的边形成一个 star domain环形。然后对于循环中的每条边,您将点与边的叉积。如果该点在循环定义的形状内,则所有叉积将指向同一方向。共面四边形(即投影到屏幕空间的四边形)总是形成一个星域。
关于c++ - 四个旋转顶点之间的 HitTest ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14424768/
...沮丧。我希望我的游戏仅在横向模式下运行。我已将适当的键/值添加到 Info.plist 文件中,以强制设备方向在启动时正确。 我现在正在尝试旋转 OpenGL 坐标空间以匹配设备的坐标空间。我正
我如何创建一个旋转矩阵,将 X 旋转 a,Y 旋转 b,Z 旋转 c? 我需要公式,除非您使用的是 ardor3d api 的函数/方法。 矩阵是这样设置的 xx, xy, xz, yx, yy, y
假设我有一个包含 3 个 vector 的类(一个用于位置,一个用于缩放,一个用于旋转)我可以使用它们生成一个变换矩阵,该矩阵表示对象在 3D 空间中的位置、旋转和大小。然后我添加对象之间的父/子关系
所以我只是在玩一个小的 javascript 游戏,构建一个 pacman 游戏。你可以在这里看到它:http://codepen.io/acha5066/pen/rOyaPW 不过我对旋转有疑问。你
在我的应用程序中,我有一个 MKMapView,其中显示了多个注释。 map 根据设备的航向旋转。要旋转 map ,请执行以下语句(由方法 locationManager 调用:didUpdateHe
使用此 jquery 插件时:http://code.google.com/p/jqueryrotate/wiki/Documentation我将图像旋转 90 度,无论哪个方向,它们最终都会变得模糊
我有以下代码:CSS: .wrapper { margin:80px auto; width:300px; border:none; } .square { widt
我只想通过小部件的轴移动图像并围绕小部件的中心旋转(就像任何数字绘画软件中的 Canvas ),但它围绕其左顶点旋转...... QPainter p(this); QTransform trans;
我需要先旋转图像,然后再将其加载到 Canvas 中。据我所知,我无法使用 canvas.rotate() 旋转它,因为它会旋转整个场景。 有没有好的JS方法来旋转图片? [不依赖于浏览器的方式] 最
我需要知道我的 Android 设备屏幕何时从一个横向旋转到另一个横向(rotation_90 到 rotation_270)。在我的 Android 服务中,我重新实现了 onConfigurati
**摘要:**本篇文章主要讲解Python调用OpenCV实现图像位移操作、旋转和翻转效果,包括四部分知识:图像缩放、图像旋转、图像翻转、图像平移。 本文分享自华为云社区《[Python图像处理] 六
我只是在玩MTKView中的模板设置;并且,我一直在尝试了解以下内容: 相机的默认位置。 使用MDLMesh和MTKMesh创建基元时的默认位置。 为什么轮换还涉及翻译。 相关代码: matrix_f
我正在尝试使用包 dendexend 创建一个树状图。它创建了非常好的 gg 树状图,但不幸的是,当你把它变成一个“圆圈”时,标签跟不上。我将在下面提供一个示例。 我的距离对象在这里:http://s
我想将一个完整的 ggplot 对象旋转 90°。 我不想使用 coord_flip因为这似乎会干扰 scale="free"和 space="free"使用刻面时。 例如: qplot(as.fac
我目前可以通过首先平移到轴心点然后执行旋转最后平移回原点来围绕轴心点旋转。在我的例子中,我很容易为肩膀做到这一点。但是,我不知道如何为前臂添加绕肘部的旋转。 我已经尝试了以下围绕肘部旋转的前臂: 平移
我想使用此功能旋转然后停止在特定点或角度。现在该元素只是旋转而不停止。代码如下: $(function() { var $elie = $("#bkgimg");
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
我正在尝试创建一个非常简单的关键帧动画,其中图形通过给定的中点从一个角度旋转到另一个角度。 (目的是能够通过大于 180 度的 OBTUSE 弧角来制作旋转动画,而不是让动画“作弊”并走最短路线,即通
我需要旋转 NSView 实例的框架,使其宽度变为其高度,其高度变为其宽度。该 View 包含一个字符串,并且该字符串也被旋转,这一点很重要。 我查看了 NSView 的 setFrameRotati
我正在编写一个脚本,用于在 javascript 中旋转/循环浏览图像,同时遵守循环浏览图像的次数限制。我所拥有的如下: var delay = 3000; //6000 = change to
我是一名优秀的程序员,十分优秀!