本文整理汇总了C#中BoundingSphere.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingSphere.Transform方法的具体用法?C# BoundingSphere.Transform怎么用?C# BoundingSphere.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingSphere
的用法示例。
在下文中一共展示了BoundingSphere.Transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VertexInsideBoundingSphereCheck
public void VertexInsideBoundingSphereCheck()
{
var transform = Matrix.CreateScale(3.0f)*Matrix.CreateRotationY(MathHelper.PiOver4);
var sphere = new BoundingSphere(Vector3.Zero, 1.0f);
var transformedSphere = sphere.Transform(transform);
var triangleOut = new Triangle(new Vector3(2.1f, 2.1f, 0.0f),
new Vector3(2.1f, 0.0f, 0.0f),
new Vector3(4.2f, 2.1f, 0.0f),
String.Empty);
Assert.False(triangleOut.HasAtLeastOnPointInsideBoundingSphere(sphere));
var transformedTriangleOut = new Triangle(Vector3.Transform(triangleOut.Point0, transform),
Vector3.Transform(triangleOut.Point1, transform),
Vector3.Transform(triangleOut.Point2, transform),
String.Empty);
Assert.False(transformedTriangleOut.HasAtLeastOnPointInsideBoundingSphere(transformedSphere));
var triangleIn = new Triangle(new Vector3(2.1f, 2.1f, 0.0f),
new Vector3(0.9f, 0.0f, 0.0f), // It's in!
new Vector3(4.2f, 2.1f, 0.0f),
String.Empty);
Assert.True(triangleIn.HasAtLeastOnPointInsideBoundingSphere(sphere));
var transformedTriangleIn = new Triangle(Vector3.Transform(triangleIn.Point0, transform),
Vector3.Transform(triangleIn.Point1, transform),
Vector3.Transform(triangleIn.Point2, transform),
String.Empty);
Assert.True(transformedTriangleIn.HasAtLeastOnPointInsideBoundingSphere(transformedSphere));
}
示例2: TransformingWithOnlyTranslationShouldPositionSphereCorrectly
public void TransformingWithOnlyTranslationShouldPositionSphereCorrectly()
{
var boundingSphere = new BoundingSphere(Vector.Zero, 1);
var position = new Vector(10, 5, 3);
var matrix = Matrix.CreateTranslation(position);
var transformedBoundingSphere = boundingSphere.Transform(matrix);
Assert.That(transformedBoundingSphere.Center, Is.EqualTo(position));
}
示例3: TransormingWith90DegreesRotationAroundYAndTranslationShouldPositionSphereCorrectly
public void TransormingWith90DegreesRotationAroundYAndTranslationShouldPositionSphereCorrectly()
{
var boundingSphere = new BoundingSphere(Vector.Zero, 1);
var position = new Vector(10, 5, 3);
var translationMatrix = Matrix.CreateTranslation(position);
var rotationMatrix = Matrix.CreateRotationY(90f);
var matrix = translationMatrix * rotationMatrix;
var transformedBoundingSphere = boundingSphere.Transform(matrix);
var expectedPosition = position*rotationMatrix;
Assert.That(transformedBoundingSphere.Center, Is.EqualTo(expectedPosition));
}
示例4: GetGlobalBoundingSphere
public static BoundingSphere GetGlobalBoundingSphere( Model model )
{
Matrix[] absoluteBoneTransforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo( absoluteBoneTransforms );
BoundingSphere globalBoundingSphere = new BoundingSphere();
foreach( ModelMesh mesh in model.Meshes) {
CustomMeshData meshData = mesh.Tag as CustomMeshData;
BoundingSphere meshBoundingSphere = new BoundingSphere();
if ( meshData != null ) {
meshBoundingSphere = meshData.BoundingSphere;
} else {
meshBoundingSphere = mesh.BoundingSphere;
}
meshBoundingSphere = meshBoundingSphere.Transform( absoluteBoneTransforms[mesh.ParentBone.Index] );
globalBoundingSphere = BoundingSphere.CreateMerged( globalBoundingSphere, meshBoundingSphere );
}
return globalBoundingSphere;
}
示例5: GetBoundingSphere
public BoundingSphere GetBoundingSphere()
{
BoundingSphere sphere = new BoundingSphere(new Vector3(0.0f, 0.0f, 0.0f), 1.0f);
sphere = sphere.Transform(GetWorld());
return sphere;
}
示例6: 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;
}
}
}
示例7: UpdateBoundingSpheres
public void UpdateBoundingSpheres()
{
Matrix[] worldTransforms = updatedModel.getWorldTransforms();
for (int index = 0; index < skinnedSpheres.Length; index++)
{
SkinnedSphere source = skinnedSpheres[index];
Vector3 center = new Vector3(source.Offset, 0, 0);
BoundingSphere sphere = new BoundingSphere(center, source.Radius);
int boneIndex = skinningData.BoneIndices[source.BoneName];
boundingSpheres[index] = sphere.Transform(worldTransforms[boneIndex]);
}
}
示例8: TransformSphere
private void TransformSphere()
{
_transformed = BoundingSphere;
_transformed = _transformed.Transform(_worldTransform);
}
示例9: Update
protected override void Update(GameTime gameTime)
{
BoundingSphere sphere;
model.Meshes[0].MeshParts[0].Effect = effect[ExcNum];
for (int i = 0; i < NR_MODELS; i++)
{
sphere = new BoundingSphere();
sphere = BoundingSphere.CreateMerged(sphere, model2[i].Meshes[0].BoundingSphere);
InViewFrustum[i] = camera.InView(sphere.Transform(World2n[i]));
}
float timeStep = (float)gameTime.ElapsedGameTime.TotalSeconds * 60.0f;
//Keyboard usage
KeyboardState KeyState = Keyboard.GetState();
//Change Rotation using the 'left' and 'right' keys
if (KeyState.IsKeyDown(Keys.Z))
{
rotationAmount = rotationAmount + timeStep / 100;
}
if (KeyState.IsKeyDown(Keys.G))
{
if (!Gpressed) { postGray = !postGray; }
Gpressed = true;
}
if (KeyState.IsKeyUp(Keys.G)) { Gpressed = false; }
if (KeyState.IsKeyDown(Keys.B))
{
if (!Bpressed) { postBlur = !postBlur; }
Bpressed = true;
}
if (KeyState.IsKeyUp(Keys.B)) { Bpressed = false; }
if (KeyState.IsKeyDown(Keys.X))
{
rotationAmount = rotationAmount - timeStep / 100;
}
if (KeyState.IsKeyDown(Keys.Space))
{
if (!SpacePressed) { ExcNum = (ExcNum + 1) % (maxExc + 1); }
SpacePressed = true;
}
if (KeyState.IsKeyUp(Keys.Space)) { SpacePressed = false; }
// Update Excersize
model.Meshes[0].MeshParts[0].Effect = effect[ExcNum];
// Update the window title
Window.Title = "XNA Renderer | FPS: " + frameRateCounter.FrameRate;
base.Update(gameTime);
}
示例10: drawPlayer
public void drawPlayer()
{
GraphicsDevice.RenderState.CullMode = CullMode.None;
//Matrix newViewMatrix = Matrix.CreateLookAt(new Vector3(camX, 300.0f, 0.0f), new Vector3(camX, 0.0f, -1000.0f), new Vector3(0.0f, 1.0f, 0.0f));
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.Projection = projMatrix;
effect.View = viewMatrix;
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(MathHelper.ToRadians(rotation))
* Matrix.CreateScale(100.0f) * Matrix.CreateTranslation(new Vector3(camX, 0.0f, -250.0f));
effect.Texture = carTexture;
}
playerSphere = mesh.BoundingSphere;
playerSphere.Transform(transforms[mesh.ParentBone.Index]);
playerSphere.Center = new Vector3(camX, 0.0f, -250.0f);
playerSphere.Radius = (mesh.BoundingSphere.Radius * 250.0f);
//Console.WriteLine(boundingSphere.Radius.ToString());
//Render(boundingSphere, GraphicsDevice, viewMatrix, projMatrix, Color.SaddleBrown);
mesh.Draw();
}
}
示例11: UpdateBoundingSpheres
/// <summary>
/// Updates the boundingSpheres array to match the current animation state.
/// </summary>
void UpdateBoundingSpheres()
{
// Look up the current world space bone positions.
Matrix[] worldTransforms = animationPlayer.GetWorldTransforms();
for (int i = 0; i < skinnedSpheres.Length; i++)
{
// Convert the SkinnedSphere description to a BoundingSphere.
SkinnedSphere source = skinnedSpheres[i];
Vector3 center = new Vector3(source.Offset, 0, 0);
BoundingSphere sphere = new BoundingSphere(center, source.Radius);
// Transform the BoundingSphere by its parent bone matrix,
// and store the result into the boundingSpheres array.
int boneIndex = skinningData.BoneIndices[source.BoneName];
boundingSpheres[i] = sphere.Transform(worldTransforms[boneIndex]);
}
}
开发者ID:MayoTomale,项目名称:BNO055-project-moving-InMoov-hobot-hand-and-XNA-demo,代码行数:22,代码来源:SkinningSample.cs
示例12: UpdateBoundingVolume
public virtual void UpdateBoundingVolume()
{
if (Model != null)
{
BoundingSphere = new BoundingSphere();
foreach (var mesh in Model.Meshes)
{
BoundingSphere = BoundingSphere.CreateMerged(mesh.BoundingSphere.Transform(mesh.ParentBone.Transform), BoundingSphere);
}
BoundingSphere = BoundingSphere.Transform(Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position));
}
}
示例13: CollidesWith
public bool CollidesWith(Model modelo1, Matrix mundo1, Model modelo2, Matrix mundo2)
{
// Loop through each ModelMesh in both objects and compare
// all bounding spheres for collisions
float aspectRatio = (float)device.Viewport.Width / device.Viewport.Height;
foreach (ModelMesh myModelMeshes in modelo1.Meshes)
{
foreach (ModelMesh hisModelMeshes in modelo2.Meshes)
{
BoundingSphere esfera1, esfera2;
//radio*155
Vector3 centro2 = hisModelMeshes.BoundingSphere.Center;
centro2.X -= 360;
esfera1= new BoundingSphere(myModelMeshes.BoundingSphere.Center,(myModelMeshes.BoundingSphere.Radius*300));
esfera2= new BoundingSphere(centro2,(hisModelMeshes.BoundingSphere.Radius*25));
BoundingSphereRenderer.Render(esfera1.Transform(mundo1), device, Matrix.CreateLookAt(cameraPosition, lookAt, Vector3.Up), Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 100000.0f), Color.Blue);
BoundingSphereRenderer.Render(esfera2.Transform(mundo2), device, Matrix.CreateLookAt(cameraPosition, lookAt, Vector3.Up), Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 100000.0f), Color.Red);
//BoundingBox caja =new BoundingBox(new Vector3(30f,99f,110f),posicionBlanco);
//BoundingBoxRenderer.Render(caja, device, Matrix.CreateLookAt(cameraPosition, lookAt, Vector3.Up), Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 100000.0f), Color.Blue);
if (esfera1.Transform(
mundo1).Intersects(
esfera2.Transform(mundo2)))
return true;
/*if (myModelMeshes.BoundingSphere.Transform(
mundo1).Intersects(
hisModelMeshes.BoundingSphere.Transform(mundo2)))
return true;*/
}
}
return false;
}
示例14: LoadModelBoundingSphere
/// <summary>
/// Loads the bounding sphere of the model into it's tag.
/// </summary>
private void LoadModelBoundingSphere()
{
completeBoundingSphere = new BoundingSphere();
foreach (ModelMesh mesh in model.Meshes)
{
BoundingSphere origMeshSphere = mesh.BoundingSphere;
BoundingSphere transMeshSphere = XNAUtils.TransformBoundingSphere(origMeshSphere,
originalTransforms[mesh.ParentBone.Index]);
completeBoundingSphere =
BoundingSphere.CreateMerged(completeBoundingSphere, transMeshSphere);
}
model.Tag = completeBoundingSphere.Transform(Matrix.CreateScale(0.5f));
}
示例15: SpheresIntersect
private bool SpheresIntersect(Vector3 p1, BoundingSphere s1, Vector3 p2, BoundingSphere s2)
{
var shere1 = s1.Transform(Matrix.CreateTranslation(p1));
var shere2 = s2.Transform(Matrix.CreateTranslation(p2));
return shere1.Intersects(shere2);
}