1#include <cgv/render/view.h>
2#include <cgv/math/geom.h>
4using namespace cgv::math;
11 : focus(0,0,0), view_up_dir(0,1,0), view_dir(0,0,-1), y_view_angle(0), y_extent_at_focus(2)
28 dvec3& axis,
double& angle)
30 dmat3 R = cgv::math::build_orthogonal_frame(view_dir, view_up_dir);
32 R = cgv::math::build_orthogonal_frame(target_view_dir, target_view_up_dir)*R;
35 int res = cgv::math::decompose_rotation_to_axis_and_angle(R, daxis, dangle);
44 return tan(.008726646260*((ensure_non_zero && (y_view_angle <= 0.01)) ? 0.01 : y_view_angle));
70 return y_extent_at_focus;
94 view_up_dir = normalize(vud);
100 view_dir = normalize(vd);
106 y_extent_at_focus = ext;
111 y_view_angle = angle;
117 return y_view_angle == 0;
135 dvec3::value_type l = new_view_dir.
length();
136 if (l < 10 * std::numeric_limits<dvec3::value_type>::epsilon())
138 dvec3::value_type inv_l = dvec3::value_type(1) / l;
139 view_dir = inv_l*new_view_dir;
151 dvec3::value_type l = new_view_dir.
length();
152 if (l < 10 * std::numeric_limits<dvec3::value_type>::epsilon())
154 dvec3::value_type inv_l = dvec3::value_type(1) / l;
155 view_dir = inv_l*new_view_dir;
156 y_view_angle = atan(0.5*y_extent_at_focus*inv_l)*114.5915590;
215 x = cross(view_up_dir, z);
233 view_up_dir = normalize(cgv::math::rotate(view_up_dir, view_dir, angle));
242void view::rotate(
double axis_direction_x,
double axis_direction_y,
double axis_point_depth)
246 dvec3 axis_dir = axis_direction_x*x + axis_direction_y*y;
247 double angle = axis_dir.
length();
248 if (angle < 10 * std::numeric_limits<double>::epsilon())
250 axis_dir *= 1.0 / angle;
251 dvec3 axis_point =
get_eye() + axis_point_depth*view_dir;
252 focus = cgv::math::rotate(
focus - axis_point, axis_dir, angle) + axis_point;
253 view_dir = normalize(cgv::math::rotate(view_dir, axis_dir, angle));
254 view_up_dir = normalize(cgv::math::rotate(view_up_dir, axis_dir, angle));
260 focus += step*view_dir;
268 focus += step_x*x + step_y* y;
274 y_extent_at_focus *= factor;
278 const dmat4** DPV_pptr,
279 const dmat4** DPV_other_pptr,
int* x_other_ptr,
int* y_other_ptr,
280 int* vp_col_idx_ptr,
int* vp_row_idx_ptr,
281 int* vp_width_ptr,
int *vp_height_ptr,
282 int* vp_center_x_ptr,
int* vp_center_y_ptr,
283 int* vp_center_x_other_ptr,
int* vp_center_y_other_ptr)
const
319 rect.push_back(c + x + y);
320 rect.push_back(c - x + y);
321 rect.push_back(c - x - y);
322 rect.push_back(c + x - y);
327 std::vector<dvec3> drect;
330 for (
const auto& p : drect)
331 rect.push_back(
vec3(p));
matrix of fixed size dimensions
void transpose()
transpose matrix
T normalize()
normalize the vector using the L2-Norm and return the length
T length() const
length of the vector L2-Norm
base class for all drawables, which is independent of the used rendering API.
defines a symmetric view with the following quantities:
virtual double get_z_and_unproject(context &ctx, int x, int y, dvec3 &p)
given an opengl pixel location x,y return the window z-value from the depth buffer
double & ref_y_extent_at_focus()
write access to extent at focus
bool set_eye_keep_view_angle(const dvec3 &eye)
set the view dir and y extent at focus keeping focus and y view angle such that get_eye() returns the...
virtual int get_modelview_projection_window_matrices(int x, int y, int width, int height, const dmat4 **MPW_pptr, const dmat4 **MPW_other_pptr=0, int *x_other_ptr=0, int *y_other_ptr=0, int *vp_col_idx_ptr=0, int *vp_row_idx_ptr=0, int *vp_width_ptr=0, int *vp_height_ptr=0, int *vp_center_x_ptr=0, int *vp_center_y_ptr=0, int *vp_center_x_other_ptr=0, int *vp_center_y_other_ptr=0) const
given an opengl pixel location and the size in pixels of the opengl window, return the modelview_proj...
const dvec3 & get_focus() const
query focus point
virtual bool is_viewport_splitting_enabled(unsigned *nr_cols_ptr=0, unsigned *nr_rows_ptr=0) const
check whether viewport splitting is activated and optionally set the number of columns and rows if co...
double get_y_extent_at_focus() const
query y extent of viewing window at focus point
virtual bool does_viewport_use_individual_view(unsigned col_index, unsigned row_index) const
check whether viewport manage its own view
void rotate(double axis_direction_x, double axis_direction_y, double axis_point_depth)
rotated view around axis by angle
dvec3 & ref_view_up_dir()
write access to view up direction
bool set_eye_keep_extent(const dvec3 &eye)
set view dir and y view angle keeping focus and y extent such that get_eye() returns the passed point...
const dvec3 get_eye() const
query the eye point, which is computed from focus, view dir, y extent at focus and y view angle
virtual void set_view_dir(const dvec3 &vd)
set view direction without ensuring orthogonality to view up direction
double get_y_extent_at_depth(double depth, bool ensure_non_zero) const
get y extent of viewing window at an arbitrary depth, if ensure_non_zero is true, replace y view angl...
dvec3 & ref_focus()
write access to focus point
double & ref_y_view_angle()
write access to view angle
view()
construct a parallel view with focus in the world origin looking in negative z-direction and the y-di...
virtual void set_y_extent_at_focus(double ext)
set y extent of viewing window at focus point keeping y view angle resulting in a zoom
dvec3 focus
focus of the view
virtual void set_view_up_dir(const dvec3 &vud)
set view up direction without ensuring orthogonality to view direction
double get_y_view_angle() const
query opening angle (degrees) of view in y-direction
dvec3 & ref_view_dir()
write access to view dir
const dvec3 & get_view_dir() const
query current view direction
virtual view & ref_viewport_view(unsigned col_index, unsigned row_index)
access the view of a given viewport
void put_coordinate_system(dvec3 &x, dvec3 &y, dvec3 &z) const
construct coordinate system with z in negative view direction and x and y aligned with the right and ...
void compute_screen_rectangle(std::vector< dvec3 > &rect, double depth, double aspect) const
fill rect with four points covering the screen rectangle at given depth from eye with given aspect ra...
void view_look_at_keep_view_angle(const dvec3 &eye, const dvec3 &foc, const dvec3 &vud)
set the view according to the standard view lookat definition from eye, focus and view up direction k...
virtual void enable_viewport_splitting(unsigned nr_cols, unsigned nr_rows)
call this function before a drawing process to support viewport splitting inside the draw call via th...
double get_tan_of_half_of_fovy(bool ensure_non_zero) const
compute tan of half of y view angle, if ensure_non_zero is true, replace y view angles < 0....
virtual void enable_viewport_individual_view(unsigned col_index, unsigned row_index, bool enable=true)
make a viewport manage its own view
virtual void deactivate_split_viewport(context &ctx)
deactivate the previously split viewport
double get_depth_of_focus() const
return the depth of the focus point
const dvec3 & get_view_up_dir() const
query current view up direction
virtual void disable_viewport_splitting()
disable viewport splitting
int compute_axis_and_angle(const dvec3 &target_view_dir, const dvec3 &target_view_up_dir, dvec3 &axis, double &angle)
compute axis and angle of a rotation that the current view_dir and view_up_dir to the given target_vi...
virtual void set_y_view_angle(double angle)
set opening angle (degrees) of view in y-direction keeping y extent at focus resulting in a dolly zoo...
void move(double step)
move along view direction by given step length in world coordinates
virtual void activate_split_viewport(context &ctx, unsigned col_index, unsigned row_index)
inside the drawing process activate the sub-viewport with the given column and row indices,...
void view_look_at_keep_extent(const dvec3 &eye, const dvec3 &foc, const dvec3 &vud)
set the view according to the standard view lookat definition from eye, focus and view up direction k...
void pan(double step_x, double step_y)
move in screen x and screen y directions by given step lengths in world coordinates
void roll(double angle)
roll view around view direction by angle
virtual void set_focus(const dvec3 &foc)
set a new focus point keeping y extent at focus and y view angle fix, such that the eye position is a...
void zoom(double factor)
zoom by given factor
bool is_parallel() const
return whether the y view angle is zero
cgv::math::fvec< double, 3 > dvec3
declare type of 3d double precision floating point vectors