22 : nverts(0), space(OBJECT_SPACE),
23 tu1(0), tv1(0), tangent(0), binormal(0)
41 if (!m || !
nverts || !preserve) {
42 bool additional_tex_coords = (
tu1 != 0);
56 tu =
new(__FILE__,__LINE__)
float[
nverts];
57 tv =
new(__FILE__,__LINE__)
float[
nverts];
58 rw =
new(__FILE__,__LINE__)
float[
nverts];
62 if (additional_tex_coords)
96 float* new_rw =
new(__FILE__,__LINE__)
float[
nverts];
97 float* new_tu =
new(__FILE__,__LINE__)
float[
nverts];
98 float* new_tv =
new(__FILE__,__LINE__)
float[
nverts];
101 DWORD* new_diffuse =
new(__FILE__,__LINE__) DWORD[
nverts];
102 DWORD* new_specular =
new(__FILE__,__LINE__) DWORD[
nverts];
105 new_tu1 =
new(__FILE__,__LINE__)
float[
nverts];
108 new_tv1 =
new(__FILE__,__LINE__)
float[
nverts];
111 CopyMemory(new_loc,
loc, np *
sizeof(
Vec3));
117 CopyMemory(new_nrm,
nrm, np *
sizeof(
Vec3));
123 CopyMemory(new_s_loc,
s_loc, np *
sizeof(
Vec3));
129 CopyMemory(new_tu,
tu, np *
sizeof(
float));
135 CopyMemory(new_tv,
tv, np *
sizeof(
float));
141 CopyMemory(new_tu1,
tu1, np *
sizeof(
float));
147 CopyMemory(new_tv1,
tv1, np *
sizeof(
float));
153 CopyMemory(new_diffuse,
diffuse, np *
sizeof(DWORD));
159 CopyMemory(new_specular,
specular, np *
sizeof(DWORD));
202 ZeroMemory(
nrm,
sizeof(
Vec3) * nverts);
203 ZeroMemory(
s_loc,
sizeof(
Vec3) * nverts);
204 ZeroMemory(
tu,
sizeof(
float) * nverts);
205 ZeroMemory(
tv,
sizeof(
float) * nverts);
206 ZeroMemory(
rw,
sizeof(
float) * nverts);
207 ZeroMemory(
diffuse,
sizeof(DWORD) * nverts);
208 ZeroMemory(
specular,
sizeof(DWORD) * nverts);
211 ZeroMemory(
tu1,
sizeof(
float) * nverts);
214 ZeroMemory(
tv1,
sizeof(
float) * nverts);
253 tu1 =
new(__FILE__,__LINE__)
float[
nverts];
254 tv1 =
new(__FILE__,__LINE__)
float[
nverts];
263 if (src >= 0 && src < nverts && dst >= 0 && dst <
nverts) {
298 CopyMemory(result->
rw,
rw,
nverts *
sizeof(
float));
299 CopyMemory(result->
tu,
tu,
nverts *
sizeof(
float));
300 CopyMemory(result->
tv,
tv,
nverts *
sizeof(
float));
306 result->
tu1 =
new(__FILE__,__LINE__)
float[
nverts];
313 result->
tv1 =
new(__FILE__,__LINE__)
float[
nverts];
338 plus =
Point(-1e6, -1e6, -1e6);
339 minus =
Point( 1e6, 1e6, 1e6);
341 for (
int i = 0; i <
nverts; i++) {
342 if (
loc[i].x > plus.
x) plus.
x =
loc[i].
x;
343 if (
loc[i].x < minus.
x) minus.
x =
loc[i].
x;
344 if (
loc[i].y > plus.
y) plus.
y =
loc[i].
y;
345 if (
loc[i].y < minus.
y) minus.
y =
loc[i].
y;
346 if (
loc[i].z > plus.
z) plus.
z =
loc[i].
z;
347 if (
loc[i].z < minus.
z) minus.
z =
loc[i].
z;
356 : nverts(0), visible(1), material(0), vertex_set(0), sortval(0), flatness(0)
366 static inline double extent3(
double a,
double b,
double c)
368 double d1 = fabs(a-b);
369 double d2 = fabs(a-c);
370 double d3 = fabs(b-c);
420 for (i = 0; i <
nverts; i++) {
423 case 1: projverts[i] =
Vec2(loc.
y, loc.
z);
break;
424 case -1: projverts[i] =
Vec2(loc.
z, loc.
y);
break;
425 case 2: projverts[i] =
Vec2(loc.
z, loc.
x);
break;
426 case -2: projverts[i] =
Vec2(loc.
x, loc.
z);
break;
427 case 3: projverts[i] =
Vec2(loc.
x, loc.
y);
break;
428 case -3: projverts[i] =
Vec2(loc.
y, loc.
x);
break;
435 case 1: test.
x = pt.
y; test.
y = pt.
z;
break;
436 case -1: test.
x = pt.
z; test.
y = pt.
y;
break;
437 case 2: test.
x = pt.
z; test.
y = pt.
x;
break;
438 case -2: test.
x = pt.
x; test.
y = pt.
z;
break;
439 case 3: test.
x = pt.
x; test.
y = pt.
y;
break;
440 case -3: test.
x = pt.
y; test.
y = pt.
x;
break;
443 const float INSIDE_EPSILON = -0.01f;
447 for (i = 0; i < nverts-1; i++) {
449 Vec2 segment = projverts[i+1] - projverts[i];
451 Vec2 tdelta = projverts[i] - test;
452 float inside = segnorm * tdelta;
453 if (inside < INSIDE_EPSILON)
460 Vec2 segment = projverts[0] - projverts[nverts-1];
461 float inside = segment.
normal() * (projverts[0] - test);
462 if (inside < INSIDE_EPSILON)
475 : power(1.0f), brilliance(1.0f), bump(0.0f), blend(MTL_SOLID),
476 shadow(true), luminous(false),
477 tex_diffuse(0), tex_specular(0), tex_bumpmap(0), tex_emissive(0),
478 tex_alternate(0), tex_detail(0), thumbnail(0)
513 if (
this == &m)
return 1;
515 if (
Ka != m.
Ka)
return 0;
516 if (
Kd != m.
Kd)
return 0;
517 if (
Ks != m.
Ks)
return 0;
518 if (
Ke != m.
Ke)
return 0;
565 if (pass > 1) pass--;
567 for (
int i = 0; i <
NAMELEN; i++) {
575 else if (
shader[i] != 0) {
577 ZeroMemory(shader_name, NAMELEN);
579 char* s = shader_name;
580 while (i < NAMELEN &&
shader[i] != 0 &&
shader[i] !=
'/') {
610 DWORD* image =
new(__FILE__,__LINE__) DWORD[size*size];
613 for (
int j = 0; j < size; j++) {
614 for (
int i = 0; i < size; i++) {
627 double x = i - size/2;
628 double y = j - size/2;
629 double r = 0.9 * size/2;
630 double d = sqrt(x*x + y*y);
633 double z = sqrt(r*r - x*x - y*y);
641 ColorValue white(1,1,1);
643 double diffuse = nrm*light;
644 double v = 1 - (acos(nrm.
y)/
PI);
645 double u = asin(nrm.
x / sin(acos(nrm.
y))) /
PI + 0.5;
678 double du = (du1 + du2) / 512 * 1e-8;
679 double dv = (dv1 + dv2) / 512 * 1e-8;
690 v = 1 - (acos(nrm.
y)/
PI);
691 u = asin(nrm.
x / sin(acos(nrm.
y))) /
PI + 0.5;
709 c += cd * (white * diffuse);
713 double spec = ((nrm * 2*(nrm*light) - light) * eye);
715 spec = pow(spec, (
double)
power);
716 c += cs * (white * spec);
724 c += cd * (white * diffuse);
730 double spec = ((nrm * 2*(nrm*light) - light) * eye);
732 spec = pow(spec, (
double)
power);
733 c += cs * (white * spec) * 0.7;
743 return result.
Value();