CAM: Simulator — fix model centering when HiDPI scaling is active
This commit is contained in:
committed by
Kacper Donat
parent
da4ebb56cb
commit
af2d42a4aa
@@ -238,10 +238,10 @@ void DlgCAMSimulator::startSimulation(const Part::TopoShape& stock, float qualit
|
||||
|
||||
void DlgCAMSimulator::initialize()
|
||||
{
|
||||
mMillSimulator->InitSimulation(mQuality);
|
||||
|
||||
const qreal retinaScale = devicePixelRatio();
|
||||
glViewport(0, 0, width() * retinaScale, height() * retinaScale);
|
||||
mMillSimulator->InitSimulation(mQuality, retinaScale);
|
||||
|
||||
glViewport(0, 0, (int)(width() * retinaScale), (int)(height() * retinaScale));
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::checkInitialization()
|
||||
|
||||
@@ -89,7 +89,7 @@ void MillSimulation::SimNext()
|
||||
}
|
||||
}
|
||||
|
||||
void MillSimulation::InitSimulation(float quality)
|
||||
void MillSimulation::InitSimulation(float quality, qreal devicePixelRatio)
|
||||
{
|
||||
ClearMillPathSegments();
|
||||
millPathLine.Clear();
|
||||
@@ -121,7 +121,7 @@ void MillSimulation::InitSimulation(float quality)
|
||||
}
|
||||
mNPathSteps = (int)MillPathSegments.size();
|
||||
millPathLine.GenerateModel();
|
||||
InitDisplay(quality);
|
||||
InitDisplay(quality, devicePixelRatio);
|
||||
}
|
||||
|
||||
EndMill* MillSimulation::GetTool(int toolId)
|
||||
@@ -529,7 +529,7 @@ void MillSimulation::HandleGuiAction(eGuiItems actionItem, bool checked)
|
||||
}
|
||||
|
||||
|
||||
void MillSimulation::InitDisplay(float quality)
|
||||
void MillSimulation::InitDisplay(float quality, qreal devicePixelRatio)
|
||||
{
|
||||
// generate tools
|
||||
for (unsigned int i = 0; i < mToolTable.size(); i++) {
|
||||
@@ -537,7 +537,7 @@ void MillSimulation::InitDisplay(float quality)
|
||||
}
|
||||
|
||||
// init 3d display
|
||||
simDisplay.InitGL();
|
||||
simDisplay.InitGL(devicePixelRatio);
|
||||
|
||||
// init gui elements
|
||||
guiDisplay.InitGui();
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
void ClearMillPathSegments();
|
||||
void Clear();
|
||||
void SimNext();
|
||||
void InitSimulation(float quality);
|
||||
void InitSimulation(float quality, qreal devicePixelRatio);
|
||||
void AddTool(EndMill* tool);
|
||||
void AddTool(const std::vector<float>& toolProfile, int toolid, float diameter);
|
||||
bool ToolExists(int toolid)
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
void InitDisplay(float quality);
|
||||
void InitDisplay(float quality, qreal devicePixelRatio);
|
||||
void GlsimStart();
|
||||
void GlsimToolStep1(void);
|
||||
void GlsimToolStep2(void);
|
||||
|
||||
@@ -240,7 +240,7 @@ SimDisplay::~SimDisplay()
|
||||
CleanGL();
|
||||
}
|
||||
|
||||
void SimDisplay::InitGL()
|
||||
void SimDisplay::InitGL(qreal devicePixelRatio)
|
||||
{
|
||||
if (displayInitiated) {
|
||||
return;
|
||||
@@ -249,8 +249,9 @@ void SimDisplay::InitGL()
|
||||
// setup light object
|
||||
mlightObject.GenerateBoxStock(-0.5f, -0.5f, -0.5f, 1, 1, 1);
|
||||
|
||||
mWidth = gWindowSizeW;
|
||||
mHeight = gWindowSizeH;
|
||||
mDevicePixelRatio = devicePixelRatio;
|
||||
mWidth = (int)(gWindowSizeW * mDevicePixelRatio);
|
||||
mHeight = (int)(gWindowSizeH * mDevicePixelRatio);
|
||||
InitShaders();
|
||||
CreateDisplayFbos();
|
||||
CreateSsaoFbos();
|
||||
@@ -550,8 +551,8 @@ void SimDisplay::UpdateEyeFactor(float factor)
|
||||
|
||||
void SimDisplay::UpdateWindowScale()
|
||||
{
|
||||
mWidth = gWindowSizeW;
|
||||
mHeight = gWindowSizeH;
|
||||
mWidth = (int)(gWindowSizeW * mDevicePixelRatio);
|
||||
mHeight = (int)(gWindowSizeH * mDevicePixelRatio);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
|
||||
CleanFbos();
|
||||
CreateDisplayFbos();
|
||||
|
||||
@@ -47,7 +47,7 @@ class SimDisplay
|
||||
{
|
||||
public:
|
||||
~SimDisplay();
|
||||
void InitGL();
|
||||
void InitGL(qreal devicePixelRatio);
|
||||
void CleanGL();
|
||||
void CleanFbos();
|
||||
void PrepareDisplay(vec3 objCenter);
|
||||
@@ -108,6 +108,7 @@ protected:
|
||||
mat4x4 mMatLookAt;
|
||||
StockObject mlightObject;
|
||||
|
||||
qreal mDevicePixelRatio;
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user