⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simple_rapid.br

📁 用于GPU通用计算的编程语言BrookGPU 0.4
💻 BR
📖 第 1 页 / 共 2 页
字号:
     ?
     ((!(isect1 .y < isect2 .x || isect2 .y < isect1 .x))
      ?1
      :0)
     :ret;    
  
  return ret;
}


kernel float TrianglesHaveContact (float3 mRx,
                                   float3 mRy,
                                   float3 mRz,
                                   float3 mT,
                                   float3 t1A<>, 
                                   float3 t1B<>, 
                                   float3 t1C<>, 
                                   float3 t2A<>,
                                   float3 t2B<>,
                                   float3 t2C<>) {
  float3 i1 = matVecMult(mRx,mRy,mRz,t1A)+mT;
  float3 i2 = matVecMult(mRx,mRy,mRz,t1B)+mT;
  float3 i3 = matVecMult(mRx,mRy,mRz,t1C)+mT;
  return tri_contact(i1,i2,i3,t2A,t2B,t2C);

}

kernel void SimpleCheckTriangleCollide(float3 mRx,
                                       float3 mRy,
                                       float3 mRz,
                                       float3 mT,
                                       float3 t1A<>,
                                       float3 t1B<>,
                                       float3 t1C<>,
                                       float3 t2A<>,
                                       float3 t2B<>,
                                       float3 t2C<>,
                                       out float4 hits<>) {
  float4 neg1=-1;
  //  hits= TrianglesHaveContact(mRx,mRy,mRz,mT,
  //                           t1,t2)?(indexof hits):neg1;
  hits= tri_contact(t1A,t1B,t1C,t2A,t2B,t2C)?(indexof hits):neg1;
}
void doTest (float * matrix, int trisizex, int trisizey, float3 *a, float3 * b, float4 * ohits) {
  float3 triangles1A <trisizex,trisizey>;
  float3 triangles1B <trisizex,trisizey>;
  float3 triangles1C <trisizex,trisizey>;
  float3 triangles2A <trisizex,trisizey>;
  float3 triangles2B <trisizex,trisizey>;
  float3 triangles2C <trisizex,trisizey>;
  float4 hits <trisizex,trisizey>;
  float3 mRx,mRy,mRz,mT;
  int i;
  float3 * temptri;
  temptri = (float3*)malloc(sizeof(float3)*trisizex*trisizey);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = a[i*3];
  }
  streamRead(triangles1A,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = a[i*3+1];
  }
  streamRead(triangles1B,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = a[i*3+2];
  }
  streamRead(triangles1C,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = b[i*3];
  }
  streamRead(triangles2A,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = b[i*3+1];
  }
  streamRead(triangles2B,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = b[i*3+2];
  }
  streamRead(triangles2C,temptri);
  free(temptri);
  mRx.x=matrix[0];
  mRx.y=matrix[1];
  mRx.z=matrix[2];
  mRy.x=matrix[4];
  mRy.y=matrix[5];
  mRy.z=matrix[6];
  mRz.x=matrix[8];
  mRz.y=matrix[9];
  mRz.z=matrix[10];
  mT.x=matrix[12];
  mT.y=matrix[13];
  mT.z=matrix[14];

  //streamRead(trianglesA,a);
  //streamRead(trianglesB,b);
  SimpleCheckTriangleCollide(mRx,mRy,mRz,mT,
                             triangles1A,triangles1B,triangles1C,
                             triangles2A,triangles2B,triangles2C,hits);
  streamWrite(hits,ohits);
}


kernel void SimpleCheckTriangleCollideNoDiv(float3 mRx,
                                            float3 mRy,
                                            float3 mRz,
                                            float3 mT,
                                            float3 t1A<>,
                                            float3 t1B<>,
                                            float3 t1C<>,
                                            float3 t2A<>,
                                            float3 t2B<>,
                                            float3 t2C<>,
                                            out float4 hits<>) {
  float4 neg1=-1;
  hits= tri_contact_nodiv(t1A,t1B,t1C,t2A,t2B,t2C)?(indexof hits):neg1;
}
void doTestNoDiv (float * matrix, int trisizex, int trisizey, float3 *a, float3 * b, float4 * ohits) {
  float3 triangles1A <trisizex,trisizey>;
  float3 triangles1B <trisizex,trisizey>;
  float3 triangles1C <trisizex,trisizey>;
  float3 triangles2A <trisizex,trisizey>;
  float3 triangles2B <trisizex,trisizey>;
  float3 triangles2C <trisizex,trisizey>;
  float4 hits <trisizex,trisizey>;
  float3 mRx,mRy,mRz,mT;
  int i;
  float3 * temptri;
  temptri = (float3*)malloc(sizeof(float3)*trisizex*trisizey);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = a[i*3];
  }
  streamRead(triangles1A,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = a[i*3+1];
  }
  streamRead(triangles1B,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = a[i*3+2];
  }
  streamRead(triangles1C,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = b[i*3];
  }
  streamRead(triangles2A,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = b[i*3+1];
  }
  streamRead(triangles2B,temptri);
  for (i=0;i<trisizex*trisizey;++i) {
    temptri[i] = b[i*3+2];
  }
  streamRead(triangles2C,temptri);
  free(temptri);

  mRx.x=matrix[0];
  mRx.y=matrix[1];
  mRx.z=matrix[2];
  mRy.x=matrix[4];
  mRy.y=matrix[5];
  mRy.z=matrix[6];
  mRz.x=matrix[8];
  mRz.y=matrix[9];
  mRz.z=matrix[10];
  mT.x=matrix[12];
  mT.y=matrix[13];
  mT.z=matrix[14];
  
  //streamRead(trianglesA,a);
  //streamRead(trianglesB,b);
  SimpleCheckTriangleCollideNoDiv(mRx,mRy,mRz,mT,
                                  triangles1A,
                                  triangles1B,
                                  triangles1C,
                                  triangles2A,
                                  triangles2B,
                                  triangles2C,
                                  hits);
  streamWrite(hits,ohits);
}


kernel float obb_disjoint (float3 Bx,
                           float3 By,
                           float3 Bz,
                           float3 T,
                           float3 a<>,
                           float3 b<>) {
  float t, s;
  float r;
  float3 Bfx;
  float3 Bfy;
  float3 Bfz;
  const float reps = 1e-6;

  // Bf = abs (B)
  Bfx = abs(Bx)+reps;
  Bfy = abs(By)+reps;
  Bfz = abs(Bz)+reps;

  // if any of these tests are one-sided, then the polyhedra are disjoint
  r = 1;

  // A1 x A2 = A0
  t = abs (T.x);

  r = r&& (t <= (a.x + dot(b,Bfx)));
  //if (!r) return 1;

  // B1 x B2 = B0
  s = T.x * Bx.x + T.y * By.x + T.z * Bz.x;
  t = abs (s);

  r =r&& (t <= (b.x + a.x * Bfx.x + a.y * Bfy.x + a.z * Bfz.x));
  //if (!r) return 2;

  // A2 x A0 = A1
  t = abs (T.y);

  r = r&&(t <= (a.y + dot(b,Bfy)));
  //if (!r) return 3;

  // A0 x A1 = A2
  t = abs (T.z);

  r =r&& (t <= (a.z + dot(b,Bfz)));
  //if (!r) return 4;

  // B2 x B0 = B1
  s = T.x * Bx.y + T.y * By.y + T.z * Bz.y;
  t = abs (s);

  r =r&& (t <= (b.y + a.x * Bfx.y + a.y * Bfy.y + a.z * Bfz.y));
  //if (!r) return 5;

  // B0 x B1 = B2
  s = T.x * Bx.z + T.y * By.z + T.z * Bz.z;
  t = abs (s);

  r =r&& (t <= (b.z + a.x * Bfx.z + a.y * Bfy.z + a.z * Bfz.z));
  //if (!r) return 6;

  // A0 x B0
  s = T.z * By.x - T.y * Bz.x;
  t = abs (s);

  r =r&& (t <= (a.y * Bfz.x + a.z * Bfy.x + b.y * Bfx.z + b.z * Bfx.y));
  //if (!r) return 7;

  // A0 x B1
  s = T.z * By.y - T.y * Bz.y;
  t = abs (s);

  r =r&& (t <= (a.y * Bfz.y + a.z * Bfy.y + b.x * Bfx.z + b.z * Bfx.x));
  //if (!r) return 8;

  // A0 x B2
  s = T.z * By.z - T.y * Bz.z;
  t = abs (s);

  r =r&& (t <= (a.y * Bfz.z + a.z * Bfy.z + b.x * Bfx.y + b.y * Bfx.x));
  //if (!r) return 9;

  // A1 x B0
  s = T.x * Bz.x - T.z * Bx.x;
  t = abs (s);

  r =r&& (t <= (a.x * Bfz.x + a.z * Bfx.x + b.y * Bfy.z + b.z * Bfy.y));
  //if (!r) return 10;

  // A1 x B1
  s = T.x * Bz.y - T.z * Bx.y;
  t = abs (s);

  r =r&& (t <= (a.x * Bfz.y + a.z * Bfx.y + b.x * Bfy.z + b.z * Bfy.x));
  //if (!r) return 11;

  // A1 x B2
  s = T.x * Bz.z - T.z * Bx.z;
  t = abs (s);

  r =r&& (t <= (a.x * Bfz.z + a.z * Bfx.z + b.x * Bfy.y + b.y * Bfy.x));
  //if (!r) return 12;

  // A2 x B0
  s = T.y * Bx.x - T.x * By.x;
  t = abs (s);

  r =r&& (t <= (a.x * Bfy.x + a.y * Bfx.x + b.y * Bfz.z + b.z * Bfz.y));
  //if (!r) return 13;

  // A2 x B1
  s = T.y * Bx.y - T.x * By.y;
  t = abs (s);

  r =r&& (t <= (a.x * Bfy.y + a.y * Bfx.y + b.x * Bfz.z + b.z * Bfz.x));
  //if (!r) return 14;

  // A2 x B2
  s = T.y * Bx.z - T.x * By.z;
  t = abs (s);

  r =r&& (t <= (a.x * Bfy.z + a.y * Bfx.z + b.x * Bfz.y + b.y * Bfz.x));
  //if (!r) return 15;

  return r?0:1;  // should equal 0
}

kernel void OBBDisjoint(float3 X, float3 Y, float3 Z, float3 T,
                        float3 a<>, float3 b<>, out float rez<>) {
  rez = obb_disjoint(X,Y,Z,T,a,b);
}
float TestObbDisjoint (float3 X, float3 Y, float3 Z, float3 T,
                      float3  a, float3 b) {
  float rez;
  float rez_stream<1,1>;
  float3 a_stream<1,1>;
  float3 b_stream<1,1>;
  streamRead(a_stream,&a);
  streamRead(b_stream,&b);
  OBBDisjoint(X,Y,Z,T,a_stream,b_stream,rez_stream);
  streamWrite(rez_stream,&rez);
  return rez;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -