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

Function createTriangulatedSphere

tutorials/collide/collide_device.cpp:74–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74unsigned int createTriangulatedSphere (RTCScene scene, const Vec3fa& p, float r)
75{
76 /* create triangle mesh */
77 std::unique_ptr<collide2::Mesh> sphere (new collide2::Mesh());
78 sphere->x_.resize (numTheta*(numPhi-1)+2);
79 sphere->tris_.resize (2*numTheta*(numPhi-1));
80
81 /* create sphere */
82 int tri = 0;
83 const float rcpNumTheta = rcp((float)numTheta);
84 const float rcpNumPhi = rcp((float)numPhi);
85 sphere->x_[0].x = p.x;
86 sphere->x_[0].y = p.y + r;
87 sphere->x_[0].z = p.z;
88
89 for (int phi=0; phi<numPhi-1; phi++)
90 {
91 const float phif = (phi+1)*float(pi)*rcpNumPhi;
92 const float sinp = sin(phif);
93 const float cosp = cos(phif);
94 for (int theta=0; theta<numTheta; theta++)
95 {
96 const float thetaf = theta*2.0f*float(pi)*rcpNumTheta;
97
98 auto& v = sphere->x_[phi*(numTheta)+theta+1];
99 v.x = p.x + r*sinp*sin(thetaf);
100 v.y = p.y + r*cosp;
101 v.z = p.z + r*sinp*cos(thetaf);
102 }
103 }
104 sphere->x_[numTheta*(numPhi-1)+1].x = p.x;
105 sphere->x_[numTheta*(numPhi-1)+1].y = p.y - r;
106 sphere->x_[numTheta*(numPhi-1)+1].z = p.z;
107
108 for (int theta=0; theta<numTheta; theta++) {
109 sphere->tris_[tri].v0 = theta+1;
110 sphere->tris_[tri].v1 = 0;
111 sphere->tris_[theta].v2 = (theta+1)%numTheta + 1;
112 tri++;
113 }
114
115 for (int phi=0; phi<numPhi-2; phi++)
116 {
117 for (int theta=0; theta<numTheta; theta++)
118 {
119 int p00 = phi*numTheta + 1 + theta;
120 int p01 = phi*numTheta + 1 + (theta+1)%numTheta;
121 int p10 = (phi+1)*numTheta + 1 + theta;
122 int p11 = (phi+1)*numTheta + 1 + (theta+1)%numTheta;
123
124 sphere->tris_[tri].v0 = p10;
125 sphere->tris_[tri].v1 = p01;
126 sphere->tris_[tri].v2 = p00;
127 tri++;
128
129 sphere->tris_[tri].v0 = p11;
130 sphere->tris_[tri].v1 = p01;
131 sphere->tris_[tri].v2 = p10;

Callers 1

device_initFunction · 0.70

Calls 13

rtcAttachGeometryFunction · 0.85
rtcSetGeometryUserDataFunction · 0.85
rtcCommitGeometryFunction · 0.85
rtcReleaseGeometryFunction · 0.85
rcpFunction · 0.50
sinFunction · 0.50
cosFunction · 0.50
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected