~zjm/Moon3D

ref: 0fe31db4998f636b8f65ca790b75c0585ba47d86 Moon3D/src/3d/image/project.h -rw-r--r-- 1.1 KiB
0fe31db4Zack Michener refactor camera/projection to avoid globals 4 months ago
                                                                                
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
#pragma once

#include "../abstract.h"
#include <stdbool.h>
#include "camera.h"

typedef enum ProjectionType {
	ORTHO, PERSPECTIVE
} ProjectionType;

typedef struct PerspectiveProjection {
	ProjectionType type;
	double near;
	double far;
	double fov;
	double aspect;
} PerspectiveProjection;

typedef struct OrthoProjection {
	ProjectionType type;
	double near;
	double far;
	double left;
	double right;
	double bottom;
	double top;
} OrthoProjection;

typedef union Projection {
	PerspectiveProjection perspective;
	OrthoProjection ortho;
} Projection;

void InitDeviceTransform(unsigned int width, unsigned int height);

Projection *NewOrthoProjection(AABBox vol);
Projection *NewPerspectiveProjection(double fov, double aspect, double near, double far);

Transform OrthoTransform(Projection *projection);
Transform PerspectiveTransform(Projection *projection);
Transform GetProjectionTransform(Camera *camera, Projection *projection);

Vertex ProjectPoint(Vertex p, Transform t);
Vertex ViewmapPoint(Vertex p);
Polygon *ProjectPolygon(Polygon *polygon, Transform t);
void ViewmapPolygon(Polygon *polygon);