-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
132 lines (101 loc) · 3.9 KB
/
main.cpp
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* spriteClass.cpp
*
* Ce programme est distribué sous les termes de la Licence Publique
* Générale GNU, version 3.0, telle que publiée par la Free Software
* Foundation. Consultez la Licence Publique Générale GNU pour plus de
* détails.
*
* Vous devez avoir reçu une copie de la Licence Publique Générale GNU
* en même temps que ce programme. Si ce n'est pas le cas, consultez
* <https://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////
//CECI N'EST QU'UN EXEMPLE POUR TESTER SI BBOP EST BIEN INSTALLER
////////////////////////////////////////////////////////////////////
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <cmath>
#include <glm/fwd.hpp>
#include <glm/glm.hpp>
#include <chrono>
#include "include/BBOP/Graphics.h"
#include "include/BBOP/Graphics/animatedSpriteClass.h"
#include "include/BBOP/Graphics/bbopGlobal.h"
#include "include/BBOP/Graphics/bbopMathClass.h"
#include "include/BBOP/Graphics/collisionBoxClass.h"
#include "include/BBOP/Graphics/fontsClass.h"
#include "include/BBOP/Graphics/shapeClass.h"
using namespace std;
float fast_rand(float min, float max) {
static unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
seed = (214013 * seed + 2531011); // LCG constants
return min + (seed >> 16) * (1.0f / 65535.0f) * (max - min); // Scale to [min, max]
}
//tentative de simuler une bougie
int main() {
GLFWwindow * window;
bbopInit(1920,1080,"name",window);
Scene scene(0.1f, Vector3i(255,255,255));
Camera cam;
AnimatedSprite bougie("imgTesting/bougie/sprite_sheet_candle1-sheet.png",Vector2i(5,1),0.1f,0);
Sprite rock("imgTesting/rock.png");
rock.setNormalMap(Texture("imgTesting/rock_map.png"));
rock.setPosition(800.f,400.f);
rock.setSize(500.f,500.f);
Sprite box("imgTesting/box.png");
box.setNormalMap(Texture("imgTesting/box_normal.png"));
box.setPosition(100.f,100.f);
box.setSize(500.f,500.f);
bougie.setSize(270.f,270.f);
bougie.setOrigin(bougie.getSize().x/2.f, 55.f);
Light light(Vector2f(0.f,0.f), 0.9f, Vector3i(255,255,255),1.5f,3.0f,4.5f); // bougie
Vector2f maxIntensity(0.9f,1.2f); // intensité max de la bougie
float variation = 0.10f;
// Masquer le curseur de la souris
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
// fond
RectangleShape rectangle;
while (!glfwWindowShouldClose(window))
{
// Nettoyage de la fenêtre
bbopCleanWindow(window, Vector3i(0,0,0),1.0);
//taille du fond
rectangle.setSize(BBOP_WINDOW_RESOLUTION.x , BBOP_WINDOW_RESOLUTION.y);
//poistion de la souris pour la light
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
// la bougie suit la souris
Vector2f mouseWorldPos = cam.camPosToWorldPos(cam.screenPosToCamPos(Vector2f(static_cast<float>(xpos), static_cast<float>(ypos))));
light.setPosition(mouseWorldPos);
bougie.setPosition(mouseWorldPos);
// variation de l'intensité de la bougie
light.setIntensity(light.getIntensity() + fast_rand(-variation, variation));
if(light.getIntensity() > maxIntensity.y)
light.setIntensity(maxIntensity.y - variation);
if(light.getIntensity() < maxIntensity.x)
light.setIntensity(maxIntensity.x + variation);
// On 'active' la scene pour donner au shader opengl les variables uniforms
scene.Use();
//
bougie.update();
// Affichage du rectangle
// scene.Draw(rectangle);
scene.Draw(rock);
scene.Draw(box);
scene.Draw(bougie);
// ajout de la lumière
scene.addLight(light);
// Faire le rendue du frame buffer de la fenêtre
scene.render();
// Verfication d'erreur opengl
bbopErrorCheck();
// Passage du front buffer pour afficher le rendue opengl sur la fenêtre glfw
glfwSwapBuffers(window);
glfwPollEvents();
}
// Suppression de la fenêtre
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}