forked from mortennobel/SimpleRenderEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti-cameras.cpp
More file actions
110 lines (91 loc) · 3.32 KB
/
Copy pathmulti-cameras.cpp
File metadata and controls
110 lines (91 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <vector>
#include <fstream>
#include "sre/Texture.hpp"
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"
#include "sre/impl/GL.hpp"
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <sre/Inspector.hpp>
using namespace sre;
class MultiCamExample {
public:
MultiCamExample(){
r.init();
camera.lookAt(eye,at,up);
camera.setPerspectiveProjection(60,0.1,100);
camera2.lookAt({0,0,3},{0,0,0},{0,1,0});
camera2.setPerspectiveProjection(60,0.1,100);
camera2.setViewport({0,0.8},{0.2,0.2});
material = Shader::getStandardBlinnPhong()->createMaterial();
material->setColor({1.0f,1.0f,1.0f,1.0f});
material->setSpecularity(Color(.5,.5,.5,20.0f));
mesh = Mesh::create().withCube().build();
worldLights.setAmbientLight({0.5,0.5,0.5});
worldLights.addLight(Light::create().withPointLight({0, 3,0}).withColor({1,0,0}).withRange(20).build());
worldLights.addLight(Light::create().withPointLight({3, 0,0}).withColor({0,1,0}).withRange(20).build());
worldLights.addLight(Light::create().withPointLight({0,-3,0}).withColor({0,0,1}).withRange(20).build());
worldLights.addLight(Light::create().withPointLight({-3,0,0}).withColor({1,1,1}).withRange(20).build());
r.frameRender = [&](){
render();
};
r.startEventLoop();
}
void render(){
auto renderPass = RenderPass::create()
.withCamera(camera)
.withWorldLights(&worldLights)
.withClearColor(true, {1, 0, 0, 1})
.withGUI(false)
.build();
renderPass.draw(mesh, glm::eulerAngleY(glm::radians((float)i)), material);
renderPass.finish();
auto renderPass2 = RenderPass::create()
.withCamera(camera2)
.withWorldLights(&worldLights)
.withClearColor(true, {1, 1, 0, 1})
.withGUI(true)
.build();
renderPass2.draw(mesh, glm::eulerAngleY(glm::radians((float)i)), material);
static bool lookAt = true;
ImGui::Checkbox("LookAt",&lookAt);
if (lookAt){
ImGui::DragFloat3("eye",&eye.x);
ImGui::DragFloat3("at",&at.x);
ImGui::DragFloat3("up",&up.x);
camera.lookAt(eye, at, up);
} else {
ImGui::DragFloat3("position",&position.x);
ImGui::DragFloat3("rotation",&rotation.x);
camera.setPositionAndRotation(position, rotation);
}
auto pos = camera.getPosition();
auto rot = camera.getRotationEuler();
ImGui::LabelText("GetPos","%f %f %f", pos.x, pos.y, pos.z);
ImGui::LabelText("GetRot","%f %f %f", rot.x, rot.y, rot.z);
// static Inspector prof;
// prof.update();
// prof.gui(true);
i++;
}
private:
glm::vec3 eye{0,0,3};
glm::vec3 at{0,0,0};
glm::vec3 up{0,1,0};
glm::vec3 position{0,0,3};
glm::vec3 rotation{0,0,0};
SDLRenderer r;
Camera camera;
Camera camera2;
WorldLights worldLights;
std::shared_ptr<Mesh> mesh;
std::shared_ptr<Material> material;
int i=0;
};
int main() {
std::make_unique<MultiCamExample>();
return 0;
}