cocos2D camera使屏幕缩放问题

使用照相机改变z轴,屏幕被缩放,如何使sprite3d到达屏幕指定的位置,直接setposition3d会有视差偏移,其中sprite3d的z轴固定。

没有大神回复下么,大神大神快来!!

大概的代码是这样的:

void HelloWorld::onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event)
{
    // 计算投影后坐标为(x, y)的射线,(x, y)即为鼠标点击位置的坐标
    auto locationView = touches[0]->getLocation();
    auto camera = Director::getInstance()->getRunningScene()->getDefaultCamera();
    Vec3 near(locationView.x, locationView.y, 0);
    Vec3 far(locationView.x, locationView.y, 1);
    near = camera->unprojectGL(near);
    far = camera->unprojectGL(far);
    Vec3 direction(far - near);
    direction.normalize();
    Ray ray(near, direction);
    
    Plane planeZ10(Vec3(0, 0, 1), Vec3(0, 0, 10));    // z值为10的平面,这个可以替换为你要的z值
    auto locationWorld = ray.intersects(planeZ10);
    
    auto sprite3d = static_cast<Sprite3D*>(getChildByTag(100));
    sprite3d->setPosition3D(locationWorld);
}

你好请问“Plane planeZ10(Vec3(0, 0, 1), Vec3(0, 0, 10)); // z值为10的平面,这个可以替换为你要的z值”这里的z值取决于什么参数?跟camera的lookat的target有关系吗?

@minggo
请问“Plane planeZ10(Vec3(0, 0, 1), Vec3(0, 0, 10)); // z值为10的平面,这个可以替换为你要的z值”
这里的z值取决于什么参数?跟camera的lookat的target有关系吗?