/// matrix3f.cpp
///
/// (c) 2008 by Carsten Busse <carsten.busse@googlemail.com>
///             Bastian Spiegel <bs@tkscript.de> (additional coding)
///     - Distributed under terms of the Lesser GNU General Public License (LGPL).
///       See COPYING and <http://www.gnu.org/licenses/licenses.html#LGPL> for further information.
///
///

#include <math.h>

#include "tkmath_yac.h"
#include "tkmath.h"
#include "vector3f.h"
#include "matrix3f.h"

#include "ying_Math.h"

_Matrix3f::_Matrix3f(void) {
   floats[0]=floats[1]=floats[2]=floats[3]=floats[4]=floats[5]=floats[6]=floats[7]=floats[8]=0.0f;
}

_Matrix3f::~_Matrix3f() {
}

sUI YAC_VCALL _Matrix3f::yacArrayGetNumElements(void) {
   return 9;
}

sUI YAC_VCALL _Matrix3f::yacArrayGetMaxElements(void) {
   return 9;
}

sUI YAC_VCALL _Matrix3f::yacArrayGetElementType(void) {
   return YAC_TYPE_FLOAT;
}

sUI YAC_VCALL _Matrix3f::yacArrayGetElementByteSize(void) {
   return sizeof(sF32);
}

void YAC_VCALL _Matrix3f::yacArraySet(YAC_ContextHandle _ctx, sUI _idx, YAC_Value *_val) {
   if (_idx<9) {
      sF32 v = 0.0f;
      switch (_val->type) {
         case YAC_TYPE_VOID:
            v=0.0f;
            break;
         case YAC_TYPE_INT:
            v=(sF32)_val->value.int_val;
            break;
         case YAC_TYPE_FLOAT:
            v=_val->value.float_val;
            break;
         case YAC_TYPE_OBJECT:
            if (YAC_VALID(_val->value.object_val)) {
               if (!_val->value.object_val->yacScanF32(&v))
                  v=0.0f;
            }
            break;
         default:
            Dyac_throw(TypeMismatch, "tkmath::Matrix3f::yacArraySet Unknown Type!");
            v=0.0f;
            break;
      }
      floats[_idx]=v;
   } else {
      static char buf[256];
      sprintf(buf, "tkmath::Matrix3f::yacArraySet Index too high (%d>8)", _idx);
      Dyac_throw(WriteArrayOutOfBounds, buf);
   }
}

void YAC_VCALL _Matrix3f::yacArrayGet(YAC_ContextHandle _ctx, sUI _idx, YAC_Value *_val) {
   if (_idx<9)
   {
      _val->initFloat(floats[_idx]);
   } 
   else 
   {
      static char buf[256];
      sprintf(buf, "tkmath::Matrix3f::yacArrayGet Index too high (%d>8)", _idx);
      Dyac_throw(ReadArrayOutOfBounds, buf);
      _val->initFloat(0.0f);
   }
}

void *YAC_VCALL _Matrix3f::yacArrayGetPointer(void) {
   return (void*)floats;
}

sUI YAC_VCALL _Matrix3f::yacArrayGetWidth(void) {
   return 3;
}

sUI YAC_VCALL _Matrix3f::yacArrayGetHeight(void) {
   return 3;
}

sUI YAC_VCALL _Matrix3f::yacArrayGetStride(void) {
   return 3*sizeof(sF32);
}

sSI YAC_VCALL _Matrix3f::yacTensorRank(void) {
   return YAC_TENSOR_RANK_MATRIX;
}

void YAC_VCALL _Matrix3f::yacSerialize(YAC_Object *_ofs, sUI _rtti) {
   YAC_BEG_SERIALIZE();
   YAC_SERIALIZE_F32(floats[0]);
   YAC_SERIALIZE_F32(floats[1]);
   YAC_SERIALIZE_F32(floats[2]);
   YAC_SERIALIZE_F32(floats[3]);
   YAC_SERIALIZE_F32(floats[4]);
   YAC_SERIALIZE_F32(floats[5]);
   YAC_SERIALIZE_F32(floats[6]);
   YAC_SERIALIZE_F32(floats[7]);
   YAC_SERIALIZE_F32(floats[8]);
}

sUI YAC_VCALL _Matrix3f::yacDeserialize(YAC_Object *_ifs, sUI _rtti) {
   YAC_BEG_DESERIALIZE();
   floats[0]=YAC_DESERIALIZE_F32();
   floats[1]=YAC_DESERIALIZE_F32();
   floats[2]=YAC_DESERIALIZE_F32();
   floats[3]=YAC_DESERIALIZE_F32();
   floats[4]=YAC_DESERIALIZE_F32();
   floats[5]=YAC_DESERIALIZE_F32();
   floats[6]=YAC_DESERIALIZE_F32();
   floats[7]=YAC_DESERIALIZE_F32();
   floats[8]=YAC_DESERIALIZE_F32();
   return 1;
}

void YAC_VCALL _Matrix3f::yacOperatorClamp(YAC_Object *_min, YAC_Object *_max) {
   if (YAC_CHK(_min,clid_Matrix3f)&&YAC_CHK(_max,clid_Matrix3f)) {
      _Matrix3f *min=(_Matrix3f*)_min;
      _Matrix3f *max=(_Matrix3f*)_max;
      if (floats[0]<min->floats[0]) floats[0]=min->floats[0];
      else if (floats[0]>max->floats[0]) floats[0]=max->floats[0];
      if (floats[1]<min->floats[1]) floats[1]=min->floats[1];
      else if (floats[1]>max->floats[1]) floats[1]=max->floats[1];
      if (floats[2]<min->floats[2]) floats[2]=min->floats[2];
      else if (floats[2]>max->floats[2]) floats[2]=max->floats[2];
      if (floats[3]<min->floats[3]) floats[3]=min->floats[3];
      else if (floats[3]>max->floats[3]) floats[3]=max->floats[3];
      if (floats[4]<min->floats[4]) floats[4]=min->floats[4];
      else if (floats[4]>max->floats[4]) floats[4]=max->floats[4];
      if (floats[5]<min->floats[5]) floats[5]=min->floats[5];
      else if (floats[5]>max->floats[5]) floats[5]=max->floats[5];
      if (floats[6]<min->floats[6]) floats[6]=min->floats[6];
      else if (floats[6]>max->floats[6]) floats[6]=max->floats[6];
      if (floats[7]<min->floats[7]) floats[7]=min->floats[7];
      else if (floats[7]>max->floats[7]) floats[7]=max->floats[7];
      if (floats[8]<min->floats[8]) floats[8]=min->floats[8];
      else if (floats[8]>max->floats[8]) floats[8]=max->floats[8];
   } else Dyac_throw_def(InvalidPointer, "");
}

void YAC_VCALL _Matrix3f::yacOperatorWrap(YAC_Object *_min, YAC_Object *_max) {
   if (YAC_CHK(_min,clid_Matrix3f)&&YAC_CHK(_max,clid_Matrix3f)) {
      _Matrix3f *min=(_Matrix3f*)_min;
      _Matrix3f *max=(_Matrix3f*)_max;
      if (floats[0]<min->floats[0]) floats[0]+=(max->floats[0]-min->floats[0]);
      else if (floats[0]>max->floats[0]) floats[0]-=(max->floats[0]-min->floats[0]);
      if (floats[1]<min->floats[1]) floats[1]+=(max->floats[1]-min->floats[1]);
      else if (floats[1]>max->floats[1]) floats[1]-=(max->floats[1]-min->floats[1]);
      if (floats[2]<min->floats[2]) floats[2]+=(max->floats[2]-min->floats[2]);
      else if (floats[2]>max->floats[2]) floats[2]-=(max->floats[2]-min->floats[2]);
      if (floats[3]<min->floats[3]) floats[3]+=(max->floats[3]-min->floats[3]);
      else if (floats[3]>max->floats[3]) floats[3]-=(max->floats[3]-min->floats[3]);
      if (floats[4]<min->floats[4]) floats[4]+=(max->floats[4]-min->floats[4]);
      else if (floats[4]>max->floats[4]) floats[4]-=(max->floats[4]-min->floats[4]);
      if (floats[5]<min->floats[5]) floats[5]+=(max->floats[5]-min->floats[5]);
      else if (floats[5]>max->floats[5]) floats[5]-=(max->floats[5]-min->floats[5]);
      if (floats[6]<min->floats[6]) floats[6]+=(max->floats[6]-min->floats[6]);
      else if (floats[6]>max->floats[6]) floats[6]-=(max->floats[6]-min->floats[6]);
      if (floats[7]<min->floats[7]) floats[7]+=(max->floats[7]-min->floats[7]);
      else if (floats[7]>max->floats[7]) floats[7]-=(max->floats[7]-min->floats[7]);
      if (floats[8]<min->floats[8]) floats[8]+=(max->floats[8]-min->floats[8]);
      else if (floats[8]>max->floats[8]) floats[8]-=(max->floats[8]-min->floats[8]);
   } else Dyac_throw_def(InvalidPointer, "");
}

void YAC_VCALL _Matrix3f::yacOperator(sSI _cmd,YAC_Object *_o, YAC_Value *_r) {
   if (YAC_CHK(_o,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      switch (_cmd) {
         case YAC_OP_CEQ:
            YAC_RETI( Dfltequal(floats[0], o->floats[0]) &&
                      Dfltequal(floats[1], o->floats[1]) &&
                      Dfltequal(floats[2], o->floats[2]) &&
                      Dfltequal(floats[3], o->floats[3]) &&
                      Dfltequal(floats[4], o->floats[4]) &&
                      Dfltequal(floats[5], o->floats[5]) &&
                      Dfltequal(floats[6], o->floats[6]) &&
                      Dfltequal(floats[7], o->floats[7]) &&
                      Dfltequal(floats[8], o->floats[8]) );
            break;
         case YAC_OP_CNE:
            YAC_RETI( Dfltnotequal(floats[0], o->floats[0]) || 
                      Dfltnotequal(floats[1], o->floats[1]) ||
                      Dfltnotequal(floats[2], o->floats[2]) ||
                      Dfltnotequal(floats[3], o->floats[3]) ||
                      Dfltnotequal(floats[4], o->floats[4]) ||
                      Dfltnotequal(floats[5], o->floats[5]) ||
                      Dfltnotequal(floats[6], o->floats[6]) ||
                      Dfltnotequal(floats[7], o->floats[7]) ||
                      Dfltnotequal(floats[8], o->floats[8]) );
            break;
         case YAC_OP_ASSIGN:
            floats[0]=o->floats[0];
            floats[1]=o->floats[1];
            floats[2]=o->floats[2];
            floats[3]=o->floats[3];
            floats[4]=o->floats[4];
            floats[5]=o->floats[5];
            floats[6]=o->floats[6];
            floats[7]=o->floats[7];
            floats[8]=o->floats[8];
            break;
         case YAC_OP_ADD:
            {
               //_Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
               //*r=*this;
               //r->_add(_o);
               //_r->initObject(r,1);
               _add_YAC_RSELF(_o);
            }
            break;
         case YAC_OP_SUB:
            {
               //_Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
               //*r=*this;
               //r->_sub(_o);
               //_r->initObject(r,1);
               _sub_YAC_RSELF(_o);
            }
            break;
         case YAC_OP_MUL:
            {
               //_Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
               //*r=*this;
               //r->_mul(_o);
               //_r->initObject(r,1);
               _mul_YAC_RSELF(_o);
            }
            break;
         case YAC_OP_NEG:
            floats[0]=-floats[0];
            floats[1]=-floats[1];
            floats[2]=-floats[2];
            floats[3]=-floats[3];
            floats[4]=-floats[4];
            floats[5]=-floats[5];
            floats[6]=-floats[6];
            floats[7]=-floats[7];
            floats[8]=-floats[8];
            break;
         case YAC_OP_INIT:
            floats[0]=0.0f;
            floats[1]=0.0f;
            floats[2]=0.0f;
            floats[3]=0.0f;
            floats[4]=0.0f;
            floats[5]=0.0f;
            floats[6]=0.0f;
            floats[7]=0.0f;
            floats[8]=0.0f;
            break;
         default:
         {
            static char buf[256];
            sprintf(buf, "tkmath::Matrix3f::yacOperator: unsupported cmd %d!\n", _cmd);
            Dyac_throw_def(TkMathUnsupportedOperator, buf);
            return;
         }

      }
   } else if (YAC_Is_FloatArray(_o)) {
      YAC_FloatArray *o=(YAC_FloatArray*)_o;
      switch (_cmd) {
         case YAC_OP_ASSIGN:
            if (o->num_elements<9) {
               sUI i;
               for (i=0;i<o->num_elements;i++) floats[i]=o->elements[i];
               for (;i<9;i++) floats[i]=0.0f;
            } else {
               floats[0]=o->elements[0];
               floats[1]=o->elements[1];
               floats[2]=o->elements[2];
               floats[3]=o->elements[3];
               floats[4]=o->elements[4];
               floats[5]=o->elements[5];
               floats[6]=o->elements[6];
               floats[7]=o->elements[7];
               floats[8]=o->elements[8];
            }
            break;
         default:
	    _Matrix3f t;
	    t.class_ID=clid_Matrix3f;
	    t.assignFloatArray(o);
	    yacOperator(_cmd,&t,_r);
            //Dyac_throw_def(TkMathUnsupportedOperator, "tkmath::Matrix3f::yacOperator Only Assign supported with FloatArray Type");
            break;
      }
   } else if (YAC_VALID(_o)) {
      sF32 val;
      if (_o->yacScanF32(&val)) {
         yacOperatorF32(_cmd, val, _r);
      } else
      switch (_cmd) {
         case YAC_OP_ASSIGN:
	    assignGeneric(NULL,_o);
	    break;
	 default:
	    Dyac_throw_def(TkMathUnsupportedOperator, "tkmath::Matrix3f::yacOperator Only Assign supported with Generic Type");
	    break;
      }
   } else {
      switch (_cmd) {
         case YAC_OP_NEG:
	    floats[0]=-floats[0];
	    floats[1]=-floats[1];
	    floats[2]=-floats[2];
	    floats[3]=-floats[3];
	    floats[4]=-floats[4];
	    floats[5]=-floats[5];
	    floats[6]=-floats[6];
	    floats[7]=-floats[7];
	    floats[8]=-floats[8];
	    break;
	 default:
            YAC_Object::yacOperator(_cmd,_o,_r);
      }
   }
}

void _Matrix3f::yacOperatorI(sSI _cmd, sSI val, YAC_Value *_r) {
   yacOperatorF32(_cmd, (sF32)val, _r);
}

void _Matrix3f::yacOperatorF32(sSI _cmd, sF32 val, YAC_Value *_r) {
   switch (_cmd) {
      case YAC_OP_MUL:
         _mulf_YAC_RSELF(val);
         break;
      case YAC_OP_DIV:
         if (Dfltnonzero(val)) {
            _mulf_YAC_RSELF(1.0f/val);
         } else {
            Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::yacOperatorF32 OP_DIV Cannot divide by zero");
         }
         break;
      default:
         char buf[256];
         sprintf(buf,"tkmath::Matrix3f::yacOperatorF32 Operator not supported %d",_cmd);
         Dyac_throw_def(TkMathUnsupportedOperator,buf);
   }
}

void _Matrix3f::assignFloats(sF32 *_fv, sUI _ne) {
   if(_ne != 9) {
      Dyac_throw_def(WriteArrayOutOfBounds,"tkmath::Matrix3f Array not of size 9");
   } else {
      // Copy two elements
      floats[0] = _fv[0];
      floats[1] = _fv[1];
      floats[2] = _fv[2];
      floats[3] = _fv[3];
      floats[4] = _fv[4];
      floats[5] = _fv[5];
      floats[6] = _fv[6];
      floats[7] = _fv[7];
      floats[8] = _fv[8];
   }
}

void _Matrix3f::assignFloatArray(YAC_FloatArray *_fa) {
   assignFloats(_fa->elements, _fa->num_elements);
}

void _Matrix3f::assignGeneric(YAC_ContextHandle _ctx, YAC_Object *_o) {
   sUI ne = _o->yacArrayGetNumElements();
   sUI nH = _o->yacArrayGetHeight();
   sUI nW = _o->yacArrayGetWidth();
   if (nH==0) {
      if (nW==9) { //exact number to fill the matrix - we con go on
         nH=3;
         nW=3;
      } else { //nah, throw an exception
         Dyac_throw_def(TkMathInvalidValue,"tkmath::Matrix3f Array not of size 9");
      }
   }
   if(ne > 0)
   {
      if(YAC_TYPE_FLOAT == _o->yacArrayGetElementType())
      {
         sF32 *fv = (sF32*) _o->yacArrayGetPointer();
         if(NULL != fv)
         {
            // Copy fast
            sUI i,j;
            for (i=0;(i<3)&&(i<nH);i++) {
               for (j=0;(j<3)&&(j<nW);j++) {
                  floats[(i*3)+j]=fv[(i*nW)+j];
               }
               for (;j<3;j++) {
                  if (i!=j) floats[(i*3)+j]=0.0f;
		  else floats[(i*3)+j]=1.0f;
               }
            }
            for (;(i<3);i++) {
               for (j=0;j<3;j++) {
                  if (i!=j) floats[(i*3)+j]=0.0f;
		  else floats[(i*3)+j]=1.0f;
               }
            }

            return;
         }
         else
         {
            // Retrieve individual float elements and assign
            YAC_Value v;
            sUI i,j;
            for (i=0;(i<3)&&(i<nH);i++) {
               for (j=0;(j<3)&&(j<nW);j++) {
                  _o->yacArrayGet(_ctx, (i*nW)+j, &v);
                  floats[(i*3)+j]=v.value.float_val;
               }
               for (;j<3;j++) {
                  if (i!=j) floats[(i*3)+j]=0.0f;
		  else floats[(i*3)+j]=1.0f;
               }
            }
            for (;(i<3);i++) {
               for (j=0;j<3;j++) {
                  if (i!=j) floats[(i*3)+j]=0.0f;
		  else floats[(i*3)+j]=1.0f;
               }
            }
         }
      }
      else
      {
         // Retrieve individual elements, typecast to float and assign
         YAC_Value v;
         sUI i,j;
         for (i=0;(i<3)&&(i<nH);i++) {
            for (j=0;(j<3)&&(j<nW);j++) {
               _o->yacArrayGet(_ctx, (i*nW)+j, &v);
               v.typecast(YAC_TYPE_FLOAT);
               floats[(i*3)+j]=v.value.float_val;
               v.unset();
            }
            for (;j<3;j++) {
               if (i!=j) floats[(i*3)+j]=0.0f;
	       else floats[(i*3)+j]=1.0f;
            }
         }
         for (;(i<3);i++) {
            for (j=0;j<3;j++) {
               if (i!=j) floats[(i*3)+j]=0.0f;
	       else floats[(i*3)+j]=1.0f;
            }
         }
      }
   }
   else
   {
      // Other array is empty or no array. Silently assign 0.0f
      floats[0] = floats[1] = floats[2]=floats[3]=floats[4]=floats[5]=floats[6]=floats[7]=floats[8]= 0.0f;
   }
}


//direct access methods
void _Matrix3f::_setA(sF32 x) {
   floats[0]=x;
}

void _Matrix3f::_setB(sF32 y) {
   floats[1]=y;
}

void _Matrix3f::_setC(sF32 x) {
   floats[2]=x;
}

void _Matrix3f::_setD(sF32 y) {
   floats[3]=y;
}

void _Matrix3f::_setE(sF32 y) {
   floats[4]=y;
}

void _Matrix3f::_setF(sF32 y) {
   floats[5]=y;
}

void _Matrix3f::_setG(sF32 y) {
   floats[6]=y;
}

void _Matrix3f::_setH(sF32 y) {
   floats[7]=y;
}

void _Matrix3f::_setI(sF32 y) {
   floats[8]=y;
}

sF32 _Matrix3f::_getA(void) {
   return floats[0];
}

sF32 _Matrix3f::_getB(void) {
   return floats[1];
}

sF32 _Matrix3f::_getC(void) {
   return floats[2];
}

sF32 _Matrix3f::_getD(void) {
   return floats[3];
}

sF32 _Matrix3f::_getE(void) {
   return floats[4];
}

sF32 _Matrix3f::_getF(void) {
   return floats[5];
}

sF32 _Matrix3f::_getG(void) {
   return floats[6];
}

sF32 _Matrix3f::_getH(void) {
   return floats[7];
}

sF32 _Matrix3f::_getI(void) {
   return floats[8];
}

//generate string representation
sBool YAC_VCALL _Matrix3f::yacToString(YAC_String *s) const {
   s->yacArrayAlloc(1024,0,0,0);
   s->printf("((%g, %g, %g), (%g, %g, %g), (%g, %g, %g))",
      floats[0],floats[1],floats[2],
      floats[3],floats[4],floats[5],
      floats[6],floats[7],floats[8]);
   s->fixLength();
   return 1;
}

void _Matrix3f::_getString(YAC_Value *_r) const {
   YAC_String *s = (YAC_String*) YAC_NEW_CORE_POOLED(YAC_CLID_STRING);
   yacToString(s);
   YAC_RETS(s,1);
}

//add two matrices
void _Matrix3f::_add_YAC_RSELF(YAC_Object *_o) {
   if (YAC_CHK(_o,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      floats[0]+=o->floats[0];
      floats[1]+=o->floats[1];
      floats[2]+=o->floats[2];
      floats[3]+=o->floats[3];
      floats[4]+=o->floats[4];
      floats[5]+=o->floats[5];
      floats[6]+=o->floats[6];
      floats[7]+=o->floats[7];
      floats[8]+=o->floats[8];
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::add_SELF Object not of type Matrix3f");
   }
}

void _Matrix3f::_add_YAC_RVAL(YAC_Object *_o, YAC_Value *_r) {
   if (YAC_CHK(_o,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
      r->floats[0] = floats[0] + o->floats[0];
      r->floats[1] = floats[1] + o->floats[1];
      r->floats[2] = floats[2] + o->floats[2];
      r->floats[3] = floats[3] + o->floats[3];
      r->floats[4] = floats[4] + o->floats[4];
      r->floats[5] = floats[5] + o->floats[5];
      r->floats[6] = floats[6] + o->floats[6];
      r->floats[7] = floats[7] + o->floats[7];
      r->floats[8] = floats[8] + o->floats[8];
      _r->initObject(r,1);
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::add_VAL Object not of type Matrix3f");
   }
}

void _Matrix3f::_add_YAC_RARG(YAC_Object *_o, YAC_Object *_r) {
   if (YAC_CHK(_o,clid_Matrix3f)&&YAC_CHK(_r,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      _Matrix3f *r=(_Matrix3f*)_r;
      r->floats[0] = floats[0] + o->floats[0];
      r->floats[1] = floats[1] + o->floats[1];
      r->floats[2] = floats[2] + o->floats[2];
      r->floats[3] = floats[3] + o->floats[3];
      r->floats[4] = floats[4] + o->floats[4];
      r->floats[5] = floats[5] + o->floats[5];
      r->floats[6] = floats[6] + o->floats[6];
      r->floats[7] = floats[7] + o->floats[7];
      r->floats[8] = floats[8] + o->floats[8];
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::add_ARG Object not of type Matrix3f");
   }
}

//sub two matrices
void _Matrix3f::_sub_YAC_RSELF(YAC_Object *_o) {
   if (YAC_CHK(_o,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      floats[0]-=o->floats[0];
      floats[1]-=o->floats[1];
      floats[2]-=o->floats[2];
      floats[3]-=o->floats[3];
      floats[4]-=o->floats[4];
      floats[5]-=o->floats[5];
      floats[6]-=o->floats[6];
      floats[7]-=o->floats[7];
      floats[8]-=o->floats[8];
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::sub_SELF Object not of type Matrix3f");
   }
}

void _Matrix3f::_sub_YAC_RVAL(YAC_Object *_o, YAC_Value *_r) {
   if (YAC_CHK(_o,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
      r->floats[0] = floats[0] - o->floats[0];
      r->floats[1] = floats[1] - o->floats[1];
      r->floats[2] = floats[2] - o->floats[2];
      r->floats[3] = floats[3] - o->floats[3];
      r->floats[4] = floats[4] - o->floats[4];
      r->floats[5] = floats[5] - o->floats[5];
      r->floats[6] = floats[6] - o->floats[6];
      r->floats[7] = floats[7] - o->floats[7];
      r->floats[8] = floats[8] - o->floats[8];
      _r->initObject(r,1);
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::sub_VAL Object not of type Matrix3f");
   }
}

void _Matrix3f::_sub_YAC_RARG(YAC_Object *_o, YAC_Object *_r) {
   if (YAC_CHK(_o,clid_Matrix3f)&&YAC_CHK(_r,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      _Matrix3f *r=(_Matrix3f*)_r;
      r->floats[0] = floats[0] - o->floats[0];
      r->floats[1] = floats[1] - o->floats[1];
      r->floats[2] = floats[2] - o->floats[2];
      r->floats[3] = floats[3] - o->floats[3];
      r->floats[4] = floats[4] - o->floats[4];
      r->floats[5] = floats[5] - o->floats[5];
      r->floats[6] = floats[6] - o->floats[6];
      r->floats[7] = floats[7] - o->floats[7];
      r->floats[8] = floats[8] - o->floats[8];
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::sub_ARG Object not of type Matrix3f");
   }
}

//multiply matrix with scalar
void _Matrix3f::_mulf_YAC_RSELF(sF32 s) {
   floats[0]*=s;
   floats[1]*=s;
   floats[2]*=s;
   floats[3]*=s;
   floats[4]*=s;
   floats[5]*=s;
   floats[6]*=s;
   floats[7]*=s;
   floats[8]*=s;
}

void _Matrix3f::_mulf_YAC_RVAL(sF32 s, YAC_Value *_r) {
   _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
   r->floats[0] = floats[0] * s;
   r->floats[1] = floats[1] * s;
   r->floats[2] = floats[2] * s;
   r->floats[3] = floats[3] * s;
   r->floats[4] = floats[4] * s;
   r->floats[5] = floats[5] * s;
   r->floats[6] = floats[6] * s;
   r->floats[7] = floats[7] * s;
   r->floats[8] = floats[8] * s;
   _r->initObject(r,1);
}

void _Matrix3f::_mulf_YAC_RARG(sF32 s, YAC_Object *_r) {
   if (YAC_CHK(_r, clid_Matrix3f)) {
      _Matrix3f *r=(_Matrix3f*)_r;
      r->floats[0] = floats[0] * s;
      r->floats[1] = floats[1] * s;
      r->floats[2] = floats[2] * s;
      r->floats[3] = floats[3] * s;
      r->floats[4] = floats[4] * s;
      r->floats[5] = floats[5] * s;
      r->floats[6] = floats[6] * s;
      r->floats[7] = floats[7] * s;
      r->floats[8] = floats[8] * s;
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::mulf_ARG Return object not of type Matrix3f");
   }
}

//multiply two matrices
void _Matrix3f::_mul_YAC_RSELF(YAC_Object *_o) {
   if (YAC_CHK(_o,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      sF32 a,b,c,d,e,f,g,h,i;
      a=floats[0]*o->floats[0]+floats[1]*o->floats[3]+floats[2]*o->floats[6];
      b=floats[0]*o->floats[1]+floats[1]*o->floats[4]+floats[2]*o->floats[7];
      c=floats[0]*o->floats[2]+floats[1]*o->floats[5]+floats[2]*o->floats[8];
      d=floats[3]*o->floats[0]+floats[4]*o->floats[3]+floats[5]*o->floats[6];
      e=floats[3]*o->floats[1]+floats[4]*o->floats[4]+floats[5]*o->floats[7];
      f=floats[3]*o->floats[2]+floats[4]*o->floats[5]+floats[5]*o->floats[8];
      g=floats[6]*o->floats[0]+floats[7]*o->floats[3]+floats[8]*o->floats[6];
      h=floats[6]*o->floats[1]+floats[7]*o->floats[4]+floats[8]*o->floats[7];
      i=floats[6]*o->floats[2]+floats[7]*o->floats[5]+floats[8]*o->floats[8];
      floats[0]=a;
      floats[1]=b;
      floats[2]=c;
      floats[3]=d;
      floats[4]=e;
      floats[5]=f;
      floats[6]=g;
      floats[7]=h;
      floats[8]=i;
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::mul_SELF Object not of type Matrix3f!\n");
   }
}

void _Matrix3f::_mul_YAC_RVAL(YAC_Object *_o, YAC_Value *_r) {
   if (YAC_CHK(_o,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
      r->floats[0]=floats[0]*o->floats[0]+floats[1]*o->floats[3]+floats[2]*o->floats[6];
      r->floats[1]=floats[0]*o->floats[1]+floats[1]*o->floats[4]+floats[2]*o->floats[7];
      r->floats[2]=floats[0]*o->floats[2]+floats[1]*o->floats[5]+floats[2]*o->floats[8];
      r->floats[3]=floats[3]*o->floats[0]+floats[4]*o->floats[3]+floats[5]*o->floats[6];
      r->floats[4]=floats[3]*o->floats[1]+floats[4]*o->floats[4]+floats[5]*o->floats[7];
      r->floats[5]=floats[3]*o->floats[2]+floats[4]*o->floats[5]+floats[5]*o->floats[8];
      r->floats[6]=floats[6]*o->floats[0]+floats[7]*o->floats[3]+floats[8]*o->floats[6];
      r->floats[7]=floats[6]*o->floats[1]+floats[7]*o->floats[4]+floats[8]*o->floats[7];
      r->floats[8]=floats[6]*o->floats[2]+floats[7]*o->floats[5]+floats[8]*o->floats[8];
      _r->initObject(r,1);
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::mul_VAL Object not of type Matrix3f!\n");
   }
}

void _Matrix3f::_mul_YAC_RARG(YAC_Object *_o, YAC_Object *_r) {
   if (YAC_CHK(_o,clid_Matrix3f)&&YAC_CHK(_r,clid_Matrix3f)) {
      _Matrix3f *o=(_Matrix3f*)_o;
      _Matrix3f *r=(_Matrix3f*)_r;
      r->floats[0]=floats[0]*o->floats[0]+floats[1]*o->floats[3]+floats[2]*o->floats[6];
      r->floats[1]=floats[0]*o->floats[1]+floats[1]*o->floats[4]+floats[2]*o->floats[7];
      r->floats[2]=floats[0]*o->floats[2]+floats[1]*o->floats[5]+floats[2]*o->floats[8];
      r->floats[3]=floats[3]*o->floats[0]+floats[4]*o->floats[3]+floats[5]*o->floats[6];
      r->floats[4]=floats[3]*o->floats[1]+floats[4]*o->floats[4]+floats[5]*o->floats[7];
      r->floats[5]=floats[3]*o->floats[2]+floats[4]*o->floats[5]+floats[5]*o->floats[8];
      r->floats[6]=floats[6]*o->floats[0]+floats[7]*o->floats[3]+floats[8]*o->floats[6];
      r->floats[7]=floats[6]*o->floats[1]+floats[7]*o->floats[4]+floats[8]*o->floats[7];
      r->floats[8]=floats[6]*o->floats[2]+floats[7]*o->floats[5]+floats[8]*o->floats[8];
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::mul_ARG Object not of type Matrix3f!\n");
   }
}

//multiply matrix with vector
void _Matrix3f::_mulv_YAC_RVAL(YAC_Object *_o, YAC_Value *_r) {
   if (YAC_CHK(_o,clid_Vector3f)) {
      _Vector3f *o=(_Vector3f*)_o;
      _Vector3f *r=YAC_NEW_POOLED(Vector3f);
      r->floats[0]=floats[0]*o->floats[0]+floats[1]*o->floats[1]+floats[2]*o->floats[2];
      r->floats[1]=floats[3]*o->floats[0]+floats[4]*o->floats[1]+floats[5]*o->floats[2];
      r->floats[2]=floats[6]*o->floats[0]+floats[7]*o->floats[1]+floats[8]*o->floats[2];
      _r->initObject(r,1);
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::mulv Object not of type Vector3f");
   }
}

void _Matrix3f::_mulv_YAC_RARG(YAC_Object *_o, YAC_Object *_r) {
   if (YAC_CHK(_o,clid_Vector3f)&&(YAC_CHK(_r,clid_Vector3f))) {
      _Vector3f *o=(_Vector3f*)_o;
      _Vector3f *r=(_Vector3f*)_r;
      r->floats[0]=floats[0]*o->floats[0]+floats[1]*o->floats[1]+floats[2]*o->floats[2];
      r->floats[1]=floats[3]*o->floats[0]+floats[4]*o->floats[1]+floats[5]*o->floats[2];
      r->floats[2]=floats[6]*o->floats[0]+floats[7]*o->floats[1]+floats[8]*o->floats[2];
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::mulv Object not of type Vector3f");
   }
}

//get "length" of matrix
sF32 _Matrix3f::_getAbs(void) {
   return sqrtf(floats[0]*floats[0]+floats[1]*floats[1]+floats[2]*floats[2]+
         floats[3]*floats[3]+floats[4]*floats[4]+floats[5]*floats[5]+
         floats[6]*floats[6]+floats[7]*floats[7]+floats[8]*floats[8]);
}

//get squared "length" of matrix
sF32 _Matrix3f::_getAbsSqr(void) {
   return (floats[0]*floats[0]+floats[1]*floats[1]+floats[2]*floats[2]+
      floats[3]*floats[3]+floats[4]*floats[4]+floats[5]*floats[5]+
      floats[6]*floats[6]+floats[7]*floats[7]+floats[8]*floats[8]);
}

//scale "length" of matrix to 1
void _Matrix3f::_unit_YAC_RSELF(void) {
   sF32 absval=_getAbs();
   if (Dfltnonzero(absval)) {
      absval=1.0f/absval;
      floats[0]*=absval;
      floats[1]*=absval;
      floats[2]*=absval;
      floats[3]*=absval;
      floats[4]*=absval;
      floats[5]*=absval;
      floats[6]*=absval;
      floats[7]*=absval;
      floats[8]*=absval;
   } else {
      Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::unit_SELF Zero Matrix cannot be normalized!\n");
   }
}

void _Matrix3f::_unit_YAC_RVAL(YAC_Value *_r) {
   sF32 absval=_getAbs();
   if (Dfltnonzero(absval)) {
      _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
      absval=1.0f/absval;
      r->floats[0] = floats[0] * absval;
      r->floats[1] = floats[1] * absval;
      r->floats[2] = floats[2] * absval;
      r->floats[3] = floats[3] * absval;
      r->floats[4] = floats[4] * absval;
      r->floats[5] = floats[5] * absval;
      r->floats[6] = floats[6] * absval;
      r->floats[7] = floats[7] * absval;
      r->floats[8] = floats[8] * absval;
      _r->initObject(r,1);
   } else {
      Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::unit_VAL Zero Matrix cannot be normalized!\n");
   }
}

void _Matrix3f::_unit_YAC_RARG(YAC_Object *_r) {
   if (YAC_CHK(_r, clid_Matrix3f)) {
      sF32 absval=_getAbs();
      if (Dfltnonzero(absval)) {
         _Matrix3f *r=(_Matrix3f*)_r;
         absval=1.0f/absval;
         r->floats[0] = floats[0] * absval;
         r->floats[1] = floats[1] * absval;
         r->floats[2] = floats[2] * absval;
         r->floats[3] = floats[3] * absval;
         r->floats[4] = floats[4] * absval;
         r->floats[5] = floats[5] * absval;
         r->floats[6] = floats[6] * absval;
         r->floats[7] = floats[7] * absval;
         r->floats[8] = floats[8] * absval;
      } else {
         Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::unit_SELF Zero Matrix cannot be normalized!\n");
      }
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::unit_ARG Return object not of type Matrix3f");
   }
}

//scale "length" of matrix to s
void _Matrix3f::_unitScale_YAC_RSELF(sF32 s) {
   sF32 absval=_getAbs();
   if (Dfltnonzero(absval)) {
      absval=s/absval;
      floats[0]*=absval;
      floats[1]*=absval;
      floats[2]*=absval;
      floats[3]*=absval;
      floats[4]*=absval;
      floats[5]*=absval;
      floats[6]*=absval;
      floats[7]*=absval;
      floats[8]*=absval;
   } else {
      Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::unitScale_SELF Zero Matrix cannot be normalized");
   }
}

void _Matrix3f::_unitScale_YAC_RVAL(sF32 s, YAC_Value *_r) {
   sF32 absval=_getAbs();
   if (Dfltnonzero(absval)) {
      _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
      absval=s/absval;
      r->floats[0] = floats[0] * absval;
      r->floats[1] = floats[1] * absval;
      r->floats[2] = floats[2] * absval;
      r->floats[3] = floats[3] * absval;
      r->floats[4] = floats[4] * absval;
      r->floats[5] = floats[5] * absval;
      r->floats[6] = floats[6] * absval;
      r->floats[7] = floats[7] * absval;
      r->floats[8] = floats[8] * absval;
      _r->initObject(r,1);
   } else {
      Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::unitScale_VAL Zero Matrix cannot be normalized");
   }
}

void _Matrix3f::_unitScale_YAC_RARG(sF32 s, YAC_Object *_r) {
   if (YAC_CHK(_r,clid_Matrix3f)) {
      sF32 absval=_getAbs();
      if (Dfltnonzero(absval)) {
         _Matrix3f *r=(_Matrix3f*)_r;
         absval=s/absval;
         r->floats[0] = floats[0] * absval;
         r->floats[1] = floats[1] * absval;
         r->floats[2] = floats[2] * absval;
         r->floats[3] = floats[3] * absval;
         r->floats[4] = floats[4] * absval;
         r->floats[5] = floats[5] * absval;
         r->floats[6] = floats[6] * absval;
         r->floats[7] = floats[7] * absval;
         r->floats[8] = floats[8] * absval;
      } else {
         Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::unitScale_ARG Zero Matrix cannot be normalized");
      }
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::unitScale_ARG Return object not of type Matrix3f");
   }
}

//return determinant of matrix
sF32 _Matrix3f::_det(void) {
   return (floats[0]*floats[4]*floats[8]
      +floats[1]*floats[5]*floats[6]
      +floats[2]*floats[3]*floats[7]
      -floats[2]*floats[4]*floats[6]
      -floats[0]*floats[5]*floats[7]
      -floats[1]*floats[3]*floats[8]);
}

//invert matrix
void _Matrix3f::_invert_YAC_RSELF(void) {
   sF32 detval=_det();
   if (Dfltnonzero(detval)) {
      sF32 a,b,c,d,e,f,g,h,i;
      a=(floats[4]*floats[8]-floats[5]*floats[7])/detval;
      b=(floats[2]*floats[7]-floats[1]*floats[8])/detval;
      c=(floats[1]*floats[5]-floats[2]*floats[4])/detval;
      d=(floats[5]*floats[6]-floats[3]*floats[8])/detval;
      e=(floats[0]*floats[8]-floats[2]*floats[6])/detval;
      f=(floats[2]*floats[3]-floats[0]*floats[5])/detval;
      g=(floats[3]*floats[7]-floats[4]*floats[6])/detval;
      h=(floats[1]*floats[6]-floats[0]*floats[7])/detval;
      i=(floats[0]*floats[4]-floats[1]*floats[3])/detval;
      floats[0]=a;
      floats[1]=b;
      floats[2]=c;
      floats[3]=d;
      floats[4]=e;
      floats[5]=f;
      floats[6]=g;
      floats[7]=h;
      floats[8]=i;
   } else {
      Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::invert_SELF Invalid Matrix (det==0)");
   }
}

void _Matrix3f::_invert_YAC_RVAL(YAC_Value *_r) {
   sF32 detval=_det();
   if (Dfltnonzero(detval)) {
      _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
      r->floats[0]=(floats[4]*floats[8]-floats[5]*floats[7])/detval;
      r->floats[1]=(floats[2]*floats[7]-floats[1]*floats[8])/detval;
      r->floats[2]=(floats[1]*floats[5]-floats[2]*floats[4])/detval;
      r->floats[3]=(floats[5]*floats[6]-floats[3]*floats[8])/detval;
      r->floats[4]=(floats[0]*floats[8]-floats[2]*floats[6])/detval;
      r->floats[5]=(floats[2]*floats[3]-floats[0]*floats[5])/detval;
      r->floats[6]=(floats[3]*floats[7]-floats[4]*floats[6])/detval;
      r->floats[7]=(floats[1]*floats[6]-floats[0]*floats[7])/detval;
      r->floats[8]=(floats[0]*floats[4]-floats[1]*floats[3])/detval;
      _r->initObject(r,1);
   } else {
      Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::invert_VAL Invalid Matrix (det==0)");
   }
}

void _Matrix3f::_invert_YAC_RARG(YAC_Object *_r) {
   if (YAC_CHK(_r,clid_Matrix3f)) {
      sF32 detval=_det();
      if (Dfltnonzero(detval)) {
         _Matrix3f *r=(_Matrix3f*)_r;
         r->floats[0]=(floats[4]*floats[8]-floats[5]*floats[7])/detval;
         r->floats[1]=(floats[2]*floats[7]-floats[1]*floats[8])/detval;
         r->floats[2]=(floats[1]*floats[5]-floats[2]*floats[4])/detval;
         r->floats[3]=(floats[5]*floats[6]-floats[3]*floats[8])/detval;
         r->floats[4]=(floats[0]*floats[8]-floats[2]*floats[6])/detval;
         r->floats[5]=(floats[2]*floats[3]-floats[0]*floats[5])/detval;
         r->floats[6]=(floats[3]*floats[7]-floats[4]*floats[6])/detval;
         r->floats[7]=(floats[1]*floats[6]-floats[0]*floats[7])/detval;
         r->floats[8]=(floats[0]*floats[4]-floats[1]*floats[3])/detval;
      } else {
         Dyac_throw_def(TkMathDivisionByZero, "tkmath::Matrix3f::invert_ARG Invalid Matrix (det==0)");
      }
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::invert_ARG Return object not of type Matrix3f");
   }
}

//transpose/mirror matrix
void _Matrix3f::_transpose_YAC_RSELF(void) {
   sF32 a,b,c;
   a=floats[1];
   b=floats[2];
   c=floats[5];
   floats[1]=floats[3];
   floats[2]=floats[6];
   floats[5]=floats[7];
   floats[3]=a;
   floats[6]=b;
   floats[7]=c;
}

void _Matrix3f::_transpose_YAC_RVAL(YAC_Value *_r) {
   _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
   r->floats[0]=floats[0]; r->floats[1]=floats[3]; r->floats[2]=floats[6];
   r->floats[3]=floats[1]; r->floats[4]=floats[4]; r->floats[5]=floats[7];
   r->floats[6]=floats[2]; r->floats[7]=floats[5]; r->floats[8]=floats[8];
   _r->initObject(r,1);
}

void _Matrix3f::_transpose_YAC_RARG(YAC_Object *_r) {
   if (YAC_CHK(_r,clid_Matrix3f)) {
      _Matrix3f *r=(_Matrix3f*)_r;
      r->floats[0]=floats[0]; r->floats[1]=floats[3]; r->floats[2]=floats[6];
      r->floats[3]=floats[1]; r->floats[4]=floats[4]; r->floats[5]=floats[7];
      r->floats[6]=floats[2]; r->floats[7]=floats[5]; r->floats[8]=floats[8];
   } else {
      Dyac_throw_def(NativeClassTypeMismatch, "tkmath::Matrix3f::tranpose_ARG Return object not of type Matrix3f");
   }
}

void _Matrix3f::_setRow(sUI row, YAC_Object *_o) {
   _initRowV(row,_o);
}

void _Matrix3f::_getRow_YAC_RVAL(sUI row, YAC_Value *_r) {
   if (row>2) {
         static char buf[256];
         sprintf(buf, "tkmath::Matrix3f::getRow_VAL Wrong Row Number! (%d>2)\n", row);
         Dyac_throw_def(WriteArrayOutOfBounds, buf);
   }
   _Vector3f *r=YAC_NEW_POOLED(Vector3f);
   r->_init(floats[(row*3)+0],floats[(row*3)+1],floats[(row*3)+2]);
   _r->initObject(r,1);
}

void _Matrix3f::_getRow_YAC_RARG(sUI row, YAC_Object *_r) {
   if (row>2) {
         static char buf[256];
         sprintf(buf, "tkmath::Matrix3f::getRow_ARG Wrong Row Number! (%d>2)\n", row);
         Dyac_throw_def(WriteArrayOutOfBounds, buf);
   }
   if (!YAC_CHK(_r,clid_Vector3f)) {
      Dyac_throw_def(NativeClassTypeMismatch,"tkmath::Matrix3f::getRow_ARG Return object not of type Vector3f");
   }
   _Vector3f *r=(_Vector3f*)_r;
   r->_init(floats[(row*3)+0],floats[(row*3)+1],floats[(row*3)+2]);
}

void _Matrix3f::_setCol(sUI col, YAC_Object *_o) {
   _initColV(col,_o);
}


void _Matrix3f::_getCol_YAC_RVAL(sUI col, YAC_Value *_r) {
   if (col>2) {
         static char buf[256];
         sprintf(buf, "tkmath::Matrix3f::getCol_VAL Wrong Row Number! (%d>2)\n", col);
         Dyac_throw_def(WriteArrayOutOfBounds, buf);
   }
   _Vector3f *r=YAC_NEW_POOLED(Vector3f);
   r->_init(floats[0+col],floats[3+col],floats[6+col]);
   _r->initObject(r,1);
}

void _Matrix3f::_getCol_YAC_RARG(sUI col, YAC_Object *_r) {
   if (col>2) {
         static char buf[256];
         sprintf(buf, "tkmath::Matrix3f::getCol_ARG Wrong Row Number! (%d>2)\n", col);
         Dyac_throw_def(WriteArrayOutOfBounds, buf);
   }
   if (!YAC_CHK(_r,clid_Vector3f)) {
      Dyac_throw_def(NativeClassTypeMismatch,"tkmath::Matrix3f::getCol_ARG Return object not of type Vector3f");
   }
   _Vector3f *r=(_Vector3f*)_r;
   r->_init(floats[0+col],floats[3+col],floats[6+col]);
}

//initialisation methods
void _Matrix3f::_init(sF32 a, sF32 b, sF32 c, sF32 d, sF32 e, sF32 f, sF32 g, sF32 h, sF32 i) {
   floats[0]=a;
   floats[1]=b;
   floats[2]=c;
   floats[3]=d;
   floats[4]=e;
   floats[5]=f;
   floats[6]=g;
   floats[7]=h;
   floats[8]=i;
}

void _Matrix3f::_initRow(sUI row, sF32 x, sF32 y, sF32 z) {
   if (row<3) {
      floats[row*3]=x;
      floats[row*3+1]=y;
      floats[row*3+2]=z;
   } else {
      static char buf[256];
      sprintf(buf, "tkmath::Matrix3f::initRow Wrong Row Number! (%d>2)", row);
      Dyac_throw_def(WriteArrayOutOfBounds, buf);
   }
}

void _Matrix3f::_initCol(sUI col, sF32 x, sF32 y, sF32 z) {
   if (col<3) {
      floats[col]=x;
      floats[col+3]=y;
      floats[col+6]=z;
   } else {
      static char buf[256];
      sprintf(buf, "tkmath::Matrix3f::initCol Wrong Col Number! (%d>2)\n", col);
      Dyac_throw_def(WriteArrayOutOfBounds, buf);
   }
}

void _Matrix3f::_initRowV(sUI row, YAC_Object *_o) {
   if (YAC_VALID(_o)) {
      _Vector3f t;
      t.class_ID=clid_Vector3f;
      t.assignGeneric(NULL,_o);
      if (row>2) {
         static char buf[256];
         sprintf(buf, "tkmath::Matrix3f::initRowV Wrong Row Number! (%d>2)\n", row);
         Dyac_throw_def(WriteArrayOutOfBounds, buf);
      }
      floats[(row*3)+0]=t.floats[0];
      floats[(row*3)+1]=t.floats[1];
      floats[(row*3)+2]=t.floats[2];
   } else {
      Dyac_throw_def(TkMathInvalidValue,"tkmath::Matrix3f::initRowV: Invalid Object Value");
   }
}

void _Matrix3f::_initColV(sUI col, YAC_Object *_o) {
   if (YAC_VALID(_o)) {
      _Vector3f t;
      t.class_ID=clid_Vector3f;
      t.assignGeneric(NULL,_o);
      if (col>2) {
         static char buf[256];
         sprintf(buf, "tkmath::Matrix3f::initColV Wrong Col Number! (%d>2)\n", col);
         Dyac_throw_def(WriteArrayOutOfBounds, buf);
      }
      floats[0+col]=t.floats[0];
      floats[3+col]=t.floats[1];
      floats[6+col]=t.floats[2];
   } else {
      Dyac_throw_def(TkMathInvalidValue,"tkmath::Matrix3f::initColV: Invalid Object Value");
   }
}

void _Matrix3f::_initIdentity(void) {
   floats[ 0] = 1.0f;
   floats[ 1] = 0.0f;
   floats[ 2] = 0.0f;

   floats[ 3] = 0.0f;
   floats[ 4] = 1.0f;
   floats[ 5] = 0.0f;

   floats[ 6] = 0.0f;
   floats[ 7] = 0.0f;
   floats[ 8] = 1.0f;
}

void _Matrix3f::_New(sF32 a, sF32 b, sF32 c, sF32 d, sF32 e, sF32 f, sF32 g, sF32 h, sF32 i, YAC_Value *_r) {
   _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
   r->_init(a,b,c,d,e,f,g,h,i);
   _r->initObject(r,1);
}

void YAC_CALL _matrix3f(sF32 a, sF32 b, sF32 c, sF32 d, sF32 e, sF32 f, sF32 g, sF32 h, sF32 i, YAC_Value *_r) {
   _Matrix3f *r=YAC_NEW_POOLED(Matrix3f);
   r->_init(a,b,c,d,e,f,g,h,i);
   _r->initObject(r,1);
}
