summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-25 23:41:30 +0800
committerchai <chaifix@163.com>2020-02-25 23:41:30 +0800
commit1a94259666a0d98e98e6999f19cf07475b618e65 (patch)
tree502450d9ce77dca2234898badaf22a43ecf89d7e /src/main.c
parent87b9482459c1a27b8756514473ae392453db39ec (diff)
*camera
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/main.c b/src/main.c
index 292d663..9f0a017 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,10 +5,11 @@
#include "ssr.h"
#include "example/example.h"
#include "extern/wog.h"
+#include "shaders/common.h"
#include "extend/camera.h"
-#define SCREEN_WIDTH 600
-#define SCREEN_HEIGHT 480
+#define SCREEN_WIDTH 600.f
+#define SCREEN_HEIGHT 480.f
typedef void(*F)(void*);
@@ -38,22 +39,28 @@ int main(int argc, char* argv[]) {
};
ssr_init(&config);
SETEXAMPLE(EXAMPLECUR);
- onload(NULL);
- wog_show(wnd);
/*set up global camera*/
- Camera cam;
- camera_init(&cam, wnd);
+ CameraConfig cam_config = { /*default camera setting*/
+ {0, 700, 0},
+ {0, 0, 0},
+ 60, SCREEN_WIDTH / SCREEN_HEIGHT, 0.1, 2000,
+ 5, 150,
+ 4000,
+ };
+ onload(&cam_config);
+ Camera* camera = camera_create(wnd, &cam_config);
+ wog_show(wnd);
/* main loop */
uint prev = wog_tick();
uint dt = 0;
- float _dt = 0;
+ float _dt = 0, _duration;
uint frame_count = 0;
uint time_stamp = 0;
wog_Event e;
while (1) {
/*handle events*/
while (wog_pollEvent(wnd, &e)) {
- camera_onevent(&cam, &e, _dt);
+ camera_onevent(&camera, &e, _dt);
if (e.type == WOG_ECLOSE) {
goto quit;
} else {
@@ -71,22 +78,17 @@ int main(int argc, char* argv[]) {
time_stamp -= 1000;
frame_count = 0;
}
+
+ _time.x = _dt;
+ _time.y = prev / 1000.f;
/*update*/
_dt = dt / 1000.f;
- camera_onupdate(&cam, _dt);
+ camera_onupdate(&camera, _dt);
onupdate(&_dt);
-
- /*set vp matrix*/
- ssr_matrixmode(MATRIX_PROJECTION);
- camera_getprojmatrix(&cam, NULL);
- ssr_loadmatrix(&cam.proj_matrix);
- ssr_matrixmode(MATRIX_VIEW);
- camera_getviewmatrix(&cam, NULL);
- ssr_loadmatrix(&cam.view_matrix);
- ssr_matrixmode(MATRIX_MODEL);
-
+
/*draw*/
+ camera_ondraw(camera);
ondraw(NULL);
ssr_present();
@@ -95,6 +97,7 @@ int main(int argc, char* argv[]) {
}
quit:
+ camera_destroy(camera);
wog_destroyWindow(wnd);
return 0;