Choreonoid  1.8
SceneCameras.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_UTIL_SCENE_CAMERAS_H
7 #define CNOID_UTIL_SCENE_CAMERAS_H
8 
9 #include "SceneGraph.h"
10 #include "exportdecl.h"
11 
12 namespace cnoid {
13 
14 class CNOID_EXPORT SgCamera : public SgPreprocessed
15 {
16 protected:
17  SgCamera(int classId);
18  SgCamera(const SgCamera& org);
19 
20 public:
21  static Isometry3 positionLookingFor(const Vector3& eye, const Vector3& direction, const Vector3& up);
22  static Isometry3 positionLookingAt(const Vector3& eye, const Vector3& center, const Vector3& up);
23 
24  template<class Scalar, int Mode, int Options>
25  static Eigen::Matrix<Scalar, 3, 1> right(const Eigen::Transform<Scalar, 3, Mode, Options>& T){
26  return T.linear().col(0);
27  }
28  template<class Scalar, int Mode, int Options>
29  static Eigen::Matrix<Scalar, 3, 1> direction(const Eigen::Transform<Scalar, 3, Mode, Options>& T){
30  return -T.linear().col(2);
31  }
32  template<class Scalar, int Mode, int Options>
33  static Eigen::Matrix<Scalar, 3, 1> up(const Eigen::Transform<Scalar, 3, Mode, Options>& T){
34  return T.linear().col(1);
35  }
36 
37  double nearClipDistance() const { return nearClipDistance_; }
38  void setNearClipDistance(double d) { nearClipDistance_ = d; }
39  double farClipDistance() const { return farClipDistance_; }
40  void setFarClipDistance(double d) { farClipDistance_ = d; }
41 
42 #ifdef CNOID_BACKWARD_COMPATIBILITY
43  double nearDistance() const { return nearClipDistance_; }
44  void setNearDistance(double d) { nearClipDistance_ = d; }
45  double farDistance() const { return farClipDistance_; }
46  void setFarDistance(double d) { farClipDistance_ = d; }
47 #endif
48 
49 private:
50  double nearClipDistance_;
51  double farClipDistance_;
52 };
54 
55 
56 class CNOID_EXPORT SgPerspectiveCamera : public SgCamera
57 {
58 protected:
59  SgPerspectiveCamera(int classId);
60 
61 public:
64 
65  double fieldOfView() const { return fieldOfView_; }
66  void setFieldOfView(double fov) { fieldOfView_ = fov; }
67 
68  static double fovy(double aspectRatio, double fieldOfView);
69 
70  double fovy(double aspectRatio) const {
71  return SgPerspectiveCamera::fovy(aspectRatio, fieldOfView_);
72  }
73 
74 protected:
75  virtual Referenced* doClone(CloneMap* cloneMap) const override;
76 
77 private:
78  double fieldOfView_;
79 };
81 
82 
83 class CNOID_EXPORT SgOrthographicCamera : public SgCamera
84 {
85 protected:
86  SgOrthographicCamera(int classId);
87 
88 public:
91 
92  double height() const { return height_; }
93  void setHeight(double h) { height_ = h; }
94 
95 protected:
96  virtual Referenced* doClone(CloneMap* cloneMap) const override;
97 
98 private:
99  double height_;
100 };
102 
103 }
104 
105 #endif
cnoid::Vector3
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
cnoid::SgCamera::right
static Eigen::Matrix< Scalar, 3, 1 > right(const Eigen::Transform< Scalar, 3, Mode, Options > &T)
Definition: SceneCameras.h:25
cnoid::SgPerspectiveCamera
Definition: SceneCameras.h:56
cnoid::SgPerspectiveCamera::fovy
static double fovy(double aspectRatio, double fieldOfView)
Definition: SceneCameras.cpp:77
cnoid::SgOrthographicCamera::height
double height() const
Definition: SceneCameras.h:92
cnoid::Isometry3
Eigen::Isometry3d Isometry3
Definition: EigenTypes.h:73
cnoid::SgCamera
Definition: SceneCameras.h:14
cnoid::SgCamera::setFarClipDistance
void setFarClipDistance(double d)
Definition: SceneCameras.h:40
cnoid::SgCamera::direction
static Eigen::Matrix< Scalar, 3, 1 > direction(const Eigen::Transform< Scalar, 3, Mode, Options > &T)
Definition: SceneCameras.h:29
cnoid::SgPreprocessed
Definition: SceneGraph.h:595
cnoid::ref_ptr< SgCamera >
cnoid::SgCamera::up
static Eigen::Matrix< Scalar, 3, 1 > up(const Eigen::Transform< Scalar, 3, Mode, Options > &T)
Definition: SceneCameras.h:33
cnoid::SgPerspectiveCamera::fieldOfView
double fieldOfView() const
Definition: SceneCameras.h:65
cnoid::SgCamera::nearClipDistance
double nearClipDistance() const
Definition: SceneCameras.h:37
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::CloneMap
Definition: CloneMap.h:13
cnoid::SgCamera::farClipDistance
double farClipDistance() const
Definition: SceneCameras.h:39
cnoid::SgPerspectiveCamera::setFieldOfView
void setFieldOfView(double fov)
Definition: SceneCameras.h:66
cnoid::SgCamera::setNearClipDistance
void setNearClipDistance(double d)
Definition: SceneCameras.h:38
cnoid::SgOrthographicCameraPtr
ref_ptr< SgOrthographicCamera > SgOrthographicCameraPtr
Definition: SceneCameras.h:101
cnoid::SgOrthographicCamera::setHeight
void setHeight(double h)
Definition: SceneCameras.h:93
cnoid::Referenced
Definition: Referenced.h:54
cnoid::SgPerspectiveCameraPtr
ref_ptr< SgPerspectiveCamera > SgPerspectiveCameraPtr
Definition: SceneCameras.h:80
SceneGraph.h
cnoid::SgPerspectiveCamera::fovy
double fovy(double aspectRatio) const
Definition: SceneCameras.h:70
cnoid::SgCameraPtr
ref_ptr< SgCamera > SgCameraPtr
Definition: SceneCameras.h:53
cnoid::SgOrthographicCamera
Definition: SceneCameras.h:83