欢迎光临散文网 会员登陆 & 注册

【C++&Live2D官方SDK】实现一个桌宠,附教程

2023-07-05 13:23 作者:LearningLog  | 我要投稿

void LAppDelegate::PosHandler()

{

if (_canMove)

{


POINT pt;

::GetCursorPos(&pt);

::SetWindowPos(_hw, NULL, pt.x - _deviationPoint.x, pt.y - _deviationPoint.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

}


if (s_instance != NULL)

{

if (s_instance->_view == NULL)

{

return;

}

//鼠标坐标

POINT pos = { 0 };

GetCursorPos(&pos);

//模型坐标

RECT rect;

::GetWindowRect(_hw, &rect);

long rectX = rect.left + RenderTargetWidth * 0.5;

long rectY = rect.top + RenderTargetHeight * 0.5;


if (pos.x <= rectX)

{

pos.x = LONG(((float)pos.x / (float)rectX)*((float)RenderTargetWidth * 0.5));

}

else {

pos.x -= rectX;

pos.x = LONG(((float)pos.x / (float)(_windowWidth - rectX))*((float)RenderTargetWidth * 0.5));

pos.x += LONG((float)RenderTargetWidth * 0.5);

}

if (pos.y <= rectY)

{

pos.y = LONG(((float)pos.y / (float)rectY)*((float)RenderTargetHeight * 0.5));

}

else {

pos.y -= rectY;

pos.y = LONG(((float)pos.y / (float)(_windowHeight - rectY))*((float)RenderTargetHeight * 0.5));

pos.y += LONG((float)RenderTargetHeight * 0.5);


}

s_instance->_mouseX = pos.x;

s_instance->_mouseY = pos.y;

s_instance->_captured = true;


//LAppPal::PrintLog("[APP]tap point in pos : {x:%.2f y:%.2f}", s_instance->_mouseX, s_instance->_mouseY);

s_instance->_view->OnTouchesMoved(s_instance->_mouseX, s_instance->_mouseY);

}


}

【C++&Live2D官方SDK】实现一个桌宠,附教程的评论 (共 条)

分享到微博请遵守国家法律