Skip to content

Commit cbdd7ef

Browse files
authored
Merge pull request #1878 from RubioJr9/legend_fix
Closes #1435
2 parents 7cbe529 + 66adc84 commit cbdd7ef

File tree

7 files changed

+500
-156
lines changed

7 files changed

+500
-156
lines changed

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ namespace SCIRun {
7979
//------------------------------------------------------------------------------
8080
SRInterface::SRInterface(std::shared_ptr<Gui::GLContext> context,
8181
int frameInitLimit) :
82+
orientSize(1.0),
83+
orientPosX(0.5),
84+
orientPosY(0.5),
8285
mSelectedID(0),
8386
mZoomSpeed(65),
8487
mMouseMode(MOUSE_OLDSCIRUN),
@@ -565,6 +568,43 @@ namespace SCIRun {
565568
showOrientation_ = value;
566569
}
567570

571+
//------------------------------------------------------------------------------
572+
void SRInterface::setOrientSize(int size)
573+
{
574+
// Remap from 1:100 to 0.1:10
575+
orientSize = ((float)size)/10.0f;
576+
}
577+
578+
//------------------------------------------------------------------------------
579+
void SRInterface::setOrientPosX(int pos)
580+
{
581+
// Remap 0:100 to -0.5:0.5
582+
float x = ((float)pos-50)/100;
583+
orientPosX = x;
584+
}
585+
586+
//------------------------------------------------------------------------------
587+
void SRInterface::setOrientPosY(int pos)
588+
{
589+
// Remap 0:100 to -0.5:0.5
590+
float y = ((float)pos-50)/100;
591+
orientPosY = y;
592+
}
593+
594+
//------------------------------------------------------------------------------
595+
void SRInterface::setDefaultOrientPos()
596+
{
597+
float y = 0.5f;
598+
float x = 0.5f;
599+
}
600+
601+
//------------------------------------------------------------------------------
602+
void SRInterface::setCenterOrientPos()
603+
{
604+
float y = 0.0f;
605+
float x = 0.0f;
606+
}
607+
568608
//------------------------------------------------------------------------------
569609
void SRInterface::setBackgroundColor(QColor color)
570610
{
@@ -1626,16 +1666,37 @@ namespace SCIRun {
16261666
// variable.
16271667
gen::StaticScreenDims* dims = mCore.getStaticComponent<gen::StaticScreenDims>();
16281668
float aspect = static_cast<float>(dims->width) / static_cast<float>(dims->height);
1629-
glm::mat4 projection = glm::perspective(0.59f, aspect, 1.0f, 2000.0f);
1630-
1669+
// Project onto a orthographic plane with respect to aspect ratio
1670+
glm::mat4 projection = glm::ortho(-aspect/2, aspect/2, -0.5f, 0.5f, 0.0f, 2.0f);
1671+
16311672
// Build world transform for all axes. Rotates about uninverted camera's
16321673
// view, then translates to a specified corner on the screen.
16331674
glm::mat4 axesRot = mCamera->getWorldToView();
16341675
axesRot[3][0] = 0.0f;
16351676
axesRot[3][1] = 0.0f;
16361677
axesRot[3][2] = 0.0f;
1637-
glm::mat4 invCamTrans = glm::translate(glm::mat4(1.0f), glm::vec3(0.375f * aspect, 0.37f, -1.5f));
1638-
glm::mat4 axesScale = glm::scale(glm::mat4(1.0f), glm::vec3(0.8f));
1678+
1679+
// Remap x and y position(-0.5 to 0.5) so the edge doesn't pass the margin, regardless of size
1680+
float margin = orientSize / 10.0f;
1681+
float xLow2 = -aspect/2 + margin;
1682+
float xHigh2 = aspect/2 - margin;
1683+
float yLow2 = -0.5 + margin;
1684+
float yHigh2 = 0.5 - margin;
1685+
float xPos, yPos;
1686+
1687+
// If the scale is larger than the width, the scale centers at 0
1688+
if(xLow2 > 0 && xHigh2 < 0)
1689+
{
1690+
xPos = 0;
1691+
}
1692+
else
1693+
{
1694+
xPos = xLow2 + (orientPosX + 0.5f) * (xHigh2 - xLow2);
1695+
}
1696+
yPos = yLow2 + (orientPosY + 0.5f) * (yHigh2 - yLow2);
1697+
1698+
glm::mat4 invCamTrans = glm::translate(glm::mat4(1.0f), glm::vec3(xPos, yPos, -1.5f));
1699+
glm::mat4 axesScale = glm::scale(glm::mat4(1.0f), glm::vec3(orientSize));
16391700
glm::mat4 axesTransform = axesScale * axesRot;
16401701

16411702
GLint locCamViewVec = glGetUniformLocation(shader, "uCamViewVec");

src/Interface/Modules/Render/ES/SRInterface.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ namespace SCIRun {
161161
/// Toggle Orientation Axes
162162
void showOrientation(bool value);
163163

164+
/// Set Orientation size
165+
void setOrientSize(int size);
166+
167+
/// Set Orientation X Position
168+
void setOrientPosX(int pos);
169+
170+
/// Set Orientation Y Position
171+
void setOrientPosY(int pos);
172+
173+
/// Set Orientation Top Right Corner
174+
void setDefaultOrientPos();
175+
176+
/// Set Orientation Center Corner
177+
void setCenterOrientPos();
178+
164179
/// Set the Background Color
165180
void setBackgroundColor(QColor color);
166181

@@ -347,6 +362,10 @@ namespace SCIRun {
347362
bool widgetSelected_; ///< Whether or not a widget is currently selected.
348363
bool widgetExists_; ///< Geometry contains a widget to find.
349364

365+
float orientSize; /// Size of coordinate axes
366+
float orientPosX; /// X Position of coordinate axes
367+
float orientPosY; /// Y Position of coordinate axes
368+
350369
uint64_t mSelectedID;
351370
int mZoomSpeed;
352371
MouseMode mMouseMode; ///< Current mouse mode.

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,38 @@ void ViewSceneDialog::showOrientationChecked(bool value)
555555
spire->showOrientation(value);
556556
}
557557

558+
void ViewSceneDialog::setOrientAxisSize(int value)
559+
{
560+
auto spire = mSpire.lock();
561+
spire->setOrientSize(value);
562+
}
563+
564+
void ViewSceneDialog::setOrientAxisPosX(int pos)
565+
{
566+
auto spire = mSpire.lock();
567+
spire->setOrientPosX(pos);
568+
}
569+
570+
void ViewSceneDialog::setOrientAxisPosY(int pos)
571+
{
572+
auto spire = mSpire.lock();
573+
spire->setOrientPosY(pos);
574+
}
575+
576+
void ViewSceneDialog::setCenterOrientPos()
577+
{
578+
setOrientAxisPosX(50);
579+
setOrientAxisPosY(50);
580+
//setSliderCenterPos();
581+
}
582+
583+
void ViewSceneDialog::setDefaultOrientPos()
584+
{
585+
setOrientAxisPosX(100);
586+
setOrientAxisPosY(100);
587+
//setSliderDefaultPos();
588+
}
589+
558590
//------------------------------------------------------------------------------
559591
void ViewSceneDialog::showAxisChecked(bool value)
560592
{

src/Interface/Modules/Render/ViewScene.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ namespace SCIRun {
7878
void autoViewOnLoadChecked(bool value);
7979
void useOrthoViewChecked(bool value);
8080
void showOrientationChecked(bool value);
81+
void setOrientAxisSize(int value);
82+
void setOrientAxisPosX(int pos);
83+
void setOrientAxisPosY(int pos);
84+
void setCenterOrientPos();
85+
void setDefaultOrientPos();
8186
void showAxisChecked(bool value);
8287
void viewBarButtonClicked();
8388
void viewAxisSelected(const QString& name);

0 commit comments

Comments
 (0)