Shiokaze Framework
A research-oriented fluid solver for computer graphics
camera3_interface.h
Go to the documentation of this file.
1 /*
2 ** camera3_interface.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on July 16, 2019.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_CAMERA3_INTERFACE_H
26 #define SHKZ_CAMERA3_INTERFACE_H
27 //
30 #include <shiokaze/math/vec.h>
31 #include <cmath>
32 #include "UI_interface.h"
33 //
35 //
40 public:
41  //
42  DEFINE_MODULE(camera3_interface,"Camera 3D","Camera","3D Camera module")
51  virtual void set_bounding_box( const double *p0, const double *p1 ) = 0;
64  virtual void look_at( const double *target, const double *position, const double *up, double fov ) = 0;
77  virtual void get( double *target, double *position, double *up, double *fov ) const = 0;
84  void look_at( const double *target ) {
85  //
86  double target_old[3], position[3], up[3], fov;
87  get(target_old,position,up,&fov);
88  look_at(target,position,up,fov);
89  }
108  void look_from( const double *target, const double *direction, double distance, const double *up, double fov, double near, double far ) {
109  //
110  double len = sqrt(direction[0]*direction[0]+direction[1]*direction[1]+direction[2]*direction[2]);
111  double position[3] = { target[0]+distance*direction[0]/len, target[1]+distance*direction[1]/len, target[2]+distance*direction[2]/len };
112  look_at(target,position,up,fov);
113  }
120  void set_distance( double distance ) {
121  //
122  double target[3], position[3], up[3], fov;
123  get(target,position,up,&fov);
124  double direction[3] = { position[0]-target[0], position[1]-target[1], position[2]-target[2] };
125  double len = sqrt(direction[0]*direction[0]+direction[1]*direction[1]+direction[2]*direction[2]);
126  position[0] = target[0]+distance*direction[0]/len;
127  position[1] = target[1]+distance*direction[1]/len;
128  position[2] = target[2]+distance*direction[2]/len;
129  look_at(target,position,up,fov);
130  }
137  double get_distance() const {
138  double target[3], position[3], up[3], fov;
139  get(target,position,up,&fov);
140  double direction[3] = { position[0]-target[0], position[1]-target[1], position[2]-target[2] };
141  return sqrt(direction[0]*direction[0]+direction[1]*direction[1]+direction[2]*direction[2]);
142  }
149  void set_fov( double fov ) {
150  //
151  double target[3], position[3], up[3], fov_old;
152  get(target,position,up,&fov_old);
153  look_at(target,position,up,fov);
154  }
163  virtual UI_interface::event_structure convert( const UI_interface::event_structure &event ) const = 0;
164 };
165 //
166 using camera3_ptr = std::unique_ptr<camera3_interface>;
168 //
170 //
171 #endif
172 //
camera3_interface::set_bounding_box
virtual void set_bounding_box(const double *p0, const double *p1)=0
Set a bounding box.
camera3_interface::get_distance
double get_distance() const
Get the distance of camera from the target position.
Definition: camera3_interface.h:137
camera3_interface::set_fov
void set_fov(double fov)
Change the field of view.
Definition: camera3_interface.h:149
recursive_configurable_driver
Class that encapsulates recursive_configurable class.
Definition: recursive_configurable_module.h:76
camera3_interface::look_from
void look_from(const double *target, const double *direction, double distance, const double *up, double fov, double near, double far)
Set up a camera with a target position, origin position and fov.
Definition: camera3_interface.h:108
DEFINE_MODULE
#define DEFINE_MODULE(CLASS_T, LNG_NAME, ARG_NAME, DESCRIPTION)
Definition that simplifies the loading module.
Definition: recursive_configurable_module.h:39
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
camera3_interface::set_distance
void set_distance(double distance)
Change the distance of camera from the target position.
Definition: camera3_interface.h:120
camera3_interface::convert
virtual UI_interface::event_structure convert(const UI_interface::event_structure &event) const =0
Convert event.
UI_interface::event_structure
Event information structure.
Definition: UI_interface.h:96
camera3_interface::get
virtual void get(double *target, double *position, double *up, double *fov) const =0
Get camera information about the target position, origin position, fov and others.
UI_interface
Interface for input APIs.
Definition: UI_interface.h:38
camera3_interface::look_at
virtual void look_at(const double *target, const double *position, const double *up, double fov)=0
Set up a camera with a target position, origin position, fov and others.
camera3_interface
Interface for 3D camera manipulations.
Definition: camera3_interface.h:39
vec.h
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
UI_interface.h
recursive_configurable_module.h
recursive_configurable_module
recursive_configurable class that also inherits module.
Definition: recursive_configurable_module.h:49
graphics_engine.h