1 #include "animationMode.hpp"
3 AnimationMode::AnimationMode(std::string modelPath) {
4 const aiScene *scene = importer.ReadFile(
5 modelPath, aiProcess_Triangulate | aiProcess_CalcTangentSpace |
6 aiProcess_GenNormals | aiProcess_FlipUVs);
8 std::cerr << importer.GetErrorString() << std::endl;
12 if (scene->mNumCameras > 0) {
13 aiCamera *cam = scene->mCameras[0];
15 if (findNodeTrans(scene->mRootNode, cam->mName, &camTrans) != 0)
16 abort(); // there must be a node with the same name as camera
18 camPos = {camTrans[3][0], camTrans[3][1], camTrans[3][2]};
21 glm::vec3(cam->mLookAt.x, cam->mLookAt.y, cam->mLookAt.z);
22 camFront = camLookAt - camPos;
24 camUp = glm::vec3(cam->mUp.x, cam->mUp.y, cam->mUp.z);
26 fov = cam->mHorizontalFOV;
27 // TODO: aspectRatio = cam->mAspect;
28 znear = cam->mClipPlaneNear;
29 zfar = cam->mClipPlaneFar;
32 for (int i = 0; i < scene->mNumLights; i++) {
33 aiLight *light = scene->mLights[i];
35 findNodeTrans(scene->mRootNode, light->mName, &trans);
36 glm::vec3 col = {light->mColorAmbient.r, light->mColorAmbient.g,
37 light->mColorAmbient.b};
38 Light l = {trans, col};
42 sceneModel = new Model(scene, *pbrProg);
45 void AnimationMode::display(float d) override {
46 sceneModel->draw(skyboxes[activeSkybox], d * 1000);
48 for (Light &light: lights) drawLight(light);
51 void drawLight(Light &light) {
52 drawPlainProg(plainProg, lightVao, light.trans, light.color);
55 void AnimationMode::timer() override {};
56 void AnimationMode::motion(int x, int y, int dx, int dy) override {}
57 void AnimationMode::passiveMotion(int x, int y, int dx, int dy) override {}
58 void AnimationMode::mouse(int button, int state, int x, int y) override {}
60 std::vector<Light> AnimationMode::getLights(float d) {
61 std::vector<Light> ls = lights;
64 for (int i = 0; i < 3; i++)
65 auto m = glm::translate(glm::mat4(1.f), glm::vec3(-2.5, 0, 0));
66 m = glm::rotate(m, glm::radians(d * 100 + i * 30), glm::vec3(1, 0, 0));
67 m = glm::rotate(m, glm::radians(d * 100 + i * 30), glm::vec3(0, 1, 0));
68 m = glm::rotate(m, glm::radians(d * 100 + i * 30), glm::vec3(0, 0, 1));
69 Light l = { glm::translate(glm::mat4(1), glm::vec3(m * glm::vec4(5, 0, 0, 1)))
72 if (i % 3 == 0) l.color.x = sin(d);
73 if (i % 3 == 1) l.color.y = cos(d * 3);
74 if (i % 3 == 2) l.color.z = cos(d);