Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (55 loc) · 1.91 KB
/
Copy pathmain.cpp
File metadata and controls
62 lines (55 loc) · 1.91 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
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <SDL2/SDL.h>
#include "3DLib/Render3D.h"
float SCREEN_WIDTH = 640*1.5;
float SCREEN_HEIGHT = 480*1.5;
int main(){
float near = 0.1;
float far = 100;
float fov = 0.1;
float fps = 30;
// Object3D Cube = {std::vector<Point3D> {Point3D{0,0,0},Point3D{1,0,0},Point3D{1,1,0},Point3D{0,1,0},Point3D{0,0,1},Point3D{1,0,1},Point3D{1,1,1},Point3D{0,1,1}},{},{}};
Object3D Teapot = loadObj("Mesh/teapot");
Object3D Cube = loadObj("Mesh/cube");
Object3D Thingy = loadObj("Mesh/weird");
Object3D Monkey = loadObj("Mesh/monkey");
std::vector<Object3D> objects = {Teapot};
SDL_Window* window = SDL_CreateWindow("3D Engine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_Init(SDL_INIT_VIDEO);
Point3D camPos = {0,0,0};
Render3D R1(fps, (SCREEN_WIDTH), (SCREEN_HEIGHT), near, far, fov, camPos, objects);
std::vector<float> tr = {0,-2,-2,0};
std::vector<float> tr1 = {0.0,0.01,0.01,0};
std::vector<float> tr2 = {0,-1,-6,0};
std::vector<float> tr3 = {0,1,-8,0};
Point3D neworig = {0,-1,-6};
Point3D neworige = {0,-1,-8};
R1.Translate(0, tr2);
//R1.Translate(1, tr3);
//R1.Translate(1, tr3);
// for (int i = 0; i < 30; i++){
// R1.Translate(0,tr1);
// }
int quit = 0;
while(!quit){
SDL_Event event;
//SDL_Delay(100);
R1.RotateX(0, 0.01, neworig);
R1.RotateY(0, 0.01, neworig);
R1.RotateZ(0, 0.01, neworig);
R1.RenderTris(window, renderer);
while (SDL_PollEvent(&event)) {
//SDL_Delay(1000);
if (event.type == SDL_QUIT) {
quit = 1;
puts("QUIT!");
break;
}
}
}
}