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){
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;
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';
1212void medium_copy_field0(
int itype,
void* source,
void* dest);
1213void *returnInterpolatorPointer (
int nodeType);
1214int SFNode_Setter0(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval,
int isCurrentScriptNode){
1218 int ftype, kind, ihave, nr, builtIn;
1222 ihave = getFieldFromNodeAndIterator(node, index, &name, &
ftype, &kind, &value, &builtIn);
1225 switch(fwval->itype){
1227 value->sfbool = fwval->_boolean;
1230 value->sfint32 = fwval->_integer;
1234 value->sffloat = (float)fwval->_numeric;
1238 value->sftime = fwval->_numeric;
1242 value->sfstring = newASCIIString(fwval->_string);
1246 if(!strcmp(name,
"children")){
1249 AddRemoveChildren(node,(
void*)value,(
void*)any->p,any->n,0,__FILE__,__LINE__);
1251 medium_copy_field0(
ftype,fwval->_web3dval.native,value);
1255 if(node->_nodeType == NODE_Script) {
1257 struct Shader_Script *script = X3D_SCRIPT(node)->__scriptObj;
1259 field = Shader_Script_getScriptField(script,index);
1260 if(kind == PKW_inputOutput || kind == PKW_outputOnly)
1261 field->valueChanged = TRUE;
1262 if(!isCurrentScriptNode) {
1263 if(kind == PKW_inputOnly || kind == PKW_inputOutput) {
1266 field->eventInSet = TRUE;
1271 void (* interpolatorPointer)(
void*);
1272 interpolatorPointer = returnInterpolatorPointer(node->_nodeType);
1274 if(interpolatorPointer){
1276 interpolatorPointer(node);
1285int SFNode_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
1286 return SFNode_Setter0(fwt,index,ec,fwn,fwval,FALSE);
1288void * SFNode_Constructor(
FWType fwtype,
int nargs,
FWval fwpars){
1291 if(fwpars[0].itype ==
'S'){
1303 const char *_c = fwpars[0]._string;
1306 gglobal()->ProdCon.savedParser = (
void *)globalParser; globalParser = NULL;
1307 retGroup = createNewX3DNode(NODE_Group);
1308 ra = EAI_CreateVrml(
"String",_c,X3D_NODE(retGroup),retGroup);
1309 globalParser = (
struct VRMLParser*)gglobal()->ProdCon.savedParser;
1311 ptr = malloc(
sizeof(
void *));
1312 *ptr = retGroup->children.p[0];
1313 (*ptr)->_parentVector->n = 0;
1314 }
else if(fwpars->itype ==
'W'){
1315 if(fwpars->_web3dval.fieldType == FIELDTYPE_SFNode){
1319 ptr = malloc(
sizeof(
void *));
1320 *ptr = ((
union anyVrml*)fwpars[0]._web3dval.native)->sfnode;
1342int SFNode_getNodeName(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1350 context = (
struct X3D_Proto *)node->_executionContext;
1355 if(context->__DEFnames)
1356 for(i=0;i<vectorSize(context->__DEFnames);i++){
1357 def = vector_get(
struct brotoDefpair, context->__DEFnames,i);
1358 if(def.node == node){
1365 fwretval->_string = name;
1366 fwretval->itype =
'S';
1372int SFNode_equals(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1374 struct X3D_Node *lhs = *(
void * *)fwn;
1377 fwretval->_boolean = lhs == rhs;
1378 fwretval->itype =
'B';
1381int SFNode_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1383 void* *ptr = (
void * *)fwn;
1386 printf(
"node address=%p nodetype=%s\n",node,stringNodeType(node->_nodeType));
1390 void *sfptr = malloc(
sizeof(
void*));
1391 memcpy(sfptr,(
void *)(fwn),
sizeof(
void*));
1392 fwretval->_web3dval.native = (
void *)sfptr;
1393 fwretval->_web3dval.gc = 1;
1394 fwretval->itype =
'W';
1396 fwretval->_jsobject = *ptr;
1397 fwretval->itype =
'X';
1401int SFNode_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1404 void **ptr = (
void **)fwn;
1405 sprintf(str,
"_%p_",(*ptr));
1406 fwretval->_string = strdup(str);
1407 fwretval->itype =
'S';
1411 {
"getNodeName", SFNode_getNodeName,
'S',{0,0,0,NULL}},
1417 {
"equals", SFNode_equals,
'B',{1,-1,0,
"W"}},
1418 {
"valueOf", SFNode_valueOf,
'X',{0,0,0,NULL}},
1419 {
"toString", SFNode_toString,
'S',{0,0,0,NULL}},
1424struct FWTYPE SFNodeType = {
1430 SFNode_ConstructorArgs,
1442struct FWTYPE MFNodeType = {
1448 MFW_ConstructorArgs,
1459double MIND3(
double a,
double b,
double c) {
1461 if((a<b)&&(a<c))min=a;
else if((b<a)&&(b<c))min=b;
else min=c;
return min;
1464double MAXD3(
double a,
double b,
double c) {
1466 if((a>b)&&(a>c))max=a;
else if((b>a)&&(b>c))max=b;
else max=c;
return max;
1469void convertRGBtoHSV_duk(
double r,
double g,
double b,
double *h,
double *s,
double *v) {
1470 double my_min, my_max, delta;
1472 my_min = MIND3( r, g, b );
1473 my_max = MAXD3( r, g, b );
1475 delta = my_max - my_min;
1477 *s = delta / my_max;
1485 *h = ( g - b ) / delta;
1486 else if( g == my_max )
1487 *h = 2 + ( b - r ) / delta;
1489 *h = 4 + ( r - g ) / delta;
1494void convertHSVtoRGB_duk(
double h,
double s,
double v ,
double *r,
double *g,
double *b)
1504 i = (int) floor( h );
1507 q = v * ( 1 - s * f );
1508 t = v * ( 1 - s * ( 1 - f ) );
1510 case 0: *r = v; *g = t; *b = p;
break;
1511 case 1: *r = q; *g = v; *b = p;
break;
1512 case 2: *r = p; *g = v; *b = t;
break;
1513 case 3: *r = p; *g = q; *b = v;
break;
1514 case 4: *r = t; *g = p; *b = v;
break;
1515 default: *r = v; *g = p; *b = q;
break;
1520int SFColor_getHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1526 convertRGBtoHSV_duk((
double)ptr->c[0], (
double)ptr->c[1], (
double)ptr->c[2],&xp[0],&xp[1],&xp[2]);
1528 sf3d = malloc(
sizeof(
struct SFVec3d));
1529 memcpy(sf3d->c,xp,
sizeof(
double)*3);
1530 fwretval->_web3dval.native = sf3d;
1531 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
1532 fwretval->_web3dval.gc =
'T';
1533 fwretval->itype =
'W';
1537int SFColor_setHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1542 convertHSVtoRGB_duk((
double)fwpars[0]._numeric, (
double)fwpars[1]._numeric, (
double)fwpars[2]._numeric,&xp[0],&xp[1],&xp[2]);
1543 ptr->c[0] = (float)xp[0];
1544 ptr->c[1] = (float)xp[1];
1545 ptr->c[2] = (float)xp[2];
1549int SFColor_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1551 char buff[STRING], *str;
1553 memset(buff, 0, STRING);
1554 sprintf(buff,
"%.3g %.3g %.3g",
1555 ptr->c[0], ptr->c[1], ptr->c[2]);
1557 str = malloc(len+1);
1559 fwretval->_string = str;
1560 fwretval->itype =
'S';
1565 {
"getHSV", SFColor_getHSV,
'W',{0,0,0,NULL}},
1566 {
"setHSV", SFColor_setHSV, 0,{3,-1,
'T',
"DDD"}},
1567 {
"toString", SFColor_toString,
'S',{0,-1,0,NULL}},
1571int SFColor_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1575 if(index > -1 && index < 3){
1581 fwretval->_numeric = ptr->c[index];
1587 fwretval->itype =
'F';
1590int SFColor_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
1593 if(index > -1 && index < 3){
1598 ptr->c[index] = (float) fwval->_numeric;
1606void * SFColor_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
1608 struct SFColor *ptr = malloc(fwtype->size_of);
1609 if(fwtype->ConstructorArgs[0].nfixedArg == 3){
1611 ptr->c[i] = (
float) fwpars[i]._numeric;
1612 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
1614 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
1638struct FWTYPE SFColorType = {
1643 SFColor_Constructor,
1644 SFColor_ConstructorArgs,
1655struct FWTYPE MFColorType = {
1661 MFW_ConstructorArgs,
1671int SFColorRGBA_getHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1677 convertRGBtoHSV_duk((
double)ptr->c[0], (
double)ptr->c[1], (
double)ptr->c[2],&xp[0],&xp[1],&xp[2]);
1679 sf3d = malloc(
sizeof(
struct SFVec3d));
1680 memcpy(sf3d->c,xp,
sizeof(
double)*3);
1681 fwretval->_web3dval.native = sf3d;
1682 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
1683 fwretval->_web3dval.gc =
'T';
1684 fwretval->itype =
'W';
1688int SFColorRGBA_setHSV(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1693 convertHSVtoRGB_duk((
double)fwpars[0]._numeric, (
double)fwpars[1]._numeric, (
double)fwpars[2]._numeric,&xp[0],&xp[1],&xp[2]);
1694 ptr->c[0] = (float)xp[0];
1695 ptr->c[1] = (float)xp[1];
1696 ptr->c[2] = (float)xp[2];
1701int SFColorRGBA_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1703 char buff[STRING], *str;
1705 memset(buff, 0, STRING);
1706 sprintf(buff,
"%.3g %.3g %.3g %.3g",
1707 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
1709 str = malloc(len+1);
1711 fwretval->_string = str;
1712 fwretval->itype =
'S';
1717 {
"getHSV", SFColor_getHSV,
'W',{0,0,0,NULL}},
1718 {
"setHSV", SFColor_setHSV, 0,{3,-1,
'T',
"DDD"}},
1719 {
"toString", SFColorRGBA_toString,
'S',{0,-1,0,NULL}},
1723int SFColorRGBA_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1727 if(index > -1 && index < 4){
1734 fwretval->_numeric = ptr->c[index];
1740 fwretval->itype =
'F';
1743int SFColorRGBA_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
1746 if(index > -1 && index < 4){
1752 ptr->c[index] = (float) fwval->_numeric;
1760void * SFColorRGBA_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
1762 struct SFColorRGBA *ptr = malloc(fwtype->size_of);
1765 ptr->c[i] = (
float) fwpars[i]._numeric;
1766 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
1768 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
1796struct FWTYPE SFColorRGBAType = {
1797 FIELDTYPE_SFColorRGBA,
1801 SFColorRGBA_Constructor,
1802 SFColorRGBA_ConstructorArgs,
1803 SFColorRGBA_Properties,
1808 SFColorRGBA_Functions,
1811struct FWTYPE MFColorRGBAType = {
1812 FIELDTYPE_MFColorRGBA,
1817 MFW_ConstructorArgs,
1826int SFDouble_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1828 double *ptr = (
double *)fwn;
1829 fwretval->_numeric = *(ptr);
1830 fwretval->itype =
'D';
1833int SFDouble_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1836 double *ptr = (
double *)fwn;
1837 sprintf(str,
"%g",(*ptr));
1838 fwretval->_string = strdup(str);
1839 fwretval->itype =
'S';
1844 {
"valueOf", SFDouble_valueOf,
'D',{0,0,0,NULL}},
1845 {
"toString", SFDouble_toString,
'S',{0,0,0,NULL}},
1850struct FWTYPE SFTimeType = {
1865void * MFTime_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
1869 lenSF = sizeofSF(fwtype->itype);
1873 ptr->p = malloc(ptr->n * lenSF);
1875 for(i=0;i<ptr->n;i++){
1876 if(fwpars[i].itype ==
'W')
1877 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1878 else if(fwpars[i].itype ==
'D')
1879 memcpy(p,&fwpars[i]._numeric,lenSF);
1891struct FWTYPE MFTimeType = {
1897 MFTime_ConstructorArgs,
1906int SFString_valueOf(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1909 fwretval->_string = ptr->strptr;
1910 fwretval->itype =
'S';
1913int SFString_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
1916 fwretval->_string = strdup(ptr->strptr);
1917 fwretval->itype =
'S';
1922 {
"valueOf", SFString_valueOf,
'S',{0,0,0,NULL}},
1923 {
"toString", SFString_toString,
'S',{0,0,0,NULL}},
1928struct FWTYPE SFStringType = {
1943void * MFString_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
1947 lenSF = sizeofSF(fwtype->itype);
1951 ptr->p = malloc(ptr->n * lenSF);
1953 for(i=0;i<ptr->n;i++){
1955 if(fwpars[i].itype ==
'W' && fwpars[i]._web3dval.fieldType == FIELDTYPE_SFString)
1956 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
1957 else if(fwpars[i].itype ==
'S'){
1958 void *tmp = newASCIIString(fwpars[i]._string);
1959 memcpy(p,&tmp,lenSF);
1961 }
else if(fwpars[i].itype ==
'F' || fwpars[i].itype ==
'D'){
1964 sprintf(str,
"%f", fwpars[i]._numeric);
1965 tmp = newASCIIString(str);
1966 memcpy(p,&tmp,lenSF);
1967 }
else if(fwpars[i].itype ==
'I' ){
1970 sprintf(str,
"%d", fwpars[i]._integer);
1971 tmp = newASCIIString(str);
1972 memcpy(p,&tmp,lenSF);
1973 }
else if(fwpars[i].itype ==
'B' ){
1975 const char *str =
"false";
1976 if(fwpars[i]._boolean) str =
"true";
1977 tmp = newASCIIString(str);
1978 memcpy(p,&tmp,lenSF);
1994struct FWTYPE MFStringType = {
1999 MFString_Constructor,
2000 MFString_ConstructorArgs,
2027int SFVec2f_add(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2029 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2030 struct SFVec2f *res = malloc(fwtype->size_of);
2031 vecadd2f(res->c,ptr->c,rhs->c);
2032 fwretval->_web3dval.native = res;
2033 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2034 fwretval->_web3dval.gc =
'T';
2035 fwretval->itype =
'W';
2038int SFVec2f_subtract(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2040 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2041 struct SFVec2f *res = malloc(fwtype->size_of);
2042 vecdif2f(res->c,ptr->c,rhs->c);
2043 fwretval->_web3dval.native = res;
2044 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2045 fwretval->_web3dval.gc =
'T';
2046 fwretval->itype =
'W';
2049int SFVec2f_divide(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2052 double rhs = fwpars[0]._numeric;
2057 res = malloc(fwtype->size_of);
2058 vecscale2f(res->c,ptr->c,(
float)rhs);
2059 fwretval->_web3dval.native = res;
2060 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2061 fwretval->_web3dval.gc =
'T';
2062 fwretval->itype =
'W';
2065int SFVec2f_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2067 double rhs = fwpars[0]._numeric;
2068 struct SFVec2f *res = malloc(fwtype->size_of);
2069 vecscale2f(res->c,ptr->c,(
float)rhs);
2070 fwretval->_web3dval.native = res;
2071 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2072 fwretval->_web3dval.gc =
'T';
2073 fwretval->itype =
'W';
2076int SFVec2f_normalize(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2078 struct SFVec2f *res = malloc(fwtype->size_of);
2079 vecnormal2f(res->c,ptr->c);
2080 fwretval->_web3dval.native = res;
2081 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2082 fwretval->_web3dval.gc =
'T';
2083 fwretval->itype =
'W';
2087int SFVec2f_length(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2090 res = veclength2f(ptr->c);
2091 fwretval->_numeric = res;
2092 fwretval->itype =
'F';
2095int SFVec2f_dot(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2097 struct SFVec2f *rhs = fwpars[0]._web3dval.native;
2099 res = vecdot2f(ptr->c,rhs->c);
2100 fwretval->_numeric = res;
2101 fwretval->itype =
'F';
2105int SFVec2f_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2107 char buff[STRING], *str;
2109 memset(buff, 0, STRING);
2110 sprintf(buff,
"%.9g %.9g",
2111 ptr->c[0], ptr->c[1]);
2113 str = malloc(len+1);
2115 fwretval->_string = str;
2116 fwretval->itype =
'S';
2120 {
"add", SFVec2f_add,
'W',{1,-1,0,
"W"}},
2121 {
"divide", SFVec2f_divide,
'W',{1,-1,0,
"F"}},
2122 {
"dot", SFVec2f_dot,
'F',{1,-1,0,
"W"}},
2123 {
"length", SFVec2f_length,
'F',{0,-1,0,NULL}},
2124 {
"multiply", SFVec2f_multiply,
'W',{1,-1,0,
"F"}},
2125 {
"normalize", SFVec2f_normalize,
'W',{0,-1,0,NULL}},
2126 {
"subtract", SFVec2f_subtract,
'W',{1,-1,0,
"W"}},
2127 {
"toString", SFVec2f_toString,
'S',{0,-1,0,NULL}},
2131int SFVec2f_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2135 if(index > -1 && index < 2){
2140 fwretval->_numeric = ptr->c[index];
2146 fwretval->itype =
'F';
2149int SFVec2f_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
2152 if(index > -1 && index < 2){
2156 ptr->c[index] = (float) fwval->_numeric;
2164void * SFVec2f_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
2166 struct SFVec2f *ptr = malloc(fwtype->size_of);
2169 ptr->c[i] = (
float) fwpars[i]._numeric;
2170 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
2172 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
2190struct FWTYPE SFVec2fType = {
2195 SFVec2f_Constructor,
2196 SFVec2f_ConstructorArgs,
2206struct FWTYPE MFVec2fType = {
2212 MFW_ConstructorArgs,
2238int SFImage_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2240 FWType mfint32type = getFWTYPE(FIELDTYPE_MFInt32);
2241 str = mfToString(mfint32type, fwn);
2242 fwretval->_string = str;
2243 fwretval->itype =
'S';
2248 {
"toString", SFImage_toString,
'S',{0,-1,0,NULL}},
2252int SFImage_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2256 if(index > -1 && index < 4){
2262 fwretval->_integer = ptr->p[index];
2263 fwretval->itype =
'I';
2267 fwretval->_web3dval.native = ptr;
2268 fwretval->_web3dval.fieldType = FIELDTYPE_MFInt32;
2269 fwretval->_web3dval.gc = 0;
2270 fwretval->itype =
'W';
2278int SFImage_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
2282 if(index > -1 && index < 4){
2287 ptr->p[index] = fwval->_integer;
2289 if(ptr->n < (p[0] * p[1] * p[2]) ){
2291 ptr->n = (p[0] * p[1] * p[2]);
2292 ptr->p = realloc(ptr->p,ptr->n);
2297 if(fwval->itype ==
'W' && fwval->_web3dval.fieldType == FIELDTYPE_MFInt32 ){
2301 ncopy = min(ptr->n,im->n);
2303 memcpy(&ptr->p[3],&im->p[3],(ncopy-3)*
sizeof(
int));
2314void * SFImage_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
2317 int width, height, comp;
2318 struct Multi_Int32 *ptr = malloc(fwtype->size_of);
2321 width = fwpars[0]._integer;
2322 height = fwpars[1]._integer;
2323 comp = fwpars[2]._integer;
2329 ptr->n = comp * width * height;
2330 ptr->p = malloc(ptr->n *
sizeof(
int));
2331 if(fwpars[3].itype ==
'W' && fwpars[3]._web3dval.fieldType == FIELDTYPE_MFInt32){
2334 struct Multi_Int32 *im = fwpars[3]._web3dval.native;
2335 ncopy = min(ptr->n,im->n);
2336 for(i=0;i<ncopy;i++)
2337 ptr->p[i] = im->p[i];
2347 {
"width", 0,
'I', 0},
2348 {
"height", 1,
'I', 0},
2349 {
"comp", 2,
'I', 0},
2350 {
"array", 3,
'W', 0},
2360struct FWTYPE SFImageType = {
2365 SFImage_Constructor,
2366 SFImage_ConstructorArgs,
2375#define FIELDTYPE_MFImage 43
2376struct FWTYPE MFImageType = {
2382 MFW_ConstructorArgs,
2407int SFVec3d_add(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2409 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2410 struct SFVec3d *res = malloc(fwtype->size_of);
2411 vecaddd(res->c,ptr->c,rhs->c);
2412 fwretval->_web3dval.native = res;
2413 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2414 fwretval->_web3dval.gc =
'T';
2415 fwretval->itype =
'W';
2418int SFVec3d_cross(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2420 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2421 struct SFVec3d *res = malloc(fwtype->size_of);
2422 veccrossd(res->c,ptr->c,rhs->c);
2423 fwretval->_web3dval.native = res;
2424 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2425 fwretval->_web3dval.gc =
'T';
2426 fwretval->itype =
'W';
2429int SFVec3d_subtract(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2431 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2432 struct SFVec3d *res = malloc(fwtype->size_of);
2433 vecdifd(res->c,ptr->c,rhs->c);
2434 fwretval->_web3dval.native = res;
2435 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2436 fwretval->_web3dval.gc =
'T';
2437 fwretval->itype =
'W';
2440int SFVec3d_divide(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2443 double rhs = fwpars[0]._numeric;
2448 res = malloc(fwtype->size_of);
2449 vecscaled(res->c,ptr->c,rhs);
2450 fwretval->_web3dval.native = res;
2451 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2452 fwretval->_web3dval.gc =
'T';
2453 fwretval->itype =
'W';
2456int SFVec3d_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2458 double rhs = fwpars[0]._numeric;
2459 struct SFVec3d *res = malloc(fwtype->size_of);
2460 vecscaled(res->c,ptr->c,rhs);
2461 fwretval->_web3dval.native = res;
2462 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2463 fwretval->_web3dval.gc =
'T';
2464 fwretval->itype =
'W';
2467int SFVec3d_normalize(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2469 struct SFVec3d *res = malloc(fwtype->size_of);
2470 vecnormald(res->c,ptr->c);
2471 fwretval->_web3dval.native = res;
2472 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2473 fwretval->_web3dval.gc =
'T';
2474 fwretval->itype =
'W';
2478int SFVec3d_negate(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2480 struct SFVec3d *res = malloc(fwtype->size_of);
2481 vecscaled(res->c,ptr->c,-1.0);
2482 fwretval->_web3dval.native = res;
2483 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3d;
2484 fwretval->_web3dval.gc =
'T';
2485 fwretval->itype =
'W';
2488int SFVec3d_length(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2491 res = veclengthd(ptr->c);
2492 fwretval->_numeric = res;
2493 fwretval->itype =
'D';
2496int SFVec3d_dot(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2498 struct SFVec3d *rhs = fwpars[0]._web3dval.native;
2500 res = vecdotd(ptr->c,rhs->c);
2501 fwretval->_numeric = res;
2502 fwretval->itype =
'D';
2506int SFVec3d_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2508 char buff[STRING], *str;
2510 memset(buff, 0, STRING);
2511 sprintf(buff,
"%.9g %.9g %.9g",
2512 ptr->c[0], ptr->c[1], ptr->c[2]);
2514 str = malloc(len+1);
2516 fwretval->_string = str;
2517 fwretval->itype =
'S';
2522 {
"add", SFVec3d_add,
'W',{1,-1,0,
"W"}},
2523 {
"cross", SFVec3d_cross,
'W',{1,-1,0,
"W"}},
2524 {
"divide", SFVec3d_divide,
'W',{1,-1,0,
"D"}},
2525 {
"dot", SFVec3d_dot,
'D',{1,-1,0,
"W"}},
2526 {
"length", SFVec3d_length,
'D',{0,-1,0,NULL}},
2527 {
"multiply", SFVec3d_multiply,
'W',{1,-1,0,
"D"}},
2528 {
"negate", SFVec3d_negate,
'W',{0,-1,0,NULL}},
2529 {
"normalize", SFVec3d_normalize,
'W',{0,-1,0,NULL}},
2530 {
"subtract", SFVec3d_subtract,
'W',{1,-1,0,
"W"}},
2531 {
"toString", SFVec3d_toString,
'S',{0,-1,0,NULL}},
2535int SFVec3d_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2539 if(index > -1 && index < 3){
2545 fwretval->_numeric = ptr->c[index];
2551 fwretval->itype =
'D';
2554int SFVec3d_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
2557 if(index > -1 && index < 3){
2562 ptr->c[index] = fwval->_numeric;
2570void * SFVec3d_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
2572 struct SFVec3d *ptr = malloc(fwtype->size_of);
2575 ptr->c[i] = fwpars[i]._numeric;
2576 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
2578 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
2596struct FWTYPE SFVec3dType = {
2601 SFVec3d_Constructor,
2602 SFVec3d_ConstructorArgs,
2613struct FWTYPE MFVec3dType = {
2619 MFW_ConstructorArgs,
2631struct FWTYPE SFDoubleType = {
2646void * MFDouble_Constructor(
FWType fwtype,
int argc,
FWval fwpars){
2650 lenSF = sizeofSF(fwtype->itype);
2654 ptr->p = malloc(ptr->n * lenSF);
2656 for(i=0;i<ptr->n;i++){
2657 if(fwpars[i].itype ==
'W')
2658 memcpy(p,&fwpars[i]._web3dval.native,lenSF);
2659 else if(fwpars[i].itype ==
'D')
2660 memcpy(p,&fwpars[i]._numeric,lenSF);
2671struct FWTYPE MFDoubleType = {
2676 MFDouble_Constructor,
2677 MFDouble_ConstructorArgs,
2737int X3DMatrix3_setTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2741 float angle, scaleangle;
2743 struct SFVec3f *scaleOrientation;
2745 float *matrix[3], m2[9], *mat[3];
2748 struct SFVec2f *translation = fwpars[0]._web3dval.native;
2749 struct SFVec3f *rotation = NULL;
2750 if(fwpars[1].itype ==
'W' && fwpars[1]._web3dval.fieldType == FIELDTYPE_SFVec3f){
2751 rotation = fwpars[1]._web3dval.native;
2752 angle = rotation->c[0];
2754 if(fwpars[1].itype ==
'F')
2755 angle = (float)fwpars[1]._numeric;
2756 scale = fwpars[2]._web3dval.native;
2757 scaleOrientation = NULL;
2758 if(fwpars[3].itype ==
'W' && fwpars[3]._web3dval.fieldType == FIELDTYPE_SFVec3f){
2759 scaleOrientation = fwpars[3]._web3dval.native;
2760 scaleangle = scaleOrientation->c[0];
2762 if(fwpars[3].itype ==
'F')
2763 scaleangle = (float)fwpars[3]._numeric;
2764 center = fwpars[4]._web3dval.native;
2766 matrix[0] = &ptr->c[i*3];
2770 matidentity3f(matrix[0]);
2774 matidentity3f(mat[0]);
2775 veccopy2f(mat[2],center->c);
2776 vecscale2f(mat[2],mat[3],-1.0f);
2777 matmultiply3f(matrix[0],mat[0],matrix[0]);
2780 if(scaleangle != 0.0f){
2781 matidentity3f(mat[0]);
2782 mat[0][0] = mat[1][1] = cosf(-scaleangle);
2783 mat[0][1] = mat[1][0] = sinf(-scaleangle);
2784 mat[0][1] = -mat[0][1];
2785 matmultiply3f(matrix[0],mat[0],matrix[0]);
2789 matidentity4f(mat[0]);
2791 vecmult2f(mat[i],mat[i],scale->c);
2792 matmultiply3f(matrix[0],mat[0],matrix[0]);
2795 if(scaleangle != 0.0f){
2796 matidentity3f(mat[0]);
2797 mat[0][0] = mat[1][1] = cosf(scaleangle);
2798 mat[0][1] = mat[1][0] = sinf(scaleangle);
2799 mat[0][1] = -mat[0][1];
2800 matmultiply3f(matrix[0],mat[0],matrix[0]);
2804 matidentity3f(mat[0]);
2805 mat[0][0] = mat[1][1] = cosf(angle);
2806 mat[0][1] = mat[1][0] = sinf(angle);
2807 mat[0][1] = -mat[0][1];
2808 matmultiply3f(matrix[0],mat[0],matrix[0]);
2812 matidentity3f(mat[0]);
2813 veccopy2f(mat[2],center->c);
2814 matmultiply3f(matrix[0],mat[0],matrix[0]);
2818 matidentity3f(mat[0]);
2819 veccopy2f(mat[2],translation->c);
2820 matmultiply3f(matrix[0],mat[0],matrix[0]);
2826int X3DMatrix3_getTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2831 float *matrix[3], retscale[2];
2834 struct SFVec2f *translation = fwpars[0]._web3dval.native;
2835 struct SFVec3f *rotation = NULL;
2836 if(fwpars[1].itype ==
'W' && fwpars[1]._web3dval.fieldType == FIELDTYPE_SFVec3f){
2837 rotation = fwpars[1]._web3dval.native;
2838 angle = rotation->c[3];
2839 }
else if(fwpars[1].itype ==
'F'){
2840 angle = (float)fwpars[1]._numeric;
2842 scale = fwpars[2]._web3dval.native;
2844 matrix[i] = &ptr->c[i*3];
2848 retscale[i] = (
float)sqrt(vecdot3f(matrix[i],matrix[i]));
2851 veccopy2f(translation->c,matrix[2]);
2860 if(ff != 0.0f) ff = 1/ff;
2861 vecscale3f(&m2[i*3],matrix[i],ff);
2863 angle = atan2f(m2[1],m2[2]);
2866 rotation->c[3] = angle;
2871 veccopy2f(scale->c,retscale);
2874 fwretval->itype =
'F';
2875 fwretval->_numeric = angle;
2879int X3DMatrix3_inverse(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2883 matrix3x3_inverse_float(ptr->c, ret->c);
2885 fwretval->_pointer.native = ret;
2886 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2887 fwretval->_pointer.gc =
'T';
2888 fwretval->itype =
'P';
2891int X3DMatrix3_transpose(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2895 mattranspose3f(ret->c, ptr->c);
2897 fwretval->_pointer.native = ret;
2898 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2899 fwretval->_pointer.gc =
'T';
2900 fwretval->itype =
'P';
2904int X3DMatrix3_multLeft(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2909 matmultiply3f(ret->c, lhs->c , ptr->c);
2911 fwretval->_pointer.native = ret;
2912 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2913 fwretval->itype =
'P';
2914 fwretval->_pointer.gc =
'T';
2917int X3DMatrix3_multRight(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2921 fwretval->_pointer.native = ret;
2923 matmultiply3f(ret->c, ptr->c, rhs->c);
2925 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix3;
2926 fwretval->_pointer.gc =
'T';
2927 fwretval->itype =
'P';
2930int X3DMatrix3_multVecMatrix(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2932 struct SFVec2f *rhs = (
struct SFVec2f *)fwpars[0]._web3dval.native;
2935 veccopy2f(a3,rhs->c);
2937 vecmultmat3f(r3, a3, ptr->c);
2939 float wi = 1.0f/r3[2];
2940 vecscale2f(ret->c,r3,wi);
2942 veccopy2f(ret->c,r3);
2945 fwretval->_web3dval.native = ret;
2946 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2947 fwretval->_web3dval.gc =
'T';
2948 fwretval->itype =
'W';
2951int X3DMatrix3_multMatrixVec(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2953 struct SFVec2f *rhs = (
struct SFVec2f *)fwpars[0]._web3dval.native;
2956 veccopy2f(a3,rhs->c);
2958 matmultvec3f(r3, ptr->c,a3);
2960 float wi = 1.0f/r3[2];
2961 vecscale2f(ret->c,r3,wi);
2963 veccopy2f(ret->c,r3);
2966 fwretval->_web3dval.native = ret;
2967 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2f;
2968 fwretval->_web3dval.gc =
'T';
2969 fwretval->itype =
'W';
2973int X3DMatrix3_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
2977 FWType sfvec3ftype = getFWTYPE(FIELDTYPE_SFVec3f);
2981 r = sfToString(sfvec3ftype,&ptr->c[i*3]);
2982 str = realloc(str,strlen(str)+strlen(r)+2);
2983 str = strcat(str,r);
2985 fwretval->_string = str;
2986 fwretval->itype =
'S';
2991 {
"setTransform", X3DMatrix3_setTransform, 0,{5,-1,0,
"WWWWW"}},
2992 {
"getTransform", X3DMatrix3_getTransform,
'P',{1,-1,0,
"W"}},
2993 {
"inverse", X3DMatrix3_inverse,
'P',{0,-1,0,NULL}},
2994 {
"transpose", X3DMatrix3_transpose,
'P',{0,-1,0,NULL}},
2995 {
"multLeft", X3DMatrix3_multLeft,
'P',{1,-1,0,
"P"}},
2996 {
"multRight", X3DMatrix3_multRight,
'P',{1,-1,0,
"P"}},
2997 {
"multVecMatrix", X3DMatrix3_multVecMatrix,
'W',{1,-1,0,
"W"}},
2998 {
"multMatrixVec", X3DMatrix3_multMatrixVec,
'W',{1,-1,0,
"W"}},
2999 {
"toString", X3DMatrix3_toString,
'S',{0,-1,0,NULL}},
3003int X3DMatrix3_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3007 if(index > -1 && index < 9){
3009 fwretval->_numeric = ptr->c[index];
3011 fwretval->itype =
'F';
3014int X3DMatrix3_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3017 if(index > -1 && index < 9){
3018 if(fwval->itype ==
'F'){
3019 ptr->c[index] = (float) fwval->_numeric;
3026void * X3DMatrix3_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3028 struct SFVec3d *ptr = malloc(fwtype->size_of);
3030 ptr->c[i] = fwpars[i]._numeric;
3035 {9,0,
'T',
"FFFFFFFFF"},
3039struct FWTYPE X3DMatrix3Type = {
3044 X3DMatrix3_Constructor,
3045 X3DMatrix3_ConstructorArgs,
3051 X3DMatrix3_Functions,
3090int X3DMatrix4_setTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3096 struct SFVec3f *translation = fwpars[0]._web3dval.native;
3097 struct SFRotation *rotation = fwpars[1]._web3dval.native;
3098 struct SFVec3f *scale = fwpars[2]._web3dval.native;
3099 struct SFRotation *scaleOrientation = fwpars[3]._web3dval.native;
3100 struct SFVec3f *center = fwpars[4]._web3dval.native;
3102 float *matrix[4], *mat[4], m2[16];
3104 matrix[i] = &ptr->c[i*4];
3108 matidentity4f(matrix[0]);
3111 matidentity4f(mat[0]);
3112 veccopy3f(mat[3],center->c);
3113 vecscale3f(mat[3],mat[3],-1.0f);
3114 matmultiply4f(matrix[0],mat[0],matrix[0]);
3117 if(scaleOrientation){
3118 scaleOrientation->c[3] = -scaleOrientation->c[3];
3119 matidentity4f(mat[0]);
3121 axisangle_rotate3f(mat[i], mat[i], scaleOrientation->c);
3122 matmultiply4f(matrix[0],mat[0],matrix[0]);
3123 scaleOrientation->c[3] = -scaleOrientation->c[3];
3127 matidentity4f(mat[0]);
3129 vecmult3f(mat[i],mat[i],scale->c);
3130 matmultiply4f(matrix[0],mat[0],matrix[0]);
3133 if(scaleOrientation){
3134 matidentity4f(mat[0]);
3136 axisangle_rotate3f(mat[i], mat[i], scaleOrientation->c);
3137 matmultiply4f(matrix[0],mat[0],matrix[0]);
3141 matidentity4f(mat[0]);
3143 axisangle_rotate3f(mat[i], mat[i], rotation->c);
3144 matmultiply4f(matrix[0],mat[0],matrix[0]);
3149 matidentity4f(mat[0]);
3150 veccopy3f(mat[3],center->c);
3151 matmultiply4f(matrix[0],mat[0],matrix[0]);
3155 matidentity4f(mat[0]);
3156 veccopy3f(mat[3],translation->c);
3157 matmultiply4f(matrix[0],mat[0],matrix[0]);
3163int X3DMatrix4_getTransform(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3167 struct SFVec3f *translation = fwpars[0]._web3dval.native;
3168 struct SFRotation *rotation = fwpars[1]._web3dval.native;
3169 struct SFVec3f *scale = fwpars[2]._web3dval.native;
3170 float *matrix[4], retscale[3];
3176 matrix[i] = &ptr->c[i*4];
3180 retscale[i] = (
float)sqrt(vecdot4f(matrix[i],matrix[i]));
3183 veccopy3f(translation->c,matrix[3]);
3192 if(ff != 0.0f) ff = 1/ff;
3193 vecscale4f(&m2[i*4],matrix[i],ff);
3196 for(i=0;i<16;i++) matrixd[i] = (
double) m2[i];
3197 matrix_to_quaternion (&quat, matrixd);
3198 #ifdef JSVRMLCLASSESVERBOSE
3199 printf (
"quaternion %f %f %f %f\n",quat.x,quat.y,quat.z,quat.w);
3203 quaternion_to_vrmlrot(&quat, &qu[0],&qu[1],&qu[2],&qu[3]);
3207 rotation->c[i] = (
float) qu[i];
3212 veccopy3f(scale->c,retscale);
3218int X3DMatrix4_inverse(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3223 matinverse4f(ret->c,ptr->c);
3225 fwretval->_pointer.native = ret;
3226 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3227 fwretval->_pointer.gc =
'T';
3228 fwretval->itype =
'P';
3231int X3DMatrix4_transpose(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3236 mattranspose4f(ret->c, ptr->c);
3238 fwretval->_pointer.native = ret;
3239 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3240 fwretval->_pointer.gc =
'T';
3241 fwretval->itype =
'P';
3245int X3DMatrix4_multLeft(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3252 matmultiply4f(ptr->c,rhs->c,ptr->c);
3254 fwretval->_pointer.native = ret;
3255 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3256 fwretval->_pointer.gc =
'T';
3257 fwretval->itype =
'P';
3260int X3DMatrix4_multRight(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3265 fwretval->_pointer.native = ret;
3267 matmultiply4f(ptr->c,ptr->c,rhs->c);
3269 fwretval->_pointer.fieldType = AUXTYPE_X3DMatrix4;
3270 fwretval->_pointer.gc =
'T';
3271 fwretval->itype =
'P';
3274int X3DMatrix4_multVecMatrix(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3277 struct SFVec3f *rhs = (
struct SFVec3f *)fwpars[0]._web3dval.native;
3280 veccopy3f(a4,rhs->c);
3282 vecmultmat4f(r4, a4, ptr->c);
3284 float wi = 1.0f/r4[3];
3285 vecscale3f(ret->c,r4,wi);
3287 veccopy3f(ret->c,r4);
3290 fwretval->_web3dval.native = ret;
3291 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
3292 fwretval->_web3dval.gc =
'T';
3293 fwretval->itype =
'W';
3296int X3DMatrix4_multMatrixVec(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3299 struct SFVec3f *rhs = (
struct SFVec3f *)fwpars[0]._web3dval.native;
3303 veccopy3f(a4,rhs->c);
3305 matmultvec4f(r4, ptr->c, a4 );
3307 float wi = 1.0f/r4[3];
3308 vecscale3f(ret->c,r4,wi);
3310 veccopy3f(ret->c,r4);
3313 fwretval->_web3dval.native = ret;
3314 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec3f;
3315 fwretval->_web3dval.gc =
'T';
3316 fwretval->itype =
'W';
3320int X3DMatrix4_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3324 FWType sfvec4ftype = getFWTYPE(FIELDTYPE_SFVec4f);
3328 r = sfToString(sfvec4ftype,&ptr->c[i*4]);
3329 str = realloc(str,strlen(str)+strlen(r)+2);
3330 str = strcat(str,r);
3332 fwretval->_string = str;
3333 fwretval->itype =
'S';
3339 {
"setTransform", X3DMatrix4_setTransform, 0,{5,-1,0,
"WWWWW"}},
3340 {
"getTransform", X3DMatrix4_getTransform,
'P',{1,-1,0,
"W"}},
3341 {
"inverse", X3DMatrix4_inverse,
'P',{0,-1,0,NULL}},
3342 {
"transpose", X3DMatrix4_transpose,
'P',{0,-1,0,NULL}},
3343 {
"multLeft", X3DMatrix4_multLeft,
'P',{1,-1,0,
"P"}},
3344 {
"multRight", X3DMatrix4_multRight,
'P',{1,-1,0,
"P"}},
3345 {
"multVecMatrix", X3DMatrix4_multVecMatrix,
'W',{1,-1,0,
"W"}},
3346 {
"multMatrixVec", X3DMatrix4_multMatrixVec,
'W',{1,-1,0,
"W"}},
3347 {
"toString", X3DMatrix4_toString,
'S',{0,-1,0,NULL}},
3351int X3DMatrix4_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3355 if(index > -1 && index < 9){
3357 fwretval->_numeric = ptr->c[index];
3359 fwretval->itype =
'F';
3362int X3DMatrix4_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3365 if(index > -1 && index < 9){
3366 if(fwval->itype ==
'F'){
3367 ptr->c[index] = (float)fwval->_numeric;
3374void * X3DMatrix4_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3376 struct SFVec3d *ptr = malloc(fwtype->size_of);
3378 ptr->c[i] = fwpars[i]._numeric;
3383 {9,0,
'T',
"FFFFFFFFF"},
3387struct FWTYPE X3DMatrix4Type = {
3392 X3DMatrix4_Constructor,
3393 X3DMatrix4_ConstructorArgs,
3399 X3DMatrix4_Functions,
3421int SFVec2d_add(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3423 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3424 struct SFVec2d *res = malloc(fwtype->size_of);
3425 vecadd2d(res->c,ptr->c,rhs->c);
3426 fwretval->_web3dval.native = res;
3427 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3428 fwretval->_web3dval.gc =
'T';
3429 fwretval->itype =
'W';
3432int SFVec2d_subtract(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3434 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3435 struct SFVec2d *res = malloc(fwtype->size_of);
3436 vecdif2d(res->c,ptr->c,rhs->c);
3437 fwretval->_web3dval.native = res;
3438 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3439 fwretval->_web3dval.gc =
'T';
3440 fwretval->itype =
'W';
3443int SFVec2d_divide(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3446 double rhs = fwpars[0]._numeric;
3451 res = malloc(fwtype->size_of);
3452 vecscale2d(res->c,ptr->c,rhs);
3453 fwretval->_web3dval.native = res;
3454 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3455 fwretval->_web3dval.gc =
'T';
3456 fwretval->itype =
'W';
3459int SFVec2d_multiply(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3461 double rhs = fwpars[0]._numeric;
3462 struct SFVec2d *res = malloc(fwtype->size_of);
3463 vecscale2d(res->c,ptr->c,rhs);
3464 fwretval->_web3dval.native = res;
3465 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3466 fwretval->_web3dval.gc =
'T';
3467 fwretval->itype =
'W';
3470int SFVec2d_normalize(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3472 struct SFVec2d *res = malloc(fwtype->size_of);
3473 vecnormal2d(res->c,ptr->c);
3474 fwretval->_web3dval.native = res;
3475 fwretval->_web3dval.fieldType = FIELDTYPE_SFVec2d;
3476 fwretval->_web3dval.gc =
'T';
3477 fwretval->itype =
'W';
3481int SFVec2d_length(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3484 res = veclength2d(ptr->c);
3485 fwretval->_numeric = res;
3486 fwretval->itype =
'D';
3489int SFVec2d_dot(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3491 struct SFVec2d *rhs = fwpars[0]._web3dval.native;
3493 res = vecdot2d(ptr->c,rhs->c);
3494 fwretval->_numeric = res;
3495 fwretval->itype =
'D';
3498int SFVec2d_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3500 char buff[STRING], *str;
3502 memset(buff, 0, STRING);
3503 sprintf(buff,
"%.9g %.9g",
3504 ptr->c[0], ptr->c[1]);
3506 str = malloc(len+1);
3508 fwretval->_string = str;
3509 fwretval->itype =
'S';
3513 {
"add", SFVec2d_add,
'W',{1,-1,0,
"W"}},
3514 {
"divide", SFVec2d_divide,
'W',{1,-1,0,
"D"}},
3515 {
"dot", SFVec2d_dot,
'D',{1,-1,0,
"W"}},
3516 {
"length", SFVec2d_length,
'D',{0,-1,0,NULL}},
3517 {
"multiply", SFVec2d_multiply,
'W',{1,-1,0,
"D"}},
3518 {
"normalize", SFVec2d_normalize,
'W',{0,-1,0,NULL}},
3519 {
"subtract", SFVec2d_subtract,
'W',{1,-1,0,
"W"}},
3520 {
"toString", SFVec2d_toString,
'S',{0,-1,0,NULL}},
3524int SFVec2d_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3528 if(index > -1 && index < 2){
3533 fwretval->_numeric = ptr->c[index];
3539 fwretval->itype =
'D';
3542int SFVec2d_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3545 if(index > -1 && index < 2){
3549 ptr->c[index] = fwval->_numeric;
3557void * SFVec2d_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3559 struct SFVec2d *ptr = malloc(fwtype->size_of);
3560 memset(ptr,0,fwtype->size_of);
3563 ptr->c[i] = fwpars[i]._numeric;
3564 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
3566 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
3584struct FWTYPE SFVec2dType = {
3589 SFVec2d_Constructor,
3590 SFVec2d_ConstructorArgs,
3600struct FWTYPE MFVec2dType = {
3606 MFW_ConstructorArgs,
3615int SFVec4f_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3617 char buff[STRING], *str;
3619 memset(buff, 0, STRING);
3620 sprintf(buff,
"%.9g %.9g %.9g %.9g",
3621 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
3623 str = malloc(len+1);
3625 fwretval->_string = str;
3626 fwretval->itype =
'S';
3631 {
"toString", SFVec4f_toString,
'S',{0,-1,0,NULL}},
3635int SFVec4f_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3639 if(index > -1 && index < 4){
3646 fwretval->_numeric = ptr->c[index];
3652 fwretval->itype =
'F';
3655int SFVec4f_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3658 if(index > -1 && index < 4){
3664 ptr->c[index] = (float)fwval->_numeric;
3672void * SFVec4f_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3674 struct SFVec4f *ptr = malloc(fwtype->size_of);
3677 ptr->c[i] = (
float)fwpars[i]._numeric;
3678 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
3680 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
3701struct FWTYPE SFVec4fType = {
3706 SFVec4f_Constructor,
3707 SFVec4f_ConstructorArgs,
3717struct FWTYPE MFVec4fType = {
3723 MFW_ConstructorArgs,
3732int SFVec4d_toString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
3734 char buff[STRING], *str;
3736 memset(buff, 0, STRING);
3737 sprintf(buff,
"%.9g %.9g %.9g %.9g",
3738 ptr->c[0], ptr->c[1], ptr->c[2], ptr->c[3]);
3740 str = malloc(len+1);
3742 fwretval->_string = str;
3743 fwretval->itype =
'S';
3747 {
"toString", SFVec4d_toString,
'S',{0,-1,0,NULL}},
3751int SFVec4d_Getter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
3755 if(index > -1 && index < 4){
3762 fwretval->_numeric = ptr->c[index];
3768 fwretval->itype =
'D';
3771int SFVec4d_Setter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
3774 if(index > -1 && index < 4){
3780 ptr->c[index] = fwval->_numeric; ;
3788void * SFVec4d_Constructor(
FWType fwtype,
int ic,
FWval fwpars){
3790 struct SFVec3d *ptr = malloc(fwtype->size_of);
3791 memset(ptr,0,fwtype->size_of);
3794 ptr->c[i] = fwpars[i]._numeric;
3795 }
else if(fwpars[0].itype ==
'W' && (fwtype->itype == fwpars[0]._web3dval.fieldType)){
3797 shallow_copy_field(fwtype->itype,fwpars[0]._web3dval.native,(
void*)ptr);
3816struct FWTYPE SFVec4dType = {
3821 SFVec4d_Constructor,
3822 SFVec4d_ConstructorArgs,
3832struct FWTYPE MFVec4dType = {
3838 MFW_ConstructorArgs,
3847void initVRMLFields(
FWType* typeArray,
int *n){
3848 typeArray[*n] = &SFFloatType; (*n)++;
3849 typeArray[*n] = &MFFloatType; (*n)++;
3850 typeArray[*n] = &SFRotationType; (*n)++;
3851 typeArray[*n] = &MFRotationType; (*n)++;
3852 typeArray[*n] = &SFVec3fType; (*n)++;
3853 typeArray[*n] = &MFVec3fType; (*n)++;
3854 typeArray[*n] = &SFBoolType; (*n)++;
3855 typeArray[*n] = &MFBoolType; (*n)++;
3856 typeArray[*n] = &SFInt32Type; (*n)++;
3857 typeArray[*n] = &MFInt32Type; (*n)++;
3858 typeArray[*n] = &SFNodeType; (*n)++;
3859 typeArray[*n] = &MFNodeType; (*n)++;
3860 typeArray[*n] = &SFColorType; (*n)++;
3861 typeArray[*n] = &MFColorType; (*n)++;
3862 typeArray[*n] = &SFColorRGBAType; (*n)++;
3863 typeArray[*n] = &MFColorRGBAType; (*n)++;
3864 typeArray[*n] = &SFTimeType; (*n)++;
3865 typeArray[*n] = &MFTimeType; (*n)++;
3866 typeArray[*n] = &SFStringType; (*n)++;
3867 typeArray[*n] = &MFStringType; (*n)++;
3868 typeArray[*n] = &SFVec2fType; (*n)++;
3869 typeArray[*n] = &MFVec2fType; (*n)++;
3870 typeArray[*n] = &SFImageType; (*n)++;
3873 typeArray[*n] = &SFVec3dType; (*n)++;
3874 typeArray[*n] = &MFVec3dType; (*n)++;
3875 typeArray[*n] = &SFDoubleType; (*n)++;
3876 typeArray[*n] = &MFDoubleType; (*n)++;
3885 typeArray[*n] = &X3DMatrix3Type; (*n)++;
3886 typeArray[*n] = &X3DMatrix4Type; (*n)++;
3887 typeArray[*n] = &SFVec2dType; (*n)++;
3888 typeArray[*n] = &MFVec2dType; (*n)++;
3889 typeArray[*n] = &SFVec4fType; (*n)++;
3890 typeArray[*n] = &MFVec4fType; (*n)++;
3891 typeArray[*n] = &SFVec4dType; (*n)++;
3892 typeArray[*n] = &MFVec4dType; (*n)++;