MCPcopy Create free account
hub / github.com/RenderKit/embree / createPlane

Function createPlane

tutorials/closest_point/closest_point_device.cpp:460–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460TriangleMesh* createPlane (
461 AffineSpace3fa const& M, // transformation
462 unsigned int R) // resolution
463{
464 /* create triangle mesh */
465 TriangleMesh* plane = new TriangleMesh();
466 plane->num_vertices = (R+1)*(R+1);
467 plane->num_triangles = 2*R*R;
468 plane->vertices = (Vertex*) alignedMalloc(sizeof(Vertex)*plane->num_vertices+1, 16);
469 plane->triangles = (Triangle*) alignedMalloc(sizeof(Triangle)*plane->num_triangles, 16);
470
471 /* set vertices and vertex colors */
472 for (unsigned int y = 0; y <= R; ++y)
473 for (unsigned int x = 0; x <= R; ++x)
474 {
475 Vec3fa p((float)x/R, (float)y/R, 0.f);
476 Vec3fa pt = xfmPoint(M, p);
477 plane->vertices[y*(R+1)+x].x = pt.x;
478 plane->vertices[y*(R+1)+x].y = pt.y;
479 plane->vertices[y*(R+1)+x].z = pt.z;
480 }
481
482 /* set triangles and face colors */
483 for (unsigned int j = 0; j < R; ++j)
484 for (unsigned int i = 0; i < R; ++i)
485 {
486 plane->triangles[2*(j*R+i)+0].v0 = (j*(R+1)+i);
487 plane->triangles[2*(j*R+i)+0].v1 = (j*(R+1)+i) + (R + 1) + 1;
488 plane->triangles[2*(j*R+i)+0].v2 = (j*(R+1)+i) + (R + 1);
489 plane->triangles[2*(j*R+i)+1].v0 = (j*(R+1)+i);
490 plane->triangles[2*(j*R+i)+1].v1 = (j*(R+1)+i) + 1;
491 plane->triangles[2*(j*R+i)+1].v2 = (j*(R+1)+i) + (R + 1) + 1;
492 }
493
494 return plane;
495}
496
497
498// ======================================================================== //

Callers 1

device_initFunction · 0.85

Calls 2

alignedMallocFunction · 0.85
xfmPointFunction · 0.50

Tested by

no test coverage detected