-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.h
More file actions
69 lines (57 loc) · 1.82 KB
/
Copy pathtransform.h
File metadata and controls
69 lines (57 loc) · 1.82 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
#ifndef TRANSFORM_H
#define TRANSFORM_H
#include "geometry.h"
#include "primitive.h"
#include "camera.h"
extern const int WIDTH;
extern const int HEIGHT;
extern const float UPPER;
class Transform
{
private:
int screen_width;
int screen_height;
float depth_upper;
Matrix model;
Matrix view;
Matrix persp;
Matrix vp;
std::vector<Vec4f> clipPlanes;
// cuda device pointers
Vert* d_verts;
float* d_model_view;
float* d_model_view_inv_trans;
float* d_model_view_persp;
float* d_vp;
Vert* d_verts_rst;
// need to free pointers
Vert* verts_rst;
// other properties
int num_verts;
int num_verts_rst;
void init();
bool insideWayPlane(Vert &v, Vec4f &plane);
std::vector<Vert> sutherlandHodgeman(Vert &v0, Vert &v1, Vert &v2);
bool allInsideClipCube(std::vector<Vert> &verts);
Vert intersect(Vert &v0, Vert &v1, Vec4f &plane);
Vert transformVert(Vert &vert, Matrix &model_view, Matrix &model_view_inv_trans, Matrix &model_view_persp);
std::vector<Triangle> transform(Vert &vert0, Vert &vert1, Vert &vert2, Matrix &model_view, Matrix &model_view_inv_trans, Matrix &model_view_persp);
void updateViewMatrix(Camera &camera);
void cudaUpdateMatrix();
public:
Transform(int w, int h, int d);
Matrix calcModelMatrix(Vec3f scale, Vec3f translate);
Matrix lookAt(Vec3f eye, Vec3f center, Vec3f up = Vec3f(0., 1., 0.));
Matrix perspective(float fovY, float aspect, float near, float far);
Matrix viewport(int x, int y, int w, int h);
std::vector<Triangle> transform(std::vector<Vert> &verts);
std::vector<Triangle> transform(std::vector<Vert> &verts, Camera &camera);
void transformCuda(std::vector<Vert> &verts);
void transformCuda(std::vector<Vert> &verts, Camera &camera);
Vert* getDeviceVertsRstPtr();
int getDeviceVertsRstNum();
void cudaInit(std::vector<Vert> &verts);
void cudaRelease();
void test();
};
#endif