本文整理汇总了C#中BoundingBox.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBox.Merge方法的具体用法?C# BoundingBox.Merge怎么用?C# BoundingBox.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingBox
的用法示例。
在下文中一共展示了BoundingBox.Merge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBounds
/// <summary>
/// Get bounds
/// </summary>
/// <param name="items">Items</param>
/// <returns>Bounds</returns>
protected virtual BoundingBox GetBounds( IList<IBSPItem> items )
{
BoundingBox bounds = new BoundingBox();
foreach ( IBSPItem item in items )
{
bounds.Merge( item.Bounds );
}
return bounds;
}
示例2: Update
internal void Update(TransformComponent transformComponent, ref Matrix worldMatrix)
{
if (!Enabled || model == null)
return;
// Check if scaling is negative
var up = Vector3.Cross(worldMatrix.Right, worldMatrix.Forward);
bool isScalingNegative = Vector3.Dot(worldMatrix.Up, up) < 0.0f;
// Make sure skeleton is up to date
CheckSkeleton();
if (skeleton != null)
{
// Update model view hierarchy node matrices
skeleton.NodeTransformations[0].LocalMatrix = worldMatrix;
skeleton.NodeTransformations[0].IsScalingNegative = isScalingNegative;
skeleton.UpdateMatrices();
}
// Update the bounding sphere / bounding box in world space
BoundingSphere = BoundingSphere.Empty;
BoundingBox = BoundingBox.Empty;
bool modelHasBoundingBox = false;
for (int meshIndex = 0; meshIndex < Model.Meshes.Count; meshIndex++)
{
var mesh = Model.Meshes[meshIndex];
var meshInfo = meshInfos[meshIndex];
meshInfo.BoundingSphere = BoundingSphere.Empty;
meshInfo.BoundingBox = BoundingBox.Empty;
if (mesh.Skinning != null && skeleton != null)
{
bool meshHasBoundingBox = false;
var bones = mesh.Skinning.Bones;
// For skinned meshes, bounding box is union of the bounding boxes of the unskinned mesh, transformed by each affecting bone.
for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
{
var nodeIndex = bones[boneIndex].NodeIndex;
Matrix.Multiply(ref bones[boneIndex].LinkToMeshMatrix, ref skeleton.NodeTransformations[nodeIndex].WorldMatrix, out meshInfos[meshIndex].BlendMatrices[boneIndex]);
BoundingBox skinnedBoundingBox;
BoundingBox.Transform(ref mesh.BoundingBox, ref meshInfos[meshIndex].BlendMatrices[boneIndex], out skinnedBoundingBox);
BoundingSphere skinnedBoundingSphere;
BoundingSphere.Transform(ref mesh.BoundingSphere, ref meshInfos[meshIndex].BlendMatrices[boneIndex], out skinnedBoundingSphere);
if (meshHasBoundingBox)
{
BoundingBox.Merge(ref meshInfo.BoundingBox, ref skinnedBoundingBox, out meshInfo.BoundingBox);
BoundingSphere.Merge(ref meshInfo.BoundingSphere, ref skinnedBoundingSphere, out meshInfo.BoundingSphere);
}
else
{
meshHasBoundingBox = true;
meshInfo.BoundingSphere = skinnedBoundingSphere;
meshInfo.BoundingBox = skinnedBoundingBox;
}
}
}
else
{
// If there is a skeleton, use the corresponding node's transform. Otherwise, fall back to the model transform.
var transform = skeleton != null ? skeleton.NodeTransformations[mesh.NodeIndex].WorldMatrix : worldMatrix;
BoundingBox.Transform(ref mesh.BoundingBox, ref transform, out meshInfo.BoundingBox);
BoundingSphere.Transform(ref mesh.BoundingSphere, ref transform, out meshInfo.BoundingSphere);
}
if (modelHasBoundingBox)
{
BoundingBox.Merge(ref BoundingBox, ref meshInfo.BoundingBox, out BoundingBox);
BoundingSphere.Merge(ref BoundingSphere, ref meshInfo.BoundingSphere, out BoundingSphere);
}
else
{
BoundingBox = meshInfo.BoundingBox;
BoundingSphere = meshInfo.BoundingSphere;
modelHasBoundingBox = true;
}
}
}
示例3: MergeTwoBoundingBoxes
public void MergeTwoBoundingBoxes()
{
var boxA = new BoundingBox(Vector3D.Zero, Vector3D.Zero);
boxA.Merge(new BoundingBox(-Vector3D.One, Vector3D.One));
Assert.AreEqual(boxA, new BoundingBox(-Vector3D.One, Vector3D.One));
boxA.Merge(new BoundingBox(Vector3D.Zero, Vector3D.Zero));
Assert.AreEqual(boxA, new BoundingBox(-Vector3D.One, Vector3D.One));
}