34 #if defined(JAVASCRIPT_DUK)
35 #include <system_threads.h>
39 #include <libFreeWRL.h>
44 #include "../vrml_parser/Structs.h"
45 #include "../main/headers.h"
46 #include "../vrml_parser/CParseGeneral.h"
47 #include "../main/Snapshot.h"
48 #include "../scenegraph/LinearAlgebra.h"
49 #include "../scenegraph/Collision.h"
50 #include "../scenegraph/quaternion.h"
51 #include "../scenegraph/Viewer.h"
52 #include "../input/SensInterps.h"
53 #include "../x3d_parser/Bindable.h"
54 #include "../input/InputFunctions.h"
60 #define LARGESTRING 2048
62 #define SMALLSTRING 128
65 #define malloc(A) MALLOCV(A)
66 #define free(A) FREE_IF_NZ(A)
67 #define realloc(A,B) REALLOC(A,B)
92 int type2SF(
int itype);
95 int SFFloat_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
97 float *ptr = (
float *)fwn;
98 fwretval->_numeric = (double)*(ptr);
99 fwretval->itype =
'F';
102 int SFFloat_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
105 float *ptr = (
float *)fwn;
106 sprintf(str,
"%g",(*ptr));
107 fwretval->_string = strdup(str);
108 fwretval->itype =
'S';
112 {
"valueOf", SFFloat_valueOf,
'F',{0,0,0,NULL}},
113 {
"toString", SFFloat_toString,
'S',{0,0,0,NULL}},
140 int sizeofSF(
int itype);
141 void * MFW_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
145 lenSF = sizeofSF(fwtype->itype);
149 ptr->p = malloc(ptr->n * lenSF);
151 for(i=0;i<ptr->n;i++){
152 memcpy(p,fwpars[i]._web3dval.native,lenSF);
158 {
"length", -1,
'I', 0},
161 unsigned long upper_power_of_two(
unsigned long v);
162 int MFW_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
168 fwretval->_integer = ptr->n;
169 fwretval->itype =
'I';
174 }
else if(index > -1 ){
176 char *p = (
char *)ptr->p;
177 int elen = sizeofSF(fwt->itype);
178 sftype = type2SF(fwt->itype);
187 newlen = upper_power_of_two(index+1);
188 ptr->p = realloc(p,newlen * elen);
190 memset(&p[ptr->n * elen],0,elen * (index+1 - ptr->n));
194 if(sftype == FIELDTYPE_SFNode){
202 void *sfptr = malloc(
sizeof(
void*));
203 memcpy(sfptr,(
void *)(p + index*elen),
sizeof(
void*));
204 fwretval->_web3dval.native = (
void *)sfptr;
205 fwretval->_web3dval.gc = 1;
207 int deepCopyLikeVivaty = FALSE;
208 if(deepCopyLikeVivaty){
216 void *sfptr = malloc(elen);
218 shallow_copy_field(sftype,(
void *)(p + index*elen),sfptr);
219 fwretval->_web3dval.native = (
void *)sfptr;
220 fwretval->_web3dval.gc = 1;
227 fwretval->_web3dval.native = (
void *)(p + index*elen);
228 fwretval->_web3dval.gc = 0;
231 fwretval->_web3dval.fieldType = type2SF(fwt->itype);
232 fwretval->itype =
'W';
238 int mf2sf(
int itype);
239 FWTYPE *getFWTYPE(
int itype);
240 char *sfToString(
FWType fwt,
void *fwn){
247 case FIELDTYPE_SFBool:
248 if(any->sfbool) str = strdup(
"true");
249 else str = strdup(
"false");
251 case FIELDTYPE_SFInt32:
252 sprintf(strbuf,
"%d",any->sfint32);
253 str = strdup(strbuf);
255 case FIELDTYPE_SFFloat:
256 sprintf(strbuf,
"%g",any->sffloat);
257 str = strdup(strbuf);
259 case FIELDTYPE_SFDouble:
260 case FIELDTYPE_SFTime:
261 sprintf(strbuf,
"%g",any->sfdouble);
262 str = strdup(strbuf);
264 case FIELDTYPE_SFString:{
265 str = malloc(strlen(any->sfstring->strptr)+3);
267 str = strcat(str,any->sfstring->strptr);
268 str = strcat(str,
"\"");
275 while(fwt->Functions[i].name){
276 if(!strcmp(fwt->Functions[i].name,
"toString")){
280 fwt->Functions[i].call(fwt,NULL,fwn,1,fwpars,&fwretval);
281 str = fwretval._string;
291 int type2SF(
int itype);
292 char *mfToString(
FWType fwt,
void * fwn){
294 int i, sftype, len, showType, elen;
301 if(showType) len += strlen(fwt->name);
302 str = malloc(len +1);
304 if(showType) strcat(str,fwt->name);
305 str = strcat(str,
"[ ");
307 sftype = type2SF(fwt->itype);
308 fwtsf = getFWTYPE(sftype);
310 elen = sizeofSF(fwt->itype);
311 for(i=0;i<ptr->n;i++)
313 char * sf = sfToString(fwtsf,p);
314 str = realloc(str,strlen(str)+strlen(sf)+2);
315 str = strcat(str,sf);
316 str = strcat(str,
" ");
320 str[strlen(str)-1] =
']';
324 int MFW_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
326 str = mfToString(fwtype,fwn);
327 fwretval->_string = str;
328 fwretval->itype =
'S';
333 {
"toString", MFW_toString,
'S',{0,-1,0,NULL}},
338 int MFW_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
340 int nold, nr = FALSE;
341 int elen = sizeofSF(fwt->itype);
346 ptr->n = fwval->_integer;
349 nelen = (int) upper_power_of_two(ptr->n);
350 ptr->p = realloc(ptr->p,nelen * elen);
353 }
else if(index > -1){
359 nelen = (int) upper_power_of_two(ptr->n);
360 ptr->p = realloc(ptr->p, nelen *elen);
362 p = ptr->p + index * elen;
363 if(fwval->itype ==
'W')
364 memcpy(p,fwval->_web3dval.native, elen);
367 switch(fwval->itype){
369 memcpy(p,&fwval->_boolean,elen);
break;
371 memcpy(p,&fwval->_integer,elen);
break;
373 ff = (float)fwval->_numeric;
374 memcpy(p,&ff,elen);
break;
376 memcpy(p,&fwval->_numeric,elen);
break;
378 struct Uni_String *uni = newASCIIString(fwval->_string);
379 memcpy(p,&uni,elen);
break;
388 void * MFFloat_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
392 lenSF = sizeofSF(fwtype->itype);
396 ptr->p = malloc(ptr->n * lenSF);
398 for(i=0;i<ptr->n;i++){
399 if(fwpars[i].itype ==
'W' && fwpars[i]._web3dval.fieldType == FIELDTYPE_SFFloat)
400 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
401 else if(fwpars[i].itype ==
'F'){
402 float ff = (float)fwpars[i]._numeric;
421 MFFloat_ConstructorArgs,
452 int SFRotation_getAxis(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
455 veccopy3f(res->c,ptr->c);
456 fwretval->_web3dval.native = res;
457 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
458 fwretval->_web3dval.gc =
'T';
459 fwretval->itype =
'W';
463 int SFRotation_inverse(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
470 vrmlrot_to_quaternion(&q1, (
double) ptr->c[0],
471 (
double) ptr->c[1], (
double) ptr->c[2], (
double) ptr->c[3]);
474 quaternion_inverse(&qret,&q1);
477 quaternion_to_vrmlrot(&qret, &a, &b, &c, &d);
479 res->c[0] = (float) a;
480 res->c[1] = (float) b;
481 res->c[2] = (float) c;
482 res->c[3] = (float) d;
484 fwretval->_web3dval.native = res;
485 fwretval->_web3dval.fieldType = FIELDTYPE_SFRotation;
486 fwretval->_web3dval.gc =
'T';
487 fwretval->itype =
'W';
491 int SFRotation_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
499 vrmlrot_to_quaternion(&q1, (
double) ptr->c[0],
500 (
double) ptr->c[1], (
double) ptr->c[2], (
double) ptr->c[3]);
502 vrmlrot_to_quaternion(&q2, (
double) rhs->c[0],
503 (
double) rhs->c[1], (
double) rhs->c[2], (
double) rhs->c[3]);
506 quaternion_multiply(&qret,&q1,&q2);
509 quaternion_to_vrmlrot(&qret, &a, &b, &c, &d);
511 res->c[0] = (float) a;
512 res->c[1] = (float) b;
513 res->c[2] = (float) c;
514 res->c[3] = (float) d;
516 fwretval->_web3dval.native = res;
517 fwretval->_web3dval.fieldType = FIELDTYPE_SFRotation;
518 fwretval->_web3dval.gc =
'T';
519 fwretval->itype =
'W';
523 int SFRotation_multiVec(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
531 veccopy3f(r.c,ptr->c);
532 rl = veclength3f(r.c);
534 s = (float) sin(angle);
535 c = (float) cos(angle);
536 veccross3f(c1.c,r.c,v->c);
537 vecscale3f(c1.c,c1.c,1.0f/rl);
538 veccross3f(c2.c,r.c,c1.c);
539 vecscale3f(c2.c,c2.c,1.0f/rl);
541 res->c[i] = (
float) (v->c[i] + s * c1.c[i] + (1.0-c) * c2.c[i]);
543 fwretval->_web3dval.native = res;
544 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
545 fwretval->_web3dval.gc =
'T';
546 fwretval->itype =
'W';
550 int SFRotation_setAxis(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
553 veccopy3f(ptr->c,v->c);
557 int SFRotation_slerp(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
560 double t = fwpars[1]._numeric;
573 memcpy(res->c,rot->c,4*
sizeof(
float));
574 }
else if (APPROX(t, 1)) {
575 memcpy(res->c,dest->c,4*
sizeof(
float));
578 vrmlrot_to_quaternion(&quat,
584 vrmlrot_to_quaternion(&quat_dest,
590 quaternion_slerp(&quat_ret, &quat, &quat_dest, t);
591 quaternion_to_vrmlrot(&quat_ret,&a,&b,&c,&d);
593 res->c[0] = (float) a;
594 res->c[1] = (float) b;
595 res->c[2] = (float) c;
596 res->c[3] = (float) d;
598 fwretval->_web3dval.native = res;
599 fwretval->_web3dval.fieldType = FIELDTYPE_SFRotation;
600 fwretval->_web3dval.gc =
'T';
601 fwretval->itype =
'W';
605 int SFRotation_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
607 char buff[STRING], *str;
609 memset(buff, 0, STRING);
610 sprintf(buff,
"%.9g %.9g %.9g %.9g",
611 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
615 fwretval->_string = str;
616 fwretval->itype =
'S';
622 {
"getAxis", SFRotation_getAxis,
'W',{0,-1,0,NULL}},
623 {
"inverse", SFRotation_inverse,
'W',{0,-1,0,
"W"}},
624 {
"multiply", SFRotation_multiply,
'W',{1,-1,0,
"W"}},
625 {
"multVec", SFRotation_multiVec,
'W',{1,-1,0,
"W"}},
626 {
"multiVec", SFRotation_multiVec,
'W',{1,-1,0,
"W"}},
627 {
"setAxis", SFRotation_setAxis,
'0',{1,-1,0,
"W"}},
628 {
"slerp", SFRotation_slerp,
'W',{2,-1,0,
"WF"}},
629 {
"toString", SFRotation_toString,
'S',{0,-1,0,NULL}},
632 int SFRotation_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
636 if(index > -1 && index < 4){
643 fwretval->_numeric = ptr->c[index];
649 fwretval->itype =
'F';
652 int SFRotation_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
655 if(index > -1 && index < 4){
661 ptr->c[index] = (float)fwval->_numeric;
669 void * SFRotation_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
671 struct SFRotation *ptr = malloc(fwtype->size_of);
674 ptr->c[i] = (
float)fwpars[i]._numeric;
675 }
else if(ic == 2 && fwpars[1].itype ==
'F'){
677 veccopy3f(ptr->c,fwpars[0]._web3dval.native);
678 ptr->c[3] = (float)fwpars[1]._numeric;
680 }
else if(ic == 2 && fwpars[1].itype ==
'W'){
682 struct SFVec3f *v1 = fwpars[0]._web3dval.native;
683 struct SFVec3f *v2 = fwpars[1]._web3dval.native;
684 float v1len = veclength3f(v1->c);
685 float v2len = veclength3f(v2->c);
686 float v12dp = vecdot3f(v1->c, v2->c);
687 veccross3f(ptr->c,v1->c,v2->c);
688 v12dp /= v1len * v2len;
689 ptr->c[3] = (float) atan2(sqrt(1 - v12dp * v12dp), v12dp);
690 }
else if(ic == 1 && fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
692 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
701 {
"angle", 3,
'F', 0},
713 FIELDTYPE_SFRotation,
717 SFRotation_Constructor,
718 SFRotation_ConstructorArgs,
719 SFRotation_Properties,
724 SFRotation_Functions,
731 FIELDTYPE_MFRotation,
759 #include "../scenegraph/LinearAlgebra.h"
761 int SFVec3f_add(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
763 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
764 struct SFVec3f *res = malloc(fwtype->size_of);
765 vecadd3f(res->c,ptr->c,rhs->c);
766 fwretval->_web3dval.native = res;
767 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
768 fwretval->_web3dval.gc =
'T';
769 fwretval->itype =
'W';
772 int SFVec3f_cross(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
774 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
775 struct SFVec3f *res = malloc(fwtype->size_of);
776 veccross3f(res->c,ptr->c,rhs->c);
777 fwretval->_web3dval.native = res;
778 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
779 fwretval->_web3dval.gc =
'T';
780 fwretval->itype =
'W';
783 int SFVec3f_subtract(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
785 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
786 struct SFVec3f *res = malloc(fwtype->size_of);
787 vecdif3f(res->c,ptr->c,rhs->c);
788 fwretval->_web3dval.native = res;
789 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
790 fwretval->_web3dval.gc =
'T';
791 fwretval->itype =
'W';
794 int SFVec3f_divide(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
797 float rhs = (float)fwpars[0]._numeric;
802 res = malloc(fwtype->size_of);
803 vecscale3f(res->c,ptr->c,rhs);
804 fwretval->_web3dval.native = res;
805 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
806 fwretval->_web3dval.gc =
'T';
807 fwretval->itype =
'W';
810 int SFVec3f_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
812 float rhs = (float) fwpars[0]._numeric;
813 struct SFVec3f *res = malloc(fwtype->size_of);
814 vecscale3f(res->c,ptr->c,rhs);
815 fwretval->_web3dval.native = res;
816 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
817 fwretval->_web3dval.gc =
'T';
818 fwretval->itype =
'W';
821 int SFVec3f_normalize(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
823 struct SFVec3f *res = malloc(fwtype->size_of);
824 vecnormalize3f(res->c,ptr->c);
825 fwretval->_web3dval.native = res;
826 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
827 fwretval->_web3dval.gc =
'T';
828 fwretval->itype =
'W';
832 int SFVec3f_negate(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
834 struct SFVec3f *res = malloc(fwtype->size_of);
835 vecscale3f(res->c,ptr->c,-1.0f);
836 fwretval->_web3dval.native = res;
837 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
838 fwretval->_web3dval.gc =
'T';
839 fwretval->itype =
'W';
842 int SFVec3f_length(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
845 res = veclength3f(ptr->c);
846 fwretval->_numeric = res;
847 fwretval->itype =
'F';
850 int SFVec3f_dot(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
852 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
854 res = vecdot3f(ptr->c,rhs->c);
855 fwretval->_numeric = res;
856 fwretval->itype =
'F';
860 int SFVec3f_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
862 char buff[STRING], *str;
864 memset(buff, 0, STRING);
865 sprintf(buff,
"%.9g %.9g %.9g",
866 ptr->c[0], ptr->c[1], ptr->c[2]);
870 fwretval->_string = str;
871 fwretval->itype =
'S';
876 {
"add", SFVec3f_add,
'W',{1,-1,0,
"W"}},
877 {
"cross", SFVec3f_cross,
'W',{1,-1,0,
"W"}},
878 {
"divide", SFVec3f_divide,
'W',{1,-1,0,
"F"}},
879 {
"dot", SFVec3f_dot,
'F',{1,-1,0,
"W"}},
880 {
"length", SFVec3f_length,
'F',{0,-1,0,NULL}},
881 {
"multiply", SFVec3f_multiply,
'W',{1,-1,0,
"F"}},
882 {
"negate", SFVec3f_negate,
'W',{0,-1,0,NULL}},
883 {
"normalize", SFVec3f_normalize,
'W',{0,-1,0,NULL}},
884 {
"subtract", SFVec3f_subtract,
'W',{1,-1,0,
"W"}},
885 {
"toString", SFVec3f_toString,
'S',{0,-1,0,NULL}},
889 int SFVec3f_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
893 if(index > -1 && index < 3){
899 fwretval->_numeric = ptr->c[index];
905 fwretval->itype =
'F';
908 int SFVec3f_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
911 if(index > -1 && index < 3){
916 ptr->c[index] = (float)fwval->_numeric;
924 void * SFVec3f_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
926 struct SFVec3f *ptr = malloc(fwtype->size_of);
927 if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
929 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
933 ptr->c[i] = (
float) fwpars[i]._numeric;
958 SFVec3f_ConstructorArgs,
983 int SFBool_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
985 int *ptr = (
int *)fwn;
986 fwretval->_boolean = *(ptr);
987 fwretval->itype =
'B';
990 int SFBool_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
993 int *ptr = (
int *)fwn;
998 fwretval->_string = strdup(str);
999 fwretval->itype =
'S';
1004 {
"valueOf", SFBool_valueOf,
'B',{0,0,0,NULL}},
1005 {
"toString", SFBool_toString,
'S',{0,0,0,NULL}},
1026 void * MFBool_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
1030 lenSF = sizeofSF(fwtype->itype);
1034 ptr->p = malloc(ptr->n * lenSF);
1036 for(i=0;i<ptr->n;i++){
1038 if(fwpars[i].itype ==
'W')
1039 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1040 else if(fwpars[i].itype ==
'B'){
1041 memcpy(p,&fwpars[i]._boolean,lenSF);
1060 MFBool_ConstructorArgs,
1069 int SFInt32_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1071 int *ptr = (
int *)fwn;
1072 fwretval->_integer = *(ptr);
1073 fwretval->itype =
'I';
1076 int SFInt32_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1079 int *ptr = (
int *)fwn;
1080 sprintf(str,
"%d",(*ptr));
1081 fwretval->_string = strdup(str);
1082 fwretval->itype =
'S';
1086 {
"valueOf", SFInt32_valueOf,
'I',{0,0,0,NULL}},
1087 {
"toString", SFInt32_toString,
'S',{0,0,0,NULL}},
1107 void * MFInt32_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
1111 lenSF = sizeofSF(fwtype->itype);
1115 ptr->p = malloc(ptr->n * lenSF);
1117 for(i=0;i<ptr->n;i++){
1118 if(fwpars[i].itype ==
'W')
1119 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1120 else if(fwpars[i].itype ==
'I')
1121 memcpy(p,&fwpars[i]._integer,lenSF);
1138 MFInt32_Constructor,
1139 MFInt32_ConstructorArgs,
1148 int getFieldFromNodeAndIndex(
struct X3D_Node* node,
int iifield,
const char **fieldname,
int *type,
int *kind,
union anyVrml **value);
1149 int SFNode_Iterator(
int index,
FWTYPE *fwt,
FWPointer *pointer,
char **name,
int *lastProp,
int *jndex,
char *type,
char *readOnly){
1151 int ftype, kind, ihave, iifield;
1155 if(!node)
return -1;
1159 ihave = getFieldFromNodeAndIndex(node, index, name, &ftype, &kind, &value);
1161 case FIELDTYPE_SFBool: ctype =
'B';
break;
1162 case FIELDTYPE_SFInt32: ctype =
'I';
break;
1163 case FIELDTYPE_SFFloat: ctype =
'F';
break;
1164 case FIELDTYPE_SFDouble: ctype =
'D';
break;
1165 case FIELDTYPE_SFTime: ctype =
'D';
break;
1166 case FIELDTYPE_SFString: ctype =
'S';
break;
1167 default: ctype =
'W';
break;
1171 (*lastProp) = index;
1178 int SFNode_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1180 int ftype, kind, ihave, nr;
1184 ihave = getFieldFromNodeAndIndex(node, index, &name, &ftype, &kind, &value);
1186 fwretval->_web3dval.native = value;
1187 fwretval->_web3dval.fieldType = ftype;
1188 fwretval->_web3dval.kind = kind;
1189 fwretval->_web3dval.gc = 0;
1190 fwretval->itype =
'W';
1195 void medium_copy_field0(
int itype,
void* source,
void* dest);
1196 void *returnInterpolatorPointer (
int nodeType);
1197 int SFNode_Setter0(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval,
int isCurrentScriptNode){
1201 int ftype, kind, ihave, nr;
1205 ihave = getFieldFromNodeAndIndex(node, index, &name, &ftype, &kind, &value);
1208 switch(fwval->itype){
1210 value->sfbool = fwval->_boolean;
1213 value->sfint32 = fwval->_integer;
1217 value->sffloat = (float)fwval->_numeric;
1221 value->sftime = fwval->_numeric;
1225 value->sfstring = newASCIIString(fwval->_string);
1229 if(!strcmp(name,
"children")){
1232 AddRemoveChildren(node,(
void*)value,(
void*)any->p,any->n,0,__FILE__,__LINE__);
1234 medium_copy_field0(ftype,fwval->_web3dval.native,value);
1238 if(node->_nodeType == NODE_Script) {
1240 struct Shader_Script *script = X3D_SCRIPT(node)->__scriptObj;
1242 field = Shader_Script_getScriptField(script,index);
1243 if(kind == PKW_inputOutput || kind == PKW_outputOnly)
1244 field->valueChanged = TRUE;
1245 if(!isCurrentScriptNode) {
1246 if(kind == PKW_inputOnly || kind == PKW_inputOutput) {
1249 field->eventInSet = TRUE;
1254 void (* interpolatorPointer)(
void*);
1255 interpolatorPointer = returnInterpolatorPointer(node->_nodeType);
1257 if(interpolatorPointer){
1259 interpolatorPointer(node);
1268 int SFNode_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
1269 return SFNode_Setter0(fwt,index,ec,fwn,fwval,FALSE);
1271 void * SFNode_Constructor(
FWType fwtype,
int nargs,
FWval fwpars){
1274 if(fwpars[0].itype ==
'S'){
1286 const char *_c = fwpars[0]._string;
1289 gglobal()->ProdCon.savedParser = (
void *)globalParser; globalParser = NULL;
1290 retGroup = createNewX3DNode(NODE_Group);
1291 ra = EAI_CreateVrml(
"String",_c,X3D_NODE(retGroup),retGroup);
1292 globalParser = (
struct VRMLParser*)gglobal()->ProdCon.savedParser;
1294 ptr = malloc(
sizeof(
void *));
1295 *ptr = retGroup->children.p[0];
1296 (*ptr)->_parentVector->n = 0;
1297 }
else if(fwpars->itype ==
'W'){
1298 if(fwpars->_web3dval.fieldType == FIELDTYPE_SFNode){
1302 ptr = malloc(
sizeof(
void *));
1303 *ptr = ((
union anyVrml*)fwpars[0]._web3dval.native)->sfnode;
1325 int SFNode_getNodeName(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1333 context = (
struct X3D_Proto *)node->_executionContext;
1338 if(context->__DEFnames)
1339 for(i=0;i<vectorSize(context->__DEFnames);i++){
1340 def = vector_get(
struct brotoDefpair, context->__DEFnames,i);
1341 if(def.node == node){
1348 fwretval->_string = name;
1349 fwretval->itype =
'S';
1355 int SFNode_equals(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1357 struct X3D_Node *lhs = *(
void * *)fwn;
1360 fwretval->_boolean = lhs == rhs;
1361 fwretval->itype =
'B';
1364 int SFNode_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1366 void* *ptr = (
void * *)fwn;
1369 printf(
"node address=%x nodetype=%s\n",node,stringNodeType(node->_nodeType));
1373 void *sfptr = malloc(
sizeof(
void*));
1374 memcpy(sfptr,(
void *)(fwn),
sizeof(
void*));
1375 fwretval->_web3dval.native = (
void *)sfptr;
1376 fwretval->_web3dval.gc = 1;
1377 fwretval->itype =
'W';
1379 fwretval->_jsobject = *ptr;
1380 fwretval->itype =
'X';
1384 int SFNode_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1387 void **ptr = (
void **)fwn;
1388 sprintf(str,
"_%x_",(*ptr));
1389 fwretval->_string = strdup(str);
1390 fwretval->itype =
'S';
1394 {
"getNodeName", SFNode_getNodeName,
'S',{0,0,0,NULL}},
1400 {
"equals", SFNode_equals,
'B',{1,-1,0,
"W"}},
1401 {
"valueOf", SFNode_valueOf,
'X',{0,0,0,NULL}},
1402 {
"toString", SFNode_toString,
'S',{0,0,0,NULL}},
1413 SFNode_ConstructorArgs,
1431 MFW_ConstructorArgs,
1442 double MIN(
double a,
double b,
double c) {
1444 if((a<b)&&(a<c))min=a;
else if((b<a)&&(b<c))min=b;
else min=c;
return min;
1447 double MAX(
double a,
double b,
double c) {
1449 if((a>b)&&(a>c))max=a;
else if((b>a)&&(b>c))max=b;
else max=c;
return max;
1452 void convertRGBtoHSV(
double r,
double g,
double b,
double *h,
double *s,
double *v) {
1453 double my_min, my_max, delta;
1455 my_min = MIN( r, g, b );
1456 my_max = MAX( r, g, b );
1458 delta = my_max - my_min;
1460 *s = delta / my_max;
1468 *h = ( g - b ) / delta;
1469 else if( g == my_max )
1470 *h = 2 + ( b - r ) / delta;
1472 *h = 4 + ( r - g ) / delta;
1477 void convertHSVtoRGB(
double h,
double s,
double v ,
double *r,
double *g,
double *b)
1487 i = (int) floor( h );
1490 q = v * ( 1 - s * f );
1491 t = v * ( 1 - s * ( 1 - f ) );
1493 case 0: *r = v; *g = t; *b = p;
break;
1494 case 1: *r = q; *g = v; *b = p;
break;
1495 case 2: *r = p; *g = v; *b = t;
break;
1496 case 3: *r = p; *g = q; *b = v;
break;
1497 case 4: *r = t; *g = p; *b = v;
break;
1498 default: *r = v; *g = p; *b = q;
break;
1503 int SFColor_getHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1509 convertRGBtoHSV((
double)ptr->c[0], (
double)ptr->c[1], (
double)ptr->c[2],&xp[0],&xp[1],&xp[2]);
1511 sf3d = malloc(
sizeof(
struct SFVec3d));
1512 memcpy(sf3d->c,xp,
sizeof(
double)*3);
1513 fwretval->_web3dval.native = sf3d;
1514 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
1515 fwretval->_web3dval.gc =
'T';
1516 fwretval->itype =
'W';
1520 int SFColor_setHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1525 convertHSVtoRGB((
double)fwpars[0]._numeric, (
double)fwpars[1]._numeric, (
double)fwpars[2]._numeric,&xp[0],&xp[1],&xp[2]);
1526 ptr->c[0] = (float)xp[0];
1527 ptr->c[1] = (float)xp[1];
1528 ptr->c[2] = (float)xp[2];
1532 int SFColor_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1534 char buff[STRING], *str;
1536 memset(buff, 0, STRING);
1537 sprintf(buff,
"%.3g %.3g %.3g",
1538 ptr->c[0], ptr->c[1], ptr->c[2]);
1540 str = malloc(len+1);
1542 fwretval->_string = str;
1543 fwretval->itype =
'S';
1548 {
"getHSV", SFColor_getHSV,
'W',{0,0,0,NULL}},
1549 {
"setHSV", SFColor_setHSV, 0,{3,-1,
'T',
"DDD"}},
1550 {
"toString", SFColor_toString,
'S',{0,-1,0,NULL}},
1554 int SFColor_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1558 if(index > -1 && index < 3){
1564 fwretval->_numeric = ptr->c[index];
1570 fwretval->itype =
'F';
1573 int SFColor_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
1576 if(index > -1 && index < 3){
1581 ptr->c[index] = (float) fwval->_numeric;
1589 void * SFColor_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
1591 struct SFColor *ptr = malloc(fwtype->size_of);
1592 if(fwtype->ConstructorArgs[0].nfixedArg == 3){
1594 ptr->c[i] = (
float) fwpars[i]._numeric;
1595 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
1597 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
1626 SFColor_Constructor,
1627 SFColor_ConstructorArgs,
1644 MFW_ConstructorArgs,
1654 int SFColorRGBA_getHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1660 convertRGBtoHSV((
double)ptr->c[0], (
double)ptr->c[1], (
double)ptr->c[2],&xp[0],&xp[1],&xp[2]);
1662 sf3d = malloc(
sizeof(
struct SFVec3d));
1663 memcpy(sf3d->c,xp,
sizeof(
double)*3);
1664 fwretval->_web3dval.native = sf3d;
1665 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
1666 fwretval->_web3dval.gc =
'T';
1667 fwretval->itype =
'W';
1671 int SFColorRGBA_setHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1676 convertHSVtoRGB((
double)fwpars[0]._numeric, (
double)fwpars[1]._numeric, (
double)fwpars[2]._numeric,&xp[0],&xp[1],&xp[2]);
1677 ptr->c[0] = (float)xp[0];
1678 ptr->c[1] = (float)xp[1];
1679 ptr->c[2] = (float)xp[2];
1684 int SFColorRGBA_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1686 char buff[STRING], *str;
1688 memset(buff, 0, STRING);
1689 sprintf(buff,
"%.3g %.3g %.3g %.3g",
1690 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
1692 str = malloc(len+1);
1694 fwretval->_string = str;
1695 fwretval->itype =
'S';
1700 {
"getHSV", SFColor_getHSV,
'W',{0,0,0,NULL}},
1701 {
"setHSV", SFColor_setHSV, 0,{3,-1,
'T',
"DDD"}},
1702 {
"toString", SFColorRGBA_toString,
'S',{0,-1,0,NULL}},
1706 int SFColorRGBA_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1710 if(index > -1 && index < 4){
1717 fwretval->_numeric = ptr->c[index];
1723 fwretval->itype =
'F';
1726 int SFColorRGBA_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
1729 if(index > -1 && index < 4){
1735 ptr->c[index] = (float) fwval->_numeric;
1743 void * SFColorRGBA_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
1745 struct SFColorRGBA *ptr = malloc(fwtype->size_of);
1748 ptr->c[i] = (
float) fwpars[i]._numeric;
1749 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
1751 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
1779 FWTYPE SFColorRGBAType = {
1780 FIELDTYPE_SFColorRGBA,
1784 SFColorRGBA_Constructor,
1785 SFColorRGBA_ConstructorArgs,
1786 SFColorRGBA_Properties,
1791 SFColorRGBA_Functions,
1794 FWTYPE MFColorRGBAType = {
1795 FIELDTYPE_MFColorRGBA,
1800 MFW_ConstructorArgs,
1809 int SFDouble_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1811 double *ptr = (
double *)fwn;
1812 fwretval->_numeric = *(ptr);
1813 fwretval->itype =
'D';
1816 int SFDouble_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1819 double *ptr = (
double *)fwn;
1820 sprintf(str,
"%g",(*ptr));
1821 fwretval->_string = strdup(str);
1822 fwretval->itype =
'S';
1827 {
"valueOf", SFDouble_valueOf,
'D',{0,0,0,NULL}},
1828 {
"toString", SFDouble_toString,
'S',{0,0,0,NULL}},
1848 void * MFTime_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
1852 lenSF = sizeofSF(fwtype->itype);
1856 ptr->p = malloc(ptr->n * lenSF);
1858 for(i=0;i<ptr->n;i++){
1859 if(fwpars[i].itype ==
'W')
1860 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1861 else if(fwpars[i].itype ==
'D')
1862 memcpy(p,&fwpars[i]._numeric,lenSF);
1880 MFTime_ConstructorArgs,
1889 int SFString_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1892 fwretval->_string = ptr->strptr;
1893 fwretval->itype =
'S';
1896 int SFString_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1899 fwretval->_string = strdup(ptr->strptr);
1900 fwretval->itype =
'S';
1905 {
"valueOf", SFString_valueOf,
'S',{0,0,0,NULL}},
1906 {
"toString", SFString_toString,
'S',{0,0,0,NULL}},
1926 void * MFString_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
1930 lenSF = sizeofSF(fwtype->itype);
1934 ptr->p = malloc(ptr->n * lenSF);
1936 for(i=0;i<ptr->n;i++){
1938 if(fwpars[i].itype ==
'W' && fwpars[i]._web3dval.fieldType == FIELDTYPE_SFString)
1939 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1940 else if(fwpars[i].itype ==
'S'){
1941 void *tmp = newASCIIString(fwpars[i]._string);
1942 memcpy(p,&tmp,lenSF);
1944 }
else if(fwpars[i].itype ==
'F' || fwpars[i].itype ==
'D'){
1947 sprintf(str,
"%f", fwpars[i]._numeric);
1948 tmp = newASCIIString(str);
1949 memcpy(p,&tmp,lenSF);
1950 }
else if(fwpars[i].itype ==
'I' ){
1953 sprintf(str,
"%d", fwpars[i]._integer);
1954 tmp = newASCIIString(str);
1955 memcpy(p,&tmp,lenSF);
1956 }
else if(fwpars[i].itype ==
'B' ){
1958 const char *str =
"false";
1959 if(fwpars[i]._boolean) str =
"true";
1960 tmp = newASCIIString(str);
1961 memcpy(p,&tmp,lenSF);
1982 MFString_Constructor,
1983 MFString_ConstructorArgs,
2010 int SFVec2f_add(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2012 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2013 struct SFVec2f *res = malloc(fwtype->size_of);
2014 vecadd2f(res->c,ptr->c,rhs->c);
2015 fwretval->_web3dval.native = res;
2016 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2017 fwretval->_web3dval.gc =
'T';
2018 fwretval->itype =
'W';
2021 int SFVec2f_subtract(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2023 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2024 struct SFVec2f *res = malloc(fwtype->size_of);
2025 vecdif2f(res->c,ptr->c,rhs->c);
2026 fwretval->_web3dval.native = res;
2027 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2028 fwretval->_web3dval.gc =
'T';
2029 fwretval->itype =
'W';
2032 int SFVec2f_divide(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2035 double rhs = fwpars[0]._numeric;
2040 res = malloc(fwtype->size_of);
2041 vecscale2f(res->c,ptr->c,(
float)rhs);
2042 fwretval->_web3dval.native = res;
2043 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2044 fwretval->_web3dval.gc =
'T';
2045 fwretval->itype =
'W';
2048 int SFVec2f_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2050 double rhs = fwpars[0]._numeric;
2051 struct SFVec2f *res = malloc(fwtype->size_of);
2052 vecscale2f(res->c,ptr->c,(
float)rhs);
2053 fwretval->_web3dval.native = res;
2054 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2055 fwretval->_web3dval.gc =
'T';
2056 fwretval->itype =
'W';
2059 int SFVec2f_normalize(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2061 struct SFVec2f *res = malloc(fwtype->size_of);
2062 vecnormal2f(res->c,ptr->c);
2063 fwretval->_web3dval.native = res;
2064 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2065 fwretval->_web3dval.gc =
'T';
2066 fwretval->itype =
'W';
2070 int SFVec2f_length(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2073 res = veclength2f(ptr->c);
2074 fwretval->_numeric = res;
2075 fwretval->itype =
'F';
2078 int SFVec2f_dot(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2080 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2082 res = vecdot2f(ptr->c,rhs->c);
2083 fwretval->_numeric = res;
2084 fwretval->itype =
'F';
2088 int SFVec2f_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2090 char buff[STRING], *str;
2092 memset(buff, 0, STRING);
2093 sprintf(buff,
"%.9g %.9g",
2094 ptr->c[0], ptr->c[1]);
2096 str = malloc(len+1);
2098 fwretval->_string = str;
2099 fwretval->itype =
'S';
2103 {
"add", SFVec2f_add,
'W',{1,-1,0,
"W"}},
2104 {
"divide", SFVec2f_divide,
'W',{1,-1,0,
"F"}},
2105 {
"dot", SFVec2f_dot,
'F',{1,-1,0,
"W"}},
2106 {
"length", SFVec2f_length,
'F',{0,-1,0,NULL}},
2107 {
"multiply", SFVec2f_multiply,
'W',{1,-1,0,
"F"}},
2108 {
"normalize", SFVec2f_normalize,
'W',{0,-1,0,NULL}},
2109 {
"subtract", SFVec2f_subtract,
'W',{1,-1,0,
"W"}},
2110 {
"toString", SFVec2f_toString,
'S',{0,-1,0,NULL}},
2114 int SFVec2f_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2118 if(index > -1 && index < 2){
2123 fwretval->_numeric = ptr->c[index];
2129 fwretval->itype =
'F';
2132 int SFVec2f_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
2135 if(index > -1 && index < 2){
2139 ptr->c[index] = (float) fwval->_numeric;
2147 void * SFVec2f_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
2149 struct SFVec2f *ptr = malloc(fwtype->size_of);
2152 ptr->c[i] = (
float) fwpars[i]._numeric;
2153 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
2155 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
2178 SFVec2f_Constructor,
2179 SFVec2f_ConstructorArgs,
2195 MFW_ConstructorArgs,
2221 int SFImage_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2223 FWType mfint32type = getFWTYPE(FIELDTYPE_MFInt32);
2224 str = mfToString(mfint32type, fwn);
2225 fwretval->_string = str;
2226 fwretval->itype =
'S';
2231 {
"toString", SFImage_toString,
'S',{0,-1,0,NULL}},
2235 int SFImage_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2239 if(index > -1 && index < 4){
2245 fwretval->_integer = ptr->p[index];
2246 fwretval->itype =
'I';
2250 fwretval->_web3dval.native = ptr;
2251 fwretval->_web3dval.fieldType = FIELDTYPE_MFInt32;
2252 fwretval->_web3dval.gc = 0;
2253 fwretval->itype =
'W';
2261 int SFImage_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
2265 if(index > -1 && index < 4){
2270 ptr->p[index] = fwval->_integer;
2272 if(ptr->n < (p[0] * p[1] * p[2]) ){
2274 ptr->n = (p[0] * p[1] * p[2]);
2275 ptr->p = realloc(ptr->p,ptr->n);
2280 if(fwval->itype ==
'W' && fwval->_web3dval.fieldType == FIELDTYPE_MFInt32 ){
2284 ncopy = min(ptr->n,im->n);
2286 memcpy(&ptr->p[3],&im->p[3],(ncopy-3)*
sizeof(
int));
2297 void * SFImage_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
2300 int width, height, comp;
2301 struct Multi_Int32 *ptr = malloc(fwtype->size_of);
2304 width = fwpars[0]._integer;
2305 height = fwpars[1]._integer;
2306 comp = fwpars[2]._integer;
2312 ptr->n = comp * width * height;
2313 ptr->p = malloc(ptr->n *
sizeof(
int));
2314 if(fwpars[3].itype ==
'W' && fwpars[3]._web3dval.fieldType == FIELDTYPE_MFInt32){
2317 struct Multi_Int32 *im = fwpars[3]._web3dval.native;
2318 ncopy = min(ptr->n,im->n);
2319 for(i=0;i<ncopy;i++)
2320 ptr->p[i] = im->p[i];
2330 {
"width", 0,
'I', 0},
2331 {
"height", 1,
'I', 0},
2332 {
"comp", 2,
'I', 0},
2333 {
"array", 3,
'W', 0},
2348 SFImage_Constructor,
2349 SFImage_ConstructorArgs,
2358 #define FIELDTYPE_MFImage 43
2365 MFW_ConstructorArgs,
2390 int SFVec3d_add(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2392 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2393 struct SFVec3d *res = malloc(fwtype->size_of);
2394 vecaddd(res->c,ptr->c,rhs->c);
2395 fwretval->_web3dval.native = res;
2396 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2397 fwretval->_web3dval.gc =
'T';
2398 fwretval->itype =
'W';
2401 int SFVec3d_cross(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2403 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2404 struct SFVec3d *res = malloc(fwtype->size_of);
2405 veccrossd(res->c,ptr->c,rhs->c);
2406 fwretval->_web3dval.native = res;
2407 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2408 fwretval->_web3dval.gc =
'T';
2409 fwretval->itype =
'W';
2412 int SFVec3d_subtract(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2414 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2415 struct SFVec3d *res = malloc(fwtype->size_of);
2416 vecdifd(res->c,ptr->c,rhs->c);
2417 fwretval->_web3dval.native = res;
2418 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2419 fwretval->_web3dval.gc =
'T';
2420 fwretval->itype =
'W';
2423 int SFVec3d_divide(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2426 double rhs = fwpars[0]._numeric;
2431 res = malloc(fwtype->size_of);
2432 vecscaled(res->c,ptr->c,rhs);
2433 fwretval->_web3dval.native = res;
2434 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2435 fwretval->_web3dval.gc =
'T';
2436 fwretval->itype =
'W';
2439 int SFVec3d_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2441 double rhs = fwpars[0]._numeric;
2442 struct SFVec3d *res = malloc(fwtype->size_of);
2443 vecscaled(res->c,ptr->c,rhs);
2444 fwretval->_web3dval.native = res;
2445 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2446 fwretval->_web3dval.gc =
'T';
2447 fwretval->itype =
'W';
2450 int SFVec3d_normalize(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2452 struct SFVec3d *res = malloc(fwtype->size_of);
2453 vecnormald(res->c,ptr->c);
2454 fwretval->_web3dval.native = res;
2455 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2456 fwretval->_web3dval.gc =
'T';
2457 fwretval->itype =
'W';
2461 int SFVec3d_negate(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2463 struct SFVec3d *res = malloc(fwtype->size_of);
2464 vecscaled(res->c,ptr->c,-1.0);
2465 fwretval->_web3dval.native = res;
2466 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2467 fwretval->_web3dval.gc =
'T';
2468 fwretval->itype =
'W';
2471 int SFVec3d_length(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2474 res = veclengthd(ptr->c);
2475 fwretval->_numeric = res;
2476 fwretval->itype =
'D';
2479 int SFVec3d_dot(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2481 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2483 res = vecdotd(ptr->c,rhs->c);
2484 fwretval->_numeric = res;
2485 fwretval->itype =
'D';
2489 int SFVec3d_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2491 char buff[STRING], *str;
2493 memset(buff, 0, STRING);
2494 sprintf(buff,
"%.9g %.9g %.9g",
2495 ptr->c[0], ptr->c[1], ptr->c[2]);
2497 str = malloc(len+1);
2499 fwretval->_string = str;
2500 fwretval->itype =
'S';
2505 {
"add", SFVec3d_add,
'W',{1,-1,0,
"W"}},
2506 {
"cross", SFVec3d_cross,
'W',{1,-1,0,
"W"}},
2507 {
"divide", SFVec3d_divide,
'W',{1,-1,0,
"D"}},
2508 {
"dot", SFVec3d_dot,
'D',{1,-1,0,
"W"}},
2509 {
"length", SFVec3d_length,
'D',{0,-1,0,NULL}},
2510 {
"multiply", SFVec3d_multiply,
'W',{1,-1,0,
"D"}},
2511 {
"negate", SFVec3d_negate,
'W',{0,-1,0,NULL}},
2512 {
"normalize", SFVec3d_normalize,
'W',{0,-1,0,NULL}},
2513 {
"subtract", SFVec3d_subtract,
'W',{1,-1,0,
"W"}},
2514 {
"toString", SFVec3d_toString,
'S',{0,-1,0,NULL}},
2518 int SFVec3d_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2522 if(index > -1 && index < 3){
2528 fwretval->_numeric = ptr->c[index];
2534 fwretval->itype =
'D';
2537 int SFVec3d_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
2540 if(index > -1 && index < 3){
2545 ptr->c[index] = fwval->_numeric;
2553 void * SFVec3d_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
2555 struct SFVec3d *ptr = malloc(fwtype->size_of);
2558 ptr->c[i] = fwpars[i]._numeric;
2559 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
2561 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
2584 SFVec3d_Constructor,
2585 SFVec3d_ConstructorArgs,
2602 MFW_ConstructorArgs,
2629 void * MFDouble_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
2633 lenSF = sizeofSF(fwtype->itype);
2637 ptr->p = malloc(ptr->n * lenSF);
2639 for(i=0;i<ptr->n;i++){
2640 if(fwpars[i].itype ==
'W')
2641 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
2642 else if(fwpars[i].itype ==
'D')
2643 memcpy(p,&fwpars[i]._numeric,lenSF);
2659 MFDouble_Constructor,
2660 MFDouble_ConstructorArgs,
2720 int X3DMatrix3_setTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2724 float angle, scaleangle;
2726 struct SFVec3f *scaleOrientation;
2728 float *matrix[3], m2[9], *mat[3];
2731 struct SFVec2f *translation = fwpars[0]._web3dval.native;
2732 struct SFVec3f *rotation = NULL;
2733 if(fwpars[1].itype ==
'W' && fwpars[1]._web3dval.fieldType == FIELDTYPE_SFVec3f){
2734 rotation = fwpars[1]._web3dval.native;
2735 angle = rotation->c[0];
2737 if(fwpars[1].itype ==
'F')
2738 angle = (float)fwpars[1]._numeric;
2739 scale = fwpars[2]._web3dval.native;
2740 scaleOrientation = NULL;
2741 if(fwpars[3].itype ==
'W' && fwpars[3]._web3dval.fieldType == FIELDTYPE_SFVec3f){
2742 scaleOrientation = fwpars[3]._web3dval.native;
2743 scaleangle = scaleOrientation->c[0];
2745 if(fwpars[3].itype ==
'F')
2746 scaleangle = (float)fwpars[3]._numeric;
2747 center = fwpars[4]._web3dval.native;
2749 matrix[0] = &ptr->c[i*3];
2753 matidentity3f(matrix[0]);
2757 matidentity3f(mat[0]);
2758 veccopy2f(mat[2],center->c);
2759 vecscale2f(mat[2],mat[3],-1.0f);
2760 matmultiply3f(matrix[0],mat[0],matrix[0]);
2763 if(scaleangle != 0.0f){
2764 matidentity3f(mat[0]);
2765 mat[0][0] = mat[1][1] = cosf(-scaleangle);
2766 mat[0][1] = mat[1][0] = sinf(-scaleangle);
2767 mat[0][1] = -mat[0][1];
2768 matmultiply3f(matrix[0],mat[0],matrix[0]);
2772 matidentity4f(mat[0]);
2774 vecmult2f(mat[i],mat[i],scale->c);
2775 matmultiply3f(matrix[0],mat[0],matrix[0]);
2778 if(scaleangle != 0.0f){
2779 matidentity3f(mat[0]);
2780 mat[0][0] = mat[1][1] = cosf(scaleangle);
2781 mat[0][1] = mat[1][0] = sinf(scaleangle);
2782 mat[0][1] = -mat[0][1];
2783 matmultiply3f(matrix[0],mat[0],matrix[0]);
2787 matidentity3f(mat[0]);
2788 mat[0][0] = mat[1][1] = cosf(angle);
2789 mat[0][1] = mat[1][0] = sinf(angle);
2790 mat[0][1] = -mat[0][1];
2791 matmultiply3f(matrix[0],mat[0],matrix[0]);
2795 matidentity3f(mat[0]);
2796 veccopy2f(mat[2],center->c);
2797 matmultiply3f(matrix[0],mat[0],matrix[0]);
2801 matidentity3f(mat[0]);
2802 veccopy2f(mat[2],translation->c);
2803 matmultiply3f(matrix[0],mat[0],matrix[0]);
2809 int X3DMatrix3_getTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2814 float *matrix[3], retscale[2];
2817 struct SFVec2f *translation = fwpars[0]._web3dval.native;
2818 struct SFVec3f *rotation = NULL;
2819 if(fwpars[1].itype ==
'W' && fwpars[1]._web3dval.fieldType == FIELDTYPE_SFVec3f){
2820 rotation = fwpars[1]._web3dval.native;
2821 angle = rotation->c[3];
2822 }
else if(fwpars[1].itype ==
'F'){
2823 angle = (float)fwpars[1]._numeric;
2825 scale = fwpars[2]._web3dval.native;
2827 matrix[i] = &ptr->c[i*3];
2831 retscale[i] = (float)sqrt(vecdot3f(matrix[i],matrix[i]));
2834 veccopy2f(translation->c,matrix[2]);
2843 if(ff != 0.0f) ff = 1/ff;
2844 vecscale3f(&m2[i*3],matrix[i],ff);
2846 angle = atan2f(m2[1],m2[2]);
2849 rotation->c[3] = angle;
2854 veccopy2f(scale->c,retscale);
2857 fwretval->itype =
'F';
2858 fwretval->_numeric = angle;
2862 int X3DMatrix3_inverse(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2866 matrix3x3_inverse_float(ptr->c, ret->c);
2868 fwretval->_pointer.native = ret;
2869 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2870 fwretval->_pointer.gc =
'T';
2871 fwretval->itype =
'P';
2874 int X3DMatrix3_transpose(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2878 mattranspose3f(ret->c, ptr->c);
2880 fwretval->_pointer.native = ret;
2881 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2882 fwretval->_pointer.gc =
'T';
2883 fwretval->itype =
'P';
2887 int X3DMatrix3_multLeft(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2892 matmultiply3f(ret->c, lhs->c , ptr->c);
2894 fwretval->_pointer.native = ret;
2895 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2896 fwretval->itype =
'P';
2897 fwretval->_pointer.gc =
'T';
2900 int X3DMatrix3_multRight(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2904 fwretval->_pointer.native = ret;
2906 matmultiply3f(ret->c, ptr->c, rhs->c);
2908 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2909 fwretval->_pointer.gc =
'T';
2910 fwretval->itype =
'P';
2913 int X3DMatrix3_multVecMatrix(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2915 struct SFVec2f *rhs = (
struct SFVec2f *)fwpars[0]._web3dval.native;
2918 veccopy2f(a3,rhs->c);
2920 vecmultmat3f(r3, a3, ptr->c);
2922 float wi = 1.0f/r3[2];
2923 vecscale2f(ret->c,r3,wi);
2925 veccopy2f(ret->c,r3);
2928 fwretval->_web3dval.native = ret;
2929 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2930 fwretval->_web3dval.gc =
'T';
2931 fwretval->itype =
'W';
2934 int X3DMatrix3_multMatrixVec(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2936 struct SFVec2f *rhs = (
struct SFVec2f *)fwpars[0]._web3dval.native;
2939 veccopy2f(a3,rhs->c);
2941 matmultvec3f(r3, ptr->c,a3);
2943 float wi = 1.0f/r3[2];
2944 vecscale2f(ret->c,r3,wi);
2946 veccopy2f(ret->c,r3);
2949 fwretval->_web3dval.native = ret;
2950 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2951 fwretval->_web3dval.gc =
'T';
2952 fwretval->itype =
'W';
2956 int X3DMatrix3_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2960 FWType sfvec3ftype = getFWTYPE(FIELDTYPE_SFVec3f);
2964 r = sfToString(sfvec3ftype,&ptr->c[i*3]);
2965 str = realloc(str,strlen(str)+strlen(r)+2);
2966 str = strcat(str,r);
2968 fwretval->_string = str;
2969 fwretval->itype =
'S';
2974 {
"setTransform", X3DMatrix3_setTransform, 0,{5,-1,0,
"WWWWW"}},
2975 {
"getTransform", X3DMatrix3_getTransform,
'P',{1,-1,0,
"W"}},
2976 {
"inverse", X3DMatrix3_inverse,
'P',{0,-1,0,NULL}},
2977 {
"transpose", X3DMatrix3_transpose,
'P',{0,-1,0,NULL}},
2978 {
"multLeft", X3DMatrix3_multLeft,
'P',{1,-1,0,
"P"}},
2979 {
"multRight", X3DMatrix3_multRight,
'P',{1,-1,0,
"P"}},
2980 {
"multVecMatrix", X3DMatrix3_multVecMatrix,
'W',{1,-1,0,
"W"}},
2981 {
"multMatrixVec", X3DMatrix3_multMatrixVec,
'W',{1,-1,0,
"W"}},
2982 {
"toString", X3DMatrix3_toString,
'S',{0,-1,0,NULL}},
2986 int X3DMatrix3_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2990 if(index > -1 && index < 9){
2992 fwretval->_numeric = ptr->c[index];
2994 fwretval->itype =
'F';
2997 int X3DMatrix3_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3000 if(index > -1 && index < 9){
3001 if(fwval->itype ==
'F'){
3002 ptr->c[index] = (float) fwval->_numeric;
3009 void * X3DMatrix3_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3011 struct SFVec3d *ptr = malloc(fwtype->size_of);
3013 ptr->c[i] = fwpars[i]._numeric;
3018 {9,0,
'T',
"FFFFFFFFF"},
3022 FWTYPE X3DMatrix3Type = {
3027 X3DMatrix3_Constructor,
3028 X3DMatrix3_ConstructorArgs,
3034 X3DMatrix3_Functions,
3073 int X3DMatrix4_setTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3079 struct SFVec3f *translation = fwpars[0]._web3dval.native;
3080 struct SFRotation *rotation = fwpars[1]._web3dval.native;
3081 struct SFVec3f *scale = fwpars[2]._web3dval.native;
3082 struct SFRotation *scaleOrientation = fwpars[3]._web3dval.native;
3083 struct SFVec3f *center = fwpars[4]._web3dval.native;
3085 float *matrix[4], *mat[4], m2[16];
3087 matrix[i] = &ptr->c[i*4];
3091 matidentity4f(matrix[0]);
3094 matidentity4f(mat[0]);
3095 veccopy3f(mat[3],center->c);
3096 vecscale3f(mat[3],mat[3],-1.0f);
3097 matmultiply4f(matrix[0],mat[0],matrix[0]);
3100 if(scaleOrientation){
3101 scaleOrientation->c[3] = -scaleOrientation->c[3];
3102 matidentity4f(mat[0]);
3104 axisangle_rotate3f(mat[i], mat[i], scaleOrientation->c);
3105 matmultiply4f(matrix[0],mat[0],matrix[0]);
3106 scaleOrientation->c[3] = -scaleOrientation->c[3];
3110 matidentity4f(mat[0]);
3112 vecmult3f(mat[i],mat[i],scale->c);
3113 matmultiply4f(matrix[0],mat[0],matrix[0]);
3116 if(scaleOrientation){
3117 matidentity4f(mat[0]);
3119 axisangle_rotate3f(mat[i], mat[i], scaleOrientation->c);
3120 matmultiply4f(matrix[0],mat[0],matrix[0]);
3124 matidentity4f(mat[0]);
3126 axisangle_rotate3f(mat[i], mat[i], rotation->c);
3127 matmultiply4f(matrix[0],mat[0],matrix[0]);
3132 matidentity4f(mat[0]);
3133 veccopy3f(mat[3],center->c);
3134 matmultiply4f(matrix[0],mat[0],matrix[0]);
3138 matidentity4f(mat[0]);
3139 veccopy3f(mat[3],translation->c);
3140 matmultiply4f(matrix[0],mat[0],matrix[0]);
3146 int X3DMatrix4_getTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3150 struct SFVec3f *translation = fwpars[0]._web3dval.native;
3151 struct SFRotation *rotation = fwpars[1]._web3dval.native;
3152 struct SFVec3f *scale = fwpars[2]._web3dval.native;
3153 float *matrix[4], retscale[3];
3159 matrix[i] = &ptr->c[i*4];
3163 retscale[i] = (float)sqrt(vecdot4f(matrix[i],matrix[i]));
3166 veccopy3f(translation->c,matrix[3]);
3175 if(ff != 0.0f) ff = 1/ff;
3176 vecscale4f(&m2[i*4],matrix[i],ff);
3179 for(i=0;i<16;i++) matrixd[i] = (
double) m2[i];
3180 matrix_to_quaternion (&quat, matrixd);
3181 #ifdef JSVRMLCLASSESVERBOSE
3182 printf (
"quaternion %f %f %f %f\n",quat.x,quat.y,quat.z,quat.w);
3186 quaternion_to_vrmlrot(&quat, &qu[0],&qu[1],&qu[2],&qu[3]);
3190 rotation->c[i] = (
float) qu[i];
3195 veccopy3f(scale->c,retscale);
3201 int X3DMatrix4_inverse(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3206 matinverse4f(ret->c,ptr->c);
3208 fwretval->_pointer.native = ret;
3209 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3210 fwretval->_pointer.gc =
'T';
3211 fwretval->itype =
'P';
3214 int X3DMatrix4_transpose(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3219 mattranspose4f(ret->c, ptr->c);
3221 fwretval->_pointer.native = ret;
3222 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3223 fwretval->_pointer.gc =
'T';
3224 fwretval->itype =
'P';
3228 int X3DMatrix4_multLeft(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3235 matmultiply4f(ptr->c,rhs->c,ptr->c);
3237 fwretval->_pointer.native = ret;
3238 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3239 fwretval->_pointer.gc =
'T';
3240 fwretval->itype =
'P';
3243 int X3DMatrix4_multRight(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3248 fwretval->_pointer.native = ret;
3250 matmultiply4f(ptr->c,ptr->c,rhs->c);
3252 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3253 fwretval->_pointer.gc =
'T';
3254 fwretval->itype =
'P';
3257 int X3DMatrix4_multVecMatrix(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3260 struct SFVec3f *rhs = (
struct SFVec3f *)fwpars[0]._web3dval.native;
3263 veccopy3f(a4,rhs->c);
3265 vecmultmat4f(r4, a4, ptr->c);
3267 float wi = 1.0f/r4[3];
3268 vecscale3f(ret->c,r4,wi);
3270 veccopy3f(ret->c,r4);
3273 fwretval->_web3dval.native = ret;
3274 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
3275 fwretval->_web3dval.gc =
'T';
3276 fwretval->itype =
'W';
3279 int X3DMatrix4_multMatrixVec(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3282 struct SFVec3f *rhs = (
struct SFVec3f *)fwpars[0]._web3dval.native;
3286 veccopy3f(a4,rhs->c);
3288 matmultvec4f(r4, ptr->c, a4 );
3290 float wi = 1.0f/r4[3];
3291 vecscale3f(ret->c,r4,wi);
3293 veccopy3f(ret->c,r4);
3296 fwretval->_web3dval.native = ret;
3297 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
3298 fwretval->_web3dval.gc =
'T';
3299 fwretval->itype =
'W';
3303 int X3DMatrix4_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3307 FWType sfvec4ftype = getFWTYPE(FIELDTYPE_SFVec4f);
3311 r = sfToString(sfvec4ftype,&ptr->c[i*4]);
3312 str = realloc(str,strlen(str)+strlen(r)+2);
3313 str = strcat(str,r);
3315 fwretval->_string = str;
3316 fwretval->itype =
'S';
3322 {
"setTransform", X3DMatrix4_setTransform, 0,{5,-1,0,
"WWWWW"}},
3323 {
"getTransform", X3DMatrix4_getTransform,
'P',{1,-1,0,
"W"}},
3324 {
"inverse", X3DMatrix4_inverse,
'P',{0,-1,0,NULL}},
3325 {
"transpose", X3DMatrix4_transpose,
'P',{0,-1,0,NULL}},
3326 {
"multLeft", X3DMatrix4_multLeft,
'P',{1,-1,0,
"P"}},
3327 {
"multRight", X3DMatrix4_multRight,
'P',{1,-1,0,
"P"}},
3328 {
"multVecMatrix", X3DMatrix4_multVecMatrix,
'W',{1,-1,0,
"W"}},
3329 {
"multMatrixVec", X3DMatrix4_multMatrixVec,
'W',{1,-1,0,
"W"}},
3330 {
"toString", X3DMatrix4_toString,
'S',{0,-1,0,NULL}},
3334 int X3DMatrix4_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3338 if(index > -1 && index < 9){
3340 fwretval->_numeric = ptr->c[index];
3342 fwretval->itype =
'F';
3345 int X3DMatrix4_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3348 if(index > -1 && index < 9){
3349 if(fwval->itype ==
'F'){
3350 ptr->c[index] = (float)fwval->_numeric;
3357 void * X3DMatrix4_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3359 struct SFVec3d *ptr = malloc(fwtype->size_of);
3361 ptr->c[i] = fwpars[i]._numeric;
3366 {9,0,
'T',
"FFFFFFFFF"},
3370 FWTYPE X3DMatrix4Type = {
3375 X3DMatrix4_Constructor,
3376 X3DMatrix4_ConstructorArgs,
3382 X3DMatrix4_Functions,
3404 int SFVec2d_add(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3406 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3407 struct SFVec2d *res = malloc(fwtype->size_of);
3408 vecadd2d(res->c,ptr->c,rhs->c);
3409 fwretval->_web3dval.native = res;
3410 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3411 fwretval->_web3dval.gc =
'T';
3412 fwretval->itype =
'W';
3415 int SFVec2d_subtract(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3417 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3418 struct SFVec2d *res = malloc(fwtype->size_of);
3419 vecdif2d(res->c,ptr->c,rhs->c);
3420 fwretval->_web3dval.native = res;
3421 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3422 fwretval->_web3dval.gc =
'T';
3423 fwretval->itype =
'W';
3426 int SFVec2d_divide(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3429 double rhs = fwpars[0]._numeric;
3434 res = malloc(fwtype->size_of);
3435 vecscale2d(res->c,ptr->c,rhs);
3436 fwretval->_web3dval.native = res;
3437 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3438 fwretval->_web3dval.gc =
'T';
3439 fwretval->itype =
'W';
3442 int SFVec2d_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3444 double rhs = fwpars[0]._numeric;
3445 struct SFVec2d *res = malloc(fwtype->size_of);
3446 vecscale2d(res->c,ptr->c,rhs);
3447 fwretval->_web3dval.native = res;
3448 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3449 fwretval->_web3dval.gc =
'T';
3450 fwretval->itype =
'W';
3453 int SFVec2d_normalize(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3455 struct SFVec2d *res = malloc(fwtype->size_of);
3456 vecnormal2d(res->c,ptr->c);
3457 fwretval->_web3dval.native = res;
3458 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3459 fwretval->_web3dval.gc =
'T';
3460 fwretval->itype =
'W';
3464 int SFVec2d_length(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3467 res = veclength2d(ptr->c);
3468 fwretval->_numeric = res;
3469 fwretval->itype =
'D';
3472 int SFVec2d_dot(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3474 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3476 res = vecdot2d(ptr->c,rhs->c);
3477 fwretval->_numeric = res;
3478 fwretval->itype =
'D';
3481 int SFVec2d_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3483 char buff[STRING], *str;
3485 memset(buff, 0, STRING);
3486 sprintf(buff,
"%.9g %.9g",
3487 ptr->c[0], ptr->c[1]);
3489 str = malloc(len+1);
3491 fwretval->_string = str;
3492 fwretval->itype =
'S';
3496 {
"add", SFVec2d_add,
'W',{1,-1,0,
"W"}},
3497 {
"divide", SFVec2d_divide,
'W',{1,-1,0,
"D"}},
3498 {
"dot", SFVec2d_dot,
'D',{1,-1,0,
"W"}},
3499 {
"length", SFVec2d_length,
'D',{0,-1,0,NULL}},
3500 {
"multiply", SFVec2d_multiply,
'W',{1,-1,0,
"D"}},
3501 {
"normalize", SFVec2d_normalize,
'W',{0,-1,0,NULL}},
3502 {
"subtract", SFVec2d_subtract,
'W',{1,-1,0,
"W"}},
3503 {
"toString", SFVec2d_toString,
'S',{0,-1,0,NULL}},
3507 int SFVec2d_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3511 if(index > -1 && index < 2){
3516 fwretval->_numeric = ptr->c[index];
3522 fwretval->itype =
'D';
3525 int SFVec2d_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3528 if(index > -1 && index < 2){
3532 ptr->c[index] = fwval->_numeric;
3540 void * SFVec2d_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3542 struct SFVec2d *ptr = malloc(fwtype->size_of);
3543 memset(ptr,0,fwtype->size_of);
3546 ptr->c[i] = fwpars[i]._numeric;
3547 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
3549 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
3572 SFVec2d_Constructor,
3573 SFVec2d_ConstructorArgs,
3589 MFW_ConstructorArgs,
3598 int SFVec4f_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3600 char buff[STRING], *str;
3602 memset(buff, 0, STRING);
3603 sprintf(buff,
"%.9g %.9g %.9g %.9g",
3604 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
3606 str = malloc(len+1);
3608 fwretval->_string = str;
3609 fwretval->itype =
'S';
3614 {
"toString", SFVec4f_toString,
'S',{0,-1,0,NULL}},
3618 int SFVec4f_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3622 if(index > -1 && index < 4){
3629 fwretval->_numeric = ptr->c[index];
3635 fwretval->itype =
'F';
3638 int SFVec4f_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3641 if(index > -1 && index < 4){
3647 ptr->c[index] = (float)fwval->_numeric;
3655 void * SFVec4f_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3657 struct SFVec4f *ptr = malloc(fwtype->size_of);
3660 ptr->c[i] = (
float)fwpars[i]._numeric;
3661 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
3663 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
3689 SFVec4f_Constructor,
3690 SFVec4f_ConstructorArgs,
3706 MFW_ConstructorArgs,
3715 int SFVec4d_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3717 char buff[STRING], *str;
3719 memset(buff, 0, STRING);
3720 sprintf(buff,
"%.9g %.9g %.9g %.9g",
3721 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
3723 str = malloc(len+1);
3725 fwretval->_string = str;
3726 fwretval->itype =
'S';
3730 {
"toString", SFVec4d_toString,
'S',{0,-1,0,NULL}},
3734 int SFVec4d_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3738 if(index > -1 && index < 4){
3745 fwretval->_numeric = ptr->c[index];
3751 fwretval->itype =
'D';
3754 int SFVec4d_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3757 if(index > -1 && index < 4){
3763 ptr->c[index] = fwval->_numeric; ;
3771 void * SFVec4d_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3773 struct SFVec3d *ptr = malloc(fwtype->size_of);
3774 memset(ptr,0,fwtype->size_of);
3777 ptr->c[i] = fwpars[i]._numeric;
3778 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
3780 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
3804 SFVec4d_Constructor,
3805 SFVec4d_ConstructorArgs,
3821 MFW_ConstructorArgs,
3830 void initVRMLFields(
FWTYPE** typeArray,
int *n){
3831 typeArray[*n] = &SFFloatType; (*n)++;
3832 typeArray[*n] = &MFFloatType; (*n)++;
3833 typeArray[*n] = &SFRotationType; (*n)++;
3834 typeArray[*n] = &MFRotationType; (*n)++;
3835 typeArray[*n] = &SFVec3fType; (*n)++;
3836 typeArray[*n] = &MFVec3fType; (*n)++;
3837 typeArray[*n] = &SFBoolType; (*n)++;
3838 typeArray[*n] = &MFBoolType; (*n)++;
3839 typeArray[*n] = &SFInt32Type; (*n)++;
3840 typeArray[*n] = &MFInt32Type; (*n)++;
3841 typeArray[*n] = &SFNodeType; (*n)++;
3842 typeArray[*n] = &MFNodeType; (*n)++;
3843 typeArray[*n] = &SFColorType; (*n)++;
3844 typeArray[*n] = &MFColorType; (*n)++;
3845 typeArray[*n] = &SFColorRGBAType; (*n)++;
3846 typeArray[*n] = &MFColorRGBAType; (*n)++;
3847 typeArray[*n] = &SFTimeType; (*n)++;
3848 typeArray[*n] = &MFTimeType; (*n)++;
3849 typeArray[*n] = &SFStringType; (*n)++;
3850 typeArray[*n] = &MFStringType; (*n)++;
3851 typeArray[*n] = &SFVec2fType; (*n)++;
3852 typeArray[*n] = &MFVec2fType; (*n)++;
3853 typeArray[*n] = &SFImageType; (*n)++;
3856 typeArray[*n] = &SFVec3dType; (*n)++;
3857 typeArray[*n] = &MFVec3dType; (*n)++;
3858 typeArray[*n] = &SFDoubleType; (*n)++;
3859 typeArray[*n] = &MFDoubleType; (*n)++;
3868 typeArray[*n] = &X3DMatrix3Type; (*n)++;
3869 typeArray[*n] = &X3DMatrix4Type; (*n)++;
3870 typeArray[*n] = &SFVec2dType; (*n)++;
3871 typeArray[*n] = &MFVec2dType; (*n)++;
3872 typeArray[*n] = &SFVec4fType; (*n)++;
3873 typeArray[*n] = &MFVec4fType; (*n)++;
3874 typeArray[*n] = &SFVec4dType; (*n)++;
3875 typeArray[*n] = &MFVec4dType; (*n)++;