本文整理汇总了C++中BoundingBox::Merge方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingBox::Merge方法的具体用法?C++ BoundingBox::Merge怎么用?C++ BoundingBox::Merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingBox
的用法示例。
在下文中一共展示了BoundingBox::Merge方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnWorldBoundingBoxUpdate
void DecalSet::OnWorldBoundingBoxUpdate()
{
if (!skinned_)
{
if (boundingBoxDirty_)
CalculateBoundingBox();
worldBoundingBox_ = boundingBox_.Transformed(node_->GetWorldTransform());
}
else
{
// When using skinning, update world bounding box based on the bones
BoundingBox worldBox;
for (Vector<Bone>::ConstIterator i = bones_.Begin(); i != bones_.End(); ++i)
{
Node* boneNode = i->node_;
if (!boneNode)
continue;
// Use hitbox if available. If not, use only half of the sphere radius
/// \todo The sphere radius should be multiplied with bone scale
if (i->collisionMask_ & BONECOLLISION_BOX)
worldBox.Merge(i->boundingBox_.Transformed(boneNode->GetWorldTransform()));
else if (i->collisionMask_ & BONECOLLISION_SPHERE)
worldBox.Merge(Sphere(boneNode->GetWorldPosition(), i->radius_ * 0.5f));
}
worldBoundingBox_ = worldBox;
}
}
示例2: OnWorldBoundingBoxUpdate
void BillboardSet::OnWorldBoundingBoxUpdate()
{
unsigned enabledBillboards = 0;
const Matrix3x4& worldTransform = node_->GetWorldTransform();
Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
BoundingBox worldBox;
for (unsigned i = 0; i < billboards_.Size(); ++i)
{
if (!billboards_[i]->enabled_)
continue;
float size = INV_SQRT_TWO * (billboards_[i]->size_.x_ * billboardScale.x_ + billboards_[i]->size_.y_ * billboardScale.y_);
Vector3 center = billboardTransform * billboards_[i]->position_;
Vector3 edge = Vector3::ONE * size;
worldBox.Merge(BoundingBox(center - edge, center + edge));
++enabledBillboards;
}
// Always merge the node's own position to ensure particle emitter updates continue when the relative mode is switched
worldBox.Merge(node_->GetWorldPosition());
worldBoundingBox_ = worldBox;
}
示例3: OnWorldBoundingBoxUpdate
void BillboardSet::OnWorldBoundingBoxUpdate()
{
unsigned enabledBillboards = 0;
const Matrix3x4& worldTransform = node_->GetWorldTransform();
Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
BoundingBox worldBox;
for (unsigned i = 0; i < billboards_.Size(); ++i)
{
if (!billboards_[i].enabled_)
continue;
float size = INV_SQRT_TWO * (billboards_[i].size_.x_ * billboardScale.x_ + billboards_[i].size_.y_ * billboardScale.y_);
Vector3 center = billboardTransform * billboards_[i].position_;
Vector3 edge = Vector3::ONE * size;
worldBox.Merge(BoundingBox(center - edge, center + edge));
++enabledBillboards;
}
// If no billboards enabled, the bounding box is just the node's world position
if (!enabledBillboards)
worldBox.Merge(node_->GetWorldPosition());
worldBoundingBox_ = worldBox;
}
示例4: HandlePostRenderUpdate
//显示选中物体的包围盒
void ObjectPositionEditor::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
{
EditorRoot* pEditorRoot = EditorRoot::Instance();
DebugRenderer* debug = pEditorRoot->scene_->GetComponent<DebugRenderer>();
if(debug == NULL)
return;
vector<Node*> nodes = pEditorRoot->GetUnionSelections();
for(int i = 0;i < nodes.size();i ++)
{
Node* node = nodes[i];
if(node->GetComponent<Skybox>() != NULL)
continue;
debug->AddNode(node,1.0f,false);
const Vector<SharedPtr<Component> >& components = node->GetComponents();
for(int j = 0;j < node->GetNumComponents();j ++)
{
Drawable* drawable = dynamic_cast<Drawable*>(components[j].Get());
if(drawable != NULL)
{
debug->AddBoundingBox(drawable->GetWorldBoundingBox(),Color::WHITE,true);
}
}
}
//计算总的
if(nodes.size() > 1)
{
BoundingBox allBox;
for(int i = 0;i < nodes.size();i ++)
{
Node* node = nodes[i];
if(node->GetComponent<Skybox>() != NULL)
continue;
const Vector<SharedPtr<Component> >& components = node->GetComponents();
for(int j = 0;j < node->GetNumComponents();j ++)
{
Drawable* drawable = dynamic_cast<Drawable*>(components[j].Get());
if(drawable != NULL)
{
allBox.Merge(drawable->GetWorldBoundingBox());
}
}
}
debug->AddBoundingBox(allBox,Color::BLUE,true);
}
if(CurrentHoverObject != NULL)
{
CurrentHoverObject->DrawDebugGeometry(debug,false);
}
}
示例5: GetViewBox
BoundingBox Camera::GetViewBox(const Frustum* frustum, const Scene* scene, bool receivers, bool casters)
{
BoundingBox result;
std::vector<SceneNode*> visibles;
scene->GetVisibleNodes(frustum, visibles);
for (auto& visible : visibles)
{
auto material = visible->GetMaterial().get();
if (!material) continue;
if ((receivers && material->ReceiveShadows()) || (casters && material->CastShadow()))
{
BoundingBox bb(visible->GetWorldBoundingBox());
result.Merge(bb);
}
}
return result;
}
示例6: OnWorldBoundingBoxUpdate
void StaticModelGroup::OnWorldBoundingBoxUpdate()
{
// Update transforms and bounding box at the same time to have to go through the objects only once
unsigned index = 0;
BoundingBox worldBox;
for (unsigned i = 0; i < instanceNodes_.Size(); ++i)
{
Node* node = instanceNodes_[i];
if (!node || !node->IsEnabled())
continue;
const Matrix3x4& worldTransform = node->GetWorldTransform();
worldTransforms_[index++] = worldTransform;
worldBox.Merge(boundingBox_.Transformed(worldTransform));
}
worldBoundingBox_ = worldBox;
// Store the amount of valid instances we found instead of resizing worldTransforms_. This is because this function may be
// called from multiple worker threads simultaneously
numWorldTransforms_ = index;
}
示例7: CreatePatchGeometry
void Terrain::CreatePatchGeometry(TerrainPatch* patch)
{
URHO3D_PROFILE(CreatePatchGeometry);
unsigned row = (unsigned)(patchSize_ + 1);
VertexBuffer* vertexBuffer = patch->GetVertexBuffer();
Geometry* geometry = patch->GetGeometry();
Geometry* maxLodGeometry = patch->GetMaxLodGeometry();
Geometry* occlusionGeometry = patch->GetOcclusionGeometry();
if (vertexBuffer->GetVertexCount() != row * row)
vertexBuffer->SetSize(row * row, MASK_POSITION | MASK_NORMAL | MASK_TEXCOORD1 | MASK_TANGENT);
SharedArrayPtr<unsigned char> cpuVertexData(new unsigned char[row * row * sizeof(Vector3)]);
SharedArrayPtr<unsigned char> occlusionCpuVertexData(new unsigned char[row * row * sizeof(Vector3)]);
float* vertexData = (float*)vertexBuffer->Lock(0, vertexBuffer->GetVertexCount());
float* positionData = (float*)cpuVertexData.Get();
float* occlusionData = (float*)occlusionCpuVertexData.Get();
BoundingBox box;
unsigned occlusionLevel = occlusionLodLevel_;
if (occlusionLevel > numLodLevels_ - 1)
occlusionLevel = numLodLevels_ - 1;
if (vertexData)
{
const IntVector2& coords = patch->GetCoordinates();
int lodExpand = (1 << (occlusionLevel)) - 1;
int halfLodExpand = (1 << (occlusionLevel)) / 2;
for (int z = 0; z <= patchSize_; ++z)
{
for (int x = 0; x <= patchSize_; ++x)
{
int xPos = coords.x_ * patchSize_ + x;
int zPos = coords.y_ * patchSize_ + z;
// Position
Vector3 position((float)x * spacing_.x_, GetRawHeight(xPos, zPos), (float)z * spacing_.z_);
*vertexData++ = position.x_;
*vertexData++ = position.y_;
*vertexData++ = position.z_;
*positionData++ = position.x_;
*positionData++ = position.y_;
*positionData++ = position.z_;
box.Merge(position);
// For vertices that are part of the occlusion LOD, calculate the minimum height in the neighborhood
// to prevent false positive occlusion due to inaccuracy between occlusion LOD & visible LOD
float minHeight = position.y_;
if (halfLodExpand > 0 && (x & lodExpand) == 0 && (z & lodExpand) == 0)
{
int minX = Max(xPos - halfLodExpand, 0);
int maxX = Min(xPos + halfLodExpand, numVertices_.x_ - 1);
int minZ = Max(zPos - halfLodExpand, 0);
int maxZ = Min(zPos + halfLodExpand, numVertices_.y_ - 1);
for (int nZ = minZ; nZ <= maxZ; ++nZ)
{
for (int nX = minX; nX <= maxX; ++nX)
minHeight = Min(minHeight, GetRawHeight(nX, nZ));
}
}
*occlusionData++ = position.x_;
*occlusionData++ = minHeight;
*occlusionData++ = position.z_;
// Normal
Vector3 normal = GetRawNormal(xPos, zPos);
*vertexData++ = normal.x_;
*vertexData++ = normal.y_;
*vertexData++ = normal.z_;
// Texture coordinate
Vector2 texCoord((float)xPos / (float)numVertices_.x_, 1.0f - (float)zPos / (float)numVertices_.y_);
*vertexData++ = texCoord.x_;
*vertexData++ = texCoord.y_;
// Tangent
Vector3 xyz = (Vector3::RIGHT - normal * normal.DotProduct(Vector3::RIGHT)).Normalized();
*vertexData++ = xyz.x_;
*vertexData++ = xyz.y_;
*vertexData++ = xyz.z_;
*vertexData++ = 1.0f;
}
}
vertexBuffer->Unlock();
vertexBuffer->ClearDataLost();
}
patch->SetBoundingBox(box);
if (drawRanges_.Size())
{
unsigned occlusionDrawRange = occlusionLevel << 4;
geometry->SetIndexBuffer(indexBuffer_);
geometry->SetDrawRange(TRIANGLE_LIST, drawRanges_[0].first_, drawRanges_[0].second_, false);
//.........这里部分代码省略.........
示例8: LoadMesh
//.........这里部分代码省略.........
XMLElement bufferDef;
if (geometry)
bufferDef = geometry.GetChild("vertexbuffer");
while (bufferDef)
{
if (bufferDef.HasAttribute("positions"))
vBuf->elementMask_ |= MASK_POSITION;
if (bufferDef.HasAttribute("normals"))
vBuf->elementMask_ |= MASK_NORMAL;
if (bufferDef.HasAttribute("texture_coords"))
{
vBuf->elementMask_ |= MASK_TEXCOORD1;
if (bufferDef.GetInt("texture_coords") > 1)
vBuf->elementMask_ |= MASK_TEXCOORD2;
}
unsigned vertexNum = vertexStart;
if (vertices)
{
XMLElement vertex = bufferDef.GetChild("vertex");
while (vertex)
{
XMLElement position = vertex.GetChild("position");
if (position)
{
// Convert from right- to left-handed
float x = position.GetFloat("x");
float y = position.GetFloat("y");
float z = position.GetFloat("z");
Vector3 vec(x, y, -z);
vBuf->vertices_[vertexNum].position_ = vec;
boundingBox_.Merge(vec);
}
XMLElement normal = vertex.GetChild("normal");
if (normal)
{
// Convert from right- to left-handed
float x = normal.GetFloat("x");
float y = normal.GetFloat("y");
float z = normal.GetFloat("z");
Vector3 vec(x, y, -z);
vBuf->vertices_[vertexNum].normal_ = vec;
}
XMLElement uv = vertex.GetChild("texcoord");
if (uv)
{
float x = uv.GetFloat("u");
float y = uv.GetFloat("v");
Vector2 vec(x, y);
vBuf->vertices_[vertexNum].texCoord1_ = vec;
if (vBuf->elementMask_ & MASK_TEXCOORD2)
{
uv = uv.GetNext("texcoord");
if (uv)
{
float x = uv.GetFloat("u");
float y = uv.GetFloat("v");
Vector2 vec(x, y);
vBuf->vertices_[vertexNum].texCoord2_ = vec;
}
示例9: CreatePatchGeometry
void Terrain::CreatePatchGeometry(TerrainPatch* patch)
{
PROFILE(CreatePatchGeometry);
unsigned row = patchSize_ + 1;
VertexBuffer* vertexBuffer = patch->GetVertexBuffer();
Geometry* geometry = patch->GetGeometry();
Geometry* maxLodGeometry = patch->GetMaxLodGeometry();
Geometry* minLodGeometry = patch->GetMinLodGeometry();
if (vertexBuffer->GetVertexCount() != row * row)
vertexBuffer->SetSize(row * row, MASK_POSITION | MASK_NORMAL | MASK_TEXCOORD1 | MASK_TANGENT);
SharedArrayPtr<unsigned char> cpuVertexData(new unsigned char[row * row * sizeof(Vector3)]);
float* vertexData = (float*)vertexBuffer->Lock(0, vertexBuffer->GetVertexCount());
float* positionData = (float*)cpuVertexData.Get();
BoundingBox box;
if (vertexData)
{
const IntVector2& coords = patch->GetCoordinates();
for (int z1 = 0; z1 <= patchSize_; ++z1)
{
for (int x1 = 0; x1 <= patchSize_; ++x1)
{
int xPos = coords.x_ * patchSize_ + x1;
int zPos = coords.y_ * patchSize_ + z1;
// Position
Vector3 position((float)x1 * spacing_.x_, GetRawHeight(xPos, zPos), (float)z1 * spacing_.z_);
*vertexData++ = position.x_;
*vertexData++ = position.y_;
*vertexData++ = position.z_;
*positionData++ = position.x_;
*positionData++ = position.y_;
*positionData++ = position.z_;
box.Merge(position);
// Normal
Vector3 normal = GetRawNormal(xPos, zPos);
*vertexData++ = normal.x_;
*vertexData++ = normal.y_;
*vertexData++ = normal.z_;
// Texture coordinate
Vector2 texCoord((float)xPos / (float)numVertices_.x_, 1.0f - (float)zPos / (float)numVertices_.y_);
*vertexData++ = texCoord.x_;
*vertexData++ = texCoord.y_;
// Tangent
Vector3 xyz = (Vector3::RIGHT - normal * normal.DotProduct(Vector3::RIGHT)).Normalized();
*vertexData++ = xyz.x_;
*vertexData++ = xyz.y_;
*vertexData++ = xyz.z_;
*vertexData++ = 1.0f;
}
}
vertexBuffer->Unlock();
vertexBuffer->ClearDataLost();
}
patch->SetBoundingBox(box);
if (drawRanges_.Size())
{
unsigned lastDrawRange = drawRanges_.Size() - 1;
geometry->SetIndexBuffer(indexBuffer_);
geometry->SetDrawRange(TRIANGLE_LIST, drawRanges_[0].first_, drawRanges_[0].second_, false);
geometry->SetRawVertexData(cpuVertexData, sizeof(Vector3), MASK_POSITION);
maxLodGeometry->SetIndexBuffer(indexBuffer_);
maxLodGeometry->SetDrawRange(TRIANGLE_LIST, drawRanges_[0].first_, drawRanges_[0].second_, false);
maxLodGeometry->SetRawVertexData(cpuVertexData, sizeof(Vector3), MASK_POSITION);
minLodGeometry->SetIndexBuffer(indexBuffer_);
minLodGeometry->SetDrawRange(TRIANGLE_LIST, drawRanges_[lastDrawRange].first_, drawRanges_[lastDrawRange].second_, false);
minLodGeometry->SetRawVertexData(cpuVertexData, sizeof(Vector3), MASK_POSITION);
}
// Offset the occlusion geometry by vertex spacing to reduce possibility of over-aggressive occlusion
patch->SetOcclusionOffset(-0.5f * (spacing_.x_ + spacing_.z_));
patch->ResetLod();
}
示例10: WriteVertex
void WriteVertex(float*& dest, aiMesh* mesh, unsigned index, unsigned elementMask, BoundingBox& box,
const Matrix3x4& vertexTransform, const Matrix3& normalTransform, Vector<PODVector<unsigned char> >& blendIndices,
Vector<PODVector<float> >& blendWeights)
{
Vector3 vertex = vertexTransform * ToVector3(mesh->mVertices[index]);
box.Merge(vertex);
*dest++ = vertex.x_;
*dest++ = vertex.y_;
*dest++ = vertex.z_;
if (elementMask & MASK_NORMAL)
{
Vector3 normal = normalTransform * ToVector3(mesh->mNormals[index]);
*dest++ = normal.x_;
*dest++ = normal.y_;
*dest++ = normal.z_;
}
if (elementMask & MASK_COLOR)
{
*((unsigned*)dest) = Color(mesh->mColors[0][index].r, mesh->mColors[0][index].g, mesh->mColors[0][index].b,
mesh->mColors[0][index].a).ToUInt();
++dest;
}
if (elementMask & MASK_TEXCOORD1)
{
Vector3 texCoord = ToVector3(mesh->mTextureCoords[0][index]);
*dest++ = texCoord.x_;
*dest++ = texCoord.y_;
}
if (elementMask & MASK_TEXCOORD2)
{
Vector3 texCoord = ToVector3(mesh->mTextureCoords[1][index]);
*dest++ = texCoord.x_;
*dest++ = texCoord.y_;
}
if (elementMask & MASK_TANGENT)
{
Vector3 tangent = normalTransform * ToVector3(mesh->mTangents[index]);
Vector3 normal = normalTransform * ToVector3(mesh->mNormals[index]);
Vector3 bitangent = normalTransform * ToVector3(mesh->mBitangents[index]);
// Check handedness
float w = 1.0f;
if ((tangent.CrossProduct(normal)).DotProduct(bitangent) < 0.5f)
w = -1.0f;
*dest++ = tangent.x_;
*dest++ = tangent.y_;
*dest++ = tangent.z_;
*dest++ = w;
}
if (elementMask & MASK_BLENDWEIGHTS)
{
for (unsigned i = 0; i < 4; ++i)
{
if (i < blendWeights[index].Size())
*dest++ = blendWeights[index][i];
else
*dest++ = 0.0f;
}
}
if (elementMask & MASK_BLENDINDICES)
{
unsigned char* destBytes = (unsigned char*)dest;
++dest;
for (unsigned i = 0; i < 4; ++i)
{
if (i < blendIndices[index].Size())
*destBytes++ = blendIndices[index][i];
else
*destBytes++ = 0;
}
}
}