@@ -183,6 +183,32 @@ void SlicePlane::updateWidgetEnabled() {
183183 bool enabled = getActive () && getDrawWidget ();
184184 transformGizmo.enabled = enabled;
185185}
186+
187+ void SlicePlane::setPose (glm::vec3 planePosition, glm::vec3 planeNormal) {
188+
189+ // Choose the other axes to be most similar to the current ones, which will make animations look smoother
190+ // if the grid is shown
191+ glm::vec3 currBasisX{objectTransform.get ()[1 ][0 ], objectTransform.get ()[1 ][1 ], objectTransform.get ()[1 ][2 ]};
192+ glm::vec3 currBasisY{objectTransform.get ()[2 ][0 ], objectTransform.get ()[2 ][1 ], objectTransform.get ()[2 ][2 ]};
193+
194+ glm::vec3 normal = glm::normalize (planeNormal);
195+ glm::vec3 basisX = currBasisX - normal * glm::dot (normal, currBasisX);
196+ if (glm::length (basisX) < 0.01 ) basisX = currBasisY - normal * glm::dot (normal, currBasisY);
197+ basisX = glm::normalize (basisX);
198+ glm::vec3 basisY = glm::cross (normal, basisX);
199+
200+ // Build the rotation component
201+ glm::mat4x4 newTransform = glm::mat4x4 (1.0 );
202+ for (int i = 0 ; i < 3 ; i++) newTransform[0 ][i] = normal[i];
203+ for (int i = 0 ; i < 3 ; i++) newTransform[1 ][i] = basisX[i];
204+ for (int i = 0 ; i < 3 ; i++) newTransform[2 ][i] = basisY[i];
205+
206+ // Build the translation component
207+ for (int i = 0 ; i < 3 ; i++) newTransform[3 ][i] = planePosition[i];
208+
209+ objectTransform = newTransform;
210+ polyscope::requestRedraw ();
211+ }
186212
187213bool SlicePlane::getActive () { return active.get (); }
188214void SlicePlane::setActive (bool newVal) {
0 commit comments