Posted to tcl by hypnotoad at Wed Jun 25 17:19:29 GMT 2014view raw

  1. odiemath_vectorxyz_lengthInvSqr f /Users/seandeelywoods/odie/sandbox/odielib/cmodules/math/generic/vectorxyz.c 0x7fa993447d20 153 0 65 101 136 {
  2. comment {/*
  3. * A - the vector to be tranformed
  4. * B - the affine tranformation matrix
  5. * R - a place to dump the result
  6. *
  7. * A and R MUST BE DIFFERENT
  8. */}
  9. definition {CTHULHU_INLINE double odiemath_vectorxyz_lengthInvSqr(VECTOR A);
  10. }
  11. body {{
  12. double r=A[0]+A[1]+A[2];
  13. if(abs(r)<__FLT_EPSILON__) {
  14. return NAN;
  15. }
  16. return (1.0/(A[0]*A[0]+A[1]*A[1]+A[2]*A[2]));
  17. }}
  18. }
  19. vectorxyz_method_length_inv_sqr fl /Users/seandeelywoods/odie/sandbox/odielib/cmodules/math/generic/vectorxyz.c 0x7fa993447d20 153 0 106 101 331 {
  20. comment {/*
  21. * A - the vector to be tranformed
  22. * B - the affine tranformation matrix
  23. * R - a place to dump the result
  24. *
  25. * A and R MUST BE DIFFERENT
  26. */}
  27. definition {static int vectorxyz_method_length_inv_sqr(void *pArg,Tcl_Interp *interp,int objc,Tcl_Obj *CONST objv[]);
  28. }
  29. body {{
  30. MATOBJ *A;
  31. double result;
  32. if(objc != 2) {
  33. Tcl_WrongNumArgs( interp, 1, objv, "A" );
  34. }
  35. A=Odie_GetMatrixFromTclObj(interp,objv[1],MATFORM_vectorxyz);
  36. if(!A) return TCL_ERROR;
  37.  
  38. result=odiemath_vectorxyz_lengthInvSqr(A->matrix);
  39.  
  40. Tcl_SetObjResult(interp,Tcl_NewDoubleObj(result));
  41. return TCL_OK;
  42. }}
  43. }
  44. odiemath_vectorxyz_normalize f /Users/seandeelywoods/odie/sandbox/odielib/cmodules/math/generic/vectorxyz.c 0x7fa993447d20 153 0 63 101 214 {
  45. comment {/*
  46. * A - the vector to be tranformed
  47. * B - the affine tranformation matrix
  48. * R - a place to dump the result
  49. *
  50. * A and R MUST BE DIFFERENT
  51. */}
  52. definition {CTHULHU_INLINE void odiemath_vectorxyz_normalize(VectorXYZ A);
  53. }
  54. body {{
  55. double d;
  56. double r=odiemath_vectorxyz_length(A);
  57. if(abs(r) < __FLT_EPSILON__) {
  58. A[0]=0.0;
  59. A[1]=0.0;
  60. A[3]=0.0;
  61. } else {
  62. d=1.0 / r;
  63. A[0]*=d;
  64. A[1]*=d;
  65. A[2]*=d;
  66. }
  67. }}
  68. }