-
Notifications
You must be signed in to change notification settings - Fork 3
/
rectangle.h
80 lines (59 loc) · 2.87 KB
/
rectangle.h
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
#ifndef RECTANGLE_H
#define RECTANGLE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vector3_cl.h"
//#include "color3.h"
//static const int SUPER_SAMPLING = 1;
/* Rectangle structure to be passed to OpenCL
* - the alignment is required by OpenCL
* - this struct should be as compact as possible to save vector registers on AMD OpenCL
*/
typedef struct __attribute__ ((aligned(16))) Rectangle{
Vector3 pos, width, height, n;
// Vector3 color;
cl_int3 lightmapSetup; // [0] = lightBaseIdx, [1] = tiles_width, [2] = tiles_height
// int lightNumTiles;
// int hNumTiles, vNumTiles;
// float
} Rectangle;
typedef struct {
Rectangle *data;
cl_int numItems;
cl_int maxNumItems;
} RectangleArray;
Rectangle createRectangleV( const Vector3 _pos, const Vector3 _width, const Vector3 _height, const float TILE_SIZE);
Rectangle createRectangle( float px, float py, float pz,
float wx, float wy, float wz,
float hx, float hy, float hz, float TILE_SIZE);
float distanceOfIntersectionWithPlane(Vector3 raySrc, Vector3 rayDir, Vector3 planeNormal, Vector3 planePos);
float distanceOfIntersectionWithRectPlane( Vector3 raySrc, Vector3 rayDir, const Rectangle *plane);
int getPosition(const Rectangle *plane, const Rectangle *rect);
float getDistanceToPlane(const Rectangle *plane, const Vector3 p);
float getShortestDistanceRectToPoint( const Rectangle *rect, const Vector3 p);
float intersects( const Rectangle *rect, Vector3 raySrc, Vector3 rayDir, float closestDist);
int isBehindRay( const Rectangle *rect, Vector3 raySrc, Vector3 rayDir);
int getNumTiles( const Rectangle *rect);
int getNumMipmapTexels(const Rectangle *rect);
float getArea( const Rectangle *rect);
int getTileIdAt( const Rectangle *rect, const Vector3 p);
int getMipmapTexelId( const Rectangle *rect, int x, int y, int mipmapLevel);
void mipmap( const Rectangle *rect, Vector3* texels);
Vector3 getDiffuseColor(const Rectangle *rect, const Vector3 pos);
Vector3 getOrigin( const Rectangle *rect);
Vector3 getWidthVector( const Rectangle *rect);
Vector3 getHeightVector(const Rectangle *rect);
Vector3 getTileCenter( const Rectangle *rect, int tileId);
void saveAs( const Rectangle *rect, const char *filename, const Vector3 *lights, int tintExtra);
void saveAsRaw( const Rectangle *rect, const char *filename, const Vector3 *lights);
//int saveAsMemoryPng( const Rectangle *rect, const Vector3 *lights, int tintExtra, uint8_t**data);
char* saveAsBase64Png( const Rectangle *rect, const Vector3 *lights, int tintExtra);
RectangleArray initRectangleArray();
void freeRectangleArray( RectangleArray *arr);
void resizeRectangleArray( RectangleArray *arr, int newSize);
void insertIntoRectangleArray(RectangleArray *arr, Rectangle rect);
#ifdef __cplusplus
}
#endif
#endif