Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Feb 16, 2025
1 parent cd25a33 commit d764311
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 221 deletions.
2 changes: 1 addition & 1 deletion applications/Mapple/paint_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ void PaintCanvas::pasteCamera() {
new_frame.setPosition(pos);
new_frame.setOrientation(orient);
const float duration = 0.5f;
camera()->interpolateTo(new_frame, duration);
camera()->interpolateTo(&new_frame, duration);

update();
}
Expand Down
2 changes: 1 addition & 1 deletion applications/Mapple/walk_through.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ int WalkThrough::move_to(int idx, bool animation /* = true */, float duration /*

const auto frame = kfi_->keyframe(idx);
if (animation)
camera_->interpolateTo(frame, duration);
camera_->interpolateTo(&frame, duration);
else
camera_->frame()->setPositionAndOrientation(frame.position(), frame.orientation());

Expand Down
66 changes: 28 additions & 38 deletions easy3d/renderer/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
#include <easy3d/renderer/key_frame_interpolator.h>


// \cond
namespace easy3d {


/*! Default constructor.
sceneCenter() is set to (0,0,0) and sceneRadius() is set to 1.0. type() is
Camera::PERSPECTIVE, with a \c M_PI/4 fieldOfView().
PERSPECTIVE, with a \c M_PI/4 fieldOfView().
See IODistance(), physicalDistanceToScreen(), physicalScreenWidth() and
focusDistance() documentations for default stereo parameter values. */
Expand Down Expand Up @@ -223,10 +224,10 @@ namespace easy3d {
const float zMin = zNearCoefficient() * zNearScene;
if (z < zMin)
switch (type()) {
case Camera::PERSPECTIVE:
case PERSPECTIVE:
z = zMin;
break;
case Camera::ORTHOGRAPHIC:
case ORTHOGRAPHIC:
z = 0.0;
break;
}
Expand Down Expand Up @@ -267,13 +268,13 @@ namespace easy3d {
Prefix the type with \c Camera if needed, as in:
\code
camera()->setType(Camera::ORTHOGRAPHIC);
camera()->setType(ORTHOGRAPHIC);
\endcode */
void Camera::setType(Type type) {
// make ORTHOGRAPHIC frustum fit PERSPECTIVE (at least in plane normal to
// viewDirection(), passing through RAP). Done only when CHANGING type since
// orthoCoef_ may have been changed with a setPivotPoint() in the meantime.
if ((type == Camera::ORTHOGRAPHIC) && (type_ == Camera::PERSPECTIVE))
if ((type == ORTHOGRAPHIC) && (type_ == PERSPECTIVE))
orthoCoef_ = std::tan(fieldOfView() / 2.0f);
type_ = type;
projectionMatrixIsUpToDate_ = false;
Expand Down Expand Up @@ -318,7 +319,7 @@ namespace easy3d {
frustum.
These values are only valid and used when the Camera is of type()
Camera::ORTHOGRAPHIC. They are expressed in OpenGL units and are used by
ORTHOGRAPHIC. They are expressed in OpenGL units and are used by
loadProjectionMatrix() to define the projection matrix using: \code glOrtho(
-halfWidth, halfWidth, -halfHeight, halfHeight, zNear(), zFar() ) \endcode
Expand All @@ -338,11 +339,11 @@ namespace easy3d {

/*! Computes the projection matrix associated with the Camera.
If type() is Camera::PERSPECTIVE, defines a \c GL_PROJECTION matrix similar to
If type() is PERSPECTIVE, defines a \c GL_PROJECTION matrix similar to
what would \c gluPerspective() do using the fieldOfView(), window
aspectRatio(), zNear() and zFar() parameters.
If type() is Camera::ORTHOGRAPHIC, the projection matrix is as what \c
If type() is ORTHOGRAPHIC, the projection matrix is as what \c
glOrtho() would do. Frustum's width and height are set using
getOrthoWidthHeight().
Expand All @@ -368,7 +369,7 @@ namespace easy3d {

switch (type())
{
case Camera::PERSPECTIVE:
case PERSPECTIVE:
{
// #CONNECTION# all non-null coefficients were set to 0.0 in constructor.
const float f = 1.0f / std::tan(fieldOfView() / 2.0f);
Expand All @@ -381,7 +382,7 @@ namespace easy3d {
// same as gluPerspective( 180.0*fieldOfView()/M_PI, aspectRatio(), zNear(), zFar() );
break;
}
case Camera::ORTHOGRAPHIC:
case ORTHOGRAPHIC:
{
float w, h;
getOrthoWidthHeight(w, h);
Expand Down Expand Up @@ -587,10 +588,10 @@ namespace easy3d {
camera()->upVector()); glEnd(); \endcode */
float Camera::pixelGLRatio(const vec3 &position) const {
switch (type()) {
case Camera::PERSPECTIVE:
case PERSPECTIVE:
return 2.0f * std::fabs((frame()->coordinatesOf(position)).z) *
std::tan(fieldOfView() / 2.0f) / static_cast<float>(screenHeight());
case Camera::ORTHOGRAPHIC: {
case ORTHOGRAPHIC: {
float w(0), h(0);
getOrthoWidthHeight(w, h);
return 2.0f * h / static_cast<float>(screenHeight());
Expand Down Expand Up @@ -656,7 +657,7 @@ namespace easy3d {
#else
tempFrame.setPositionAndOrientation(pos, ori);
#endif
interpolateTo(tempFrame, 0.5);
interpolateTo(&tempFrame, 0.5);
}

/*! Interpolates the Camera on a one second KeyFrameInterpolator path so that
Expand All @@ -678,7 +679,7 @@ namespace easy3d {
showEntireScene();
setFrame(originalFrame);

interpolateTo(tempFrame, 0.5);
interpolateTo(&tempFrame, 0.5);
}

/*! Smoothly interpolates the Camera on a KeyFrameInterpolator path so that it
Expand All @@ -688,13 +689,13 @@ namespace easy3d {
speed (default is 1 second).
See also interpolateToFitScene() and interpolateToZoomOnPixel(). */
void Camera::interpolateTo(const Frame &fr, float duration) {
void Camera::interpolateTo(const Frame *fr, float duration) {
if (interpolationKfi_->is_interpolation_started())
interpolationKfi_->stop_interpolation();

interpolationKfi_->delete_path();
interpolationKfi_->add_keyframe(*frame());
interpolationKfi_->add_keyframe(fr, duration);
interpolationKfi_->add_keyframe(*fr, duration);
interpolationKfi_->start_interpolation();
}

Expand Down Expand Up @@ -739,13 +740,13 @@ namespace easy3d {
void Camera::fitSphere(const vec3 &center, float radius) const {
float distance = 0.0f;
switch (type()) {
case Camera::PERSPECTIVE: {
case PERSPECTIVE: {
const float yview = radius / std::sin(fieldOfView() / 2.0f);
const float xview = radius / std::sin(horizontalFieldOfView() / 2.0f);
distance = std::max(xview, yview);
break;
}
case Camera::ORTHOGRAPHIC: {
case ORTHOGRAPHIC: {
distance = dot((center - pivotPoint()), viewDirection()) + (radius / orthoCoef_);
break;
}
Expand Down Expand Up @@ -791,14 +792,14 @@ namespace easy3d {

float distance = 0.0f;
switch (type()) {
case Camera::PERSPECTIVE: {
case PERSPECTIVE: {
const float distX =
(pointX - newCenter).norm() / std::sin(horizontalFieldOfView() / 2.0f);
const float distY = (pointY - newCenter).norm() / std::sin(fieldOfView() / 2.0f);
distance = std::max(distX, distY);
break;
}
case Camera::ORTHOGRAPHIC: {
case ORTHOGRAPHIC: {
const float dist = dot((newCenter - pivotPoint()), vd);
//#CONNECTION# getOrthoWidthHeight
const float distX = (pointX - newCenter).norm() / orthoCoef_ /
Expand Down Expand Up @@ -899,7 +900,7 @@ namespace easy3d {
Use setPosition() to set the Camera position. Other convenient methods are
showEntireScene() or fitSphere(). Actually returns \c frame()->position().
This position corresponds to the projection center of a Camera::PERSPECTIVE
This position corresponds to the projection center of a PERSPECTIVE
Camera. It is not located in the image plane, which is at a zNear() distance
ahead. */
vec3 Camera::position() const { return frame()->position(); }
Expand Down Expand Up @@ -1317,22 +1318,10 @@ namespace easy3d {
return p;
}

/*! Gives the coefficients of a 3D half-line passing through the Camera eye and
pixel (x,y).

The origin of the half line (eye position) is stored in \p orig, while \p dir
contains the properly oriented and normalized direction of the half line.
\p x and \p y are expressed in Qt format (origin in the upper left corner). Use
screenHeight() - y to convert to OpenGL units.
This method is useful for analytical intersection in a selection method.
See the <a href="../examples/select.html">select example</a> for an
illustration. */
void Camera::convertClickToLine(int x, int y, vec3 &orig, vec3 &dir) const {
switch (type()) {
case Camera::PERSPECTIVE:
case PERSPECTIVE:
orig = position();
dir = vec3(
((2.0f * static_cast<float>(x) / static_cast<float>(screenWidth())) - 1.0f) * std::tan(fieldOfView() / 2.0f) * aspectRatio(),
Expand All @@ -1343,7 +1332,7 @@ namespace easy3d {
dir.normalize();
break;

case Camera::ORTHOGRAPHIC: {
case ORTHOGRAPHIC: {
float w, h;
getOrthoWidthHeight(w, h);
orig = vec3(
Expand Down Expand Up @@ -1395,7 +1384,7 @@ namespace easy3d {

switch (type())
{
case Camera::PERSPECTIVE:
case PERSPECTIVE:
{
const float hhfov = horizontalFieldOfView() / 2.0f;
const float chhfov = std::cos(hhfov);
Expand Down Expand Up @@ -1436,7 +1425,7 @@ namespace easy3d {

break;
}
case Camera::ORTHOGRAPHIC:
case ORTHOGRAPHIC:
normal[0] = -right;
normal[1] = right;
normal[4] = up;
Expand Down Expand Up @@ -1753,5 +1742,6 @@ namespace easy3d {
// http://www.markmorley.com/opengl/frustumculling.html
// http://www.crownandcutlass.com/features/technicaldetails/frustum.html
//

}

// \endcond
Loading

0 comments on commit d764311

Please sign in to comment.