VTK  9.1.0
Camera.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Types.h"
4
5#include "Object.h"
6
7#include <VisRTX.h>
8#include <cassert>
9#include <string>
10
11namespace RTW
12{
13 class Camera : public Object
14 {
15 friend class Renderer;
16
17 public:
19 {
20 VisRTX::Context* rtx = VisRTX_GetContext();
21
22 if (type == "perspective")
23 this->camera = rtx->CreatePerspectiveCamera();
24 else if (type == "orthographic")
25 this->camera = rtx->CreateOrthographicCamera();
26 else
27 assert(false);
28 }
29
31 {
32 this->camera->Release();
33 }
34
35 void Commit() override
36 {
37 VisRTX::Vec3f pos;
38 if (this->GetVec3f({ "position" }, &pos))
39 {
40 this->camera->SetPosition(pos);
41 }
42
43 VisRTX::Vec3f dir;
44 if (this->GetVec3f({ "direction" }, &dir))
45 {
46 this->camera->SetDirection(dir);
47 }
48
49 VisRTX::Vec3f up;
50 if (this->GetVec3f({ "up" }, &up))
51 {
52 this->camera->SetUp(up);
53 }
54
55 VisRTX::Vec2f imageBegin, imageEnd;
56 if (this->GetVec2f({ "imageStart" }, &imageBegin) && this->GetVec2f({ "imageEnd" }, &imageEnd))
57 {
58 this->camera->SetImageRegion(imageBegin, imageEnd);
59 }
60
61 if (this->camera->GetType() == VisRTX::CameraType::PERSPECTIVE)
62 {
63 VisRTX::PerspectiveCamera* pc = dynamic_cast<VisRTX::PerspectiveCamera*>(this->camera);
64
65 float fovy;
66 if (this->GetFloat({ "fovy" }, &fovy))
67 {
68 pc->SetFovY(fovy);
69 }
70
71 float aspect;
72 if (this->GetFloat({ "aspect" }, &aspect))
73 {
74 pc->SetAspect(aspect);
75 }
76
77 float focalDistance;
78 if (this->GetFloat({ "focusDistance" }, &focalDistance))
79 {
80 pc->SetFocalDistance(focalDistance);
81 }
82
83 float apertureRadius;
84 if (this->GetFloat({ "apertureRadius" }, &apertureRadius))
85 {
86 pc->SetApertureRadius(apertureRadius);
87 }
88 }
89
90 else if (this->camera->GetType() == VisRTX::CameraType::ORTHOGRAPHIC)
91 {
92 VisRTX::OrthographicCamera* oc = dynamic_cast<VisRTX::OrthographicCamera*>(this->camera);
93
94 float height;
95 if (this->GetFloat({ "height" }, &height))
96 {
97 oc->SetHeight(height);
98 }
99
100 float aspect;
101 if (this->GetFloat({ "aspect" }, &aspect))
102 {
103 oc->SetAspect(aspect);
104 }
105 }
106
107 else
108 {
109 assert(false);
110 }
111 }
112
113 private:
114 VisRTX::Camera* camera = nullptr;
115 };
116}
@ RTW_CAMERA
Definition: Types.h:135
void Commit() override
Definition: Camera.h:35
~Camera()
Definition: Camera.h:30
Camera(const std::string &type)
Definition: Camera.h:18
VisRTX::Vec2f GetVec2f(const std::vector< std::string > &ids, const VisRTX::Vec2f &defaultValue=VisRTX::Vec2f(), bool *found=nullptr) const
Definition: Object.h:167
float GetFloat(const std::vector< std::string > &ids, float defaultValue=0.0f, bool *found=nullptr) const
Definition: Object.h:133
VisRTX::Vec3f GetVec3f(const std::vector< std::string > &ids, const VisRTX::Vec3f &defaultValue=VisRTX::Vec3f(), bool *found=nullptr) const
Definition: Object.h:201
Definition: Backend.h:6
@ dir
Definition: vtkX3D.h:330
@ type
Definition: vtkX3D.h:522
@ height
Definition: vtkX3D.h:260
@ string
Definition: vtkX3D.h:496