Skip to content

Commit f4c8f94

Browse files
committed
set splice plane pose
1 parent 289dcbb commit f4c8f94

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

include/polyscope/slice_plane.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class SlicePlane {
3030

3131
const std::string name;
3232
const std::string postfix;
33+
34+
// Set the position and orientation of the plane
35+
// planePosition is any 3D position which the plane touches (the center of the plane)
36+
// planeNormal is a vector giving the normal direction of the plane, objects
37+
// in this negative side of the plane will be culled
38+
void setPose(glm::vec3 planePosition, glm::vec3 planeNormal);
3339

3440
// == Some getters and setters
3541

@@ -44,6 +50,7 @@ class SlicePlane {
4450

4551
glm::mat4 getTransform();
4652
void setTransform(glm::mat4 newTransform);
53+
4754

4855
protected:
4956
// = State

src/slice_plane.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

187213
bool SlicePlane::getActive() { return active.get(); }
188214
void SlicePlane::setActive(bool newVal) {

0 commit comments

Comments
 (0)