本文整理汇总了C++中BoundingSphere::Contains方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingSphere::Contains方法的具体用法?C++ BoundingSphere::Contains怎么用?C++ BoundingSphere::Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingSphere
的用法示例。
在下文中一共展示了BoundingSphere::Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(BoundingSphere, Contains_BoundingBox)
{
BoundingSphere sphere;
sphere.Center = Vector3::Zero;
sphere.Radius = 42.0f;
auto min = Vector3::Normalize({-1.f, -1.f, -1.f}) * 42.0f;
auto max = Vector3::Normalize({1.f, 1.f, 1.f}) * 42.0f;
auto unit = Vector3::Normalize({1.f, 1.f, 1.f}) * 42.0f;
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{Vector3::Zero, max}));
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{Vector3::Zero - unit * Vector3::UnitX, max - unit * Vector3::UnitX}));
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{Vector3::Zero - unit * Vector3::UnitY, max - unit * Vector3::UnitY}));
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{Vector3::Zero - unit * Vector3::UnitZ, max - unit * Vector3::UnitZ}));
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{min, Vector3::Zero}));
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{min + unit * Vector3::UnitX, Vector3::Zero + unit * Vector3::UnitX}));
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{min + unit * Vector3::UnitY, Vector3::Zero + unit * Vector3::UnitY}));
EXPECT_EQ(ContainmentType::Contains, sphere.Contains(BoundingBox{min + unit * Vector3::UnitZ, Vector3::Zero + unit * Vector3::UnitZ}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{Vector3::Zero, max * 1.01f}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{Vector3::Zero - unit * Vector3::UnitX, max * 1.01f - unit * Vector3::UnitX}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{Vector3::Zero - unit * Vector3::UnitY, max * 1.01f - unit * Vector3::UnitY}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{Vector3::Zero - unit * Vector3::UnitZ, max * 1.01f - unit * Vector3::UnitZ}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{min * 1.01f, Vector3::Zero}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{min * 1.01f + unit * Vector3::UnitX, Vector3::Zero + unit * Vector3::UnitX}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{min * 1.01f + unit * Vector3::UnitY, Vector3::Zero + unit * Vector3::UnitY}));
EXPECT_EQ(ContainmentType::Intersects, sphere.Contains(BoundingBox{min * 1.01f + unit * Vector3::UnitZ, Vector3::Zero + unit * Vector3::UnitZ}));
EXPECT_EQ(ContainmentType::Disjoint, sphere.Contains(BoundingBox{max * 1.01f, max * 1.01f + unit}));
}
示例2: lock
Pollen() noexcept
: type((Type)Random<uint32_t>(0u,3u))
{
{
Lock lock(mxCounter);
if ((++counter) == 1)
{
//create an icosphere of radius 1.0f
std::vector<Vec3> spherePositions;
{
Mesh mesh;
auto data(mesh.Sphere({}, 1.0f, YGG_DEBUG_CONDITIONAL(2,4), true).Decompose());
for (auto i : data->Indices)
spherePositions.push_back(data->Positions[i]);
}
//deform a copy of the sphere once for each type
for (Type t = Type::Linear; t < Type::Count; t = (Type)((uint32_t)t + 1u))
{
uint32_t spikeCount(40);
switch (t)
{
case Type::Linear: spikeCount = 3 * spikeCount / 4; break;
case Type::Square: spikeCount = 2 * spikeCount / 3; break;
case Type::Circular: spikeCount = spikeCount / 2; break;
}
//pick equidistant points around unit sphere (see http://www.cmu.edu/biolphys/deserno/pdf/sphere_equi.pdf)
std::vector<Vec3> spikes;
float a((4.0f * Pi) / (float)spikeCount);
float d(sqrtf(a));
uint32_t mTheta(Round<uint32_t>(Pi / d));
float dTheta(Pi / (float)mTheta);
float dAlpha(a / dTheta);
for (uint32_t m = 0; m < mTheta; ++m)
{
float theta((Pi*((float)m + 0.5f)) / (float)mTheta);
uint32_t mAlpha(Round<uint32_t>((2.0f * Pi * sinf(theta)) / dAlpha));
for (uint32_t n = 0; n < mAlpha; ++n)
{
float alpha((2.0f * Pi * (float)n) / (float)mAlpha);
spikes.emplace_back(sinf(theta) * cosf(alpha),
sinf(theta)*sinf(alpha),
cos(theta));
}
}
//minimum distance to consider a spike as being "in range"
float rad = d / 2.1f;
//loop through the vertices and deform the sphere based
//on proximity to nearest spike
std::vector<Vec3> positions(spherePositions);
for (size_t v = 0; v < positions.size(); ++v)
{
//find closest spike
float dist(Vec3::DistanceSquared(positions[v], spikes[0]));
for (size_t s = 1; s < spikes.size(); ++s)
dist = std::min(dist, Vec3::DistanceSquared(positions[v], spikes[s]));
//convert distance into a proximity function & deform
dist = ((rad - sqrtf(dist)) / rad);
positions[v] *= metrics.Radius + metrics.Radius * 0.25f * ApplyDeformation(t, dist);
}
//create static mesh
Mesh mesh;
meshes.emplace_back(new StaticMesh(mesh.AddPositions(std::move(positions)).GenerateIndices().GenerateNormals()));
}
}
if (Game::Physics()->Started() && !rigidBodyMesh)
rigidBodyMesh = Game::Physics()->CreateSphereMesh(metrics.Radius);
}
entity.reset(Game::Scene()->Create("", this));
auto _position(PickSpawnLocation(true));
transform = entity->Add<Transform>(_position);
transform->Forward(Random<Vec3>());
static std::vector<Colour> colours
{
Yellow, Olive, BlanchedAlmond, YellowGreen
};
material.reset(new Phong(Colour(colours[Random<size_t>(0, colours.size() - 1)],0.0f)));
entity->Add<MeshRenderer>(meshes[Random<size_t>(0, meshes.size() - 1)], material);
if (Game::Physics()->Started())
rigidBody.reset(Game::Physics()->Create(rigidBodyMesh, true, _position, transform->Orientation(), metrics.Density));
entity->Add<Ticker>()->OnTick += [](Ticker* t, float deltaTime)
{
auto pollen(static_cast<Pollen*>(t->Entity()->Data));
if (Game::Physics()->Started())
pollen->transform->Pose(pollen->rigidBody->Position(), pollen->rigidBody->Orientation());
if (!world.Contains(pollen->transform->Position()))
{
Vec3 newPos(PickSpawnLocation(false));
pollen->transform->Position(newPos);
//.........这里部分代码省略.........