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)
92int type2SF(
int itype);
95int 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';
102int 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}},
119struct FWTYPE SFFloatType = {
140int sizeofSF(
int itype);
141void * 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},
161unsigned long upper_power_of_two(
unsigned long v);
162int 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 **sfnode = (
void **)(p + index*elen);
205 fwretval->itype =
'0';
210 void *sfptr = malloc(
sizeof(
void*));
211 memcpy(sfptr,(
void *)(p + index*elen),
sizeof(
void*));
212 fwretval->_web3dval.native = (
void *)sfptr;
213 fwretval->_web3dval.gc = 1;
216 int deepCopyLikeVivaty = FALSE;
217 if(deepCopyLikeVivaty){
225 void *sfptr = malloc(elen);
227 shallow_copy_field(sftype,(
void *)(p + index*elen),sfptr);
228 fwretval->_web3dval.native = (
void *)sfptr;
229 fwretval->_web3dval.gc = 1;
236 fwretval->_web3dval.native = (
void *)(p + index*elen);
237 if(sftype == FIELDTYPE_SFString){
239 if(any->sfstring == NULL){
245 fwretval->_web3dval.gc = 0;
248 fwretval->_web3dval.fieldType = type2SF(fwt->itype);
249 fwretval->itype =
'W';
256FWType getFWTYPE(
int itype);
257char *sfToString(FWType fwt,
void *fwn){
264 case FIELDTYPE_SFBool:
265 if(any->sfbool) str = strdup(
"true");
266 else str = strdup(
"false");
268 case FIELDTYPE_SFInt32:
269 sprintf(strbuf,
"%d",any->sfint32);
270 str = strdup(strbuf);
272 case FIELDTYPE_SFFloat:
273 sprintf(strbuf,
"%g",any->sffloat);
274 str = strdup(strbuf);
276 case FIELDTYPE_SFDouble:
277 case FIELDTYPE_SFTime:
278 sprintf(strbuf,
"%g",any->sfdouble);
279 str = strdup(strbuf);
281 case FIELDTYPE_SFString:{
282 str = malloc(strlen(any->sfstring->strptr)+3);
284 str = strcat(str,any->sfstring->strptr);
285 str = strcat(str,
"\"");
292 while(fwt->Functions[i].name){
293 if(!strcmp(fwt->Functions[i].name,
"toString")){
295 struct FWVAL fwretval;
297 fwt->Functions[i].call(fwt,NULL,fwn,1,fwpars,&fwretval);
298 str = strdup(fwretval._string);
308int type2SF(
int itype);
309char *mfToString(FWType fwt,
void * fwn){
311 int i, sftype, len, showType, elen;
318 if(showType) len += strlen(fwt->name);
319 str = malloc(len +1);
321 if(showType) strcat(str,fwt->name);
322 str = strcat(str,
"[ ");
324 sftype = type2SF(fwt->itype);
325 fwtsf = getFWTYPE(sftype);
327 elen = sizeofSF(fwt->itype);
328 for(i=0;i<ptr->n;i++)
330 char * sf = sfToString(fwtsf,p);
331 str = realloc(str,strlen(str)+strlen(sf)+2);
332 str = strcat(str,sf);
333 str = strcat(str,
" ");
337 str[strlen(str)-1] =
']';
341int MFW_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
343 str = mfToString(fwtype,fwn);
344 fwretval->_string = str;
345 fwretval->itype =
'S';
350 {
"toString", MFW_toString,
'S',{0,-1,0,NULL}},
355int MFW_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
357 int nold, nr = FALSE;
358 int elen = sizeofSF(fwt->itype);
363 ptr->n = fwval->_integer;
366 nelen = (int) upper_power_of_two(ptr->n);
367 ptr->p = realloc(ptr->p,nelen * elen);
370 }
else if(index > -1){
376 nelen = (int) upper_power_of_two(ptr->n);
377 ptr->p = realloc(ptr->p, nelen *elen);
379 p = ptr->p + index * elen;
380 if(fwval->itype ==
'W')
381 memcpy(p,fwval->_web3dval.native, elen);
384 switch(fwval->itype){
386 memcpy(p,&fwval->_boolean,elen);
break;
388 memcpy(p,&fwval->_integer,elen);
break;
390 ff = (float)fwval->_numeric;
391 memcpy(p,&ff,elen);
break;
393 memcpy(p,&fwval->_numeric,elen);
break;
395 struct Uni_String *uni = newASCIIString(fwval->_string);
396 memcpy(p,&uni,elen);
break;
405void * MFFloat_Constructor(FWType fwtype,
int argc, FWval fwpars){
409 lenSF = sizeofSF(fwtype->itype);
413 ptr->p = malloc(ptr->n * lenSF);
415 for(i=0;i<ptr->n;i++){
416 if(fwpars[i].itype ==
'W' && fwpars[i]._web3dval.fieldType == FIELDTYPE_SFFloat)
417 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
418 else if(fwpars[i].itype ==
'F'){
419 float ff = (float)fwpars[i]._numeric;
432struct FWTYPE MFFloatType = {
438 MFFloat_ConstructorArgs,
469int SFRotation_getAxis(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
472 veccopy3f(res->c,ptr->c);
473 fwretval->_web3dval.native = res;
474 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
475 fwretval->_web3dval.gc =
'T';
476 fwretval->itype =
'W';
480int SFRotation_inverse(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
487 vrmlrot_to_quaternion(&q1, (
double) ptr->c[0],
488 (
double) ptr->c[1], (
double) ptr->c[2], (
double) ptr->c[3]);
491 quaternion_inverse(&qret,&q1);
494 quaternion_to_vrmlrot(&qret, &a, &b, &c, &d);
496 res->c[0] = (float) a;
497 res->c[1] = (float) b;
498 res->c[2] = (float) c;
499 res->c[3] = (float) d;
501 fwretval->_web3dval.native = res;
502 fwretval->_web3dval.fieldType = FIELDTYPE_SFRotation;
503 fwretval->_web3dval.gc =
'T';
504 fwretval->itype =
'W';
508int SFRotation_multiply(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
512 Quaternion q1,q2,qret;
516 vrmlrot_to_quaternion(&q1, (
double) ptr->c[0],
517 (
double) ptr->c[1], (
double) ptr->c[2], (
double) ptr->c[3]);
519 vrmlrot_to_quaternion(&q2, (
double) rhs->c[0],
520 (
double) rhs->c[1], (
double) rhs->c[2], (
double) rhs->c[3]);
523 quaternion_multiply(&qret,&q1,&q2);
526 quaternion_to_vrmlrot(&qret, &a, &b, &c, &d);
528 res->c[0] = (float) a;
529 res->c[1] = (float) b;
530 res->c[2] = (float) c;
531 res->c[3] = (float) d;
533 fwretval->_web3dval.native = res;
534 fwretval->_web3dval.fieldType = FIELDTYPE_SFRotation;
535 fwretval->_web3dval.gc =
'T';
536 fwretval->itype =
'W';
540int SFRotation_multiVec(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
548 veccopy3f(r.c,ptr->c);
549 rl = veclength3f(r.c);
551 s = (float) sin(angle);
552 c = (float) cos(angle);
553 veccross3f(c1.c,r.c,v->c);
554 vecscale3f(c1.c,c1.c,1.0f/rl);
555 veccross3f(c2.c,r.c,c1.c);
556 vecscale3f(c2.c,c2.c,1.0f/rl);
558 res->c[i] = (
float) (v->c[i] + s * c1.c[i] + (1.0-c) * c2.c[i]);
560 fwretval->_web3dval.native = res;
561 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
562 fwretval->_web3dval.gc =
'T';
563 fwretval->itype =
'W';
567int SFRotation_setAxis(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
570 veccopy3f(ptr->c,v->c);
574int SFRotation_slerp(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
577 double t = fwpars[1]._numeric;
579 Quaternion quat,quat_dest,quat_ret;
590 memcpy(res->c,rot->c,4*
sizeof(
float));
591 }
else if (APPROX(t, 1)) {
592 memcpy(res->c,dest->c,4*
sizeof(
float));
595 vrmlrot_to_quaternion(&quat,
601 vrmlrot_to_quaternion(&quat_dest,
607 quaternion_slerp(&quat_ret, &quat, &quat_dest, t);
608 quaternion_to_vrmlrot(&quat_ret,&a,&b,&c,&d);
610 res->c[0] = (float) a;
611 res->c[1] = (float) b;
612 res->c[2] = (float) c;
613 res->c[3] = (float) d;
615 fwretval->_web3dval.native = res;
616 fwretval->_web3dval.fieldType = FIELDTYPE_SFRotation;
617 fwretval->_web3dval.gc =
'T';
618 fwretval->itype =
'W';
622int SFRotation_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
624 char buff[STRING], *str;
626 memset(buff, 0, STRING);
627 sprintf(buff,
"%.9g %.9g %.9g %.9g",
628 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
632 fwretval->_string = str;
633 fwretval->itype =
'S';
639 {
"getAxis", SFRotation_getAxis,
'W',{0,-1,0,NULL}},
640 {
"inverse", SFRotation_inverse,
'W',{0,-1,0,
"W"}},
641 {
"multiply", SFRotation_multiply,
'W',{1,-1,0,
"W"}},
642 {
"multVec", SFRotation_multiVec,
'W',{1,-1,0,
"W"}},
643 {
"multiVec", SFRotation_multiVec,
'W',{1,-1,0,
"W"}},
644 {
"setAxis", SFRotation_setAxis,
'0',{1,-1,0,
"W"}},
645 {
"slerp", SFRotation_slerp,
'W',{2,-1,0,
"WF"}},
646 {
"toString", SFRotation_toString,
'S',{0,-1,0,NULL}},
649int SFRotation_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
653 if(index > -1 && index < 4){
660 fwretval->_numeric = ptr->c[index];
666 fwretval->itype =
'F';
669int SFRotation_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
672 if(index > -1 && index < 4){
678 ptr->c[index] = (float)fwval->_numeric;
686void * SFRotation_Constructor(FWType fwtype,
int ic, FWval fwpars){
688 struct SFRotation *ptr = malloc(fwtype->size_of);
691 ptr->c[i] = (
float)fwpars[i]._numeric;
692 }
else if(ic == 2 && fwpars[1].itype ==
'F'){
694 veccopy3f(ptr->c,fwpars[0]._web3dval.native);
695 ptr->c[3] = (float)fwpars[1]._numeric;
697 }
else if(ic == 2 && fwpars[1].itype ==
'W'){
699 struct SFVec3f *v1 = fwpars[0]._web3dval.native;
700 struct SFVec3f *v2 = fwpars[1]._web3dval.native;
701 float v1len = veclength3f(v1->c);
702 float v2len = veclength3f(v2->c);
703 float v12dp = vecdot3f(v1->c, v2->c);
704 veccross3f(ptr->c,v1->c,v2->c);
705 v12dp /= v1len * v2len;
706 ptr->c[3] = (float) atan2(sqrt(1 - v12dp * v12dp), v12dp);
707 }
else if(ic == 1 && fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
709 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
718 {
"angle", 3,
'F', 0},
729struct FWTYPE SFRotationType = {
730 FIELDTYPE_SFRotation,
734 SFRotation_Constructor,
735 SFRotation_ConstructorArgs,
736 SFRotation_Properties,
741 SFRotation_Functions,
747struct FWTYPE MFRotationType = {
748 FIELDTYPE_MFRotation,
776#include "../scenegraph/LinearAlgebra.h"
778int SFVec3f_add(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
780 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
781 struct SFVec3f *res = malloc(fwtype->size_of);
782 vecadd3f(res->c,ptr->c,rhs->c);
783 fwretval->_web3dval.native = res;
784 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
785 fwretval->_web3dval.gc =
'T';
786 fwretval->itype =
'W';
789int SFVec3f_cross(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
791 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
792 struct SFVec3f *res = malloc(fwtype->size_of);
793 veccross3f(res->c,ptr->c,rhs->c);
794 fwretval->_web3dval.native = res;
795 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
796 fwretval->_web3dval.gc =
'T';
797 fwretval->itype =
'W';
800int SFVec3f_subtract(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
802 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
803 struct SFVec3f *res = malloc(fwtype->size_of);
804 vecdif3f(res->c,ptr->c,rhs->c);
805 fwretval->_web3dval.native = res;
806 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
807 fwretval->_web3dval.gc =
'T';
808 fwretval->itype =
'W';
811int SFVec3f_divide(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
814 float rhs = (float)fwpars[0]._numeric;
819 res = malloc(fwtype->size_of);
820 vecscale3f(res->c,ptr->c,rhs);
821 fwretval->_web3dval.native = res;
822 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
823 fwretval->_web3dval.gc =
'T';
824 fwretval->itype =
'W';
827int SFVec3f_multiply(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
829 float rhs = (float) fwpars[0]._numeric;
830 struct SFVec3f *res = malloc(fwtype->size_of);
831 vecscale3f(res->c,ptr->c,rhs);
832 fwretval->_web3dval.native = res;
833 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
834 fwretval->_web3dval.gc =
'T';
835 fwretval->itype =
'W';
838int SFVec3f_normalize(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
840 struct SFVec3f *res = malloc(fwtype->size_of);
841 vecnormalize3f(res->c,ptr->c);
842 fwretval->_web3dval.native = res;
843 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
844 fwretval->_web3dval.gc =
'T';
845 fwretval->itype =
'W';
849int SFVec3f_negate(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
851 struct SFVec3f *res = malloc(fwtype->size_of);
852 vecscale3f(res->c,ptr->c,-1.0f);
853 fwretval->_web3dval.native = res;
854 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
855 fwretval->_web3dval.gc =
'T';
856 fwretval->itype =
'W';
859int SFVec3f_length(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
862 res = veclength3f(ptr->c);
863 fwretval->_numeric = res;
864 fwretval->itype =
'F';
867int SFVec3f_dot(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
869 struct SFVec3f *rhs = fwpars[0]._web3dval.native;
871 res = vecdot3f(ptr->c,rhs->c);
872 fwretval->_numeric = res;
873 fwretval->itype =
'F';
877int SFVec3f_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
879 char buff[STRING], *str;
881 memset(buff, 0, STRING);
882 sprintf(buff,
"%.9g %.9g %.9g",
883 ptr->c[0], ptr->c[1], ptr->c[2]);
887 fwretval->_string = str;
888 fwretval->itype =
'S';
893 {
"add", SFVec3f_add,
'W',{1,-1,0,
"W"}},
894 {
"cross", SFVec3f_cross,
'W',{1,-1,0,
"W"}},
895 {
"divide", SFVec3f_divide,
'W',{1,-1,0,
"F"}},
896 {
"dot", SFVec3f_dot,
'F',{1,-1,0,
"W"}},
897 {
"length", SFVec3f_length,
'F',{0,-1,0,NULL}},
898 {
"multiply", SFVec3f_multiply,
'W',{1,-1,0,
"F"}},
899 {
"negate", SFVec3f_negate,
'W',{0,-1,0,NULL}},
900 {
"normalize", SFVec3f_normalize,
'W',{0,-1,0,NULL}},
901 {
"subtract", SFVec3f_subtract,
'W',{1,-1,0,
"W"}},
902 {
"toString", SFVec3f_toString,
'S',{0,-1,0,NULL}},
906int SFVec3f_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
910 if(index > -1 && index < 3){
916 fwretval->_numeric = ptr->c[index];
922 fwretval->itype =
'F';
925int SFVec3f_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
928 if(index > -1 && index < 3){
933 ptr->c[index] = (float)fwval->_numeric;
941void * SFVec3f_Constructor(FWType fwtype,
int ic, FWval fwpars){
943 struct SFVec3f *ptr = malloc(fwtype->size_of);
944 if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
946 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
950 ptr->c[i] = (
float) fwpars[i]._numeric;
969struct FWTYPE SFVec3fType = {
975 SFVec3f_ConstructorArgs,
985struct FWTYPE MFVec3fType = {
1000int SFBool_valueOf(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
1002 int *ptr = (
int *)fwn;
1003 fwretval->_boolean = *(ptr);
1004 fwretval->itype =
'B';
1007int SFBool_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
1010 int *ptr = (
int *)fwn;
1015 fwretval->_string = strdup(str);
1016 fwretval->itype =
'S';
1021 {
"valueOf", SFBool_valueOf,
'B',{0,0,0,NULL}},
1022 {
"toString", SFBool_toString,
'S',{0,0,0,NULL}},
1027struct FWTYPE SFBoolType = {
1043void * MFBool_Constructor(FWType fwtype,
int argc, FWval fwpars){
1047 lenSF = sizeofSF(fwtype->itype);
1051 ptr->p = malloc(ptr->n * lenSF);
1053 for(i=0;i<ptr->n;i++){
1055 if(fwpars[i].itype ==
'W')
1056 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1057 else if(fwpars[i].itype ==
'B'){
1058 memcpy(p,&fwpars[i]._boolean,lenSF);
1071struct FWTYPE MFBoolType = {
1077 MFBool_ConstructorArgs,
1086int SFInt32_valueOf(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
1088 int *ptr = (
int *)fwn;
1089 fwretval->_integer = *(ptr);
1090 fwretval->itype =
'I';
1093int SFInt32_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
1096 int *ptr = (
int *)fwn;
1097 sprintf(str,
"%d",(*ptr));
1098 fwretval->_string = strdup(str);
1099 fwretval->itype =
'S';
1103 {
"valueOf", SFInt32_valueOf,
'I',{0,0,0,NULL}},
1104 {
"toString", SFInt32_toString,
'S',{0,0,0,NULL}},
1108struct FWTYPE SFInt32Type = {
1124void * MFInt32_Constructor(FWType fwtype,
int argc, FWval fwpars){
1128 lenSF = sizeofSF(fwtype->itype);
1132 ptr->p = malloc(ptr->n * lenSF);
1134 for(i=0;i<ptr->n;i++){
1135 if(fwpars[i].itype ==
'W')
1136 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1137 else if(fwpars[i].itype ==
'I')
1138 memcpy(p,&fwpars[i]._integer,lenSF);
1150struct FWTYPE MFInt32Type = {
1155 MFInt32_Constructor,
1156 MFInt32_ConstructorArgs,
1165int getFieldFromNodeAndIterator(
struct X3D_Node* node,
int iifield,
const char **fieldname,
int *type,
int *kind,
union anyVrml **value,
int *builtIn);
1166int SFNode_Iterator(
int index, FWType fwt, FWPointer *pointer,
const char **name,
int *lastProp,
int *jndex,
char *type,
char *readOnly){
1168 int ftype, kind, ihave, iifield, builtIn;
1172 if(!node)
return -1;
1176 ihave = getFieldFromNodeAndIterator(node, index, name, &
ftype, &kind, &value,&builtIn);
1178 case FIELDTYPE_SFBool: ctype =
'B';
break;
1179 case FIELDTYPE_SFInt32: ctype =
'I';
break;
1180 case FIELDTYPE_SFFloat: ctype =
'F';
break;
1181 case FIELDTYPE_SFDouble: ctype =
'D';
break;
1182 case FIELDTYPE_SFTime: ctype =
'D';
break;
1183 case FIELDTYPE_SFString: ctype =
'S';
break;
1184 default: ctype =
'W';
break;
1188 (*lastProp) = index;
1195int SFNode_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
1197 int ftype, kind, ihave, nr, builtIn;
1201 ihave = getFieldFromNodeAndIterator(node, index, &name, &
ftype, &kind, &value,&builtIn);
1203 fwretval->_web3dval.native = value;
1204 fwretval->_web3dval.fieldType =
ftype;
1205 fwretval->_web3dval.kind = kind;
1206 fwretval->_web3dval.gc = 0;
1207 fwretval->itype =
'W';
1215int type_dimension(
int itype) {
1219 case FIELDTYPE_MFDouble:
1220 case FIELDTYPE_MFFloat: ndim = -1;
break;
1221 case FIELDTYPE_SFVec2f:
1222 case FIELDTYPE_SFVec2d: ndim = 2;
break;
1223 case FIELDTYPE_SFVec3f:
1224 case FIELDTYPE_SFVec3d: ndim = 3;
break;
1225 case FIELDTYPE_SFRotation:
1226 case FIELDTYPE_SFVec4f:
1227 case FIELDTYPE_SFVec4d: ndim = 4;
break;
1228 case FIELDTYPE_SFMatrix3f:
1229 case FIELDTYPE_SFMatrix3d:
1230 case AUXTYPE_X3DMatrix3: ndim = 9;
break;
1231 case FIELDTYPE_SFMatrix4f:
1232 case FIELDTYPE_SFMatrix4d:
1233 case AUXTYPE_X3DMatrix4:
1234 case AUXTYPE_VrmlMatrix:ndim = 16;
break;
1238int type_precision(
int itype) {
1242 case FIELDTYPE_SFFloat:
1243 case FIELDTYPE_MFFloat:
1244 case FIELDTYPE_SFVec2f:
1245 case FIELDTYPE_SFVec3f:
1246 case FIELDTYPE_SFVec4f:
1247 case FIELDTYPE_SFRotation:
1248 case FIELDTYPE_SFMatrix3f:
1249 case FIELDTYPE_SFMatrix4f:ipre = 1;
break;
1251 case FIELDTYPE_SFDouble:
1252 case FIELDTYPE_MFDouble:
1253 case FIELDTYPE_SFTime:
1254 case FIELDTYPE_SFVec2d:
1255 case FIELDTYPE_SFVec3d:
1256 case FIELDTYPE_SFVec4d:
1257 case FIELDTYPE_SFMatrix3d:
1258 case FIELDTYPE_SFMatrix4d:
1259 case AUXTYPE_X3DMatrix3:
1260 case AUXTYPE_X3DMatrix4:
1261 case AUXTYPE_VrmlMatrix:
1267int sizeofSForMFduk(
int itype) {
1270 case AUXTYPE_X3DMatrix3: iz =
sizeof(
struct SFMatrix3d);
break;
1271 case AUXTYPE_X3DMatrix4: iz =
sizeof(
struct SFMatrix4d);
break;
1272 case AUXTYPE_VrmlMatrix: iz =
sizeof(
struct SFMatrix4d);
break;
1274 iz = sizeofSForMF(itype);
1279void deleteMallocedFieldValue(
int type,
union anyVrml *fieldPtr);
1281void shallow_copy_field_precision(
int sourcetypeIndex,
int desttypeIndex,
union anyVrml* source,
union anyVrml* dest)
1283 int i, src_isize, dst_isize;
1284 int src_sftype, src_isMF, dst_sftype, dst_isMF;
1287 src_isMF = sourcetypeIndex % 2;
1288 src_sftype = sourcetypeIndex - src_isMF;
1289 dst_isMF = desttypeIndex % 2;
1290 dst_sftype = desttypeIndex - dst_isMF;
1294 src_isize = sizeofSForMFduk(src_sftype);
1295 dst_isize = sizeofSForMFduk(dst_sftype);
1297 if (dst_isMF && src_isMF)
1304 if (mfs->p != mfd->p) {
1306 deleteMallocedFieldValue(desttypeIndex, dest);
1308 if (src_sftype == FIELDTYPE_SFNode) nele = (int)upper_power_of_two(nele);
1314 mfd->p = MALLOC(
struct X3D_Node**, dst_isize * nele);
1315 bzero(mfd->p, dst_isize * nele);
1319 for (i = 0; i < mfs->n; i++)
1321 shallow_copy_field_precision(src_sftype, dst_sftype, (
union anyVrml*)ps, (
union anyVrml*)pd);
1330 if (source == dest)
return;
1331 switch (desttypeIndex)
1333 case FIELDTYPE_SFString:
1337 if (source != dest) {
1338 deleteMallocedFieldValue(desttypeIndex, dest);
1343 sd->strptr = STRDUP((*ss)->strptr);
1344 dest->sfstring = sd;
1349 case FIELDTYPE_SFImage:
1352 si = &source->sfimage;
1353 di = &dest->sfimage;
1354 if (di == si)
return;
1357 FREE_IF_NZ(di->arr.p);
1358 int nele = si->arr.n;
1359 nele = (int)upper_power_of_two(nele);
1363 di->whc[0] = di->whc[1] = di->whc[2] = 0;
1366 int jsize =
sizeof(int);
1367 di->arr.p = MALLOC(
int*, jsize * nele);
1368 bzero(di->arr.p, jsize * nele);
1369 di->arr.n = si->arr.n;
1370 memcpy(di->arr.p, si->arr.p, jsize * si->arr.n);
1371 memcpy(di->whc, si->whc, 3 *
sizeof(
int));
1379 if (sourcetypeIndex == desttypeIndex) {
1381 memcpy(dest, source, src_isize);
1386 int src_dim = type_dimension(src_sftype);
1387 int dst_dim = type_dimension(dst_sftype);
1388 int src_pre = type_precision(src_sftype);
1389 int dst_pre = type_precision(dst_sftype);
1390 if (src_pre == dst_pre) {
1391 memset(dest, 0, dst_isize);
1392 int nbytes = dst_isize < src_isize ? dst_isize : src_isize;
1393 memcpy(dest, source, nbytes);
1396 memset(dest, 0, dst_isize);
1397 int ndim = src_dim < dst_dim ? src_dim : dst_dim;
1402 fs = (
float*)source;
1403 ds = (
double*)source;
1404 for (
int k = 0; k < ndim; k++) {
1405 switch (src_pre + dst_pre * 10) {
1420void medium_copy_field0(
int itype,
void* source,
void* dest);
1421void *returnInterpolatorPointer (
int nodeType);
1422int SFNode_Setter0(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval,
int isCurrentScriptNode){
1426 int ftype, kind, ihave, nr, builtIn;
1430 ihave = getFieldFromNodeAndIterator(node, index, &name, &
ftype, &kind, &value, &builtIn);
1434 switch(fwval->itype){
1436 value->sfbool = fwval->_boolean;
1439 value->sfint32 = fwval->_integer;
1443 value->sffloat = (float)fwval->_numeric;
1447 value->sftime = fwval->_numeric;
1451 value->sfstring = newASCIIString(fwval->_string);
1455 if(!strcmp(name,
"children")){
1458 AddRemoveChildren(node,(
void*)value,(
void*)any->p,any->n,0,__FILE__,__LINE__);
1461 shallow_copy_field_precision(fwval->_web3dval.fieldType,
ftype, fwval->_web3dval.native, value);
1466 if(node->_nodeType == NODE_Script) {
1468 struct Shader_Script *script = X3D_SCRIPT(node)->__scriptObj;
1470 field = Shader_Script_getScriptField(script,index);
1471 if(kind == PKW_inputOutput || kind == PKW_outputOnly)
1472 field->valueChanged = TRUE;
1473 if(!isCurrentScriptNode) {
1474 if(kind == PKW_inputOnly || kind == PKW_inputOutput) {
1477 field->eventInSet = TRUE;
1482 void (* interpolatorPointer)(
void*);
1483 interpolatorPointer = returnInterpolatorPointer(node->_nodeType);
1485 if(interpolatorPointer){
1487 interpolatorPointer(node);
1496int SFNode_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
1497 return SFNode_Setter0(fwt,index,ec,fwn,fwval,FALSE);
1499void * SFNode_Constructor(FWType fwtype,
int nargs, FWval fwpars){
1502 if(fwpars[0].itype ==
'S'){
1512 ttglobal tg = gglobal();
1514 const char *_c = fwpars[0]._string;
1517 gglobal()->ProdCon.savedParser = (
void *)globalParser; globalParser = NULL;
1518 retGroup = createNewX3DNode(NODE_Group);
1519 ra = EAI_CreateVrml(
"String",_c,X3D_NODE(retGroup),retGroup);
1520 globalParser = (
struct VRMLParser*)gglobal()->ProdCon.savedParser;
1522 ptr = malloc(
sizeof(
void *));
1523 *ptr = retGroup->children.p[0];
1524 (*ptr)->_parentVector->n = 0;
1525 }
else if(fwpars->itype ==
'W'){
1526 if(fwpars->_web3dval.fieldType == FIELDTYPE_SFNode){
1530 ptr = malloc(
sizeof(
void *));
1531 *ptr = ((
union anyVrml*)fwpars[0]._web3dval.native)->sfnode;
1553int SFNode_getNodeName(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
1561 context = (
struct X3D_Proto *)node->_executionContext;
1566 if(context->__DEFnames)
1567 for(i=0;i<vectorSize(context->__DEFnames);i++){
1568 def = vector_get(
struct brotoDefpair, context->__DEFnames,i);
1569 if(def.node == node){
1576 fwretval->_string = name;
1577 fwretval->itype =
'S';
1583int SFNode_equals(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
1585 struct X3D_Node *lhs = *(
void * *)fwn;
1588 fwretval->_boolean = lhs == rhs;
1589 fwretval->itype =
'B';
1592int SFNode_valueOf(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
1594 void* *ptr = (
void * *)fwn;
1597 printf(
"node address=%p nodetype=%s\n",node,stringNodeType(node->_nodeType));
1601 void *sfptr = malloc(
sizeof(
void*));
1602 memcpy(sfptr,(
void *)(fwn),
sizeof(
void*));
1603 fwretval->_web3dval.native = (
void *)sfptr;
1604 fwretval->_web3dval.gc = 1;
1605 fwretval->itype =
'W';
1607 fwretval->_jsobject = *ptr;
1608 fwretval->itype =
'X';
1612int SFNode_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
1615 void **ptr = (
void **)fwn;
1619 sprintf(str,
"_%p_",(*ptr));
1620 fwretval->_string = strdup(str);
1621 fwretval->itype =
'S';
1625 {
"getNodeName", SFNode_getNodeName,
'S',{0,0,0,NULL}},
1631 {
"equals", SFNode_equals,
'B',{1,-1,0,
"W"}},
1632 {
"valueOf", SFNode_valueOf,
'X',{0,0,0,NULL}},
1633 {
"toString", SFNode_toString,
'S',{0,0,0,NULL}},
1640struct FWTYPE SFNodeType = {
1646 SFNode_ConstructorArgs,
1658struct FWTYPE MFNodeType = {
1664 MFW_ConstructorArgs,
1675double MIND3(
double a,
double b,
double c) {
1677 if((a<b)&&(a<c))min=a;
else if((b<a)&&(b<c))min=b;
else min=c;
return min;
1680double MAXD3(
double a,
double b,
double c) {
1682 if((a>b)&&(a>c))max=a;
else if((b>a)&&(b>c))max=b;
else max=c;
return max;
1685void convertRGBtoHSV_duk(
double r,
double g,
double b,
double *h,
double *s,
double *v) {
1686 double my_min, my_max, delta;
1688 my_min = MIND3( r, g, b );
1689 my_max = MAXD3( r, g, b );
1691 delta = my_max - my_min;
1693 *s = delta / my_max;
1701 *h = ( g - b ) / delta;
1702 else if( g == my_max )
1703 *h = 2 + ( b - r ) / delta;
1705 *h = 4 + ( r - g ) / delta;
1710void convertHSVtoRGB_duk(
double h,
double s,
double v ,
double *r,
double *g,
double *b)
1720 i = (int) floor( h );
1723 q = v * ( 1 - s * f );
1724 t = v * ( 1 - s * ( 1 - f ) );
1726 case 0: *r = v; *g = t; *b = p;
break;
1727 case 1: *r = q; *g = v; *b = p;
break;
1728 case 2: *r = p; *g = v; *b = t;
break;
1729 case 3: *r = p; *g = q; *b = v;
break;
1730 case 4: *r = t; *g = p; *b = v;
break;
1731 default: *r = v; *g = p; *b = q;
break;
1736int SFColor_getHSV(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
1742 convertRGBtoHSV_duk((
double)ptr->c[0], (
double)ptr->c[1], (
double)ptr->c[2],&xp[0],&xp[1],&xp[2]);
1744 sf3d = malloc(
sizeof(
struct SFVec3d));
1745 memcpy(sf3d->c,xp,
sizeof(
double)*3);
1746 fwretval->_web3dval.native = sf3d;
1747 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
1748 fwretval->_web3dval.gc =
'T';
1749 fwretval->itype =
'W';
1753int SFColor_setHSV(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
1758 convertHSVtoRGB_duk((
double)fwpars[0]._numeric, (
double)fwpars[1]._numeric, (
double)fwpars[2]._numeric,&xp[0],&xp[1],&xp[2]);
1759 ptr->c[0] = (float)xp[0];
1760 ptr->c[1] = (float)xp[1];
1761 ptr->c[2] = (float)xp[2];
1765int SFColor_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
1767 char buff[STRING], *str;
1769 memset(buff, 0, STRING);
1770 sprintf(buff,
"%.3g %.3g %.3g",
1771 ptr->c[0], ptr->c[1], ptr->c[2]);
1773 str = malloc(len+1);
1775 fwretval->_string = str;
1776 fwretval->itype =
'S';
1781 {
"getHSV", SFColor_getHSV,
'W',{0,0,0,NULL}},
1782 {
"setHSV", SFColor_setHSV, 0,{3,-1,
'T',
"DDD"}},
1783 {
"toString", SFColor_toString,
'S',{0,-1,0,NULL}},
1787int SFColor_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
1791 if(index > -1 && index < 3){
1797 fwretval->_numeric = ptr->c[index];
1803 fwretval->itype =
'F';
1806int SFColor_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
1809 if(index > -1 && index < 3){
1814 ptr->c[index] = (float) fwval->_numeric;
1822void * SFColor_Constructor(FWType fwtype,
int ic, FWval fwpars){
1824 struct SFColor *ptr = malloc(fwtype->size_of);
1825 if(fwtype->ConstructorArgs[0].nfixedArg == 3){
1827 ptr->c[i] = (
float) fwpars[i]._numeric;
1828 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
1830 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
1854struct FWTYPE SFColorType = {
1859 SFColor_Constructor,
1860 SFColor_ConstructorArgs,
1871struct FWTYPE MFColorType = {
1877 MFW_ConstructorArgs,
1887int SFColorRGBA_getHSV(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
1893 convertRGBtoHSV_duk((
double)ptr->c[0], (
double)ptr->c[1], (
double)ptr->c[2],&xp[0],&xp[1],&xp[2]);
1895 sf3d = malloc(
sizeof(
struct SFVec3d));
1896 memcpy(sf3d->c,xp,
sizeof(
double)*3);
1897 fwretval->_web3dval.native = sf3d;
1898 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
1899 fwretval->_web3dval.gc =
'T';
1900 fwretval->itype =
'W';
1904int SFColorRGBA_setHSV(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
1909 convertHSVtoRGB_duk((
double)fwpars[0]._numeric, (
double)fwpars[1]._numeric, (
double)fwpars[2]._numeric,&xp[0],&xp[1],&xp[2]);
1910 ptr->c[0] = (float)xp[0];
1911 ptr->c[1] = (float)xp[1];
1912 ptr->c[2] = (float)xp[2];
1917int SFColorRGBA_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
1919 char buff[STRING], *str;
1921 memset(buff, 0, STRING);
1922 sprintf(buff,
"%.3g %.3g %.3g %.3g",
1923 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
1925 str = malloc(len+1);
1927 fwretval->_string = str;
1928 fwretval->itype =
'S';
1933 {
"getHSV", SFColor_getHSV,
'W',{0,0,0,NULL}},
1934 {
"setHSV", SFColor_setHSV, 0,{3,-1,
'T',
"DDD"}},
1935 {
"toString", SFColorRGBA_toString,
'S',{0,-1,0,NULL}},
1939int SFColorRGBA_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
1943 if(index > -1 && index < 4){
1950 fwretval->_numeric = ptr->c[index];
1956 fwretval->itype =
'F';
1959int SFColorRGBA_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
1962 if(index > -1 && index < 4){
1968 ptr->c[index] = (float) fwval->_numeric;
1976void * SFColorRGBA_Constructor(FWType fwtype,
int ic, FWval fwpars){
1978 struct SFColorRGBA *ptr = malloc(fwtype->size_of);
1981 ptr->c[i] = (
float) fwpars[i]._numeric;
1982 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
1984 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
2012struct FWTYPE SFColorRGBAType = {
2013 FIELDTYPE_SFColorRGBA,
2017 SFColorRGBA_Constructor,
2018 SFColorRGBA_ConstructorArgs,
2019 SFColorRGBA_Properties,
2024 SFColorRGBA_Functions,
2027struct FWTYPE MFColorRGBAType = {
2028 FIELDTYPE_MFColorRGBA,
2033 MFW_ConstructorArgs,
2042int SFDouble_valueOf(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
2044 double *ptr = (
double *)fwn;
2045 fwretval->_numeric = *(ptr);
2046 fwretval->itype =
'D';
2049int SFDouble_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
2052 double *ptr = (
double *)fwn;
2053 sprintf(str,
"%g",(*ptr));
2054 fwretval->_string = strdup(str);
2055 fwretval->itype =
'S';
2060 {
"valueOf", SFDouble_valueOf,
'D',{0,0,0,NULL}},
2061 {
"toString", SFDouble_toString,
'S',{0,0,0,NULL}},
2066struct FWTYPE SFTimeType = {
2081void * MFTime_Constructor(FWType fwtype,
int argc, FWval fwpars){
2085 lenSF = sizeofSF(fwtype->itype);
2089 ptr->p = malloc(ptr->n * lenSF);
2091 for(i=0;i<ptr->n;i++){
2092 if(fwpars[i].itype ==
'W')
2093 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
2094 else if(fwpars[i].itype ==
'D')
2095 memcpy(p,&fwpars[i]._numeric,lenSF);
2107struct FWTYPE MFTimeType = {
2113 MFTime_ConstructorArgs,
2122int SFString_valueOf(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
2125 fwretval->_string = ptr->strptr;
2126 fwretval->itype =
'S';
2129int SFString_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval)
2132 fwretval->_string = strdup(ptr->strptr);
2133 fwretval->itype =
'S';
2138 {
"valueOf", SFString_valueOf,
'S',{0,0,0,NULL}},
2139 {
"toString", SFString_toString,
'S',{0,0,0,NULL}},
2144struct FWTYPE SFStringType = {
2159void * MFString_Constructor(FWType fwtype,
int argc, FWval fwpars){
2163 lenSF = sizeofSF(fwtype->itype);
2167 ptr->p = malloc(ptr->n * lenSF);
2169 for(i=0;i<ptr->n;i++){
2171 if(fwpars[i].itype ==
'W' && fwpars[i]._web3dval.fieldType == FIELDTYPE_SFString)
2172 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
2173 else if(fwpars[i].itype ==
'S'){
2174 void *tmp = newASCIIString(fwpars[i]._string);
2175 memcpy(p,&tmp,lenSF);
2177 }
else if(fwpars[i].itype ==
'F' || fwpars[i].itype ==
'D'){
2180 sprintf(str,
"%f", fwpars[i]._numeric);
2181 tmp = newASCIIString(str);
2182 memcpy(p,&tmp,lenSF);
2183 }
else if(fwpars[i].itype ==
'I' ){
2186 sprintf(str,
"%d", fwpars[i]._integer);
2187 tmp = newASCIIString(str);
2188 memcpy(p,&tmp,lenSF);
2189 }
else if(fwpars[i].itype ==
'B' ){
2191 const char *str =
"false";
2192 if(fwpars[i]._boolean) str =
"true";
2193 tmp = newASCIIString(str);
2194 memcpy(p,&tmp,lenSF);
2210struct FWTYPE MFStringType = {
2215 MFString_Constructor,
2216 MFString_ConstructorArgs,
2243int SFVec2f_add(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2245 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2246 struct SFVec2f *res = malloc(fwtype->size_of);
2247 vecadd2f(res->c,ptr->c,rhs->c);
2248 fwretval->_web3dval.native = res;
2249 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2250 fwretval->_web3dval.gc =
'T';
2251 fwretval->itype =
'W';
2254int SFVec2f_subtract(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2256 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2257 struct SFVec2f *res = malloc(fwtype->size_of);
2258 vecdif2f(res->c,ptr->c,rhs->c);
2259 fwretval->_web3dval.native = res;
2260 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2261 fwretval->_web3dval.gc =
'T';
2262 fwretval->itype =
'W';
2265int SFVec2f_divide(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2268 double rhs = fwpars[0]._numeric;
2273 res = malloc(fwtype->size_of);
2274 vecscale2f(res->c,ptr->c,(
float)rhs);
2275 fwretval->_web3dval.native = res;
2276 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2277 fwretval->_web3dval.gc =
'T';
2278 fwretval->itype =
'W';
2281int SFVec2f_multiply(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2283 double rhs = fwpars[0]._numeric;
2284 struct SFVec2f *res = malloc(fwtype->size_of);
2285 vecscale2f(res->c,ptr->c,(
float)rhs);
2286 fwretval->_web3dval.native = res;
2287 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2288 fwretval->_web3dval.gc =
'T';
2289 fwretval->itype =
'W';
2292int SFVec2f_normalize(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2294 struct SFVec2f *res = malloc(fwtype->size_of);
2295 vecnormal2f(res->c,ptr->c);
2296 fwretval->_web3dval.native = res;
2297 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2298 fwretval->_web3dval.gc =
'T';
2299 fwretval->itype =
'W';
2303int SFVec2f_length(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2306 res = veclength2f(ptr->c);
2307 fwretval->_numeric = res;
2308 fwretval->itype =
'F';
2311int SFVec2f_dot(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2313 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2315 res = vecdot2f(ptr->c,rhs->c);
2316 fwretval->_numeric = res;
2317 fwretval->itype =
'F';
2321int SFVec2f_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2323 char buff[STRING], *str;
2325 memset(buff, 0, STRING);
2326 sprintf(buff,
"%.9g %.9g",
2327 ptr->c[0], ptr->c[1]);
2329 str = malloc(len+1);
2331 fwretval->_string = str;
2332 fwretval->itype =
'S';
2336 {
"add", SFVec2f_add,
'W',{1,-1,0,
"W"}},
2337 {
"divide", SFVec2f_divide,
'W',{1,-1,0,
"F"}},
2338 {
"dot", SFVec2f_dot,
'F',{1,-1,0,
"W"}},
2339 {
"length", SFVec2f_length,
'F',{0,-1,0,NULL}},
2340 {
"multiply", SFVec2f_multiply,
'W',{1,-1,0,
"F"}},
2341 {
"normalize", SFVec2f_normalize,
'W',{0,-1,0,NULL}},
2342 {
"subtract", SFVec2f_subtract,
'W',{1,-1,0,
"W"}},
2343 {
"toString", SFVec2f_toString,
'S',{0,-1,0,NULL}},
2347int SFVec2f_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
2351 if(index > -1 && index < 2){
2356 fwretval->_numeric = ptr->c[index];
2362 fwretval->itype =
'F';
2365int SFVec2f_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
2368 if(index > -1 && index < 2){
2372 ptr->c[index] = (float) fwval->_numeric;
2380void * SFVec2f_Constructor(FWType fwtype,
int ic, FWval fwpars){
2382 struct SFVec2f *ptr = malloc(fwtype->size_of);
2385 ptr->c[i] = (
float) fwpars[i]._numeric;
2386 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
2388 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
2406struct FWTYPE SFVec2fType = {
2411 SFVec2f_Constructor,
2412 SFVec2f_ConstructorArgs,
2422struct FWTYPE MFVec2fType = {
2428 MFW_ConstructorArgs,
2454int SFImage_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2462 int width, height, comp;
2463 width = sfimage->whc[0];
2464 height = sfimage->whc[1];
2465 comp = sfimage->whc[2];
2466 len = 5 + 5 + 5 + (width * height * (comp*2 + 3));
2467 str = malloc(len + 1);
2468 sprintf(str,
"%d %d %d ", width, height, comp);
2470 char* format = NULL;
2472 case 1: format =
"%#4x ";
break;
2473 case 2: format =
"%#6x ";
break;
2474 case 3: format =
"%#8x ";
break;
2475 case 4: format =
"%#10x ";
break;
2478 int count = width * height < sfimage->arr.n ? width * height : sfimage->arr.n;
2479 for (i = 0; i < count; i++)
2481 sprintf(buff, format, sfimage->arr.p[i]);
2482 str = strcat(str, buff);
2484 fwretval->_string = str;
2488 fwretval->itype =
'S';
2493 {
"toString", SFImage_toString,
'S',{0,-1,0,NULL}},
2497int SFImage_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
2501 if(index > -1 && index < 4){
2507 fwretval->_integer = ptr->whc[index];
2508 fwretval->itype =
'I';
2512 fwretval->_web3dval.native = &ptr->arr;
2513 fwretval->_web3dval.fieldType = FIELDTYPE_MFInt32;
2514 fwretval->_web3dval.gc = 0;
2515 fwretval->itype =
'W';
2523int SFImage_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
2527 if(index > -1 && index < 4){
2532 ptr->whc[index] = fwval->_integer;
2533 int* whc = ptr->whc;
2535 if(ptr->arr.n < (whc[0] * whc[1]) ){
2537 ptr->arr.n = (whc[0] * whc[1]);
2538 ptr->arr.p = realloc(ptr->arr.p,ptr->arr.n);
2543 if(fwval->itype ==
'W' && fwval->_web3dval.fieldType == FIELDTYPE_MFInt32 ){
2547 ncopy = ptr->arr.n < im->n ? ptr->arr.n : im->n;
2548 memcpy(ptr->arr.p,im->p,(ncopy)*
sizeof(
int));
2559void * SFImage_Constructor(FWType fwtype,
int ic, FWval fwpars){
2562 int width, height, comp;
2563 struct SFImage* ptr = malloc(fwtype->size_of);
2566 width = fwpars[0]._integer;
2567 height = fwpars[1]._integer;
2568 comp = fwpars[2]._integer;
2576 ptr->arr.n = width * height;
2577 ptr->arr.p = malloc(ptr->arr.n *
sizeof(
int));
2578 memset(ptr->arr.p, 0, ptr->arr.n *
sizeof(
int));
2579 if (width * height) {
2580 if (fwpars[3].itype ==
'W' && fwpars[3]._web3dval.fieldType == FIELDTYPE_MFInt32) {
2582 int i, j, ncopy, nfill;
2583 struct Multi_Int32* im = fwpars[3]._web3dval.native;
2584 ncopy = ptr->arr.n < im->n ? ptr->arr.n : im->n;
2585 for (i = 0; i < ncopy; i++)
2586 ptr->arr.p[i] = im->p[i];
2590 ptr->whc[0] = width;
2591 ptr->whc[1] = height;
2597 {
"width", 0,
'I', 0},
2598 {
"height", 1,
'I', 0},
2599 {
"comp", 2,
'I', 0},
2600 {
"array", 3,
'W', 0},
2610struct FWTYPE SFImageType = {
2615 SFImage_Constructor,
2616 SFImage_ConstructorArgs,
2626struct FWTYPE MFImageType = {
2632 MFW_ConstructorArgs,
2657int SFVec3d_add(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2659 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2660 struct SFVec3d *res = malloc(fwtype->size_of);
2661 vecaddd(res->c,ptr->c,rhs->c);
2662 fwretval->_web3dval.native = res;
2663 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2664 fwretval->_web3dval.gc =
'T';
2665 fwretval->itype =
'W';
2668int SFVec3d_cross(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2670 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2671 struct SFVec3d *res = malloc(fwtype->size_of);
2672 veccrossd(res->c,ptr->c,rhs->c);
2673 fwretval->_web3dval.native = res;
2674 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2675 fwretval->_web3dval.gc =
'T';
2676 fwretval->itype =
'W';
2679int SFVec3d_subtract(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2681 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2682 struct SFVec3d *res = malloc(fwtype->size_of);
2683 vecdifd(res->c,ptr->c,rhs->c);
2684 fwretval->_web3dval.native = res;
2685 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2686 fwretval->_web3dval.gc =
'T';
2687 fwretval->itype =
'W';
2690int SFVec3d_divide(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2693 double rhs = fwpars[0]._numeric;
2698 res = malloc(fwtype->size_of);
2699 vecscaled(res->c,ptr->c,rhs);
2700 fwretval->_web3dval.native = res;
2701 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2702 fwretval->_web3dval.gc =
'T';
2703 fwretval->itype =
'W';
2706int SFVec3d_multiply(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2708 double rhs = fwpars[0]._numeric;
2709 struct SFVec3d *res = malloc(fwtype->size_of);
2710 vecscaled(res->c,ptr->c,rhs);
2711 fwretval->_web3dval.native = res;
2712 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2713 fwretval->_web3dval.gc =
'T';
2714 fwretval->itype =
'W';
2717int SFVec3d_normalize(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2719 struct SFVec3d *res = malloc(fwtype->size_of);
2720 vecnormald(res->c,ptr->c);
2721 fwretval->_web3dval.native = res;
2722 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2723 fwretval->_web3dval.gc =
'T';
2724 fwretval->itype =
'W';
2728int SFVec3d_negate(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2730 struct SFVec3d *res = malloc(fwtype->size_of);
2731 vecscaled(res->c,ptr->c,-1.0);
2732 fwretval->_web3dval.native = res;
2733 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2734 fwretval->_web3dval.gc =
'T';
2735 fwretval->itype =
'W';
2738int SFVec3d_length(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2741 res = veclengthd(ptr->c);
2742 fwretval->_numeric = res;
2743 fwretval->itype =
'D';
2746int SFVec3d_dot(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2748 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2750 res = vecdotd(ptr->c,rhs->c);
2751 fwretval->_numeric = res;
2752 fwretval->itype =
'D';
2756int SFVec3d_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
2758 char buff[STRING], *str;
2760 memset(buff, 0, STRING);
2761 sprintf(buff,
"%.9g %.9g %.9g",
2762 ptr->c[0], ptr->c[1], ptr->c[2]);
2764 str = malloc(len+1);
2766 fwretval->_string = str;
2767 fwretval->itype =
'S';
2772 {
"add", SFVec3d_add,
'W',{1,-1,0,
"W"}},
2773 {
"cross", SFVec3d_cross,
'W',{1,-1,0,
"W"}},
2774 {
"divide", SFVec3d_divide,
'W',{1,-1,0,
"D"}},
2775 {
"dot", SFVec3d_dot,
'D',{1,-1,0,
"W"}},
2776 {
"length", SFVec3d_length,
'D',{0,-1,0,NULL}},
2777 {
"multiply", SFVec3d_multiply,
'W',{1,-1,0,
"D"}},
2778 {
"negate", SFVec3d_negate,
'W',{0,-1,0,NULL}},
2779 {
"normalize", SFVec3d_normalize,
'W',{0,-1,0,NULL}},
2780 {
"subtract", SFVec3d_subtract,
'W',{1,-1,0,
"W"}},
2781 {
"toString", SFVec3d_toString,
'S',{0,-1,0,NULL}},
2785int SFVec3d_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
2789 if(index > -1 && index < 3){
2795 fwretval->_numeric = ptr->c[index];
2801 fwretval->itype =
'D';
2804int SFVec3d_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
2807 if(index > -1 && index < 3){
2812 ptr->c[index] = fwval->_numeric;
2820void * SFVec3d_Constructor(FWType fwtype,
int ic, FWval fwpars){
2822 struct SFVec3d *ptr = malloc(fwtype->size_of);
2825 ptr->c[i] = fwpars[i]._numeric;
2826 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
2828 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
2846struct FWTYPE SFVec3dType = {
2851 SFVec3d_Constructor,
2852 SFVec3d_ConstructorArgs,
2863struct FWTYPE MFVec3dType = {
2869 MFW_ConstructorArgs,
2881struct FWTYPE SFDoubleType = {
2896void * MFDouble_Constructor(FWType fwtype,
int argc, FWval fwpars){
2900 lenSF = sizeofSF(fwtype->itype);
2904 ptr->p = malloc(ptr->n * lenSF);
2906 for(i=0;i<ptr->n;i++){
2907 if(fwpars[i].itype ==
'W')
2908 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
2909 else if(fwpars[i].itype ==
'D')
2910 memcpy(p,&fwpars[i]._numeric,lenSF);
2921struct FWTYPE MFDoubleType = {
2926 MFDouble_Constructor,
2927 MFDouble_ConstructorArgs,
3025int X3DMatrix3_setTransform(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3029 double angle, scaleangle;
3033 struct SFVec3d scaleOrientation;
3035 double* matrix[3], m2[9], * mat[3], dtmp[3];
3038 memset(&translation, 0,
sizeof(
struct SFVec2d));
3039 memset(&rotation, 0,
sizeof(
struct SFVec3d));
3040 memset(¢er, 0,
sizeof(
struct SFVec2d));
3041 scale.c[0] = scale.c[1] = 1.0;
3042 memset(&scaleOrientation, 0,
sizeof(
struct SFVec3d));
3043 angle = scaleangle = 0.0;
3046 if (fwpars[0].itype ==
'W') {
3047 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFVec2d, fwpars[0]._web3dval.native, (
union anyVrml*)&translation);
3050 if(fwpars[1].itype ==
'W' ){
3052 shallow_copy_field_precision(fwpars[1]._web3dval.fieldType, FIELDTYPE_SFVec3d, fwpars[1]._web3dval.native, (
union anyVrml*)&rotation);
3053 angle = rotation.c[2];
3055 else if (fwpars[1].itype ==
'F') {
3056 angle = (double)fwpars[1]._numeric;
3059 if (fwpars[2].itype ==
'W') {
3060 shallow_copy_field_precision(fwpars[2]._web3dval.fieldType, FIELDTYPE_SFVec2d, fwpars[2]._web3dval.native, (
union anyVrml*)&scale);
3063 if(fwpars[3].itype ==
'W'){
3064 shallow_copy_field_precision(fwpars[3]._web3dval.fieldType, FIELDTYPE_SFVec3d, fwpars[3]._web3dval.native, (
union anyVrml*)&scaleOrientation);
3065 scaleangle = scaleOrientation.c[2];
3067 else if (fwpars[3].itype ==
'F') {
3068 scaleangle = (double)fwpars[3]._numeric;
3071 if (fwpars[4].itype ==
'W') {
3072 shallow_copy_field_precision(fwpars[4]._web3dval.fieldType, FIELDTYPE_SFVec2d, fwpars[4]._web3dval.native, (
union anyVrml*)¢er);
3076 matrix[i] = &ptr->c[i*3];
3080 matidentity3d(matrix[0]);
3084 matidentity3d(mat[0]);
3085 veccopy2d(mat[2], translation.c);
3086 matmultiply3d(matrix[0], mat[0], matrix[0]);
3090 matidentity3d(mat[0]);
3091 veccopy2d(mat[2], center.c);
3092 matmultiply3d(matrix[0], mat[0], matrix[0]);
3095 if (angle != 0.0f) {
3096 matidentity3d(mat[0]);
3097 mat[0][0] = mat[1][1] = cos(angle);
3098 mat[0][1] = mat[1][0] = sin(angle);
3099 mat[1][0] = -mat[1][0];
3100 matmultiply3d(matrix[0], mat[0], matrix[0]);
3103 if (scaleangle != 0.0f) {
3104 matidentity3d(mat[0]);
3105 mat[0][0] = mat[1][1] = cos(scaleangle);
3106 mat[0][1] = mat[1][0] = sin(scaleangle);
3107 mat[1][0] = -mat[1][0];
3108 matmultiply3d(matrix[0], mat[0], matrix[0]);
3112 matidentity3d(mat[0]);
3113 for (i = 0; i < 3; i++)
3114 vecmult2d(mat[i], mat[i], scale.c);
3115 matmultiply3d(matrix[0], mat[0], matrix[0]);
3119 if (scaleangle != 0.0) {
3120 matidentity3d(mat[0]);
3121 mat[0][0] = mat[1][1] = cos(-scaleangle);
3122 mat[0][1] = mat[1][0] = sin(-scaleangle);
3123 mat[1][0] = -mat[1][0];
3124 matmultiply3d(matrix[0], mat[0], matrix[0]);
3129 matidentity3d(mat[0]);
3130 veccopy2d(mat[2],center.c);
3131 vecscale2d(mat[2], mat[2], -1.0);
3132 matmultiply3d(matrix[0],mat[0],matrix[0]);
3138int X3DMatrix3_getTransform(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3144 double *matrix[3], retscale[2];
3157 matrix[i] = &ptr->c[i*3];
3161 retscale[i] = sqrt(vecdotd(matrix[i],matrix[i]));
3162 shallow_copy_field_precision(FIELDTYPE_SFVec2d, fwpars[2]._web3dval.fieldType, (
union anyVrml*)retscale, fwpars[2]._web3dval.native );
3164 veccopy2d(translation.c,matrix[2]);
3165 shallow_copy_field_precision(FIELDTYPE_SFVec2d, fwpars[0]._web3dval.fieldType, (
union anyVrml*)&translation, fwpars[0]._web3dval.native);
3175 if(ff != 0.0f) ff = 1/ff;
3176 vecscaled(&m2[i*3],matrix[i],ff);
3178 angle = atan2(m2[1],m2[2]);
3181 memset(&rotation, 0,
sizeof(
struct SFVec3d));
3182 rotation.c[0] = cos(angle);
3183 rotation.c[1] = sin(angle);
3184 rotation.c[2] = angle;
3185 shallow_copy_field_precision(FIELDTYPE_SFVec3d, fwpars[1]._web3dval.fieldType, (
union anyVrml*)&rotation, fwpars[1]._web3dval.native);
3193 fwretval->itype =
'F';
3194 fwretval->_numeric = angle;
3198int X3DMatrix3_inverse(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3203 matinverse3d(ret->c, ptr->c);
3205 fwretval->_pointer.native = ret;
3206 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
3207 fwretval->_pointer.gc =
'T';
3208 fwretval->itype =
'P';
3211int X3DMatrix3_transpose(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3215 mattranspose3d(ret->c, ptr->c);
3217 fwretval->_pointer.native = ret;
3218 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
3219 fwretval->_pointer.gc =
'T';
3220 fwretval->itype =
'P';
3224int X3DMatrix3_multLeft(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3228 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix3d, fwpars[0]._web3dval.native, (
union anyVrml*)&lhs);
3230 matmultiply3d(ret->c, lhs.c , ptr->c);
3232 fwretval->_pointer.native = ret;
3233 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
3234 fwretval->itype =
'P';
3235 fwretval->_pointer.gc =
'T';
3238int X3DMatrix3_multRight(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3242 fwretval->_pointer.native = ret;
3243 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix3d, fwpars[0]._web3dval.native, (
union anyVrml*)&rhs);
3245 matmultiply3d(ret->c, ptr->c, rhs.c);
3247 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
3248 fwretval->_pointer.gc =
'T';
3249 fwretval->itype =
'P';
3252int X3DMatrix3_multVecMatrix(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3258 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFVec2d, fwpars[0]._web3dval.native, (
union anyVrml*)&rhs);
3260 double a3[3], r3[3];
3261 veccopy2d(a3,rhs.c);
3263 vecmultmat3d(r3, a3, ptr->c);
3265 double wi = 1.0/r3[2];
3266 vecscale2d(ret->c,r3,wi);
3268 veccopy2d(ret->c,r3);
3271 fwretval->_web3dval.native = ret;
3272 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3273 fwretval->_web3dval.gc =
'T';
3274 fwretval->itype =
'W';
3277int X3DMatrix3_multMatrixVec(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3281 double a3[3], r3[3];
3282 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFVec2d, fwpars[0]._web3dval.native, (
union anyVrml*)&rhs);
3284 veccopy2d(a3,rhs.c);
3286 matmultvec3d(r3, ptr->c,a3);
3288 double wi = 1.0/r3[2];
3289 vecscale2d(ret->c,r3,wi);
3291 veccopy2d(ret->c,r3);
3294 fwretval->_web3dval.native = ret;
3295 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3296 fwretval->_web3dval.gc =
'T';
3297 fwretval->itype =
'W';
3301int X3DMatrix3_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3305 FWType sfvec3dtype = getFWTYPE(FIELDTYPE_SFVec3d);
3310 r = sfToString(sfvec3dtype,&ptr->c[i*3]);
3311 str = realloc(str,strlen(str)+strlen(r)+3);
3312 str = strcat(str,r);
3313 str = strcat(str,
", ");
3315 fwretval->_string = str;
3316 fwretval->itype =
'S';
3321 {
"setTransform", X3DMatrix3_setTransform, 0,{5,-1,0,
"WWWWW"}},
3322 {
"getTransform", X3DMatrix3_getTransform,
'P',{3,-1,0,
"WWW"}},
3323 {
"inverse", X3DMatrix3_inverse,
'P',{0,-1,0,NULL}},
3324 {
"transpose", X3DMatrix3_transpose,
'P',{0,-1,0,NULL}},
3325 {
"multLeft", X3DMatrix3_multLeft,
'P',{1,-1,0,
"P"}},
3326 {
"multRight", X3DMatrix3_multRight,
'P',{1,-1,0,
"P"}},
3327 {
"multVecMatrix", X3DMatrix3_multVecMatrix,
'W',{1,-1,0,
"W"}},
3328 {
"multMatrixVec", X3DMatrix3_multMatrixVec,
'W',{1,-1,0,
"W"}},
3329 {
"toString", X3DMatrix3_toString,
'S',{0,-1,0,NULL}},
3333int X3DMatrix3_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';
3348 if (index > -1 && index < 3) {
3351 ret = &ptr->c[index * 3];
3352 fwretval->_web3dval.native = ret;
3353 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
3354 fwretval->_web3dval.gc = 0;
3355 fwretval->itype =
'W';
3361int X3DMatrix3_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
3364 if(index > -1 && index < 9){
3365 if(fwval->itype ==
'F'){
3366 ptr->c[index] = fwval->_numeric;
3373void * X3DMatrix3_Constructor(FWType fwtype,
int ic, FWval fwpars){
3375 struct SFMatrix3d *ptr = malloc(fwtype->size_of);
3376 matidentity3d(ptr->c);
3377 if (fwpars[0].itype ==
'W') {
3378 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix3d, fwpars[0]._web3dval.native, (
union anyVrml*)ptr);
3380 else if (fwpars[0].itype ==
'F') {
3381 memset(ptr->c, 0,
sizeof(
struct SFMatrix3d));
3382 int ncopy = ic < 9 ? ic : 9;
3383 for (i = 0; i < ncopy; i++)
3384 ptr->c[i] = fwpars[i]._numeric;
3390 {0,0,
'F',
"FFFFFFFFF"},
3395struct FWTYPE X3DMatrix3Type = {
3400 X3DMatrix3_Constructor,
3401 X3DMatrix3_ConstructorArgs,
3407 X3DMatrix3_Functions,
3446int X3DMatrix4_setTransform(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3458 double *matrix[4], *mat[4], m2[16];
3460 memset(&translation, 0,
sizeof(
struct SFVec3d));
3461 memset(&rotation, 0,
sizeof(
struct SFRotation));
3462 memset(&scale, 0,
sizeof(
struct SFVec3d));
3463 memset(&scaleOrientation, 0,
sizeof(
struct SFRotation));
3464 memset(¢er, 0,
sizeof(
struct SFVec3d));
3465 scale.c[0] = scale.c[1] = scale.c[2] = 1.0;
3466 rotation.c[0] = 1.0f;
3468 if (argc > 0 && fwpars[0].itype ==
'W') {
3469 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFVec3d, fwpars[0]._web3dval.native, (
union anyVrml*)&translation);
3471 if (argc > 1 && fwpars[1].itype ==
'W') {
3472 shallow_copy_field_precision(fwpars[1]._web3dval.fieldType, FIELDTYPE_SFRotation, fwpars[1]._web3dval.native, (
union anyVrml*)&rotation);
3474 if (argc > 2 && fwpars[2].itype ==
'W') {
3475 shallow_copy_field_precision(fwpars[2]._web3dval.fieldType, FIELDTYPE_SFVec3d, fwpars[2]._web3dval.native, (
union anyVrml*)&scale);
3477 if (argc > 3 && fwpars[3].itype ==
'W') {
3478 shallow_copy_field_precision(fwpars[3]._web3dval.fieldType, FIELDTYPE_SFRotation, fwpars[3]._web3dval.native, (
union anyVrml*)&scaleOrientation);
3480 if (argc > 4 && fwpars[4].itype ==
'W') {
3481 shallow_copy_field_precision(fwpars[4]._web3dval.fieldType, FIELDTYPE_SFVec3d, fwpars[4]._web3dval.native, (
union anyVrml*)¢er);
3485 matrix[i] = &ptr->c[i*4];
3489 matidentity4d(matrix[0]);
3495 matidentity4d(mat[0]);
3496 veccopyd(mat[3], translation.c);
3497 matmultiplyFULL(matrix[0], mat[0], matrix[0]);
3501 matidentity4d(mat[0]);
3502 veccopyd(mat[3], center.c);
3503 matmultiplyFULL(matrix[0], mat[0], matrix[0]);
3508 matidentity4d(mat[0]);
3509 for (i = 0; i < 3; i++)
3510 axisangle_rotate3d(mat[i], mat[i], rotation.c);
3511 matmultiplyFULL(matrix[0], mat[0], matrix[0]);
3516 matidentity4d(mat[0]);
3517 for (i = 0; i < 3; i++)
3518 axisangle_rotate3d(mat[i], mat[i], scaleOrientation.c);
3519 matmultiplyFULL(matrix[0], mat[0], matrix[0]);
3524 matidentity4d(mat[0]);
3525 for (i = 0; i < 4; i++)
3526 vecmult3d(mat[i], mat[i], scale.c);
3527 matmultiplyFULL(matrix[0], mat[0], matrix[0]);
3533 scaleOrientation.c[3] = -scaleOrientation.c[3];
3534 matidentity4d(mat[0]);
3535 for (i = 0; i < 3; i++)
3536 axisangle_rotate3d(mat[i], mat[i], scaleOrientation.c);
3537 matmultiplyFULL(matrix[0], mat[0], matrix[0]);
3538 scaleOrientation.c[3] = -scaleOrientation.c[3];
3543 matidentity4d(mat[0]);
3544 veccopyd(mat[3], center.c);
3545 vecscaled(mat[3], mat[3], -1.0f);
3546 matmultiplyFULL(matrix[0], mat[0], matrix[0]);
3552int X3DMatrix4_getTransform(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3559 double *matrix[4], retscale[3];
3565 matrix[i] = &ptr->c[i*4];
3569 retscale[i] = sqrt(vecdot4d(matrix[i],matrix[i]));
3572 veccopyd(translation.c,matrix[3]);
3581 if(ff != 0.0) ff = 1.0/ff;
3582 vecscale4d(&m2[i*4],matrix[i],ff);
3586 matrix_to_quaternion(&quat, m2);
3587 #ifdef JSVRMLCLASSESVERBOSE
3588 printf (
"quaternion %f %f %f %f\n",quat.x,quat.y,quat.z,quat.w);
3592 quaternion_to_vrmlrot(&quat, &qu[0],&qu[1],&qu[2],&qu[3]);
3596 rotation.c[i] = (
float) qu[i];
3601 veccopyd(scale.c,retscale);
3604 if (argc > 0 && fwpars[0].itype ==
'W') {
3605 shallow_copy_field_precision(FIELDTYPE_SFVec3d, fwpars[0]._web3dval.fieldType, (
union anyVrml*)&translation, fwpars[0]._web3dval.native );
3608 if (argc > 1 && fwpars[1].itype ==
'W') {
3609 shallow_copy_field_precision(FIELDTYPE_SFRotation, fwpars[1]._web3dval.fieldType, (
union anyVrml*)&rotation, fwpars[1]._web3dval.native);
3612 if (argc > 2 && fwpars[2].itype ==
'W') {
3613 shallow_copy_field_precision(FIELDTYPE_SFVec3d, fwpars[2]._web3dval.fieldType, (
union anyVrml*)&scale, fwpars[2]._web3dval.native);
3619int X3DMatrix4_inverse(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3624 matinverseFULL(ret->c,ptr->c);
3626 fwretval->_pointer.native = ret;
3627 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3628 fwretval->_pointer.gc =
'T';
3629 fwretval->itype =
'P';
3632int X3DMatrix4_transpose(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3637 mattranspose(ret->c, ptr->c);
3639 fwretval->_pointer.native = ret;
3640 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3641 fwretval->_pointer.gc =
'T';
3642 fwretval->itype =
'P';
3646int X3DMatrix4_multLeft(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3652 matidentity4d(ret->c);
3653 if (argc > 0 && (fwpars[0].itype ==
'P' || fwpars[0].itype ==
'W')) {
3654 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix4d, fwpars[0]._web3dval.native, (
union anyVrml*)&rhs);
3655 matmultiplyFULL(ret->c, rhs.c, ptr->c);
3659 fwretval->_pointer.native = ret;
3660 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3661 fwretval->_pointer.gc =
'T';
3662 fwretval->itype =
'P';
3665int X3DMatrix4_multRight(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3670 fwretval->_pointer.native = ret;
3671 matidentity4d(rhs.c);
3672 if (argc > 0 && (fwpars[0].itype ==
'W' || fwpars[0].itype ==
'P')) {
3673 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix4d, fwpars[0]._web3dval.native, (
union anyVrml*)&rhs);
3676 matmultiplyFULL(ret->c,ptr->c,rhs.c);
3678 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3679 fwretval->_pointer.gc =
'T';
3680 fwretval->itype =
'P';
3683int X3DMatrix4_multVecMatrix(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3688 memset(rhs.c,0,
sizeof(
struct SFVec3d));
3689 if (argc > 0 && fwpars[0].itype ==
'W') {
3690 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFVec3d, fwpars[0]._web3dval.native, (
union anyVrml*)&rhs);
3693 double a4[4], r4[4];
3696 vecmultmat4d(r4, a4, ptr->c);
3698 double wi = 1.0/r4[3];
3699 vecscaled(ret->c,r4,wi);
3701 veccopyd(ret->c,r4);
3704 fwretval->_web3dval.native = ret;
3705 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
3706 fwretval->_web3dval.gc =
'T';
3707 fwretval->itype =
'W';
3710int X3DMatrix4_multMatrixVec(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3716 double a4[4], r4[4];
3718 memset(rhs.c, 0,
sizeof(
struct SFVec3d));
3719 if (argc > 0 && fwpars[0].itype ==
'W') {
3720 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFVec3d, fwpars[0]._web3dval.native, (
union anyVrml*)&rhs);
3725 matmultvec4d(r4, ptr->c, a4 );
3727 double wi = 1.0/r4[3];
3728 vecscaled(ret->c,r4,wi);
3730 veccopyd(ret->c,r4);
3733 fwretval->_web3dval.native = ret;
3734 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
3735 fwretval->_web3dval.gc =
'T';
3736 fwretval->itype =
'W';
3740int X3DMatrix4_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3744 FWType sfvec4dtype = getFWTYPE(FIELDTYPE_SFVec4d);
3749 r = sfToString(sfvec4dtype,&ptr->c[i*4]);
3750 str = realloc(str,strlen(str)+strlen(r)+3);
3751 str = strcat(str,r);
3752 str = strcat(str,
", ");
3754 fwretval->_string = str;
3755 fwretval->itype =
'S';
3761 {
"setTransform", X3DMatrix4_setTransform, 0,{5,-1,0,
"WWWWW"}},
3762 {
"getTransform", X3DMatrix4_getTransform,
'P',{3,-1,0,
"WWW"}},
3763 {
"inverse", X3DMatrix4_inverse,
'P',{0,-1,0,NULL}},
3764 {
"transpose", X3DMatrix4_transpose,
'P',{0,-1,0,NULL}},
3765 {
"multLeft", X3DMatrix4_multLeft,
'P',{1,-1,0,
"P"}},
3766 {
"multRight", X3DMatrix4_multRight,
'P',{1,-1,0,
"P"}},
3767 {
"multVecMatrix", X3DMatrix4_multVecMatrix,
'W',{1,-1,0,
"W"}},
3768 {
"multMatrixVec", X3DMatrix4_multMatrixVec,
'W',{1,-1,0,
"W"}},
3769 {
"toString", X3DMatrix4_toString,
'S',{0,-1,0,NULL}},
3773int X3DMatrix4_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
3781 if (index > -1 && index < 4) {
3784 ret = &ptr->c[index * 4];
3785 fwretval->_web3dval.native = ret;
3786 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec4d;
3787 fwretval->_web3dval.gc = 0;
3788 fwretval->itype =
'W';
3793 if (index > -1 && index < 16) {
3795 fwretval->_numeric = ptr->c[index];
3797 fwretval->itype =
'F';
3801int X3DMatrix4_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
3806 printf(
"Matrix4 setter itype == %d\n ",fwval->itype);
3809 if (index > -1 && index < 16) {
3810 if (fwval->itype ==
'F') {
3811 ptr->c[index] = fwval->_numeric;
3819void * X3DMatrix4_Constructor(FWType fwtype,
int ic, FWval fwpars){
3821 struct SFMatrix4d *ptr = malloc(fwtype->size_of);
3822 matidentity4d(ptr->c);
3824 if (ic > 0 && fwpars[0].itype ==
'W') {
3825 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix4d, fwpars[0]._web3dval.native, (
union anyVrml*)ptr);
3827 else if (ic > 0 && fwpars[0].itype ==
'F') {
3828 memset(ptr->c, 0,
sizeof(
struct SFMatrix4d));
3829 int ncopy = ic < 16 ? ic : 16;
3830 for (i = 0; i < ncopy; i++)
3831 ptr->c[i] = fwpars[i]._numeric;
3837 {0,0,
'F',
"FFFFFFFFFFFFFFFF"},
3842struct FWTYPE X3DMatrix4Type = {
3847 X3DMatrix4_Constructor,
3848 X3DMatrix4_ConstructorArgs,
3854 X3DMatrix4_Functions,
3859int VrmlMatrix_setTransform(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3860 int iret = X3DMatrix4_setTransform(fwtype, ec, fwn, argc, fwpars, fwretval);
3864int VrmlMatrix_getTransform(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3865 int iret = X3DMatrix4_getTransform(fwtype, ec, fwn, argc,fwpars, fwretval);
3869int VrmlMatrix_inverse(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3870 int iret = X3DMatrix4_inverse(fwtype, ec, fwn, argc, fwpars, fwretval);
3871 fwretval->_pointer.fieldType = AUXTYPE_VrmlMatrix;
3874int VrmlMatrix_transpose(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3875 int iret = X3DMatrix4_transpose(fwtype, ec, fwn, argc, fwpars, fwretval);
3876 fwretval->_pointer.fieldType = AUXTYPE_VrmlMatrix;
3879int VrmlMatrix_multLeft(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3880 int iret = X3DMatrix4_multLeft(fwtype, ec, fwn, argc, fwpars, fwretval);
3881 fwretval->_pointer.fieldType = AUXTYPE_VrmlMatrix;
3884int VrmlMatrix_multRight(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3885 int iret = X3DMatrix4_multRight(fwtype, ec, fwn, argc, fwpars, fwretval);
3886 fwretval->_pointer.fieldType = AUXTYPE_VrmlMatrix;
3889int VrmlMatrix_multVecMatrix(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3890 int iret = X3DMatrix4_multVecMatrix(fwtype, ec, fwn, argc, fwpars, fwretval);
3893int VrmlMatrix_multMatrixVec(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3894 int iret = X3DMatrix4_multMatrixVec(fwtype, ec, fwn, argc, fwpars, fwretval);
3898int VrmlMatrix_toString(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
3899 int iret = X3DMatrix4_toString(fwtype, ec, fwn, argc, fwpars, fwretval);
3905 {
"setTransform", VrmlMatrix_setTransform, 0,{5,-1,0,
"WWWWW"}},
3906 {
"getTransform", VrmlMatrix_getTransform,
'P',{3,-1,0,
"WWW"}},
3907 {
"inverse", VrmlMatrix_inverse,
'P',{0,-1,0,NULL}},
3908 {
"transpose", VrmlMatrix_transpose,
'P',{0,-1,0,NULL}},
3909 {
"multLeft", VrmlMatrix_multLeft,
'P',{1,-1,0,
"P"}},
3910 {
"multRight", VrmlMatrix_multRight,
'P',{1,-1,0,
"P"}},
3911 {
"multVecMatrix", VrmlMatrix_multVecMatrix,
'W',{1,-1,0,
"W"}},
3912 {
"multMatrixVec", VrmlMatrix_multMatrixVec,
'W',{1,-1,0,
"W"}},
3913 {
"toString", VrmlMatrix_toString,
'S',{0,-1,0,NULL}},
3917int VrmlMatrix_Getter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwretval) {
3918 int iret = X3DMatrix4_Getter(fwt, index, ec, fwn, fwretval);
3921int VrmlMatrix_Setter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwval) {
3922 int iret = X3DMatrix4_Setter(fwt, index, ec, fwn, fwval);
3926void* VrmlMatrix_Constructor(FWType fwtype,
int ic, FWval fwpars) {
3927 void* ret = X3DMatrix4_Constructor(fwtype, ic, fwpars);
3932 {0,0,
'F',
"FFFFFFFFFFFFFFFF"},
3937struct FWTYPE VrmlMatrixType = {
3942 VrmlMatrix_Constructor,
3943 VrmlMatrix_ConstructorArgs,
3949 VrmlMatrix_Functions,
3973int SFVec2d_add(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3975 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3976 struct SFVec2d *res = malloc(fwtype->size_of);
3977 vecadd2d(res->c,ptr->c,rhs->c);
3978 fwretval->_web3dval.native = res;
3979 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3980 fwretval->_web3dval.gc =
'T';
3981 fwretval->itype =
'W';
3984int SFVec2d_subtract(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3986 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3987 struct SFVec2d *res = malloc(fwtype->size_of);
3988 vecdif2d(res->c,ptr->c,rhs->c);
3989 fwretval->_web3dval.native = res;
3990 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3991 fwretval->_web3dval.gc =
'T';
3992 fwretval->itype =
'W';
3995int SFVec2d_divide(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
3998 double rhs = fwpars[0]._numeric;
4003 res = malloc(fwtype->size_of);
4004 vecscale2d(res->c,ptr->c,rhs);
4005 fwretval->_web3dval.native = res;
4006 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
4007 fwretval->_web3dval.gc =
'T';
4008 fwretval->itype =
'W';
4011int SFVec2d_multiply(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
4013 double rhs = fwpars[0]._numeric;
4014 struct SFVec2d *res = malloc(fwtype->size_of);
4015 vecscale2d(res->c,ptr->c,rhs);
4016 fwretval->_web3dval.native = res;
4017 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
4018 fwretval->_web3dval.gc =
'T';
4019 fwretval->itype =
'W';
4022int SFVec2d_normalize(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
4024 struct SFVec2d *res = malloc(fwtype->size_of);
4025 vecnormal2d(res->c,ptr->c);
4026 fwretval->_web3dval.native = res;
4027 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
4028 fwretval->_web3dval.gc =
'T';
4029 fwretval->itype =
'W';
4033int SFVec2d_length(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
4036 res = veclength2d(ptr->c);
4037 fwretval->_numeric = res;
4038 fwretval->itype =
'D';
4041int SFVec2d_dot(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
4043 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
4045 res = vecdot2d(ptr->c,rhs->c);
4046 fwretval->_numeric = res;
4047 fwretval->itype =
'D';
4050int SFVec2d_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
4052 char buff[STRING], *str;
4054 memset(buff, 0, STRING);
4055 sprintf(buff,
"%.9g %.9g",
4056 ptr->c[0], ptr->c[1]);
4058 str = malloc(len+1);
4060 fwretval->_string = str;
4061 fwretval->itype =
'S';
4065 {
"add", SFVec2d_add,
'W',{1,-1,0,
"W"}},
4066 {
"divide", SFVec2d_divide,
'W',{1,-1,0,
"D"}},
4067 {
"dot", SFVec2d_dot,
'D',{1,-1,0,
"W"}},
4068 {
"length", SFVec2d_length,
'D',{0,-1,0,NULL}},
4069 {
"multiply", SFVec2d_multiply,
'W',{1,-1,0,
"D"}},
4070 {
"normalize", SFVec2d_normalize,
'W',{0,-1,0,NULL}},
4071 {
"subtract", SFVec2d_subtract,
'W',{1,-1,0,
"W"}},
4072 {
"toString", SFVec2d_toString,
'S',{0,-1,0,NULL}},
4076int SFVec2d_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
4080 if(index > -1 && index < 2){
4085 fwretval->_numeric = ptr->c[index];
4091 fwretval->itype =
'D';
4094int SFVec2d_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
4097 if(index > -1 && index < 2){
4101 ptr->c[index] = fwval->_numeric;
4109void * SFVec2d_Constructor(FWType fwtype,
int ic, FWval fwpars){
4111 struct SFVec2d *ptr = malloc(fwtype->size_of);
4112 memset(ptr,0,fwtype->size_of);
4115 ptr->c[i] = fwpars[i]._numeric;
4116 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
4118 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
4136struct FWTYPE SFVec2dType = {
4141 SFVec2d_Constructor,
4142 SFVec2d_ConstructorArgs,
4152struct FWTYPE MFVec2dType = {
4158 MFW_ConstructorArgs,
4167int SFVec4f_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
4169 char buff[STRING], *str;
4171 memset(buff, 0, STRING);
4172 sprintf(buff,
"%.9g %.9g %.9g %.9g",
4173 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
4175 str = malloc(len+1);
4177 fwretval->_string = str;
4178 fwretval->itype =
'S';
4183 {
"toString", SFVec4f_toString,
'S',{0,-1,0,NULL}},
4187int SFVec4f_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
4191 if(index > -1 && index < 4){
4198 fwretval->_numeric = ptr->c[index];
4204 fwretval->itype =
'F';
4207int SFVec4f_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
4210 if(index > -1 && index < 4){
4216 ptr->c[index] = (float)fwval->_numeric;
4224void * SFVec4f_Constructor(FWType fwtype,
int ic, FWval fwpars){
4226 struct SFVec4f *ptr = malloc(fwtype->size_of);
4229 ptr->c[i] = (
float)fwpars[i]._numeric;
4230 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
4232 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
4253struct FWTYPE SFVec4fType = {
4258 SFVec4f_Constructor,
4259 SFVec4f_ConstructorArgs,
4269struct FWTYPE MFVec4fType = {
4275 MFW_ConstructorArgs,
4284int SFVec4d_toString(FWType fwtype,
void *ec,
void *fwn,
int argc, FWval fwpars, FWval fwretval){
4286 char buff[STRING], *str;
4288 memset(buff, 0, STRING);
4289 sprintf(buff,
"%.9g %.9g %.9g %.9g",
4290 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
4292 str = malloc(len+1);
4294 fwretval->_string = str;
4295 fwretval->itype =
'S';
4299 {
"toString", SFVec4d_toString,
'S',{0,-1,0,NULL}},
4303int SFVec4d_Getter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwretval){
4307 if(index > -1 && index < 4){
4314 fwretval->_numeric = ptr->c[index];
4320 fwretval->itype =
'D';
4323int SFVec4d_Setter(FWType fwt,
int index,
void *ec,
void *fwn, FWval fwval){
4326 if(index > -1 && index < 4){
4332 ptr->c[index] = fwval->_numeric; ;
4340void * SFVec4d_Constructor(FWType fwtype,
int ic, FWval fwpars){
4342 struct SFVec3d *ptr = malloc(fwtype->size_of);
4343 memset(ptr,0,fwtype->size_of);
4346 ptr->c[i] = fwpars[i]._numeric;
4347 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
4349 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
4368struct FWTYPE SFVec4dType = {
4373 SFVec4d_Constructor,
4374 SFVec4d_ConstructorArgs,
4384struct FWTYPE MFVec4dType = {
4390 MFW_ConstructorArgs,
4400int SFMatrix3f_toString(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
4404 FWType sfvec3ftype = getFWTYPE(FIELDTYPE_SFVec3f);
4408 for (i = 0; i < 3; i++) {
4409 r = sfToString(sfvec3ftype, &ptr->c[i * 3]);
4410 str = realloc(str, strlen(str) + strlen(r) + 3);
4411 str = strcat(str, r);
4412 str = strcat(str,
", ");
4414 fwretval->_string = str;
4415 fwretval->itype =
'S';
4419 {
"toString", SFMatrix3f_toString,
'S',{0,-1,0,NULL}},
4423int SFMatrix3f_Getter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwretval) {
4427 if (index > -1 && index < 9) {
4428 fwretval->_numeric = ptr->c[index];
4430 fwretval->itype =
'D';
4433int SFMatrix3f_Setter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwval) {
4436 if (index > -1 && index < 9) {
4437 ptr->c[index] = fwval->_numeric; ;
4444void* SFMatrix3f_Constructor(FWType fwtype,
int ic, FWval fwpars) {
4446 struct SFMatrix3f* ptr = malloc(fwtype->size_of);
4447 matidentity3f(ptr->c);
4450 for (i = 0; i < 9; i++)
4451 ptr->c[i] = fwpars[i]._numeric;
4453 else if (fwpars[0].itype ==
'W') {
4455 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType,FIELDTYPE_SFMatrix3f, fwpars[0]._web3dval.native, (
void*)ptr);
4464 {9,0,
'T',
"FFFFFFFFF"},
4470struct FWTYPE SFMatrix3fType = {
4471 FIELDTYPE_SFMatrix3f,
4475 SFMatrix3f_Constructor,
4476 SFMatrix3f_ConstructorArgs,
4477 SFMatrix3f_Properties,
4482 SFMatrix3f_Functions,
4486struct FWTYPE MFMatrix3fType = {
4487 FIELDTYPE_MFMatrix3f,
4492 MFW_ConstructorArgs,
4502int SFMatrix3d_toString(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
4506 FWType sfvec3dtype = getFWTYPE(FIELDTYPE_SFVec3d);
4510 for (i = 0; i < 3; i++) {
4511 r = sfToString(sfvec3dtype, &ptr->c[i * 3]);
4512 str = realloc(str, strlen(str) + strlen(r) + 3);
4513 str = strcat(str, r);
4514 str = strcat(str,
", ");
4516 fwretval->_string = str;
4517 fwretval->itype =
'S';
4521 {
"toString", SFMatrix3d_toString,
'S',{0,-1,0,NULL}},
4525int SFMatrix3d_Getter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwretval) {
4529 if (index > -1 && index < 9) {
4530 fwretval->_numeric = ptr->c[index];
4532 fwretval->itype =
'D';
4535int SFMatrix3d_Setter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwval) {
4538 if (index > -1 && index < 9) {
4539 ptr->c[index] = fwval->_numeric; ;
4546void* SFMatrix3d_Constructor(FWType fwtype,
int ic, FWval fwpars) {
4548 struct SFMatrix3d* ptr = malloc(fwtype->size_of);
4549 matidentity3d(ptr->c);
4552 for (i = 0; i < 9; i++)
4553 ptr->c[i] = fwpars[i]._numeric;
4555 else if (fwpars[0].itype ==
'W') {
4557 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix3d, fwpars[0]._web3dval.native, (
void*)ptr);
4566 {9,0,
'T',
"FFFFFFFFF"},
4571struct FWTYPE SFMatrix3dType = {
4572 FIELDTYPE_SFMatrix3d,
4576 SFMatrix3d_Constructor,
4577 SFMatrix3d_ConstructorArgs,
4578 SFMatrix3d_Properties,
4583 SFMatrix3d_Functions,
4587struct FWTYPE MFMatrix3dType = {
4588 FIELDTYPE_MFMatrix3d,
4593 MFW_ConstructorArgs,
4603int SFMatrix4f_toString(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
4607 FWType sfvec4ftype = getFWTYPE(FIELDTYPE_SFVec4f);
4611 for (i = 0; i < 4; i++) {
4612 r = sfToString(sfvec4ftype, &ptr->c[i * 4]);
4613 str = realloc(str, strlen(str) + strlen(r) + 3);
4614 str = strcat(str, r);
4615 str = strcat(str,
", ");
4617 fwretval->_string = str;
4618 fwretval->itype =
'S';
4622 {
"toString", SFMatrix4f_toString,
'S',{0,-1,0,NULL}},
4626int SFMatrix4f_Getter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwretval) {
4630 if (index > -1 && index < 16) {
4631 fwretval->_numeric = ptr->c[index];
4633 fwretval->itype =
'D';
4636int SFMatrix4f_Setter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwval) {
4639 if (index > -1 && index < 16) {
4640 ptr->c[index] = fwval->_numeric; ;
4647void* SFMatrix4f_Constructor(FWType fwtype,
int ic, FWval fwpars) {
4649 struct SFMatrix4f* ptr = malloc(fwtype->size_of);
4650 matidentity4f(ptr->c);
4653 for (i = 0; i < 9; i++)
4654 ptr->c[i] = fwpars[i]._numeric;
4656 else if (fwpars[0].itype ==
'W') {
4658 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix4f, fwpars[0]._web3dval.native, (
void*)ptr);
4667 {16,0,
'T',
"FFFFFFFFFFFFFFFF"},
4672struct FWTYPE SFMatrix4fType = {
4673 FIELDTYPE_SFMatrix4f,
4677 SFMatrix4f_Constructor,
4678 SFMatrix4f_ConstructorArgs,
4679 SFMatrix4f_Properties,
4684 SFMatrix4f_Functions,
4688struct FWTYPE MFMatrix4fType = {
4689 FIELDTYPE_MFMatrix4f,
4694 MFW_ConstructorArgs,
4704int SFMatrix4d_toString(FWType fwtype,
void* ec,
void* fwn,
int argc, FWval fwpars, FWval fwretval) {
4708 FWType sfvec4dtype = getFWTYPE(FIELDTYPE_SFVec4d);
4712 for (i = 0; i < 4; i++) {
4713 r = sfToString(sfvec4dtype, &ptr->c[i * 4]);
4714 str = realloc(str, strlen(str) + strlen(r) + 3);
4715 str = strcat(str, r);
4716 str = strcat(str,
", ");
4718 fwretval->_string = str;
4719 fwretval->itype =
'S';
4723 {
"toString", SFMatrix4d_toString,
'S',{0,-1,0,NULL}},
4727int SFMatrix4d_Getter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwretval) {
4731 if (index > -1 && index < 16) {
4732 fwretval->_numeric = ptr->c[index];
4734 fwretval->itype =
'D';
4737int SFMatrix4d_Setter(FWType fwt,
int index,
void* ec,
void* fwn, FWval fwval) {
4740 if (index > -1 && index < 16) {
4741 ptr->c[index] = fwval->_numeric; ;
4748void* SFMatrix4d_Constructor(FWType fwtype,
int ic, FWval fwpars) {
4750 struct SFMatrix4d* ptr = malloc(fwtype->size_of);
4751 matidentity4d(ptr->c);
4754 for (i = 0; i < 16; i++)
4755 ptr->c[i] = fwpars[i]._numeric;
4757 else if (fwpars[0].itype ==
'W') {
4759 shallow_copy_field_precision(fwpars[0]._web3dval.fieldType, FIELDTYPE_SFMatrix4d, fwpars[0]._web3dval.native, (
void*)ptr);
4768 {16,0,
'T',
"FFFFFFFFFFFFFFFF"},
4773struct FWTYPE SFMatrix4dType = {
4774 FIELDTYPE_SFMatrix4d,
4778 SFMatrix4d_Constructor,
4779 SFMatrix4d_ConstructorArgs,
4780 SFMatrix4d_Properties,
4785 SFMatrix4d_Functions,
4789struct FWTYPE MFMatrix4dType = {
4790 FIELDTYPE_MFMatrix4d,
4795 MFW_ConstructorArgs,
4807void initVRMLFields(FWType* typeArray,
int *n){
4808 typeArray[*n] = &SFInt32Type; (*n)++;
4809 typeArray[*n] = &MFInt32Type; (*n)++;
4810 typeArray[*n] = &SFFloatType; (*n)++;
4811 typeArray[*n] = &MFFloatType; (*n)++;
4812 typeArray[*n] = &SFTimeType; (*n)++;
4813 typeArray[*n] = &MFTimeType; (*n)++;
4814 typeArray[*n] = &SFDoubleType; (*n)++;
4815 typeArray[*n] = &MFDoubleType; (*n)++;
4816 typeArray[*n] = &SFBoolType; (*n)++;
4817 typeArray[*n] = &MFBoolType; (*n)++;
4818 typeArray[*n] = &SFNodeType; (*n)++;
4819 typeArray[*n] = &MFNodeType; (*n)++;
4820 typeArray[*n] = &SFRotationType; (*n)++;
4821 typeArray[*n] = &MFRotationType; (*n)++;
4822 typeArray[*n] = &SFColorType; (*n)++;
4823 typeArray[*n] = &MFColorType; (*n)++;
4824 typeArray[*n] = &SFColorRGBAType; (*n)++;
4825 typeArray[*n] = &MFColorRGBAType; (*n)++;
4826 typeArray[*n] = &SFStringType; (*n)++;
4827 typeArray[*n] = &MFStringType; (*n)++;
4828 typeArray[*n] = &SFVec2fType; (*n)++;
4829 typeArray[*n] = &MFVec2fType; (*n)++;
4830 typeArray[*n] = &SFVec3fType; (*n)++;
4831 typeArray[*n] = &MFVec3fType; (*n)++;
4832 typeArray[*n] = &SFVec4fType; (*n)++;
4833 typeArray[*n] = &MFVec4fType; (*n)++;
4834 typeArray[*n] = &SFVec2dType; (*n)++;
4835 typeArray[*n] = &MFVec2dType; (*n)++;
4836 typeArray[*n] = &SFVec3dType; (*n)++;
4837 typeArray[*n] = &MFVec3dType; (*n)++;
4838 typeArray[*n] = &SFVec4dType; (*n)++;
4839 typeArray[*n] = &MFVec4dType; (*n)++;
4841 typeArray[*n] = &SFImageType; (*n)++;
4842 typeArray[*n] = &MFImageType; (*n)++;
4843 typeArray[*n] = &SFMatrix3fType; (*n)++;
4844 typeArray[*n] = &MFMatrix3fType; (*n)++;
4845 typeArray[*n] = &SFMatrix3dType; (*n)++;
4846 typeArray[*n] = &MFMatrix3dType; (*n)++;
4847 typeArray[*n] = &SFMatrix4fType; (*n)++;
4848 typeArray[*n] = &MFMatrix4fType; (*n)++;
4849 typeArray[*n] = &SFMatrix4dType; (*n)++;
4850 typeArray[*n] = &MFMatrix4dType; (*n)++;
4851 typeArray[*n] = &X3DMatrix3Type; (*n)++;
4852 typeArray[*n] = &X3DMatrix4Type; (*n)++;
4853 typeArray[*n] = &VrmlMatrixType; (*n)++;