有人能帮我简单解释下这段代码都在干什么吗???咋算出来的目标坐标??屏幕坐标每个单位大小比如和世界坐标的每个单位大小不一样吗?比如50比1的比例???求解
void Sprite3DFakeShadowTest::onTouchesEnded(const std::vector<Touch*>& touches, cocos2d::Event *event)
{
for ( auto &item: touches )
{
auto touch = item;
auto location = touch->getLocationInView();
if(_camera)
{
if(_orc )
{
Vec3 nearP(location.x, location.y, -1.0f), farP(location.x, location.y, 1.0f);
auto size = Director::getInstance()->getWinSize();
nearP = _camera->unproject(nearP);
farP = _camera->unproject(farP);
Vec3 dir(farP - nearP);
float dist=0.0f;
float ndd = Vec3::dot(Vec3(0,1,0),dir);
if(ndd == 0)
dist=0.0f;
float ndo = Vec3::dot(Vec3(0,1,0),nearP);
dist= (0 - ndo) / ndd;
Vec3 p = nearP + dist * dir;
if( p.x > 100)
p.x = 100;
if( p.x < -100)
p.x = -100;
if( p.z > 100)
p.z = 100;
if( p.z < -100)
p.z = -100;
_targetPos=p;
}
}
}
}