Ooops
November 25, 2020, 07:44:43 AM

Author Topic: [bb] TForm Vector by Bobysait [ 1+ years ago ]  (Read 616 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] TForm Vector by Bobysait [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : TForm Vector
Author : Bobysait
Posted : 1+ years ago

Description : It makes the same as the original TFormVector function
It's just here for purpose and to explain how blitz3d matrix works with transformation

I won't replace the TFormNormal as it is the same except it use a VectorMag to normalize the vector.
For eg: juste use TFormVector_ Vx,Vy,Vz,Source,Dest
Vx# = TFormedX_()
Vy# = TFormedY_()
Vz# = TFormedZ_()


Code :
Code: BlitzBasic
  1. Global TFormedX_#=0.0
  2. Global TFormedY_#=0.0
  3. Global TFormedZ_#=0.0
  4.  
  5. Function TFormedX_#() Return TFormedX_ End Function
  6. Function TFormedY_#() Return TFormedY_ End Function
  7. Function TFormedZ_#() Return TFormedZ_ End Function
  8.  
  9. Function TFormVector_ ( x#, y#, z#, source=0, dest=0 )
  10.        
  11.         TFormedX_ = x;
  12.         TFormedY_ = y;
  13.         TFormedZ_ = z;
  14.        
  15.         If (source<>0)
  16.                 Local xx# = GetMatElement(source,0,0);
  17.                 Local xy# = GetMatElement(source,0,1);
  18.                 Local xz# = GetMatElement(source,0,2);
  19.                 Local yx# = GetMatElement(source,1,0);
  20.                 Local yy# = GetMatElement(source,1,1);
  21.                 Local yz# = GetMatElement(source,1,2);
  22.                 Local zx# = GetMatElement(source,2,0);
  23.                 Local zy# = GetMatElement(source,2,1);
  24.                 Local zz# = GetMatElement(source,2,2);
  25.                 TFormedX_ = x * xx + y * yx + z * zx;
  26.                 TFormedY_ = x * xy + y * yy + z * zy;
  27.                 TFormedZ_ = x * xz + y * yz + z * zz;
  28.         EndIf
  29.        
  30.         If (dest<>0)
  31.                 ; invert destination matrix
  32.                 xx# = GetMatElement(dest,0,0);
  33.                 xy# = GetMatElement(dest,0,1);
  34.                 xz# = GetMatElement(dest,0,2);
  35.                 yx# = GetMatElement(dest,1,0);
  36.                 yy# = GetMatElement(dest,1,1);
  37.                 yz# = GetMatElement(dest,1,2);
  38.                 zx# = GetMatElement(dest,2,0);
  39.                 zy# = GetMatElement(dest,2,1);
  40.                 zz# = GetMatElement(dest,2,2);
  41.                 Local x_# = xy*yz-xz*yy;
  42.                 Local y_# = xz*yx-xx*yz;
  43.                 Local z_# = xx*yy-xy*yx;
  44.                 Local t_# = 1.0 / (zx*x_+zy*y_+zz*z_);
  45.                 Local xz_# = t_*x_ ;
  46.                 Local yz_# = t_*y_ ;
  47.                 Local zz_# = t_*z_ ;
  48.                 x_ = yy*zz-yz*zy;
  49.                 y_ = zx*yz-yx*zz;
  50.                 z_ = yx*zy-yy*zx;
  51.                 Local xx_# = t_*x_ ;
  52.                 Local yx_# = t_*y_ ;
  53.                 Local zx_# = t_*z_ ;
  54.                 x_ = zy*xz-zz*xy;
  55.                 y_ = xx*zz-zx*xz;
  56.                 z_ = zx*xy-zy*xx;
  57.                 Local xy_# = t_*x_ ;
  58.                 Local yy_# = t_*y_ ;
  59.                 Local zy_# = t_*z_ ;
  60.                
  61.                 x_ = TFormedX_;
  62.                 y_ = TFormedY_;
  63.                 z_ = TFormedZ_;
  64.                 TFormedX_ = x_ * xx_ + y_ * yx_ + z_ * zx_;
  65.                 TFormedY_ = x_ * xy_ + y_ * yy_ + z_ * zy_;
  66.                 TFormedZ_ = x_ * xz_ + y_ * yz_ + z_ * zz_;
  67.         EndIf
  68.        
  69. End Function


Comments :


DareDevil(Posted 1+ years ago)

 is faster than the original?bye


Bobysait(Posted 1+ years ago)

 absolutely notthe original probably runs 4 or 5 times faster as it performs the same kind of operations .As mentionned, it's for purpose only, not really for use.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal