Skip to content

Commit

Permalink
- export parameter group
Browse files Browse the repository at this point in the history
- add option to get camera clipping planes
  • Loading branch information
cklosters committed Oct 25, 2022
1 parent 04801e6 commit 0e67d6d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/napparameter/src/parametergroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ namespace nap
// For backwards compatibility reasons, override the default 'Members' and 'Children' property names
// of the 'nap::ParameterGroup' to the property names introduced before the arrival of the generic nap::Group<T>.
template<>
nap::Group<Parameter>::Group();
NAPAPI nap::Group<Parameter>::Group();
}
44 changes: 29 additions & 15 deletions modules/naprender/src/perspcameracomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,37 @@ namespace nap
}


float PerspCameraComponentInstance::getNearClippingPlane() const
{
return mProperties.mNearClippingPlane;
}


float PerspCameraComponentInstance::getFarClippingPlane() const
{
return mProperties.mFarClippingPlane;
}


void PerspCameraComponentInstance::updateProjectionMatrices() const
{
if (mDirty)
{
const float fov = glm::radians(mProperties.mFieldOfView);
const float near_plane = mProperties.mNearClippingPlane;
const float far_plane = mProperties.mFarClippingPlane;
const float aspect_ratio = ((float)(getRenderTargetSize().x * mProperties.mGridDimensions.x)) / ((float)(getRenderTargetSize().y * mProperties.mGridDimensions.y));

float left, right, top, bottom;
calculateCameraPlanes(fov, aspect_ratio, near_plane, mProperties.mGridDimensions.x, mProperties.mGridLocation.x, left, right);
calculateCameraPlanes(fov, 1.0f, near_plane, mProperties.mGridDimensions.y, mProperties.mGridLocation.y, bottom, top);
mRenderProjectionMatrix = createASymmetricProjection(near_plane, far_plane, left, right, top, bottom);

mProjectionMatrix = glm::perspective(fov, aspect_ratio, near_plane, far_plane);
mDirty = false;
}
// Bail if there's nothing to update
if (!mDirty)
return;

// Compute projection matrix
const float fov = glm::radians(mProperties.mFieldOfView);
const float near_plane = mProperties.mNearClippingPlane;
const float far_plane = mProperties.mFarClippingPlane;
const float aspect_ratio = ((float)(getRenderTargetSize().x * mProperties.mGridDimensions.x)) / ((float)(getRenderTargetSize().y * mProperties.mGridDimensions.y));

float left, right, top, bottom;
calculateCameraPlanes(fov, aspect_ratio, near_plane, mProperties.mGridDimensions.x, mProperties.mGridLocation.x, left, right);
calculateCameraPlanes(fov, 1.0f, near_plane, mProperties.mGridDimensions.y, mProperties.mGridLocation.y, bottom, top);
mRenderProjectionMatrix = createASymmetricProjection(near_plane, far_plane, left, right, top, bottom);

mProjectionMatrix = glm::perspective(fov, aspect_ratio, near_plane, far_plane);
mDirty = false;
}


Expand Down
12 changes: 11 additions & 1 deletion modules/naprender/src/perspcameracomponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,20 @@ namespace nap
void setFieldOfView(float fov);

/**
* @return current field of view
* @return camera field of view
*/
float getFieldOfView() const;

/**
* @return camera near clipping plane
*/
float getNearClippingPlane() const;

/**
* @return camera far clipping plane
*/
float getFarClippingPlane() const;

/**
* Returns the matrix that is used to transform a 3d scene in to a 2d projection by the renderer.
* Vulkan uses a coordinate system where (-1, -1) is in the top left quadrant, instead of the bottom left quadrant.
Expand Down

0 comments on commit 0e67d6d

Please sign in to comment.