本文整理汇总了C++中Cone::randomDirectionInCone方法的典型用法代码示例。如果您正苦于以下问题:C++ Cone::randomDirectionInCone方法的具体用法?C++ Cone::randomDirectionInCone怎么用?C++ Cone::randomDirectionInCone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cone
的用法示例。
在下文中一共展示了Cone::randomDirectionInCone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emissionCone
void ParticleSystemModel::Emitter::spawnParticles(ParticleSystem* system, int newParticlesToEmit, SimTime absoluteTime, SimTime relativeTime, SimTime deltaTime, int emitterIndex) const {
// Give up and just place a particle anywhere in the noise field if we can't find
// a good location by rejection sampling after this many tries.
const int MAX_NOISE_SAMPLING_TRIES = 20;
Random& rng = Random::common();
Noise& noise = Noise::common();
debugAssert(notNull(m_spawnShape));
for (int i = 0; i < newParticlesToEmit; ++i) {
ParticleSystem::Particle particle;
particle.emitterIndex = emitterIndex;
for (int j = 0; j < MAX_NOISE_SAMPLING_TRIES; ++j) {
switch (m_specification.location) {
case SpawnLocation::FACES:
alwaysAssertM(m_spawnShape->type() == Shape::Type::MESH, "SpawnLocation::FACES requires a mesh");
{
const shared_ptr<MeshShape>& mesh = dynamic_pointer_cast<MeshShape>(m_spawnShape);
const Array<int>& indexArray = mesh->indexArray();
const Array<Point3>& vertexArray = mesh->vertexArray();
const int i = rng.integer(0, indexArray.size() / 3 - 1) * 3;
particle.position = (vertexArray[indexArray[i]] + vertexArray[indexArray[i + 1]] + vertexArray[indexArray[i + 2]]) / 3.0f;
}
break;
case SpawnLocation::VERTICES:
alwaysAssertM(m_spawnShape->type() == Shape::Type::MESH, "SpawnLocation::VERTICES requires a mesh");
{
const shared_ptr<MeshShape>& mesh = dynamic_pointer_cast<MeshShape>(m_spawnShape);
particle.position = mesh->vertexArray().randomElement();
}
break;
case SpawnLocation::SURFACE:
m_spawnShape->getRandomSurfacePoint(particle.position);
break;
case SpawnLocation::VOLUME:
particle.position = m_spawnShape->randomInteriorPoint();
if (particle.position.isNaN()) {
// For poorly formed meshes...or even good ones with really bad luck...
// sometimes randomInteriorPoint will fail. In this case, generate a surface
// point, which is technically "on the interior" still, just poorly distributed.
m_spawnShape->getRandomSurfacePoint(particle.position);
}
break;
} // switch
// Unique values every 5m for the lowest frequencies
if (m_specification.noisePower == 0.0f) {
// Accept any generated position
break;
} else {
const Vector3int32 intPos(particle.position * ((1 << 16) / (5 * units::meters())));
const float acceptProbability = pow(max(0.0f, noise.sampleFloat(intPos.x, intPos.y, intPos.z, 5)), m_specification.noisePower);
if (rng.uniform() <= acceptProbability) {
// An acceptable position!
break;
}
}
}
particle.angle = rng.uniform(0.0f, 2.0f * pif());
particle.radius = fabs(rng.gaussian(m_specification.radiusMean, sqrt(m_specification.radiusVariance)));
if (m_specification.coverageFadeInTime == 0.0f) {
particle.coverage = 1.0f;
} else {
particle.coverage = 0.0f;
}
particle.userdataFloat = 0.0f;
particle.mass = m_specification.particleMassDensity * (4.0f / 3.0f) * pif() * particle.radius * particle.radius * particle.radius;
if (m_specification.velocityConeAngleDegrees >= 180) {
particle.velocity = Vector3::random(rng);
} else if (m_specification.velocityConeAngleDegrees > 0) {
const Cone emissionCone(Point3(),
m_specification.velocityDirectionMean,
m_specification.velocityConeAngleDegrees * 0.5f);
particle.velocity = emissionCone.randomDirectionInCone(rng);
} else {
particle.velocity = m_specification.velocityDirectionMean;
}
particle.velocity *= fabs(rng.gaussian(m_specification.velocityMagnitudeMean, m_specification.velocityMagnitudeVariance));
particle.angularVelocity = rng.gaussian(m_specification.angularVelocityMean, m_specification.angularVelocityVariance);
particle.spawnTime = absoluteTime;
particle.expireTime = absoluteTime + fabs(rng.gaussian(m_specification.particleLifetimeMean, m_specification.particleLifetimeVariance));
particle.dragCoefficient = m_specification.dragCoefficient;
particle.material = m_material;
particle.userdataInt = 0;
if (system->particlesAreInWorldSpace()) {
// Transform to world space
//.........这里部分代码省略.........