本文整理汇总了C#中BoundingSphere类的典型用法代码示例。如果您正苦于以下问题:C# BoundingSphere类的具体用法?C# BoundingSphere怎么用?C# BoundingSphere使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundingSphere类属于命名空间,在下文中一共展示了BoundingSphere类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update(GameTime gameTime)
{
if (timer > 0)
{
timer -= gameTime.ElapsedGameTime.TotalSeconds;
scale += 0.12f;
alpha -= 0.016f;
}
else
isActive = false;
BoundingSphere bombSphere = new BoundingSphere(position, explosionModel.Meshes[0].BoundingSphere.Radius * scale);
for (int i = 0; i < GamePlay.asteroidList.Length; i++)
{
if (GamePlay.asteroidList[i].isActive)
{
BoundingSphere asteroidSphere = new BoundingSphere(GamePlay.asteroidList[i].position,
GamePlay.asteroidModel.Meshes[0].BoundingSphere.Radius * 0.95f);
if (asteroidSphere.Intersects(bombSphere))
{
//destroy asteroid
MainClass.soundBank.PlayCue("explosion2");
GamePlay.asteroidList[i].isActive = false;
GamePlay.playerList[index].score += GameConstants.KillBonus;
return; //exit the loop
}
}
}
}
示例2: CollideSphere
/// <summary>
/// Constructor.
/// </summary>
/// <param name="center">center position of the sphere</param>
/// <param name="radius">radius of the sphere</param>
public CollideSphere(Vector3 center, float radius)
: base()
{
localCenter = center;
boundingSphere = new BoundingSphere(localCenter, radius);
}
示例3: Planet
public Planet(Vector3 Position, float Scale, float ParentMass, Vector3 OrbitalPlaneNormal)
: base()
{
Body.CreateUVSphere(32, 32, out ModelVertices, out ModelIndices);
effect = Manager.TexturedEffect;
NoiseMap = Manager.WrappedNoiseTextures[MyGame.random.Next(Manager.WrappedNoiseTextures.Length)];
Color[] StaticNoise = Manager.GenerateStaticNoise(5, 5);
for (int i = 0; i < StaticNoise.Length; i++)
{
StaticNoise[i] = Color.Lerp(planetColors[MyGame.random.Next(planetColors.Length)]
, StaticNoise[i]
, 0.1f * (float)MyGame.random.NextDouble());
}
ColorMap = new Texture2D(MyGame.graphics.GraphicsDevice, 5, 5);
ColorMap.SetData<Color>(StaticNoise);
RotationAxis = Manager.GetRandomNormal();
RotationTime = (float)MyGame.random.NextDouble();
Bounds = new BoundingSphere(Position, 2.0f * Scale);
this.Transforms = new ScalePositionRotation(
Scale
, Position
, Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
Mass = 10.0f * (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));
this.Velocity = Body.GetRandomInitialOrbitVelocity(Position, OrbitalPlaneNormal, ParentMass, Mass);
}
示例4: GameObject
public GameObject()
{
Model = null;
Position = Vector3.Zero;
Rotation = Vector3.Zero;
BoundingSphere = new BoundingSphere();
}
示例5: Character
public Character(string textureName, Vector2 position, ContentManager content, int frameCount)
{
mContent = content;
mTextureName = textureName;
mPosition = position;
mAge = age.BABY;
mStates = states.SPAWNING;
mSpeed = new Vector2(1.0f, 0.25f);
//mSpeed = new Vector2(0, 0);
mSprite = new AnimatedSprite();
//mSprite.Load(mContent, "AnimatedSprites/" + mTextureName, frameCount, 30, 149, 139, false);
mSprite.Load(mContent, "AnimatedSprites/" + mTextureName, frameCount, 0.125f, 128, 128, false);
bSphere = new BoundingSphere(new Vector3(position.X + mSprite.getWidth() / 2, position.Y + mSprite.getHeight() / 2, 0), mSprite.getWidth() / 2);
distance = 10000;
destination = Vector2.Zero;
timeEating = 2.0f;
timeOnFire = 0.5f;
respawnRate = 3.0f;
remove = false;
multipleOfTwo = false;
hacktex = Class1.CreateCircle((int)mSprite.getWidth() / 2, Color.Yellow);
timespawning = 2.0f;
}
示例6: GetAllBroadcastersInMyRange
protected override void GetAllBroadcastersInMyRange(ref HashSet<MyDataBroadcaster> relayedBroadcasters, long localPlayerId, HashSet<long> gridsQueued)
{
var sphere = new BoundingSphere(Parent.PositionComp.GetPosition(), 0.5f);
MyRadioBroadcasters.GetAllBroadcastersInSphere(sphere, m_broadcastersInRange);
foreach (var broadcaster in m_broadcastersInRange)
{
if (relayedBroadcasters.Contains(broadcaster))
continue;
relayedBroadcasters.Add(broadcaster);
if (!CanIUseIt(broadcaster, localPlayerId))
continue;
if (broadcaster.Parent is IMyComponentOwner<MyDataReceiver>)
{
MyDataReceiver radioReceiver;
if ((broadcaster.Parent as IMyComponentOwner<MyDataReceiver>).GetComponent(out radioReceiver))
{
radioReceiver.UpdateBroadcastersInRange(relayedBroadcasters, localPlayerId, gridsQueued);
}
}
}
}
示例7: GetBoundingSphere
public BoundingSphere GetBoundingSphere(Vector3 aLowest, Vector3 aHighest, Vector3 aTranslation, Vector3 aTile)
{
Vector3 temporaryRadius = new Vector3((aHighest.X - aLowest.X) / 2, (aHighest.Y - aLowest.Y) / 2, (aHighest.Z - aLowest.Z) / 2) * aTile;
BoundingSphere temporarySphere = new BoundingSphere(aTranslation, (temporaryRadius.X + temporaryRadius.Y + temporaryRadius.Z) / 3);
return temporarySphere;
}
示例8: Initialize
public override void Initialize()
{
PourcentageVie = 1;
SphereCollision = new BoundingSphere(Position, RAYON_COLLISION);
CompteurCollision = 0;
base.Initialize();
}
示例9: Intersect
public static bool Intersect(Triangle triangle, BoundingSphere sphere, out object intersection)
{
intersection = null;
return Common.Intersection.Intersect(sphere, triangle.A.Position, out intersection) ||
Common.Intersection.Intersect(sphere, triangle.B.Position, out intersection) ||
Common.Intersection.Intersect(sphere, triangle.C.Position, out intersection);
}
示例10: Draw
public override void Draw(GraphicsDevice device, Camera cam)
{
if (filter == null)
{
return;
}
Mesh mesh = filter.meshToRender;
BoundingSphere sphere = new BoundingSphere(transform.TransformPoint(filter.boundingSphere.Center), filter.boundingSphere.Radius * Math.Max(transform.lossyScale.x, Math.Max(transform.lossyScale.y, transform.lossyScale.z)));
bool cull = cam.DoFrustumCulling(ref sphere);
if (cull)
{
#if DEBUG
if (Camera.logRenderCalls)
{
Debug.LogFormat("VP cull mesh {0} with center {1} radius {2} cam {3} at {4}", gameObject, sphere.Center, sphere.Radius, cam.gameObject, cam.transform.position);
}
#endif
return;
}
if (filter.CanBatch())
{
cam.BatchRender(filter.meshToRender, sharedMaterials, transform);
}
}
示例11: ComputeBounds
public unsafe static BoundingBox ComputeBounds(this VertexBufferBinding vertexBufferBinding, ref Matrix matrix, out BoundingSphere boundingSphere)
{
var positionOffset = vertexBufferBinding.Declaration
.EnumerateWithOffsets()
.First(x => x.VertexElement.SemanticAsText == "POSITION")
.Offset;
var boundingBox = BoundingBox.Empty;
boundingSphere = new BoundingSphere();
var vertexStride = vertexBufferBinding.Declaration.VertexStride;
fixed (byte* bufferStart = &vertexBufferBinding.Buffer.GetSerializationData().Content[vertexBufferBinding.Offset])
{
// Calculates bounding box and bounding sphere center
byte* buffer = bufferStart + positionOffset;
for (int i = 0; i < vertexBufferBinding.Count; ++i)
{
var position = (Vector3*)buffer;
Vector3 transformedPosition;
Vector3.TransformCoordinate(ref *position, ref matrix, out transformedPosition);
// Prepass calculate the center of the sphere
Vector3.Add(ref transformedPosition, ref boundingSphere.Center, out boundingSphere.Center);
BoundingBox.Merge(ref boundingBox, ref transformedPosition, out boundingBox);
buffer += vertexStride;
}
//This is the center of our sphere.
boundingSphere.Center /= (float)vertexBufferBinding.Count;
// Calculates bounding sphere center
buffer = bufferStart + positionOffset;
for (int i = 0; i < vertexBufferBinding.Count; ++i)
{
var position = (Vector3*)buffer;
Vector3 transformedPosition;
Vector3.TransformCoordinate(ref *position, ref matrix, out transformedPosition);
//We are doing a relative distance comparasin to find the maximum distance
//from the center of our sphere.
float distance;
Vector3.DistanceSquared(ref boundingSphere.Center, ref transformedPosition, out distance);
if (distance > boundingSphere.Radius)
boundingSphere.Radius = distance;
buffer += vertexStride;
}
//Find the real distance from the DistanceSquared.
boundingSphere.Radius = (float)Math.Sqrt(boundingSphere.Radius);
}
return boundingBox;
}
示例12: RayInterSection_OutsideSpherePointingAway_NoIntersection
public void RayInterSection_OutsideSpherePointingAway_NoIntersection()
{
var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
var ray = new Ray3D(sphere.Center + new Vector3D(0.2, 0.3, sphere.Radius), new Vector3D(1, 0.1, 0.1));
Point3D[] result;
Assert.IsFalse(sphere.RayIntersection(ray, out result));
}
示例13: Draw
public void Draw(ref BoundingSphere sphere, BasicEffect effect, ref Color vertexColor)
{
graphicsDevice.SetVertexBuffer(vertexBuffer);
Matrix scale;
Matrix.CreateScale(sphere.Radius, out scale);
Matrix translation;
Matrix.CreateTranslation(ref sphere.Center, out translation);
Matrix transform;
Matrix.Multiply(ref scale, ref translation, out transform);
effect.World = transform;
effect.DiffuseColor = vertexColor.ToVector3();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
//render each circle individually
graphicsDevice.DrawPrimitives(
PrimitiveType.LineStrip,
0,
sphereResolution);
graphicsDevice.DrawPrimitives(
PrimitiveType.LineStrip,
sphereResolution + 1,
sphereResolution);
graphicsDevice.DrawPrimitives(
PrimitiveType.LineStrip,
(sphereResolution + 1) * 2,
sphereResolution);
}
}
示例14: Render
public static void Render(Primitive prim, RenderContext context, Color color)
{
if (prim.PrimType == Forever.Physics.Collide.CollideType.Sphere)
{
Sphere sphere = (Sphere)prim;
BoundingSphere bs = new BoundingSphere(prim.Body.Position, sphere.Radius);
BoundingSphereRenderer.Render(bs, context, color);
}
else if (prim.PrimType == Forever.Physics.Collide.CollideType.Box)
{
Box b = (Box)prim;
Matrix world = prim.Body.World;
BoundingBoxRenderer.Render(
BoundingBox.CreateFromPoints(b.LocalVerts()),
context.GraphicsDevice,
world * b.OffsetMatrix,
context.Camera.View,
context.Camera.Projection,
color
);
}else if(prim.PrimType == Forever.Physics.Collide.CollideType.Plane){
Render((Forever.Physics.Collide.Plane)prim, context, color);
}
else
{
throw new Exception("I don't know how to draw that!");
}
}
示例15: RayPointingAwayFromBoundingSphereShouldBeIntersected
public void RayPointingAwayFromBoundingSphereShouldBeIntersected()
{
var boundingSphere = new BoundingSphere(new Vector(0, 0, 0), 1);
var ray = new Ray(new Vector(0, -10, 0), new Vector(0, -1, 0));
var result = ray.Intersects(boundingSphere);
Assert.That(result, Is.Null);
}