如何镜像CGPoint
How to mirror a CGPoint
我不想将触摸点围绕屏幕中心旋转180度(镜像它)。我尝试了ccpRotateByAngle(screenCenter, touchPoint, 180)
,但它给了我错误的数据。
三角学:
// get your center in some way, here I'm using fixed coordinates 'cuz I'm lazy
CGPoint screenCenter = ccp(240, 160);
// this creates the vector between center and touch location
CGPoint touchPointToCenter = ccpSub(screenCenter, touchPoint);
// just add the vector to screen center and you mirrored it around center
CCPoint mirror = ccpAdd(screenCenter, touchPointToCenter);
例如,假设你的触摸点是200,200:
touchPointToCenter: {240, 160} - {200, 200} = {40, -40}
mirror: {240, 160} + {40, -40} = {280, 120}
镜像点为280,120 .
注:我使用的函数来自cocos2d-iphone。我假设它们也存在于cocos2d-x中。它们的名字可能不同,我不确定。您也可以像我在示例中那样"手动"运行计算。
相关文章:
- 在python docker镜像上安装simstring(SWIG)
- 将移动设备(iOS和Android)连接到带有QT / C++和镜像显示的VNC服务器
- 将迭代器从原始容器镜像到其副本
- 更快的图像镜像算法
- C++;镜像并从 std::basic_istream<> 中穿过?
- VTK-如何翻转镜像
- 仅使用位操纵来获得镜像的六角形
- 为什么我的 iFFT 图像带有镜像副本
- 在此镜像代码中,可以是什么样的矩阵转换
- 函数来创建镜像c++
- 如何交换像素以镜像图像c++
- 减少每个像素的级别数,创建镜像,C++
- 为什么 qopenglshader程序在 qt 中显示镜像
- 如何镜像矩阵的一个维度
- 有什么方法可以在内部镜像Microsoft的符号服务器吗?
- 生成彼此不是镜像的排列
- 实现镜像
- 将控制台输出镜像到c++中的文件
- 创建具有特定格式的位图以反转/镜像该位图
- 如何镜像CGPoint