Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Feb 11, 2025
1 parent d795a8f commit 985a578
Show file tree
Hide file tree
Showing 12 changed files with 629 additions and 368 deletions.
86 changes: 50 additions & 36 deletions easy3d/gui/picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,30 @@ namespace easy3d {
*/
class Picker {
public:
/**
* \brief Constructor.
* \param cam The camera used for picking.
*/
explicit Picker(const Camera *cam);

/**
* \brief Destructor.
*/
virtual ~Picker();

/// \brief Returns the pointer of the camera.
/**
* \brief Returns the pointer of the camera.
* \return The camera pointer.
*/
const Camera *camera() const { return camera_; }

/**
* \brief Construct a picking line.
* @param x The cursor x-coordinate, relative to the left edge of the content area.
* @param y The cursor y-coordinate, relative to the top edge of the content area.
* @attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
* \param x The cursor x-coordinate, relative to the left edge of the content area.
* \param y The cursor y-coordinate, relative to the top edge of the content area.
* \attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
* \return The picking line.
*/
Line3 picking_line(int x, int y) const {
const vec3 p_near = unproject(x, y, 0);
Expand All @@ -65,60 +75,64 @@ namespace easy3d {

/**
* \brief The picking direction, pointing inside the screen.
* @param x The cursor x-coordinate, relative to the left edge of the content area.
* @param y The cursor y-coordinate, relative to the top edge of the content area.
* @attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
* \param x The cursor x-coordinate, relative to the left edge of the content area.
* \param y The cursor y-coordinate, relative to the top edge of the content area.
* \attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
* \return The picking direction.
*/
vec3 picking_dir(int x, int y) const {
return picking_line(x, y).direction();
}

/**
* \brief Project a 3D point in the world coordinate system onto the 2D screen coordinate system.
* @param p A 3D point in the world coordinate system.
* @return The x and y components of the returned value denote the projected screen point expressed in the
* screen coordinate system, with (0, 0) being the upper left corner of the content area. The z
* component ranges between 0.0 (near plane) and 1.0 (excluded, far plane).
* @attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
* \param p A 3D point in the world coordinate system.
* \return The x and y components of the returned value denote the projected screen point expressed in the
* screen coordinate system, with (0, 0) being the upper left corner of the content area. The z
* component ranges between 0.0 (near plane) and 1.0 (excluded, far plane).
* \attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
*/
vec3 project(const vec3 &p) const {
return camera()->projectedCoordinatesOf(p);
}

/**
* \brief Compute the world coordinates of a point defined in the screen coordinate system.
* @param x The cursor x-coordinate, relative to the left edge of the content area.
* @param y The cursor y-coordinate, relative to the top edge of the content area.
* @param depth The depth value of the screen point, ranging between 0.0 and 1.0 (excluded).
* @return The world unprojected coordinates of the screen point.
* @attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
* \param x The cursor x-coordinate, relative to the left edge of the content area.
* \param y The cursor y-coordinate, relative to the top edge of the content area.
* \param depth The depth value of the screen point, ranging between 0.0 and 1.0 (excluded).
* \return The world unprojected coordinates of the screen point.
* \attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
*/
vec3 unproject(int x, int y, float depth) const {
return camera()->unprojectedCoordinatesOf(vec3(static_cast<float>(x), static_cast<float>(y), depth));
}

/**
* \brief Convert a point expressed in the screen coordinate system (with an origin in the upper left corner)
* into the OpenGL coordinate system (with an origin in the lower left corner). The high DPI scaling is also
* taken into consideration, so the result always corresponds to its image pixel.
* @param x The x-coordinate, relative to the left edge of the content area.
* @param y The y-coordinate, relative to the top edge of the content area.
* @param gl_x Returns the x component of the point in the OpenGL coordinate system.
* @param gl_y Returns the y component of the point in the OpenGL coordinate system.
* @param width The width of the OpenGL viewport (may not be identical to the width of the screen in pixels).
* @param height The width of the OpenGL viewport (may not be identical to the height of the screen in pixels).
* into the OpenGL coordinate system (with an origin in the lower left corner). The high DPI scaling is
* also taken into consideration, so the result always corresponds to its image pixel.
* \param x The x-coordinate, relative to the left edge of the content area.
* \param y The y-coordinate, relative to the top edge of the content area.
* \param gl_x Returns the x component of the point in the OpenGL coordinate system.
* \param gl_y Returns the y component of the point in the OpenGL coordinate system.
* \param width The width of the OpenGL viewport (may not be identical to the width of the screen in pixels).
* \param height The width of the OpenGL viewport (may not be identical to the height of the screen in pixels).
*/
void screen_to_opengl(int x, int y, int &gl_x, int &gl_y, int width, int height) const;

protected:

// prepare a frame buffer for the offscreen rendering
/**
* \brief Prepare a frame buffer for the offscreen rendering.
* \param width The width of the frame buffer.
* \param height The height of the frame buffer.
*/
void setup_framebuffer(int width, int height);

protected:
Expand Down
34 changes: 22 additions & 12 deletions easy3d/gui/picker_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,43 @@ namespace easy3d {
*/
class ModelPicker : public Picker {
public:
/**
* \brief Constructor.
* \param cam The camera used for picking.
*/
explicit ModelPicker(const Camera *cam);

/**
* \brief Destructor.
*/
~ModelPicker() override = default;

/**
* \brief Pick a model from a set of models given the cursor position in the screen coordinate system.
* @param models The models
* @param x The cursor x-coordinate, relative to the left edge of the content area.
* @param y The cursor y-coordinate, relative to the top edge of the content area.
* @attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* \param models The models.
* \param x The cursor x-coordinate, relative to the left edge of the content area.
* \param y The cursor y-coordinate, relative to the top edge of the content area.
* \attention The screen point is expressed in the screen coordinate system with an origin in the upper left
* corner. So it doesn't necessarily correspond to a pixel on High DPI devices, e.g. a Mac with
* a Retina display.
* @return The picked model.
* \return The picked model.
*/
Model *pick(const std::vector< std::shared_ptr<Model> >& models, int x, int y);

private:

// render each model of the scene with a unique color
/**
* \brief Render each model of the scene with a unique color.
* \param models The models to render.
*/
void draw(const std::vector< std::shared_ptr<Model> >& models);
// render the drawable with color
/**
* \brief Render the drawable with color.
* \param drawable The drawable to render.
* \param color The color to use for rendering.
*/
void draw(Drawable *drawable, const vec4 &color);

private:

std::unordered_map<Drawable *, State> states_;

std::unordered_map<Drawable *, State> states_; ///< The states of the drawables.
};


Expand Down
12 changes: 5 additions & 7 deletions easy3d/renderer/key_frame_interpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,21 @@ namespace easy3d {


float KeyFrameInterpolator::duration() const {
return lastTime() - firstTime();
return last_time() - first_time();
}


float KeyFrameInterpolator::firstTime() const {
float KeyFrameInterpolator::first_time() const {
if (keyframes_.empty())
return 0.0f;
else
return keyframes_.front().time();
return keyframes_.front().time();
}


float KeyFrameInterpolator::lastTime() const {
float KeyFrameInterpolator::last_time() const {
if (keyframes_.empty())
return 0.0f;
else
return keyframes_.back().time();
return keyframes_.back().time();
}


Expand Down
Loading

0 comments on commit 985a578

Please sign in to comment.