void makeSphere(GeometryBatch &b, float radius, int divisions, bool normals, bool uvs, const LColor *color) { b.init(GL_TRIANGLES, "sphere"); b.ps.clear(); b.uvs[0].clear(); // 0, 45, 90, 135, 180 // 0 1 2 3 4 45 for (int i = 1; i < divisions-1; ++i) { float e0 = c_LPI * ((float)i / (float)divisions) - c_LPI / 2.0f; float e1 = c_LPI * (float)(i+1) / (float)divisions - c_LPI / 2.0f; for (int j = 0; j < divisions; ++j) { float a0 = 2.0f * c_LPI * (float)j / (float)divisions; float a1 = 2.0f * c_LPI * (float)(j+1) / (float)divisions; // cout << "(e=" << LDegrees(e0) << ",a=" << LDegrees(a0) << ") => " << pointOnSphere(radius, e0, a0) << "\n"; b.ps.push_back(pointOnSphere(radius, e0, a0)); b.ps.push_back(pointOnSphere(radius, e0, a1)); b.ps.push_back(pointOnSphere(radius, e1, a0)); b.ps.push_back(pointOnSphere(radius, e1, a0)); b.ps.push_back(pointOnSphere(radius, e0, a1)); b.ps.push_back(pointOnSphere(radius, e1, a1)); if (uvs) { float a0n = normalizeAzimuth(a0); float a1n = normalizeAzimuth(a1); float e0n = normalizeElevation(e0); float e1n = normalizeElevation(e1); b.uvs[0].push_back(UV(a0n,e0n)); b.uvs[0].push_back(UV(a1n,e0n)); b.uvs[0].push_back(UV(a0n,e1n)); b.uvs[0].push_back(UV(a0n,e1n)); b.uvs[0].push_back(UV(a1n,e0n)); b.uvs[0].push_back(UV(a1n,e1n)); } } } if (normals) { for (int n = 0; n < b.ps.size(); ++n) { b.ns.push_back(LNormal(b.ps[n] - LPoint(0,0,0))); } } if (color) { b.cs.assign(b.ps.size(), *color); } // ostream_iterator<LPoint> osi(cout, "\n"); // copy(b.ps.begin(), b.ps.end(), osi); }
void Particle_SphereSpread(ParticleSystem* psystem, float maxRadius, Vec3 emitterPos) { u16 n = psystem->n_particles; for (u16 i = 0; i < n; i++) { float altitude = RandRange(0, M_PI); float azimuth = RandRange(0, 2*M_PI); float radius = RandRange(0.1f, maxRadius); float sinAlt = sin(altitude); float x = sinAlt * cos(azimuth); float y = sinAlt * sin(azimuth); float z = cos(altitude); Vec3 pointOnSphere(x, y, z); Vec3 pos = pointOnSphere*radius + emitterPos; f32 speed = RandRange(3, 6); Vec3 vel = pointOnSphere * speed; psystem->positions[i] = pos; psystem->velocities[i] = vel; } }