Skip to content

Commit

Permalink
Allow vdb_view to print camera transformation matrix
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Flesher <chris.flesher@gmail.com>
  • Loading branch information
chrisflesher committed Apr 15, 2024
1 parent 45d2ce4 commit 5253a48
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions openvdb_cmd/vdb_view/Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ Camera::Camera()
}


openvdb::Mat4s
Camera::getTransformationMatrix()
{
float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
return openvdb::Mat4s(matrix);
}


void
Camera::lookAt(const openvdb::Vec3d& p, double dist)
{
Expand Down
2 changes: 2 additions & 0 deletions openvdb_cmd/vdb_view/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Camera

void aim();

openvdb::Mat4s getTransformationMatrix();

void lookAt(const openvdb::Vec3d& p, double dist = 1.0);
void lookAtTarget();

Expand Down
11 changes: 11 additions & 0 deletions openvdb_cmd/vdb_view/Viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ViewerImpl
void showNextGrid();

bool needsDisplay();
void printCameraTransformationMatrix();
void setNeedsDisplay();

void toggleRenderModule(size_t n);
Expand Down Expand Up @@ -992,6 +993,9 @@ ViewerImpl::keyCallback(int key, int action)
case 'i': case 'I':
toggleInfoText();
break;
case 'p': case 'P':
printCameraTransformationMatrix();
break;
case GLFW_KEY_LEFT:
showPrevGrid();
break;
Expand Down Expand Up @@ -1084,6 +1088,13 @@ ViewerImpl::needsDisplay()
}


void
ViewerImpl::printCameraTransformationMatrix()
{
std::cout << mCamera->getTransformationMatrix() << std::endl;
}


void
ViewerImpl::setNeedsDisplay()
{
Expand Down
1 change: 1 addition & 0 deletions openvdb_cmd/vdb_view/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ usage [[noreturn]] (const char* progName, int status)
" G (\"geometry\") look at center of geometry\n" <<
" H (\"home\") look at origin\n" <<
" I toggle on-screen grid info on/off\n" <<
" P print camera transformation matrix\n" <<
" left mouse tumble\n" <<
" right mouse pan\n" <<
" mouse wheel zoom\n" <<
Expand Down

0 comments on commit 5253a48

Please sign in to comment.