【C++&Live2D官方SDK】實現(xiàn)一個桌寵,附教程

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);
}
}