-
Notifications
You must be signed in to change notification settings - Fork 0
/
pasuli_approx.c
executable file
·136 lines (118 loc) · 4.69 KB
/
pasuli_approx.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "pasuli_approx.h"
#define PASULI_UD_AND_VD_EXISTS (PASULIOBJECT_UD != 0) && (PASULIOBJECT_VD != 0)
void approximatePaSuLi(int whatToApproximate,
pasuli_vartype u, pasuli_vartype v,
pasuli_consttype *pConstants, PaSuLiObject *pO,
parsurFunc f)
{
PaSuLiObject tempObject;
f(u, v, pConstants, pO);
pasuli_approx_type px = pO->pos[0];
pasuli_approx_type py = pO->pos[1];
pasuli_approx_type pz = pO->pos[2];
#if (PASULIOBJECT_UD != 0)
if (whatToApproximate & PASULI_APPROXIMATE_UD)
{
f(u + PASULI_APPROX_DIFFERENCE, v, pConstants, &tempObject);
pO->ud[0] = (tempObject.pos[0] - px) / PASULI_APPROX_DIFFERENCE;
pO->ud[1] = (tempObject.pos[1] - py) / PASULI_APPROX_DIFFERENCE;
pO->ud[2] = (tempObject.pos[2] - pz) / PASULI_APPROX_DIFFERENCE;
}
#endif
#if (PASULIOBJECT_VD != 0)
if (whatToApproximate & PASULI_APPROXIMATE_VD)
{
f(u, v + PASULI_APPROX_DIFFERENCE, pConstants, &tempObject);
pO->vd[0] = (tempObject.pos[0] - px) / PASULI_APPROX_DIFFERENCE;
pO->vd[1] = (tempObject.pos[1] - py) / PASULI_APPROX_DIFFERENCE;
pO->vd[2] = (tempObject.pos[2] - pz) / PASULI_APPROX_DIFFERENCE;
}
#endif
if (whatToApproximate & PASULI_APPROXIMATE_N)
{
if ((PASULI_UD_AND_VD_EXISTS != 0) &&
(whatToApproximate & PASULI_APPROXIMATE_UD) &&
(whatToApproximate & PASULI_APPROXIMATE_VD))
{
#if (PASULI_UD_AND_VD_EXISTS != 0)
pO->n[0] = pO->ud[1] * pO->vd[2] - pO->ud[2] * pO->vd[1];
pO->n[1] = pO->ud[0] * pO->vd[2] - pO->ud[2] * pO->vd[0];
pO->n[2] = pO->ud[0] * pO->vd[1] - pO->ud[1] * pO->vd[0];
#endif
}
else
{
f(u + PASULI_APPROX_DIFFERENCE, v, pConstants, &tempObject);
pasuli_approx_type xu = (tempObject.pos[0] - px) / PASULI_APPROX_DIFFERENCE;
pasuli_approx_type yu = (tempObject.pos[1] - py) / PASULI_APPROX_DIFFERENCE;
pasuli_approx_type zu = (tempObject.pos[2] - pz) / PASULI_APPROX_DIFFERENCE;
f(u, v + PASULI_APPROX_DIFFERENCE, pConstants, &tempObject);
pasuli_approx_type xv = (tempObject.pos[0] - px) / PASULI_APPROX_DIFFERENCE;
pasuli_approx_type yv = (tempObject.pos[1] - py) / PASULI_APPROX_DIFFERENCE;
pasuli_approx_type zv = (tempObject.pos[2] - pz) / PASULI_APPROX_DIFFERENCE;
pO->n[0] = yu * zv - zu * yv;
pO->n[1] = xu * zv - zu * xv;
pO->n[2] = xu * yv - yu * xv;
}
}
#if (PASULIOBJECT_UUD != 0) || (PASULIOBJECT_UVD != 0) || (PASULIOBJECT_VVD != 0)
pasuli_approx_type divisor = (PASULI_APPROX_DIFFERENCE * PASULI_APPROX_DIFFERENCE);
#endif
#if (PASULIOBJECT_UUD != 0)
if (whatToApproximate & PASULI_APPROXIMATE_UUD)
{
f(u + PASULI_APPROX_DIFFERENCE, v, pConstants, &tempObject);
pasuli_approx_type px2 = (tempObject.pos[0] - px);
pasuli_approx_type py2 = (tempObject.pos[1] - py);
pasuli_approx_type pz2 = (tempObject.pos[2] - pz);
px = tempObject.pos[0];
py = tempObject.pos[1];
pz = tempObject.pos[2];
f(u + 2 * PASULI_APPROX_DIFFERENCE, v, pConstants, &tempObject);
pasuli_approx_type xu = (tempObject.pos[0] - px);
pasuli_approx_type yu = (tempObject.pos[1] - py);
pasuli_approx_type zu = (tempObject.pos[2] - pz);
pO->uud[0] = (px2 - xu) / divisor;
pO->uud[1] = (py2 - yu) / divisor;
pO->uud[2] = (pz2 - zu) / divisor;
}
#endif
#if (PASULIOBJECT_UVD != 0)
if (whatToApproximate & PASULI_APPROXIMATE_UVD)
{
f(u + PASULI_APPROX_DIFFERENCE, v, pConstants, &tempObject);
pasuli_approx_type px2 = (tempObject.pos[0] - px);
pasuli_approx_type py2 = (tempObject.pos[1] - py);
pasuli_approx_type pz2 = (tempObject.pos[2] - pz);
//px = tO.pos[0];
//py = tO.pos[1];
//pz = tO.pos[2];
f(u + PASULI_APPROX_DIFFERENCE, v + PASULI_APPROX_DIFFERENCE, pConstants, &tempObject);
pasuli_approx_type xu = (tempObject.pos[0] - px);
pasuli_approx_type yu = (tempObject.pos[1] - py);
pasuli_approx_type zu = (tempObject.pos[2] - pz);
pO->uvd[0] = (xu - px2) / divisor;
pO->uvd[1] = (yu - py2) / divisor;
pO->uvd[2] = (zu - pz2) / divisor;
}
#endif
#if (PASULIOBJECT_VVD != 0)
if (whatToApproximate & PASULI_APPROXIMATE_VVD)
{
f(u, v + PASULI_APPROX_DIFFERENCE, pConstants, &tempObject);
pasuli_approx_type px2 = (tempObject.pos[0] - px);
pasuli_approx_type py2 = (tempObject.pos[1] - py);
pasuli_approx_type pz2 = (tempObject.pos[2] - pz);
px = tempObject.pos[0];
py = tempObject.pos[1];
pz = tempObject.pos[2];
f(u, v + 2 * PASULI_APPROX_DIFFERENCE, pConstants, &tempObject);
pasuli_approx_type xu = (tempObject.pos[0] - px);
pasuli_approx_type yu = (tempObject.pos[1] - py);
pasuli_approx_type zu = (tempObject.pos[2] - pz);
pO->vvd[0] = (px2 - xu) / divisor;
pO->vvd[1] = (py2 - yu) / divisor;
pO->vvd[2] = (pz2 - zu) / divisor;
}
#endif
}