Changeset 343


Ignore:
Timestamp:
04/04/15 20:40:02 (9 years ago)
Author:
Maciej Komosinski
Message:

Code formatting

Location:
cpp/frams
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/autoname.cpp

    r286 r343  
    99SString AutoName::makeName(Model &model)
    1010{
    11 SString t;
    12 t=firstName(model);
    13 t+=' ';
    14 t+=lastName(model);
    15 return t;
     11        SString t;
     12        t = firstName(model);
     13        t += ' ';
     14        t += lastName(model);
     15        return t;
    1616}
    1717
    1818///////////////////////////
    1919
    20 static char* cat_syl(char* str,unsigned int x)
     20static char* cat_syl(char* str, unsigned int x)
    2121{
    22 static char sp[]="bcdfghklmnprstwz",sa[]="aeiouy";
    23 x%=6*16;
    24 str[0]=sa[x%6];
    25 if (x>5)
    26         {str[1]=sp[x/6]; str[2]=0; return str+2;}
    27 else
    28         {str[1]=0; return str+1;}
     22        static char sp[] = "bcdfghklmnprstwz", sa[] = "aeiouy";
     23        x %= 6 * 16;
     24        str[0] = sa[x % 6];
     25        if (x > 5)
     26        {
     27                str[1] = sp[x / 6]; str[2] = 0; return str + 2;
     28        }
     29        else
     30        {
     31                str[1] = 0; return str + 1;
     32        }
    2933}
    3034
    3135SString AutoName::firstName(Model& model)
    3236{
    33 char buf[8];
    34 unsigned int s1=0,s2=0,s3=0;
    35 const char *x=model.getGeno().getGene();
    36 for (;*x;x++) { s1+=*x; s2=s2**x+*x; s3=(s3^*x)+*x; }
    37 char* t=buf;
    38 t=cat_syl(t,s1);
    39 t=cat_syl(t,s2);
    40 t=cat_syl(t,s3);
    41 buf[0]=(char)toupper(buf[0]);
    42 return SString(buf);
     37        char buf[8];
     38        unsigned int s1 = 0, s2 = 0, s3 = 0;
     39        SString g = model.getGeno().getGene();
     40        const char *x = g;
     41        for (; *x; x++) { s1 += *x; s2 = s2**x + *x; s3 = (s3^*x) + *x; }
     42        char* t = buf;
     43        t = cat_syl(t, s1);
     44        t = cat_syl(t, s2);
     45        t = cat_syl(t, s3);
     46        buf[0] = (char)toupper(buf[0]);
     47        return SString(buf);
    4348}
    4449
    45 static void przeplatanka(char *out,char *in1,char *in2)
     50static void przeplatanka(char *out, char *in1, char *in2)
    4651{
    47 int d1=strlen(in1),d2=strlen(in2);
    48 int p1=0,p2=0;
    49 int pp=d1+d2;
    50 int i,p;
    51 if (d2<d1)
     52        int d1 = strlen(in1), d2 = strlen(in2);
     53        int p1 = 0, p2 = 0;
     54        int pp = d1 + d2;
     55        int i, p;
     56        if (d2 < d1)
    5257        {
    53         int t=d2; d2=d1; d1=t;
    54         char *c=in1; in1=in2; in2=c;
     58                int t = d2; d2 = d1; d1 = t;
     59                char *c = in1; in1 = in2; in2 = c;
    5560        }
    56 if (pp)
    57 for (i=0;i<=pp;i++)
    58         {
    59         p=(i*d1)/pp-1; for (;p1<=p;p1++) *(out++)=*(in1++);
    60         p=(i*d2)/pp-1; for (;p2<=p;p2++) *(out++)=*(in2++);
    61         }
    62 *out=0;
     61        if (pp)
     62                for (i = 0; i <= pp; i++)
     63                {
     64                p = (i*d1) / pp - 1; for (; p1 <= p; p1++) *(out++) = *(in1++);
     65                p = (i*d2) / pp - 1; for (; p2 <= p; p2++) *(out++) = *(in2++);
     66                }
     67        *out = 0;
    6368}
    6469
    6570SString AutoName::lastName(Model& model)
    6671{
    67 char Sam[]="yeaou";
    68 char Sp[]="shtkdgmr";
     72        char Sam[] = "yeaou";
     73        char Sp[] = "shtkdgmr";
    6974
    7075#define NAME_MAXLENBODY 5
     
    7580#define NAME_BRAININP 1.0
    7681
    77 char naz[NAME_MAXLENBODY+NAME_MAXLENBRAIN+1];
    78 int poz,nextpoz,i;
     82        char naz[NAME_MAXLENBODY + NAME_MAXLENBRAIN + 1];
     83        int poz, nextpoz, i;
    7984
    80 double w;
    81 int cialo=-1;
    82 int mozg=-1;
     85        double w;
     86        int cialo = -1;
     87        int mozg = -1;
    8388
    84 char tmpc[NAME_MAXLENBODY+1],tmpm[NAME_MAXLENBRAIN+1];
     89        char tmpc[NAME_MAXLENBODY + 1], tmpm[NAME_MAXLENBRAIN + 1];
    8590
    86 if (model.getPartCount()>0)
    87 {
    88 cialo=min((int)(sqrt(double(model.getPartCount())-1)*NAME_BODYLEN),NAME_MAXLENBODY-1);
    89 poz=0;
    90 for (i=0;i<=cialo;i++) // budowanie "opisu" ciala
     91        if (model.getPartCount() > 0)
    9192        {
    92         nextpoz=((model.getPartCount())*(i+1))/(cialo+1)-1;
    93         w=1.0;
    94         for (;poz<=nextpoz;poz++) w=max(w,model.getPart(poz)->mass);
    95         tmpc[i]=Sp[min(int((w-1.0)*NAME_BODYMASS),int(sizeof(Sp))-2)];
     93                cialo = min((int)(sqrt(double(model.getPartCount()) - 1)*NAME_BODYLEN), NAME_MAXLENBODY - 1);
     94                poz = 0;
     95                for (i = 0; i <= cialo; i++) // budowanie "opisu" ciala
     96                {
     97                        nextpoz = ((model.getPartCount())*(i + 1)) / (cialo + 1) - 1;
     98                        w = 1.0;
     99                        for (; poz <= nextpoz; poz++) w = max(w, model.getPart(poz)->mass);
     100                        tmpc[i] = Sp[min(int((w - 1.0)*NAME_BODYMASS), int(sizeof(Sp)) - 2)];
     101                }
     102                tmpc[i] = 0;
    96103        }
    97 tmpc[i]=0;
    98 }
    99 else tmpc[0]=0;
     104        else tmpc[0] = 0;
    100105
    101 int wint;
     106        int wint;
    102107
    103 if (model.getNeuroCount()>0)
    104 {
    105 mozg=min((int)(sqrt((double)model.getNeuroCount())*NAME_BRAINLEN),NAME_MAXLENBRAIN-1);
    106 poz=0;
    107 for (i=0;i<=mozg;i++) // budowanie "opisu" mozgu
     108        if (model.getNeuroCount() > 0)
    108109        {
    109         nextpoz=(model.getNeuroCount()*(i+1))/(mozg+1)-1;
    110         wint=0;
    111         for (;poz<=nextpoz;poz++) wint=max(wint,model.getNeuro(poz)->getInputCount());
    112         tmpm[i]=Sam[min(int(wint*NAME_BRAININP),int(sizeof(Sam))-2)];
     110                mozg = min((int)(sqrt((double)model.getNeuroCount())*NAME_BRAINLEN), NAME_MAXLENBRAIN - 1);
     111                poz = 0;
     112                for (i = 0; i <= mozg; i++) // budowanie "opisu" mozgu
     113                {
     114                        nextpoz = (model.getNeuroCount()*(i + 1)) / (mozg + 1) - 1;
     115                        wint = 0;
     116                        for (; poz <= nextpoz; poz++) wint = max(wint, model.getNeuro(poz)->getInputCount());
     117                        tmpm[i] = Sam[min(int(wint*NAME_BRAININP), int(sizeof(Sam)) - 2)];
     118                }
     119                tmpm[i] = 0;
    113120        }
    114 tmpm[i]=0;
    115 }
    116 else tmpm[0]=0;
     121        else tmpm[0] = 0;
    117122
    118 if ((mozg+1) < ((cialo+2)/2))
     123        if ((mozg + 1) < ((cialo + 2) / 2))
    119124        {
    120         for (i=mozg+1;i<=cialo/2;i++) tmpm[i]='i';
    121         tmpm[i]=0;
     125                for (i = mozg + 1; i <= cialo / 2; i++) tmpm[i] = 'i';
     126                tmpm[i] = 0;
    122127        }
    123128
    124 przeplatanka(naz,tmpc,tmpm);
     129        przeplatanka(naz, tmpc, tmpm);
    125130
    126 naz[0]=(char)toupper(naz[0]);
    127 return SString(naz);
     131        naz[0] = (char)toupper(naz[0]);
     132        return SString(naz);
    128133}
    129 
    130 
    131 
  • cpp/frams/model/autoname.h

    r286 r343  
    1111class AutoName
    1212{
    13 static SString firstName(Model&);
    14 static SString lastName(Model&);
     13        static SString firstName(Model&);
     14        static SString lastName(Model&);
    1515public:
    16 static SString makeName(Model&);
     16        static SString makeName(Model&);
    1717};
    1818
  • cpp/frams/param/param.cpp

    r342 r343  
    604604                        after = e.deserialize(v + strlen(SERIALIZATION_PREFIX));
    605605                        if ((after == NULL) || (*after))
    606                                 {
     606                        {
    607607                                FMprintf("ParamInterface", "set", FMLV_WARN, "serialization format mismatch in %s.%s", (getName() ? getName() : "<Unknown>"), id(i));
    608608                                e.setEmpty();
    609                                 }
     609                        }
    610610                }
    611611                else if ((after = e.parseNumber(v)) && (*after == 0)) //consumed the whole string
  • cpp/frams/util/advlist.cpp

    r286 r343  
    1010void AdvList::remove(int i)
    1111{
    12 l_del.action(i);
    13 SList::remove(i);
    14 l_postdel.action(i);
     12        l_del.action(i);
     13        SList::remove(i);
     14        l_postdel.action(i);
    1515}
    1616
    1717void AdvList::clear()
    1818{
    19 int i;
    20 for (i=size()-1;i>=0;i--) remove(i);
    21 resize(0);
    22 used=0;
     19        int i;
     20        for (i = size() - 1; i >= 0; i--) remove(i);
     21        resize(0);
     22        used = 0;
    2323}
    2424
    2525void AdvList::operator-=(void* e)
    2626{
    27 int i=find(e);
    28 if (i>=0) remove(i);
     27        int i = find(e);
     28        if (i >= 0) remove(i);
    2929}
    3030
    3131int AdvList::operator+=(void* e)
    3232{
    33 int p=size();
    34 SList::operator+=(e);
    35 l_add.action(p);
    36 return p;
     33        int p = size();
     34        SList::operator+=(e);
     35        l_add.action(p);
     36        return p;
    3737}
    3838
    3939void AdvList::mod(int x)
    4040{
    41 if (x<-1) x=-1;
    42 l_mod.action(x);
     41        if (x < -1) x = -1;
     42        l_mod.action(x);
    4343}
  • cpp/frams/util/advlist.h

    r286 r343  
    1919/// sorting functions moved to SortView class
    2020
    21 class AdvList: public SList
     21class AdvList : public SList
    2222{
    2323public:
    24 Callback l_add, l_del, l_mod, l_postdel;
    25 void remove(int);
    26 virtual void mod(int=-1); ///< call this when you change one or more elements in list (-1 means all elements)
    27 void clear();
    28 AdvList() {}
    29 ~AdvList() {clear();}
    30 int operator+=(void*);
    31 void operator-=(void*);
    32 void operator-=(int i) {remove(i);}
     24        Callback l_add, l_del, l_mod, l_postdel;
     25        void remove(int);
     26        virtual void mod(int = -1); ///< call this when you change one or more elements in list (-1 means all elements)
     27        void clear();
     28        AdvList() {}
     29        ~AdvList() { clear(); }
     30        int operator+=(void*);
     31        void operator-=(void*);
     32        void operator-=(int i) { remove(i); }
    3333};
    3434
  • cpp/frams/vm/classes/3dobject.cpp

    r286 r343  
    1111{
    1212#define FIELDSTRUCT Pt3D_Ext
    13 static ParamEntry paramtab[]=
    14 {
    15 {"XYZ",1,18,"XYZ","3D vector"},
    16 
    17 {"x",0,PARAM_NOSTATIC,"x","f",FIELD(p.x),},
    18 {"y",0,PARAM_NOSTATIC,"y","f",FIELD(p.y),},
    19 {"z",0,PARAM_NOSTATIC,"z","f",FIELD(p.z),},
    20 {"new",0,0,"create new XYZ object","p oXYZ(f x,f y,f z)",PROCEDURE(p_new),"3D vectors objects can be also created using the (x,y,z) notation, i.e. var v=(1,2,3) is the same as var v=XYZ.new(1,2,3);",},
    21 {"newFromVector",0,0,"create new XYZ object","p oXYZ(oVector)",PROCEDURE(p_newFromVector),"used for deserialization"},
    22 {"clone",0,PARAM_NOSTATIC,"create new XYZ object copying the coordinates","p oXYZ()",PROCEDURE(p_clone),"Note: copying object references does not create new objects. Use clone() if a new object is needed.\n\nExample:\nvar o1=(1,2,3), o2=o1, o3=o1.clone();\no1.y=9999;\n//o2 is now (1,9999,3) but o3 is still (1,2,3)",},
    23 {"set",0,PARAM_NOSTATIC,"set (copy) coordinates from another XYZ object","p(oXYZ)",PROCEDURE(p_set),},
    24 {"set3",0,PARAM_NOSTATIC,"set individual 3 coordinates","p(f x,f y,f z)",PROCEDURE(p_set3),},
    25 {"add",0,PARAM_NOSTATIC,"add","p(oXYZ)",PROCEDURE(p_addvec),"Note: it does not return a new object, just modifies the existing one"},
    26 {"sub",0,PARAM_NOSTATIC,"subtract","p(oXYZ)",PROCEDURE(p_subvec),"Note: it does not return a new object, just modifies the existing one"},
    27 {"scale",0,PARAM_NOSTATIC,"multiply by scalar","p(f)",PROCEDURE(p_scale),},
    28 {"length",0,PARAM_READONLY | PARAM_NOSTATIC,"length","f",GETONLY(length),},
    29 {"normalize",0,PARAM_NOSTATIC,"normalize","p()",PROCEDURE(p_normalize),"scales the vector length to 1.0"},
    30 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"textual form","s",GETONLY(toString),},
    31 {"toVector",0,PARAM_READONLY | PARAM_NOSTATIC,"vector of [x,y,z]","oVector",GETONLY(toVector),},
    32 {"rotate",0,PARAM_NOSTATIC,"rotate using Orient object","p(oOrient)",PROCEDURE(p_rotate),},
    33 {"revRotate",0,PARAM_NOSTATIC,"reverse rotate using Orient object","p(oOrient)",PROCEDURE(p_revrotate),},
    34 {"get",0,PARAM_NOSTATIC,"get one of coordinates","p f(d index)",PROCEDURE(p_get),"this function makes the XYZ objects \"indexable\" (so you can use [] for accessing subsequent fields, like in Vector)",},
    35 {0,0,0,},
    36 };
     13        static ParamEntry paramtab[] =
     14        {
     15                { "XYZ", 1, 18, "XYZ", "3D vector" },
     16
     17                { "x", 0, PARAM_NOSTATIC, "x", "f", FIELD(p.x), },
     18                { "y", 0, PARAM_NOSTATIC, "y", "f", FIELD(p.y), },
     19                { "z", 0, PARAM_NOSTATIC, "z", "f", FIELD(p.z), },
     20                { "new", 0, 0, "create new XYZ object", "p oXYZ(f x,f y,f z)", PROCEDURE(p_new), "3D vectors objects can be also created using the (x,y,z) notation, i.e. var v=(1,2,3) is the same as var v=XYZ.new(1,2,3);", },
     21                { "newFromVector", 0, 0, "create new XYZ object", "p oXYZ(oVector)", PROCEDURE(p_newFromVector), "used for deserialization" },
     22                { "clone", 0, PARAM_NOSTATIC, "create new XYZ object copying the coordinates", "p oXYZ()", PROCEDURE(p_clone), "Note: copying object references does not create new objects. Use clone() if a new object is needed.\n\nExample:\nvar o1=(1,2,3), o2=o1, o3=o1.clone();\no1.y=9999;\n//o2 is now (1,9999,3) but o3 is still (1,2,3)", },
     23                { "set", 0, PARAM_NOSTATIC, "set (copy) coordinates from another XYZ object", "p(oXYZ)", PROCEDURE(p_set), },
     24                { "set3", 0, PARAM_NOSTATIC, "set individual 3 coordinates", "p(f x,f y,f z)", PROCEDURE(p_set3), },
     25                { "add", 0, PARAM_NOSTATIC, "add", "p(oXYZ)", PROCEDURE(p_addvec), "Note: it does not return a new object, just modifies the existing one" },
     26                { "sub", 0, PARAM_NOSTATIC, "subtract", "p(oXYZ)", PROCEDURE(p_subvec), "Note: it does not return a new object, just modifies the existing one" },
     27                { "scale", 0, PARAM_NOSTATIC, "multiply by scalar", "p(f)", PROCEDURE(p_scale), },
     28                { "length", 0, PARAM_READONLY | PARAM_NOSTATIC, "length", "f", GETONLY(length), },
     29                { "normalize", 0, PARAM_NOSTATIC, "normalize", "p()", PROCEDURE(p_normalize), "scales the vector length to 1.0" },
     30                { "toString", 0, PARAM_READONLY | PARAM_NOSTATIC, "textual form", "s", GETONLY(toString), },
     31                { "toVector", 0, PARAM_READONLY | PARAM_NOSTATIC, "vector of [x,y,z]", "oVector", GETONLY(toVector), },
     32                { "rotate", 0, PARAM_NOSTATIC, "rotate using Orient object", "p(oOrient)", PROCEDURE(p_rotate), },
     33                { "revRotate", 0, PARAM_NOSTATIC, "reverse rotate using Orient object", "p(oOrient)", PROCEDURE(p_revrotate), },
     34                { "get", 0, PARAM_NOSTATIC, "get one of coordinates", "p f(d index)", PROCEDURE(p_get), "this function makes the XYZ objects \"indexable\" (so you can use [] for accessing subsequent fields, like in Vector)", },
     35                { 0, 0, 0, },
     36        };
    3737#undef FIELDSTRUCT
    38 return paramtab;
    39 }
    40 
    41 void Pt3D_Ext::p_new(ExtValue *args,ExtValue *ret)
    42 {
    43 *ret=makeDynamicObject(new Pt3D_Ext(args[2].getDouble(),args[1].getDouble(),args[0].getDouble()));
    44 }
    45 
    46 static double doubleFromVec(VectorObject *vec,int i)
    47 {
    48 if (i>=vec->data.size()) return 0;
    49 ExtValue *v=(ExtValue*)vec->data.get(i);
    50 if (v)
    51         return v->getDouble();
    52 return 0;
    53 }
    54 
    55 static Pt3D pt3DFromVec(VectorObject* v,int offset=0)
    56 {
    57 return Pt3D(doubleFromVec(v,offset),doubleFromVec(v,offset+1),doubleFromVec(v,offset+2));
    58 }
    59 
    60 void Pt3D_Ext::p_newFromVector(ExtValue *args,ExtValue *ret)
    61 {
    62 VectorObject *vec=VectorObject::fromObject(args->getObject());
    63 if (vec)
    64         *ret=makeDynamicObject(new Pt3D_Ext(pt3DFromVec(vec)));
    65 else
    66         ret->setEmpty();
    67 }
    68 
    69 void Pt3D_Ext::p_clone(ExtValue *args,ExtValue *ret)
    70 {
    71 *ret=makeDynamicObject(new Pt3D_Ext(p.x,p.y,p.z));
    72 }
    73 
    74 void Pt3D_Ext::p_set3(ExtValue *args,ExtValue *ret)
    75 {
    76 p.x=args[2].getDouble();
    77 p.y=args[1].getDouble();
    78 p.z=args[0].getDouble();
    79 ret->setEmpty();
    80 }
    81 
    82 void Pt3D_Ext::p_set(ExtValue *args,ExtValue *ret)
    83 {
    84 Pt3D_Ext *other=fromObject(args[0]);
    85 if (other)
    86         p=other->p;
    87 ret->setEmpty();
     38        return paramtab;
     39}
     40
     41void Pt3D_Ext::p_new(ExtValue *args, ExtValue *ret)
     42{
     43        *ret = makeDynamicObject(new Pt3D_Ext(args[2].getDouble(), args[1].getDouble(), args[0].getDouble()));
     44}
     45
     46static double doubleFromVec(VectorObject *vec, int i)
     47{
     48        if (i >= vec->data.size()) return 0;
     49        ExtValue *v = (ExtValue*)vec->data.get(i);
     50        if (v)
     51                return v->getDouble();
     52        return 0;
     53}
     54
     55static Pt3D pt3DFromVec(VectorObject* v, int offset = 0)
     56{
     57        return Pt3D(doubleFromVec(v, offset), doubleFromVec(v, offset + 1), doubleFromVec(v, offset + 2));
     58}
     59
     60void Pt3D_Ext::p_newFromVector(ExtValue *args, ExtValue *ret)
     61{
     62        VectorObject *vec = VectorObject::fromObject(args->getObject());
     63        if (vec)
     64                *ret = makeDynamicObject(new Pt3D_Ext(pt3DFromVec(vec)));
     65        else
     66                ret->setEmpty();
     67}
     68
     69void Pt3D_Ext::p_clone(ExtValue *args, ExtValue *ret)
     70{
     71        *ret = makeDynamicObject(new Pt3D_Ext(p.x, p.y, p.z));
     72}
     73
     74void Pt3D_Ext::p_set3(ExtValue *args, ExtValue *ret)
     75{
     76        p.x = args[2].getDouble();
     77        p.y = args[1].getDouble();
     78        p.z = args[0].getDouble();
     79        ret->setEmpty();
     80}
     81
     82void Pt3D_Ext::p_set(ExtValue *args, ExtValue *ret)
     83{
     84        Pt3D_Ext *other = fromObject(args[0]);
     85        if (other)
     86                p = other->p;
     87        ret->setEmpty();
    8888}
    8989
    9090void Pt3D_Ext::get_length(ExtValue *ret)
    9191{
    92 ret->setDouble(p.length());
     92        ret->setDouble(p.length());
    9393}
    9494
    9595void Pt3D_Ext::get_toString(ExtValue *ret)
    9696{
    97 SString s="(";
    98 ExtValue v;
    99 v.setDouble(p.x); s+=v.getString();
    100 s+=",";
    101 v.setDouble(p.y); s+=v.getString();
    102 s+=",";
    103 v.setDouble(p.z); s+=v.getString();
    104 s+=")";
    105 ret->setString(s);
    106 }
    107 
    108 static void add3Coords(VectorObject* vec,const Pt3D& p)
    109 {
    110 vec->data+=new ExtValue(p.x);
    111 vec->data+=new ExtValue(p.y);
    112 vec->data+=new ExtValue(p.z);
     97        SString s = "(";
     98        ExtValue v;
     99        v.setDouble(p.x); s += v.getString();
     100        s += ",";
     101        v.setDouble(p.y); s += v.getString();
     102        s += ",";
     103        v.setDouble(p.z); s += v.getString();
     104        s += ")";
     105        ret->setString(s);
     106}
     107
     108static void add3Coords(VectorObject* vec, const Pt3D& p)
     109{
     110        vec->data += new ExtValue(p.x);
     111        vec->data += new ExtValue(p.y);
     112        vec->data += new ExtValue(p.z);
    113113}
    114114
    115115void Pt3D_Ext::get_toVector(ExtValue *ret)
    116116{
    117 VectorObject *vec=new VectorObject;
    118 add3Coords(vec,p);
    119 ret->setObject(ExtObject(&VectorObject::par,vec));
    120 }
    121 
    122 void Pt3D_Ext::p_addvec(ExtValue *args,ExtValue *ret)
    123 {
    124 Pt3D_Ext *other=fromObject(args[0]);
    125 if (other)
    126         p+=other->p;
    127 ret->setEmpty();
    128 }
    129 
    130 void Pt3D_Ext::p_subvec(ExtValue *args,ExtValue *ret)
    131 {
    132 Pt3D_Ext *other=fromObject(args[0]);
    133 if (other)
    134         p-=other->p;
    135 ret->setEmpty();
    136 }
    137 
    138 void Pt3D_Ext::p_scale(ExtValue *args,ExtValue *ret)
    139 {
    140 double d=args[0].getDouble();
    141 p.x*=d; p.y*=d; p.z*=d;
    142 ret->setEmpty();
    143 }
    144 
    145 void Pt3D_Ext::p_normalize(ExtValue *args,ExtValue *ret)
    146 {
    147 p.normalize();
    148 ret->setEmpty();
    149 }
    150 
    151 void Pt3D_Ext::p_rotate(ExtValue *args,ExtValue *ret)
    152 {
    153 Orient_Ext *o=Orient_Ext::fromObject(args[0]);
    154 if (o)
    155         {
    156         Pt3D tmp=p;
    157         o->o.transform(p,tmp);
    158         }
    159 ret->setEmpty();
    160 }
    161 
    162 void Pt3D_Ext::p_revrotate(ExtValue *args,ExtValue *ret)
    163 {
    164 Orient_Ext *o=Orient_Ext::fromObject(args[0]);
    165 if (o)
    166         {
    167         Pt3D tmp=p;
    168         o->o.revTransform(p,tmp);
    169         }
    170 ret->setEmpty();
    171 }
    172 
    173 void Pt3D_Ext::p_get(ExtValue *args,ExtValue *ret)
    174 {
    175 int index=args->getInt();
    176 if ((index<0)||(index>2))
    177         ret->setEmpty();
    178 else
    179         ret->setDouble((&p.x)[index]);
     117        VectorObject *vec = new VectorObject;
     118        add3Coords(vec, p);
     119        ret->setObject(ExtObject(&VectorObject::par, vec));
     120}
     121
     122void Pt3D_Ext::p_addvec(ExtValue *args, ExtValue *ret)
     123{
     124        Pt3D_Ext *other = fromObject(args[0]);
     125        if (other)
     126                p += other->p;
     127        ret->setEmpty();
     128}
     129
     130void Pt3D_Ext::p_subvec(ExtValue *args, ExtValue *ret)
     131{
     132        Pt3D_Ext *other = fromObject(args[0]);
     133        if (other)
     134                p -= other->p;
     135        ret->setEmpty();
     136}
     137
     138void Pt3D_Ext::p_scale(ExtValue *args, ExtValue *ret)
     139{
     140        double d = args[0].getDouble();
     141        p.x *= d; p.y *= d; p.z *= d;
     142        ret->setEmpty();
     143}
     144
     145void Pt3D_Ext::p_normalize(ExtValue *args, ExtValue *ret)
     146{
     147        p.normalize();
     148        ret->setEmpty();
     149}
     150
     151void Pt3D_Ext::p_rotate(ExtValue *args, ExtValue *ret)
     152{
     153        Orient_Ext *o = Orient_Ext::fromObject(args[0]);
     154        if (o)
     155        {
     156                Pt3D tmp = p;
     157                o->o.transform(p, tmp);
     158        }
     159        ret->setEmpty();
     160}
     161
     162void Pt3D_Ext::p_revrotate(ExtValue *args, ExtValue *ret)
     163{
     164        Orient_Ext *o = Orient_Ext::fromObject(args[0]);
     165        if (o)
     166        {
     167                Pt3D tmp = p;
     168                o->o.revTransform(p, tmp);
     169        }
     170        ret->setEmpty();
     171}
     172
     173void Pt3D_Ext::p_get(ExtValue *args, ExtValue *ret)
     174{
     175        int index = args->getInt();
     176        if ((index < 0) || (index>2))
     177                ret->setEmpty();
     178        else
     179                ret->setDouble((&p.x)[index]);
    180180}
    181181
     
    183183{
    184184#ifdef __CODEGUARD__
    185 static Pt3D_Ext static_pt3dobj;
    186 static Param static_pt3dparam(getStaticParamtab(),&static_pt3dobj);
     185        static Pt3D_Ext static_pt3dobj;
     186        static Param static_pt3dparam(getStaticParamtab(),&static_pt3dobj);
    187187#else
    188 static Param static_pt3dparam(getStaticParamtab());
     188        static Param static_pt3dparam(getStaticParamtab());
    189189#endif
    190 return static_pt3dparam;
    191 }
    192 
    193 Pt3D_Ext* Pt3D_Ext::fromObject(const ExtValue& v,bool warn)
    194 {
    195 return (Pt3D_Ext*)v.getObjectTarget(getStaticParam().getName(), warn);
    196 }
    197 
    198 ParamInterface* Pt3D_Ext::getInterface() {return &getStaticParam();}
     190        return static_pt3dparam;
     191}
     192
     193Pt3D_Ext* Pt3D_Ext::fromObject(const ExtValue& v, bool warn)
     194{
     195        return (Pt3D_Ext*)v.getObjectTarget(getStaticParam().getName(), warn);
     196}
     197
     198ParamInterface* Pt3D_Ext::getInterface() { return &getStaticParam(); }
    199199
    200200ExtObject Pt3D_Ext::makeStaticObject(Pt3D* p)
    201 {return ExtObject(&getStaticParam(),((char*)p)+(((char*)&p->x)-((char*)&((Pt3D_Ext*)p)->p.x)));}
     201{
     202        return ExtObject(&getStaticParam(), ((char*)p) + (((char*)&p->x) - ((char*)&((Pt3D_Ext*)p)->p.x)));
     203}
    202204
    203205ExtObject Pt3D_Ext::makeDynamicObject(Pt3D_Ext* p)
    204 {return ExtObject(&getStaticParam(),p);}
     206{
     207        return ExtObject(&getStaticParam(), p);
     208}
    205209
    206210ExtObject Pt3D_Ext::makeDynamicObject(const Pt3D& p)
    207211{
    208 Pt3D_Ext *pe=new Pt3D_Ext(p);
    209 return ExtObject(&getStaticParam(),pe);
     212        Pt3D_Ext *pe = new Pt3D_Ext(p);
     213        return ExtObject(&getStaticParam(), pe);
    210214}
    211215
     
    215219{
    216220#define FIELDSTRUCT Orient_Ext
    217 static ParamEntry paramtab[]=
    218 {
    219 {"Orient",1,29,"Orient","3D orientation, stored as 3x3 matrix."},
    220 
    221 {"xx",1,PARAM_NOSTATIC,"orientation.x.x","f",FIELD(o.x.x),},
    222 {"xy",1,PARAM_NOSTATIC,"orientation.x.y","f",FIELD(o.x.y),},
    223 {"xz",1,PARAM_NOSTATIC,"orientation.x.z","f",FIELD(o.x.z),},
    224 {"yx",1,PARAM_NOSTATIC,"orientation.y.x","f",FIELD(o.y.x),},
    225 {"yy",1,PARAM_NOSTATIC,"orientation.y.y","f",FIELD(o.y.y),},
    226 {"yz",1,PARAM_NOSTATIC,"orientation.y.z","f",FIELD(o.y.z),},
    227 {"zx",1,PARAM_NOSTATIC,"orientation.z.x","f",FIELD(o.z.x),},
    228 {"zy",1,PARAM_NOSTATIC,"orientation.z.y","f",FIELD(o.z.y),},
    229 {"zz",1,PARAM_NOSTATIC,"orientation.z.z","f",FIELD(o.z.z),},
    230 
    231 {"x",0,PARAM_NOSTATIC | PARAM_READONLY,"x vector","oXYZ",GETONLY(x),},
    232 {"y",0,PARAM_NOSTATIC | PARAM_READONLY,"y vector","oXYZ",GETONLY(y),},
    233 {"z",0,PARAM_NOSTATIC | PARAM_READONLY,"z vector","oXYZ",GETONLY(z),},
    234 
    235 {"new",0,0,"create new Orient object","p oOrient()",PROCEDURE(p_new),},
    236 {"newFromVector",0,0,"create new Orient object","p oOrient(oVector)",PROCEDURE(p_newFromVector),},
    237 {"toVector",0,PARAM_READONLY | PARAM_NOSTATIC,"vector representation","oVector",GETONLY(toVector),"for serialization"},
    238 {"clone",0,PARAM_NOSTATIC,"create new Orient object","p oOrient()",PROCEDURE(p_clone),},
    239 {"set",0,PARAM_NOSTATIC,"copy from another Orient object","p(oOrient)",PROCEDURE(p_set),},
    240 {"reset",0,PARAM_NOSTATIC,"set identity matrix","p()",PROCEDURE(p_reset),},
    241 {"rotate3",0,PARAM_NOSTATIC,"rotate around 3 axes","p(f x,f y,f z)",PROCEDURE(p_rotate3),},
    242 {"rotate",0,PARAM_NOSTATIC,"rotate using Orient object","p(oOrient)",PROCEDURE(p_rotate),},
    243 {"revRotate",0,PARAM_NOSTATIC,"reverse rotate using Orient object","p(oOrient)",PROCEDURE(p_revrotate),},
    244 {"lookAt",0,PARAM_NOSTATIC,"calculate rotation from 2 vectors","p(oXYZ direction,oXYZ up)",PROCEDURE(p_lookat),},
    245 {"normalize",0,PARAM_NOSTATIC,"normalize","p()",PROCEDURE(p_normalize),},
    246 {"between2",0,PARAM_NOSTATIC,"interpolate orientation","p(oOrient,oOrient,f amount)",PROCEDURE(p_between2),"The calling Orient receives the orientation interpolated from 2 input orientations.\nExample:\n"
    247         "var o1=Orient.new(), o2=Orient.new(), o3=Orient.new();\n"
    248         "o2.rotate3(0,Math.pi/2,0);\n"
    249         "o3.between2(o1,o2,0); // o3 equals o2\n"
    250         "o3.between2(o1,o2,1); // o3 equals o1\n"
    251         "o3.between2(o1,o2,0.5); // o3 is halfway between o1 and o2\n"},
    252 {"betweenOV",0,PARAM_NOSTATIC,"interpolate orientation","p(oOrient,oXYZ,f amount)",PROCEDURE(p_betweenOV),"Like between2(), but the second Orient is composed of the supplied XYZ vector (X component) and Y Z vectors from the calling object.\n"
    253         "Example:\n"
    254         "var o=Orient.new();\n"
    255         "o.betweenOV(o,(0,1,0),1); //no change, o remains 100 010 001\n"
    256         "o.betweenOV(o,(0,1,0),0.9); //o is slightly rotated towards (0,1,0)\n"
    257         "o.betweenOV(o,(0,1,0),0); //o is completely transformed, o.x=(0,1,0)\n"
    258         },
    259 {"localToWorld",0,PARAM_NOSTATIC,"transform coordinates","p oXYZ(oXYZ point,oXYZ center)",PROCEDURE(p_localToWorld),},
    260 {"worldToLocal",0,PARAM_NOSTATIC,"transform coordinates","p oXYZ(oXYZ point,oXYZ center)",PROCEDURE(p_worldToLocal),},
    261 {"angles",0,PARAM_READONLY | PARAM_NOSTATIC,"Euler angles representation","oXYZ",GETONLY(angles),},
    262 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"textual form","s",GETONLY(toString),},
    263 {0,0,0,},
    264 };
     221        static ParamEntry paramtab[] =
     222        {
     223                { "Orient", 1, 29, "Orient", "3D orientation, stored as 3x3 matrix." },
     224
     225                { "xx", 1, PARAM_NOSTATIC, "orientation.x.x", "f", FIELD(o.x.x), },
     226                { "xy", 1, PARAM_NOSTATIC, "orientation.x.y", "f", FIELD(o.x.y), },
     227                { "xz", 1, PARAM_NOSTATIC, "orientation.x.z", "f", FIELD(o.x.z), },
     228                { "yx", 1, PARAM_NOSTATIC, "orientation.y.x", "f", FIELD(o.y.x), },
     229                { "yy", 1, PARAM_NOSTATIC, "orientation.y.y", "f", FIELD(o.y.y), },
     230                { "yz", 1, PARAM_NOSTATIC, "orientation.y.z", "f", FIELD(o.y.z), },
     231                { "zx", 1, PARAM_NOSTATIC, "orientation.z.x", "f", FIELD(o.z.x), },
     232                { "zy", 1, PARAM_NOSTATIC, "orientation.z.y", "f", FIELD(o.z.y), },
     233                { "zz", 1, PARAM_NOSTATIC, "orientation.z.z", "f", FIELD(o.z.z), },
     234
     235                { "x", 0, PARAM_NOSTATIC | PARAM_READONLY, "x vector", "oXYZ", GETONLY(x), },
     236                { "y", 0, PARAM_NOSTATIC | PARAM_READONLY, "y vector", "oXYZ", GETONLY(y), },
     237                { "z", 0, PARAM_NOSTATIC | PARAM_READONLY, "z vector", "oXYZ", GETONLY(z), },
     238
     239                { "new", 0, 0, "create new Orient object", "p oOrient()", PROCEDURE(p_new), },
     240                { "newFromVector", 0, 0, "create new Orient object", "p oOrient(oVector)", PROCEDURE(p_newFromVector), },
     241                { "toVector", 0, PARAM_READONLY | PARAM_NOSTATIC, "vector representation", "oVector", GETONLY(toVector), "for serialization" },
     242                { "clone", 0, PARAM_NOSTATIC, "create new Orient object", "p oOrient()", PROCEDURE(p_clone), },
     243                { "set", 0, PARAM_NOSTATIC, "copy from another Orient object", "p(oOrient)", PROCEDURE(p_set), },
     244                { "reset", 0, PARAM_NOSTATIC, "set identity matrix", "p()", PROCEDURE(p_reset), },
     245                { "rotate3", 0, PARAM_NOSTATIC, "rotate around 3 axes", "p(f x,f y,f z)", PROCEDURE(p_rotate3), },
     246                { "rotate", 0, PARAM_NOSTATIC, "rotate using Orient object", "p(oOrient)", PROCEDURE(p_rotate), },
     247                { "revRotate", 0, PARAM_NOSTATIC, "reverse rotate using Orient object", "p(oOrient)", PROCEDURE(p_revrotate), },
     248                { "lookAt", 0, PARAM_NOSTATIC, "calculate rotation from 2 vectors", "p(oXYZ direction,oXYZ up)", PROCEDURE(p_lookat), },
     249                { "normalize", 0, PARAM_NOSTATIC, "normalize", "p()", PROCEDURE(p_normalize), },
     250                { "between2", 0, PARAM_NOSTATIC, "interpolate orientation", "p(oOrient,oOrient,f amount)", PROCEDURE(p_between2), "The calling Orient receives the orientation interpolated from 2 input orientations.\nExample:\n"
     251                "var o1=Orient.new(), o2=Orient.new(), o3=Orient.new();\n"
     252                "o2.rotate3(0,Math.pi/2,0);\n"
     253                "o3.between2(o1,o2,0); // o3 equals o2\n"
     254                "o3.between2(o1,o2,1); // o3 equals o1\n"
     255                "o3.between2(o1,o2,0.5); // o3 is halfway between o1 and o2\n" },
     256                { "betweenOV", 0, PARAM_NOSTATIC, "interpolate orientation", "p(oOrient,oXYZ,f amount)", PROCEDURE(p_betweenOV), "Like between2(), but the second Orient is composed of the supplied XYZ vector (X component) and Y Z vectors from the calling object.\n"
     257                "Example:\n"
     258                "var o=Orient.new();\n"
     259                "o.betweenOV(o,(0,1,0),1); //no change, o remains 100 010 001\n"
     260                "o.betweenOV(o,(0,1,0),0.9); //o is slightly rotated towards (0,1,0)\n"
     261                "o.betweenOV(o,(0,1,0),0); //o is completely transformed, o.x=(0,1,0)\n"
     262                },
     263                { "localToWorld", 0, PARAM_NOSTATIC, "transform coordinates", "p oXYZ(oXYZ point,oXYZ center)", PROCEDURE(p_localToWorld), },
     264                { "worldToLocal", 0, PARAM_NOSTATIC, "transform coordinates", "p oXYZ(oXYZ point,oXYZ center)", PROCEDURE(p_worldToLocal), },
     265                { "angles", 0, PARAM_READONLY | PARAM_NOSTATIC, "Euler angles representation", "oXYZ", GETONLY(angles), },
     266                { "toString", 0, PARAM_READONLY | PARAM_NOSTATIC, "textual form", "s", GETONLY(toString), },
     267                { 0, 0, 0, },
     268        };
    265269#undef FIELDSTRUCT
    266 return paramtab;
    267 }
    268 
    269 void Orient_Ext::p_new(ExtValue *args,ExtValue *ret)
    270 {
    271 *ret=makeDynamicObject(new Orient_Ext());
    272 }
    273 
    274 void Orient_Ext::p_newFromVector(ExtValue *args,ExtValue *ret)
    275 {
    276 VectorObject *vec=VectorObject::fromObject(args->getObject());
    277 if (vec)
    278         *ret=makeDynamicObject(new Orient_Ext(Orient(pt3DFromVec(vec,0),pt3DFromVec(vec,3),pt3DFromVec(vec,6))));
    279 else
    280         ret->setEmpty();
     270        return paramtab;
     271}
     272
     273void Orient_Ext::p_new(ExtValue *args, ExtValue *ret)
     274{
     275        *ret = makeDynamicObject(new Orient_Ext());
     276}
     277
     278void Orient_Ext::p_newFromVector(ExtValue *args, ExtValue *ret)
     279{
     280        VectorObject *vec = VectorObject::fromObject(args->getObject());
     281        if (vec)
     282                *ret = makeDynamicObject(new Orient_Ext(Orient(pt3DFromVec(vec, 0), pt3DFromVec(vec, 3), pt3DFromVec(vec, 6))));
     283        else
     284                ret->setEmpty();
    281285}
    282286
    283287void Orient_Ext::get_toVector(ExtValue *ret)
    284288{
    285 VectorObject *vec=new VectorObject;
    286 add3Coords(vec,o.x);
    287 add3Coords(vec,o.y);
    288 add3Coords(vec,o.z);
    289 ret->setObject(ExtObject(&VectorObject::par,vec));
    290 }
    291 
    292 void Orient_Ext::p_clone(ExtValue *args,ExtValue *ret)
    293 {
    294 *ret=makeDynamicObject(new Orient_Ext(o));
    295 }
    296 
    297 void Orient_Ext::p_set(ExtValue *args,ExtValue *ret)
    298 {
    299 Orient_Ext *other=fromObject(args[0]);
    300 if (other)
    301         o=other->o;
    302 ret->setEmpty();
    303 }
    304 
    305 void Orient_Ext::p_reset(ExtValue *args,ExtValue *ret)
    306 {
    307 o=Orient_1;
    308 ret->setEmpty();
     289        VectorObject *vec = new VectorObject;
     290        add3Coords(vec, o.x);
     291        add3Coords(vec, o.y);
     292        add3Coords(vec, o.z);
     293        ret->setObject(ExtObject(&VectorObject::par, vec));
     294}
     295
     296void Orient_Ext::p_clone(ExtValue *args, ExtValue *ret)
     297{
     298        *ret = makeDynamicObject(new Orient_Ext(o));
     299}
     300
     301void Orient_Ext::p_set(ExtValue *args, ExtValue *ret)
     302{
     303        Orient_Ext *other = fromObject(args[0]);
     304        if (other)
     305                o = other->o;
     306        ret->setEmpty();
     307}
     308
     309void Orient_Ext::p_reset(ExtValue *args, ExtValue *ret)
     310{
     311        o = Orient_1;
     312        ret->setEmpty();
    309313}
    310314
    311315void Orient_Ext::get_x(PARAMGETARGS)
    312316{
    313 *ret=Pt3D_Ext::makeStaticObject(&o.x);
     317        *ret = Pt3D_Ext::makeStaticObject(&o.x);
    314318}
    315319
    316320void Orient_Ext::get_y(PARAMGETARGS)
    317321{
    318 *ret=Pt3D_Ext::makeStaticObject(&o.y);
     322        *ret = Pt3D_Ext::makeStaticObject(&o.y);
    319323}
    320324
    321325void Orient_Ext::get_z(PARAMGETARGS)
    322326{
    323 *ret=Pt3D_Ext::makeStaticObject(&o.z);
    324 }
    325 
    326 void Orient_Ext::p_lookat(ExtValue *args,ExtValue *ret)
    327 {
    328 Pt3D_Ext *dir=Pt3D_Ext::fromObject(args[1]),*up=Pt3D_Ext::fromObject(args[0]);
    329 if (dir&&up)
    330         o.lookAt(dir->p,up->p);
    331 ret->setEmpty();
    332 }
    333 
    334 void Orient_Ext::p_rotate3(ExtValue *args,ExtValue *ret)
    335 {
    336 Pt3D p(args[2].getDouble(),args[1].getDouble(),args[0].getDouble());
    337 o.rotate(p);
    338 ret->setEmpty();
    339 }
    340 
    341 void Orient_Ext::p_rotate(ExtValue *args,ExtValue *ret)
    342 {
    343 Orient_Ext *obj=Orient_Ext::fromObject(args[0]);
    344 if (!obj)
    345         {
    346         Orient tmp=o;
    347         obj->o.transform(o,tmp);
    348         }
    349 ret->setEmpty();
    350 }
    351 
    352 void Orient_Ext::p_revrotate(ExtValue *args,ExtValue *ret)
    353 {
    354 Orient_Ext *obj=Orient_Ext::fromObject(args[0]);
    355 if (obj)
    356         {
    357         Orient tmp=o;
    358         obj->o.revTransform(o,tmp);
    359         }
    360 ret->setEmpty();
    361 }
    362 
    363 void Orient_Ext::p_normalize(ExtValue *args,ExtValue *ret)
    364 {
    365 o.normalize();
    366 ret->setEmpty();
    367 }
    368 
    369 void Orient_Ext::p_between2(ExtValue *args,ExtValue *ret)
    370 {
    371 Orient_Ext *o1=Orient_Ext::fromObject(args[2]);
    372 Orient_Ext *o2=Orient_Ext::fromObject(args[1]);
    373 if (o1&&o2)
    374         {
    375         double q1=args[0].getDouble(),q2=1.0-q1;
    376         o.x.x=q1*o1->o.x.x+q2*o2->o.x.x;
    377         o.x.y=q1*o1->o.x.y+q2*o2->o.x.y;
    378         o.x.z=q1*o1->o.x.z+q2*o2->o.x.z;
    379         o.y.x=q1*o1->o.y.x+q2*o2->o.y.x;
    380         o.y.y=q1*o1->o.y.y+q2*o2->o.y.y;
    381         o.y.z=q1*o1->o.y.z+q2*o2->o.y.z;
    382         o.z.x=q1*o1->o.z.x+q2*o2->o.z.x;
    383         o.z.y=q1*o1->o.z.y+q2*o2->o.z.y;
    384         o.z.z=q1*o1->o.z.z+q2*o2->o.z.z;
     327        *ret = Pt3D_Ext::makeStaticObject(&o.z);
     328}
     329
     330void Orient_Ext::p_lookat(ExtValue *args, ExtValue *ret)
     331{
     332        Pt3D_Ext *dir = Pt3D_Ext::fromObject(args[1]), *up = Pt3D_Ext::fromObject(args[0]);
     333        if (dir&&up)
     334                o.lookAt(dir->p, up->p);
     335        ret->setEmpty();
     336}
     337
     338void Orient_Ext::p_rotate3(ExtValue *args, ExtValue *ret)
     339{
     340        Pt3D p(args[2].getDouble(), args[1].getDouble(), args[0].getDouble());
     341        o.rotate(p);
     342        ret->setEmpty();
     343}
     344
     345void Orient_Ext::p_rotate(ExtValue *args, ExtValue *ret)
     346{
     347        Orient_Ext *obj = Orient_Ext::fromObject(args[0]);
     348        if (!obj)
     349        {
     350                Orient tmp = o;
     351                obj->o.transform(o, tmp);
     352        }
     353        ret->setEmpty();
     354}
     355
     356void Orient_Ext::p_revrotate(ExtValue *args, ExtValue *ret)
     357{
     358        Orient_Ext *obj = Orient_Ext::fromObject(args[0]);
     359        if (obj)
     360        {
     361                Orient tmp = o;
     362                obj->o.revTransform(o, tmp);
     363        }
     364        ret->setEmpty();
     365}
     366
     367void Orient_Ext::p_normalize(ExtValue *args, ExtValue *ret)
     368{
    385369        o.normalize();
    386         }
    387 ret->setEmpty();
    388 }
    389 
    390 void Orient_Ext::p_betweenOV(ExtValue *args,ExtValue *ret)
    391 {
    392 Orient_Ext *o1=Orient_Ext::fromObject(args[2]);
    393 Pt3D_Ext *p2=Pt3D_Ext::fromObject(args[1]);
    394 if (o1&&p2)
    395         {
    396         double q1=args[0].getDouble(),q2=1.0-q1;
    397         o.x.x=q1*o1->o.x.x+q2*p2->p.x;
    398         o.x.y=q1*o1->o.x.y+q2*p2->p.y;
    399         o.x.z=q1*o1->o.x.z+q2*p2->p.z;
    400         o.normalize();
    401         }
    402 ret->setEmpty();
    403 }
    404 
    405 void Orient_Ext::p_localToWorld(ExtValue *args,ExtValue *ret)
    406 {
    407 Pt3D_Ext *center,*point;
    408 point=Pt3D_Ext::fromObject(args[1]);
    409 center=Pt3D_Ext::fromObject(args[0]);
    410 if (center && point)
    411         {
    412         Pt3D d;
    413         Pt3D src=point->p;
    414         o.transform(d,src);
    415         d+=center->p;
    416         *ret=Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(d));
    417         }
    418 else
    419         ret->setEmpty();
    420 }
    421 
    422 void Orient_Ext::p_worldToLocal(ExtValue *args,ExtValue *ret)
    423 {
    424 Pt3D_Ext *center,*point;
    425 point=Pt3D_Ext::fromObject(args[1]);
    426 center=Pt3D_Ext::fromObject(args[0]);
    427 if (center && point)
    428         {
    429         Pt3D d;
    430         Pt3D src=point->p;
    431         d-=center->p;
    432         o.revTransform(d,src);
    433         *ret=Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(d));
    434         }
    435 else
    436         ret->setEmpty();
     370        ret->setEmpty();
     371}
     372
     373void Orient_Ext::p_between2(ExtValue *args, ExtValue *ret)
     374{
     375        Orient_Ext *o1 = Orient_Ext::fromObject(args[2]);
     376        Orient_Ext *o2 = Orient_Ext::fromObject(args[1]);
     377        if (o1&&o2)
     378        {
     379                double q1 = args[0].getDouble(), q2 = 1.0 - q1;
     380                o.x.x = q1*o1->o.x.x + q2*o2->o.x.x;
     381                o.x.y = q1*o1->o.x.y + q2*o2->o.x.y;
     382                o.x.z = q1*o1->o.x.z + q2*o2->o.x.z;
     383                o.y.x = q1*o1->o.y.x + q2*o2->o.y.x;
     384                o.y.y = q1*o1->o.y.y + q2*o2->o.y.y;
     385                o.y.z = q1*o1->o.y.z + q2*o2->o.y.z;
     386                o.z.x = q1*o1->o.z.x + q2*o2->o.z.x;
     387                o.z.y = q1*o1->o.z.y + q2*o2->o.z.y;
     388                o.z.z = q1*o1->o.z.z + q2*o2->o.z.z;
     389                o.normalize();
     390        }
     391        ret->setEmpty();
     392}
     393
     394void Orient_Ext::p_betweenOV(ExtValue *args, ExtValue *ret)
     395{
     396        Orient_Ext *o1 = Orient_Ext::fromObject(args[2]);
     397        Pt3D_Ext *p2 = Pt3D_Ext::fromObject(args[1]);
     398        if (o1&&p2)
     399        {
     400                double q1 = args[0].getDouble(), q2 = 1.0 - q1;
     401                o.x.x = q1*o1->o.x.x + q2*p2->p.x;
     402                o.x.y = q1*o1->o.x.y + q2*p2->p.y;
     403                o.x.z = q1*o1->o.x.z + q2*p2->p.z;
     404                o.normalize();
     405        }
     406        ret->setEmpty();
     407}
     408
     409void Orient_Ext::p_localToWorld(ExtValue *args, ExtValue *ret)
     410{
     411        Pt3D_Ext *center, *point;
     412        point = Pt3D_Ext::fromObject(args[1]);
     413        center = Pt3D_Ext::fromObject(args[0]);
     414        if (center && point)
     415        {
     416                Pt3D d;
     417                Pt3D src = point->p;
     418                o.transform(d, src);
     419                d += center->p;
     420                *ret = Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(d));
     421        }
     422        else
     423                ret->setEmpty();
     424}
     425
     426void Orient_Ext::p_worldToLocal(ExtValue *args, ExtValue *ret)
     427{
     428        Pt3D_Ext *center, *point;
     429        point = Pt3D_Ext::fromObject(args[1]);
     430        center = Pt3D_Ext::fromObject(args[0]);
     431        if (center && point)
     432        {
     433                Pt3D d;
     434                Pt3D src = point->p;
     435                d -= center->p;
     436                o.revTransform(d, src);
     437                *ret = Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(d));
     438        }
     439        else
     440                ret->setEmpty();
    437441}
    438442
    439443void Orient_Ext::get_angles(ExtValue *ret)
    440444{
    441 *ret=Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(o.getAngles()));
     445        *ret = Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(o.getAngles()));
    442446}
    443447
    444448void Orient_Ext::get_toString(ExtValue *ret)
    445449{
    446 Pt3D a=o.getAngles();
    447 ret->setString(SString::sprintf("Orient@(%g,%g,%g)",a.x,a.y,a.z));
     450        Pt3D a = o.getAngles();
     451        ret->setString(SString::sprintf("Orient@(%g,%g,%g)", a.x, a.y, a.z));
    448452}
    449453
     
    451455{
    452456#ifdef __CODEGUARD__
    453 static Orient_Ext static_orientobj;
    454 static Param static_orientparam(getStaticParamtab(),&static_orientobj);
     457        static Orient_Ext static_orientobj;
     458        static Param static_orientparam(getStaticParamtab(),&static_orientobj);
    455459#else
    456 static Param static_orientparam(getStaticParamtab());
     460        static Param static_orientparam(getStaticParamtab());
    457461#endif
    458 return static_orientparam;
     462        return static_orientparam;
    459463}
    460464
    461465Orient_Ext* Orient_Ext::fromObject(const ExtValue& v)
    462466{
    463 return (Orient_Ext*)v.getObjectTarget(getStaticParam().getName());
    464 }
    465 
    466 ParamInterface* Orient_Ext::getInterface() {return &getStaticParam();}
     467        return (Orient_Ext*)v.getObjectTarget(getStaticParam().getName());
     468}
     469
     470ParamInterface* Orient_Ext::getInterface() { return &getStaticParam(); }
    467471
    468472ExtObject Orient_Ext::makeStaticObject(Orient* o)
    469 {return ExtObject(&getStaticParam(),((char*)o)+(((char*)&o->x)-((char*)&((Orient_Ext*)o)->o.x)));}
     473{
     474        return ExtObject(&getStaticParam(), ((char*)o) + (((char*)&o->x) - ((char*)&((Orient_Ext*)o)->o.x)));
     475}
    470476
    471477ExtObject Orient_Ext::makeDynamicObject(Orient_Ext* p)
    472 {return ExtObject(&getStaticParam(),p);}
     478{
     479        return ExtObject(&getStaticParam(), p);
     480}
    473481
    474482/////////////
  • cpp/frams/vm/classes/3dobject.h

    r286 r343  
    99#include <frams/util/extvalue.h>
    1010
    11 class Pt3D_Ext: public DestrBase
     11class Pt3D_Ext : public DestrBase
    1212{
    13   public:
    14 Pt3D p;
     13public:
     14        Pt3D p;
    1515
    16 Pt3D_Ext(double x,double y,double z):p(x,y,z) {}
    17 Pt3D_Ext():p(0,0,0) {}
    18 Pt3D_Ext(const Pt3D &i):p(i) {}
     16        Pt3D_Ext(double x, double y, double z) :p(x, y, z) {}
     17        Pt3D_Ext() :p(0, 0, 0) {}
     18        Pt3D_Ext(const Pt3D &i) :p(i) {}
    1919#define STATRICKCLASS Pt3D_Ext
    20 PARAMPROCDEF(p_new);
    21 PARAMPROCDEF(p_newFromVector);
    22 PARAMPROCDEF(p_clone);
    23 PARAMGETDEF(length);
    24 PARAMPROCDEF(p_addvec);
    25 PARAMPROCDEF(p_subvec);
    26 PARAMPROCDEF(p_scale);
    27 PARAMPROCDEF(p_rotate);
    28 PARAMPROCDEF(p_revrotate);
    29 PARAMPROCDEF(p_normalize);
    30 PARAMGETDEF(toString);
    31 PARAMGETDEF(toVector);
    32 PARAMPROCDEF(p_set);
    33 PARAMPROCDEF(p_set3);
    34 PARAMPROCDEF(p_get);
     20        PARAMPROCDEF(p_new);
     21        PARAMPROCDEF(p_newFromVector);
     22        PARAMPROCDEF(p_clone);
     23        PARAMGETDEF(length);
     24        PARAMPROCDEF(p_addvec);
     25        PARAMPROCDEF(p_subvec);
     26        PARAMPROCDEF(p_scale);
     27        PARAMPROCDEF(p_rotate);
     28        PARAMPROCDEF(p_revrotate);
     29        PARAMPROCDEF(p_normalize);
     30        PARAMGETDEF(toString);
     31        PARAMGETDEF(toVector);
     32        PARAMPROCDEF(p_set);
     33        PARAMPROCDEF(p_set3);
     34        PARAMPROCDEF(p_get);
    3535#undef STATRICKCLASS
    3636
    37 static ParamInterface* getInterface();
    38 static ExtObject makeStaticObject(Pt3D* p);
    39 static ExtObject makeDynamicObject(Pt3D_Ext* p);
    40 static ExtObject makeDynamicObject(const Pt3D& p);
    41 static Pt3D_Ext* fromObject(const ExtValue& v,bool warn=true);
    42 static Param& getStaticParam();
    43 static ParamEntry* getStaticParamtab();
     37        static ParamInterface* getInterface();
     38        static ExtObject makeStaticObject(Pt3D* p);
     39        static ExtObject makeDynamicObject(Pt3D_Ext* p);
     40        static ExtObject makeDynamicObject(const Pt3D& p);
     41        static Pt3D_Ext* fromObject(const ExtValue& v, bool warn = true);
     42        static Param& getStaticParam();
     43        static ParamEntry* getStaticParamtab();
    4444};
    4545
    46 class Orient_Ext: public DestrBase
     46class Orient_Ext : public DestrBase
    4747{
    48   public:
    49 Orient o;
     48public:
     49        Orient o;
    5050
    51 Orient_Ext():o(Orient_1) {}
    52 Orient_Ext(const Orient& other):o(other) {}
     51        Orient_Ext() :o(Orient_1) {}
     52        Orient_Ext(const Orient& other) :o(other) {}
    5353#define STATRICKCLASS Orient_Ext
    54 PARAMPROCDEF(p_new);
    55 PARAMPROCDEF(p_newFromVector);
    56 PARAMPROCDEF(p_clone);
    57 PARAMGETDEF(toString);
    58 PARAMGETDEF(toVector);
    59 PARAMGETDEF(x);
    60 PARAMGETDEF(y);
    61 PARAMGETDEF(z);
    62 PARAMPROCDEF(p_rotate3);
    63 PARAMPROCDEF(p_rotate);
    64 PARAMPROCDEF(p_revrotate);
    65 PARAMPROCDEF(p_lookat);
    66 PARAMPROCDEF(p_normalize);
    67 PARAMPROCDEF(p_between2);
    68 PARAMPROCDEF(p_betweenOV);
    69 PARAMPROCDEF(p_set);
    70 PARAMPROCDEF(p_reset);
    71 PARAMPROCDEF(p_localToWorld);
    72 PARAMPROCDEF(p_worldToLocal);
    73 PARAMGETDEF(angles);
     54        PARAMPROCDEF(p_new);
     55        PARAMPROCDEF(p_newFromVector);
     56        PARAMPROCDEF(p_clone);
     57        PARAMGETDEF(toString);
     58        PARAMGETDEF(toVector);
     59        PARAMGETDEF(x);
     60        PARAMGETDEF(y);
     61        PARAMGETDEF(z);
     62        PARAMPROCDEF(p_rotate3);
     63        PARAMPROCDEF(p_rotate);
     64        PARAMPROCDEF(p_revrotate);
     65        PARAMPROCDEF(p_lookat);
     66        PARAMPROCDEF(p_normalize);
     67        PARAMPROCDEF(p_between2);
     68        PARAMPROCDEF(p_betweenOV);
     69        PARAMPROCDEF(p_set);
     70        PARAMPROCDEF(p_reset);
     71        PARAMPROCDEF(p_localToWorld);
     72        PARAMPROCDEF(p_worldToLocal);
     73        PARAMGETDEF(angles);
    7474#undef STATRICKCLASS
    7575
    76 static ParamInterface* getInterface();
    77 static ExtObject makeStaticObject(Orient* p);
    78 static ExtObject makeDynamicObject(Orient_Ext* p);
    79 static Orient_Ext* fromObject(const ExtValue& v);
    80 static Param& getStaticParam();
    81 static ParamEntry* getStaticParamtab();
     76        static ParamInterface* getInterface();
     77        static ExtObject makeStaticObject(Orient* p);
     78        static ExtObject makeDynamicObject(Orient_Ext* p);
     79        static Orient_Ext* fromObject(const ExtValue& v);
     80        static Param& getStaticParam();
     81        static ParamEntry* getStaticParamtab();
    8282};
    8383
Note: See TracChangeset for help on using the changeset viewer.