Advertisement
Guest User

Untitled

a guest
Oct 1st, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.06 KB | None | 0 0
  1. #include "stdio.h"
  2.  
  3. #if defined(__GNUC__)
  4. #define forceinline __attribute__((always_inline))
  5. #else
  6. #define forceinline __forceinline
  7. #endif
  8.  
  9.     struct Vec3f
  10.     {
  11.         float vec[3];
  12.     };
  13.     struct Vec4f
  14.     {
  15.         float vec[4];
  16.     };
  17.  
  18.     struct Matrix44f
  19.     {
  20.         float mat[4][4];
  21.     };
  22.  
  23.  
  24.     struct Vec4uc
  25.     {
  26.         unsigned char vec[4];
  27.     };
  28.  
  29. struct PN4f
  30. {
  31.   Vec4f pn[2];
  32. };
  33.  
  34. struct PN
  35. {
  36.   Vec3f p;
  37.   Vec3f n;
  38. };
  39.  
  40.  
  41. forceinline
  42. void transformPointNormal4x3Weight_NoW(const Matrix44f& mat,const Vec4f* pVerticiesNormals, PN& outPN)
  43. {
  44.     outPN.p.vec[0] = (pVerticiesNormals[0].vec[0]*mat.mat[0][0] + pVerticiesNormals[0].vec[1]*mat.mat[1][0] + pVerticiesNormals[0].vec[2]*mat.mat[2][0] + mat.mat[3][0]);
  45.     outPN.n.vec[0] = (pVerticiesNormals[1].vec[0]*mat.mat[0][0] + pVerticiesNormals[1].vec[1]*mat.mat[1][0] + pVerticiesNormals[1].vec[2]*mat.mat[2][0]);
  46.    
  47.     outPN.p.vec[1] = (pVerticiesNormals[0].vec[0]*mat.mat[0][1] + pVerticiesNormals[0].vec[1]*mat.mat[1][1] + pVerticiesNormals[0].vec[2]*mat.mat[2][1] + mat.mat[3][1]);
  48.     outPN.n.vec[1] = (pVerticiesNormals[1].vec[0]*mat.mat[0][1] + pVerticiesNormals[1].vec[1]*mat.mat[1][1] + pVerticiesNormals[1].vec[2]*mat.mat[2][1]);
  49.    
  50.     outPN.p.vec[2] = (pVerticiesNormals[0].vec[0]*mat.mat[0][2] + pVerticiesNormals[0].vec[1]*mat.mat[1][2] + pVerticiesNormals[0].vec[2]*mat.mat[2][2] + mat.mat[3][2]);
  51.     outPN.n.vec[2] = (pVerticiesNormals[1].vec[0]*mat.mat[0][2] + pVerticiesNormals[1].vec[1]*mat.mat[1][2] + pVerticiesNormals[1].vec[2]*mat.mat[2][2]);
  52. }
  53.  
  54.  
  55. forceinline
  56. void transformPointNormal4x3Weight(const Matrix44f& mat,const Vec4f* pVerticiesNormals, PN& outPN,float w )
  57. {
  58.     outPN.p.vec[0] = (pVerticiesNormals[0].vec[0]*mat.mat[0][0] + pVerticiesNormals[0].vec[1]*mat.mat[1][0] + pVerticiesNormals[0].vec[2]*mat.mat[2][0] + mat.mat[3][0])*w;
  59.     outPN.n.vec[0] = (pVerticiesNormals[1].vec[0]*mat.mat[0][0] + pVerticiesNormals[1].vec[1]*mat.mat[1][0] + pVerticiesNormals[1].vec[2]*mat.mat[2][0])*w;
  60.    
  61.     outPN.p.vec[1] = (pVerticiesNormals[0].vec[0]*mat.mat[0][1] + pVerticiesNormals[0].vec[1]*mat.mat[1][1] + pVerticiesNormals[0].vec[2]*mat.mat[2][1] + mat.mat[3][1])*w;
  62.     outPN.n.vec[1] = (pVerticiesNormals[1].vec[0]*mat.mat[0][1] + pVerticiesNormals[1].vec[1]*mat.mat[1][1] + pVerticiesNormals[1].vec[2]*mat.mat[2][1])*w;
  63.    
  64.     outPN.p.vec[2] = (pVerticiesNormals[0].vec[0]*mat.mat[0][2] + pVerticiesNormals[0].vec[1]*mat.mat[1][2] + pVerticiesNormals[0].vec[2]*mat.mat[2][2] + mat.mat[3][2])*w;
  65.     outPN.n.vec[2] = (pVerticiesNormals[1].vec[0]*mat.mat[0][2] + pVerticiesNormals[1].vec[1]*mat.mat[1][2] + pVerticiesNormals[1].vec[2]*mat.mat[2][2])*w;
  66. }
  67.  
  68. forceinline
  69. void transformPointNormal4x3AddWeighted(const Matrix44f& mat,const Vec4f* pVerticiesNormals, PN& outPN,float w )
  70. {
  71.     outPN.p.vec[0] += (pVerticiesNormals[0].vec[0]*mat.mat[0][0] + pVerticiesNormals[0].vec[1]*mat.mat[1][0] + pVerticiesNormals[0].vec[2]*mat.mat[2][0] + mat.mat[3][0])*w;
  72.     outPN.n.vec[0] += (pVerticiesNormals[1].vec[0]*mat.mat[0][0] + pVerticiesNormals[1].vec[1]*mat.mat[1][0] + pVerticiesNormals[1].vec[2]*mat.mat[2][0])*w;
  73.    
  74.     outPN.p.vec[1] += (pVerticiesNormals[0].vec[0]*mat.mat[0][1] + pVerticiesNormals[0].vec[1]*mat.mat[1][1] + pVerticiesNormals[0].vec[2]*mat.mat[2][1] + mat.mat[3][1])*w;
  75.     outPN.n.vec[1] += (pVerticiesNormals[1].vec[0]*mat.mat[0][1] + pVerticiesNormals[1].vec[1]*mat.mat[1][1] + pVerticiesNormals[1].vec[2]*mat.mat[2][1])*w;
  76.    
  77.     outPN.p.vec[2] += (pVerticiesNormals[0].vec[0]*mat.mat[0][2] + pVerticiesNormals[0].vec[1]*mat.mat[1][2] + pVerticiesNormals[0].vec[2]*mat.mat[2][2] + mat.mat[3][2])*w;
  78.     outPN.n.vec[2] += (pVerticiesNormals[1].vec[0]*mat.mat[0][2] + pVerticiesNormals[1].vec[1]*mat.mat[1][2] + pVerticiesNormals[1].vec[2]*mat.mat[2][2])*w;
  79. }
  80.  
  81. forceinline
  82. void ProcessVertex(
  83.                                      size_t v,
  84.                                      const PN4f* pVerticiesNormals,
  85.                                      const Vec4f* pVertexWeight,
  86.                                      const Vec4uc* pVertexBones,
  87.                                      const Matrix44f* pBoneTMList,
  88.                                      PN* skinTempPN,
  89.                                      size_t wCount)
  90. {
  91.     float w = pVertexWeight[v].vec[0];
  92.     int boneIndex = pVertexBones[v].vec[0];
  93.     const Matrix44f& boneTM = pBoneTMList[boneIndex];
  94.     if( wCount==1 )
  95.     {
  96.         transformPointNormal4x3Weight_NoW(boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v]);
  97.     }
  98.     else
  99.     {
  100.         // 1st vertex without add
  101.         transformPointNormal4x3Weight(boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  102.         if( wCount==2 )
  103.         {
  104.             // other verticies
  105.             w = pVertexWeight[v].vec[1];
  106.             boneIndex = pVertexBones[v].vec[1];
  107.             const Matrix44f& boneTM = pBoneTMList[boneIndex];
  108.             transformPointNormal4x3AddWeighted(boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  109.         }
  110.         else if( wCount==3 )
  111.         {
  112.             // other verticies
  113.             w = pVertexWeight[v].vec[1];
  114.             boneIndex = pVertexBones[v].vec[1];
  115.             const Matrix44f* boneTM = &pBoneTMList[boneIndex];
  116.             transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  117.  
  118.             // other verticies
  119.             w = pVertexWeight[v].vec[2];
  120.             boneIndex = pVertexBones[v].vec[2];
  121.             boneTM = &pBoneTMList[boneIndex];
  122.             transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  123.         }
  124.         else if( wCount==4 )
  125.         {
  126.             // other verticies
  127.             w = pVertexWeight[v].vec[1];
  128.             boneIndex = pVertexBones[v].vec[1];
  129.             const Matrix44f* boneTM = &pBoneTMList[boneIndex];
  130.             transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  131.  
  132.             // other verticies
  133.             w = pVertexWeight[v].vec[2];
  134.             boneIndex = pVertexBones[v].vec[2];
  135.             boneTM = &pBoneTMList[boneIndex];
  136.             transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  137.  
  138.             // other verticies
  139.             w = pVertexWeight[v].vec[3];
  140.             boneIndex = pVertexBones[v].vec[3];
  141.             boneTM = &pBoneTMList[boneIndex];
  142.             transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  143.         }
  144.  
  145.         /*
  146.         for(size_t i=1;i<wCount;i++)
  147.         {
  148.             // other verticies
  149.             w = pVertexWeight[v].vec[i];
  150.             boneIndex = &pVertexBones[v].vec[i];
  151.             const Matrix44f& boneTM = pBoneTMList[boneIndex];
  152.             transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
  153.         }
  154.         */
  155.     }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement