本文整理汇总了C#中BEPUphysics.Entities.Entity类的典型用法代码示例。如果您正苦于以下问题:C# Entity类的具体用法?C# Entity怎么用?C# Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于BEPUphysics.Entities命名空间,在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixedOffsetCameraControlScheme
public FixedOffsetCameraControlScheme(Entity entity, Camera camera, DemosGame game)
: base(camera, game)
{
Entity = entity;
UseCameraSmoothing = true;
CameraOffset = new Vector3(0, 0.7f, 0);
}
示例2: DisplayEntityModel
/// <summary>
/// Constructs a new display model.
/// </summary>
/// <param name="entity">Entity to follow.</param>
/// <param name="model">Model to draw on the entity.</param>
/// <param name="modelDrawer">Model drawer to use.</param>
public DisplayEntityModel(Entity entity, Model model, ModelDrawer modelDrawer)
: base(modelDrawer)
{
OffsetTransform = Matrix.Identity;
Entity = entity;
Model = model;
}
示例3: Thruster
/// <summary>
/// Constructs a thruster originating at the given position, pushing in the given direction.
/// </summary>
/// <param name="targetEntity">Entity that the force will be applied to.</param>
/// <param name="pos">Origin of the force.</param>
/// <param name="dir">Direction of the force.</param>
/// <param name="time">Total lifespan of the force. A lifespan of zero is infinite.</param>
public Thruster(Entity targetEntity, Vector3 pos, Vector3 dir, float time)
{
Target = targetEntity;
Position = pos;
Direction = dir;
LifeSpan = time;
}
示例4: FishInABarrelDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public FishInABarrelDemo(DemosGame game)
: base(game)
{
game.Camera.Position = new Vector3(0, 7, 30);
var detector = new Box(new Vector3(0, 0, 0), 1.5f, 1.5f, 1.5f);
detector.CollisionInformation.CollisionRules.Personal = CollisionRule.NoSolver;
var acceptedTriggerEntity = new Box(new Vector3(5, 0, 0), 1.6f, .7f, .4f, 1);
acceptedTrigger = acceptedTriggerEntity.CollisionInformation;
detector.Tag = "noDisplayObject";
acceptedTriggerEntity.Tag = "noDisplayObject";
Space.Add(detector);
Space.Add(acceptedTriggerEntity);
var fish = game.Content.Load<Model>("fish");
game.ModelDrawer.Add(new DisplayEntityModel(acceptedTriggerEntity, fish, game.ModelDrawer));
var barrelAndPlatform = game.Content.Load<Model>("barrelAndPlatform");
Vector3[] staticTriangleVertices;
int[] staticTriangleIndices;
ModelDataExtractor.GetVerticesAndIndicesFromModel(barrelAndPlatform, out staticTriangleVertices, out staticTriangleIndices);
//Note that the final 'margin' parameter is optional, but can be used to specify a collision margin on triangles in the static triangle group.
var fishDepositoryGroup = new StaticMesh(staticTriangleVertices, staticTriangleIndices);
CollisionRules.AddRule(fishDepositoryGroup, detector, CollisionRule.NoBroadPhase);
Space.Add(fishDepositoryGroup);
game.ModelDrawer.Add(fishDepositoryGroup);
movedBox = new Box(new Vector3(-4, 5, 0), 1, 1, 1, 1);
detector.Space.Add(movedBox);
detector.CollisionInformation.Events.InitialCollisionDetected += InitialCollisionDetected;
detector.CollisionInformation.Events.CollisionEnded += CollisionEnded;
}
示例5: SwivelHingeJoint
/// <summary>
/// Constructs a new constraint which restricts three degrees of linear freedom and one degree of angular freedom between two entities.
/// </summary>
/// <param name="connectionA">First entity of the constraint pair.</param>
/// <param name="connectionB">Second entity of the constraint pair.</param>
/// <param name="anchor">Point around which both entities rotate.</param>
/// <param name="hingeAxis">Axis of allowed rotation in world space to be attached to connectionA. Will be kept perpendicular with the twist axis.</param>
public SwivelHingeJoint(Entity connectionA, Entity connectionB, ref Vector3 anchor, ref Vector3 hingeAxis)
{
if (connectionA == null)
connectionA = TwoEntityConstraint.WorldEntity;
if (connectionB == null)
connectionB = TwoEntityConstraint.WorldEntity;
BallSocketJoint = new BallSocketJoint(connectionA, connectionB, ref anchor);
Vector3 tmp;
BallSocketJoint.OffsetB.Invert( out tmp );
AngularJoint = new SwivelHingeAngularJoint(connectionA, connectionB, ref hingeAxis, ref tmp );
HingeLimit = new RevoluteLimit(connectionA, connectionB);
HingeMotor = new RevoluteMotor(connectionA, connectionB, hingeAxis);
TwistLimit = new TwistLimit(connectionA, connectionB, ref BallSocketJoint.worldOffsetA, ref tmp, 0, 0);
TwistMotor = new TwistMotor(connectionA, connectionB, ref BallSocketJoint.worldOffsetA, ref tmp );
HingeLimit.IsActive = false;
HingeMotor.IsActive = false;
TwistLimit.IsActive = false;
TwistMotor.IsActive = false;
//Ensure that the base and test direction is perpendicular to the free axis.
Vector3 baseAxis; anchor.Sub( ref connectionA.position, out baseAxis );
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon) //anchor and connection a in same spot, so try the other way.
connectionB.position.Sub( ref anchor, out baseAxis );
baseAxis.AddScaled( ref hingeAxis, -Vector3.Dot( ref baseAxis, ref hingeAxis) , out baseAxis );
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
//However, if the free axis is totally aligned (like in an axis constraint), pick another reasonable direction.
Vector3.Cross(ref hingeAxis, ref Vector3.Up, out baseAxis);
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
Vector3.Cross(ref hingeAxis, ref Vector3.Right, out baseAxis);
}
}
HingeLimit.Basis.SetWorldAxes(ref hingeAxis, ref baseAxis, ref connectionA.orientationMatrix);
HingeMotor.Basis.SetWorldAxes( ref hingeAxis, ref baseAxis, ref connectionA.orientationMatrix);
connectionB.position.Sub( ref anchor, out baseAxis );
baseAxis.AddScaled( ref hingeAxis, -Vector3.Dot(ref baseAxis, ref hingeAxis), out baseAxis );
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
//However, if the free axis is totally aligned (like in an axis constraint), pick another reasonable direction.
Vector3.Cross(ref hingeAxis, ref Vector3.Up, out baseAxis);
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
Vector3.Cross(ref hingeAxis, ref Vector3.Right, out baseAxis);
}
}
HingeLimit.TestAxis = baseAxis;
HingeMotor.TestAxis = baseAxis;
Add(BallSocketJoint);
Add(AngularJoint);
Add(HingeLimit);
Add(HingeMotor);
Add(TwistLimit);
Add(TwistMotor);
}
示例6: PointOnPlaneJoint
/// <summary>
/// Constructs a new point on plane constraint.
/// </summary>
/// <param name="connectionA">Entity to which the constraint's plane is attached.</param>
/// <param name="connectionB">Entity to which the constraint's point is attached.</param>
/// <param name="planeAnchor">A point on the plane.</param>
/// <param name="normal">Direction, attached to the first connected entity, defining the plane's normal</param>
/// <param name="pointAnchor">The point to constrain to the plane, attached to the second connected object.</param>
public PointOnPlaneJoint(Entity connectionA, Entity connectionB, Vector3 planeAnchor, Vector3 normal, Vector3 pointAnchor)
{
ConnectionA = connectionA;
ConnectionB = connectionB;
PointAnchor = pointAnchor;
PlaneAnchor = planeAnchor;
PlaneNormal = normal;
}
示例7: SwivelHingeJoint
/// <summary>
/// Constructs a new constraint which restricts three degrees of linear freedom and one degree of angular freedom between two entities.
/// </summary>
/// <param name="connectionA">First entity of the constraint pair.</param>
/// <param name="connectionB">Second entity of the constraint pair.</param>
/// <param name="anchor">Point around which both entities rotate.</param>
/// <param name="hingeAxis">Axis of allowed rotation in world space to be attached to connectionA. Will be kept perpendicular with the twist axis.</param>
public SwivelHingeJoint(Entity connectionA, Entity connectionB, Vector3 anchor, Vector3 hingeAxis)
{
if (connectionA == null)
connectionA = TwoEntityConstraint.WorldEntity;
if (connectionB == null)
connectionB = TwoEntityConstraint.WorldEntity;
BallSocketJoint = new BallSocketJoint(connectionA, connectionB, anchor);
AngularJoint = new SwivelHingeAngularJoint(connectionA, connectionB, hingeAxis, -BallSocketJoint.OffsetB);
HingeLimit = new RevoluteLimit(connectionA, connectionB);
HingeMotor = new RevoluteMotor(connectionA, connectionB, hingeAxis);
TwistLimit = new TwistLimit(connectionA, connectionB, BallSocketJoint.OffsetA, -BallSocketJoint.OffsetB, 0, 0);
TwistMotor = new TwistMotor(connectionA, connectionB, BallSocketJoint.OffsetA, -BallSocketJoint.OffsetB);
HingeLimit.IsActive = false;
HingeMotor.IsActive = false;
TwistLimit.IsActive = false;
TwistMotor.IsActive = false;
//Ensure that the base and test direction is perpendicular to the free axis.
Vector3 baseAxis = anchor - connectionA.position;
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon) //anchor and connection a in same spot, so try the other way.
baseAxis = connectionB.position - anchor;
baseAxis -= Vector3.Dot(baseAxis, hingeAxis) * hingeAxis;
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
//However, if the free axis is totally aligned (like in an axis constraint), pick another reasonable direction.
baseAxis = Vector3.Cross(hingeAxis, Vector3.Up);
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
baseAxis = Vector3.Cross(hingeAxis, Vector3.Right);
}
}
HingeLimit.Basis.SetWorldAxes(hingeAxis, baseAxis, connectionA.orientationMatrix);
HingeMotor.Basis.SetWorldAxes(hingeAxis, baseAxis, connectionA.orientationMatrix);
baseAxis = connectionB.position - anchor;
baseAxis -= Vector3.Dot(baseAxis, hingeAxis) * hingeAxis;
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
//However, if the free axis is totally aligned (like in an axis constraint), pick another reasonable direction.
baseAxis = Vector3.Cross(hingeAxis, Vector3.Up);
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
baseAxis = Vector3.Cross(hingeAxis, Vector3.Right);
}
}
HingeLimit.TestAxis = baseAxis;
HingeMotor.TestAxis = baseAxis;
Add(BallSocketJoint);
Add(AngularJoint);
Add(HingeLimit);
Add(HingeMotor);
Add(TwistLimit);
Add(TwistMotor);
}
示例8: GetAnchorGuess
private static Vector3 GetAnchorGuess(Entity connectionA, Entity connectionB)
{
var anchor = new Vector3();
if (connectionA != null)
anchor += connectionA.position;
if (connectionB != null)
anchor += connectionB.position;
if (connectionA != null && connectionB != null)
anchor *= 0.5f;
return anchor;
}
示例9: WeldJoint
/// <summary>
/// Constructs a new constraint which restricts the linear and angular motion between two entities.
/// </summary>
/// <param name="connectionA">First entity of the constraint pair.</param>
/// <param name="connectionB">Second entity of the constraint pair.</param>
/// <param name="anchor">The location of the weld.</param>
public WeldJoint(Entity connectionA, Entity connectionB, Vector3 anchor)
{
if (connectionA == null)
connectionA = TwoEntityConstraint.WorldEntity;
if (connectionB == null)
connectionB = TwoEntityConstraint.WorldEntity;
BallSocketJoint = new BallSocketJoint(connectionA, connectionB, anchor);
NoRotationJoint = new NoRotationJoint(connectionA, connectionB);
Add(BallSocketJoint);
Add(NoRotationJoint);
}
示例10: WeldJoint
/// <summary>
/// Constructs a new constraint which restricts the linear and angular motion between two entities.
/// </summary>
/// <param name="connectionA">First entity of the constraint pair.</param>
/// <param name="connectionB">Second entity of the constraint pair.</param>
public WeldJoint(Entity connectionA, Entity connectionB)
{
if (connectionA == null)
connectionA = TwoEntityConstraint.WorldEntity;
if (connectionB == null)
connectionB = TwoEntityConstraint.WorldEntity;
BallSocketJoint = new BallSocketJoint(connectionA, connectionB, (connectionA.position + connectionB.position) * .5f);
NoRotationJoint = new NoRotationJoint(connectionA, connectionB);
Add(BallSocketJoint);
Add(NoRotationJoint);
}
示例11: GetAnchorGuess
private static Vector3 GetAnchorGuess(Entity connectionA, Entity connectionB)
{
var anchor = new Vector3();
if (connectionA != null)
anchor.Add( ref connectionA.position, out anchor );
if (connectionB != null)
anchor.Add( ref connectionB.position, out anchor );
if (connectionA != null && connectionB != null)
anchor.Mult( 0.5f, out anchor );
return anchor;
}
示例12: WeldJoint
/// <summary>
/// Constructs a new constraint which restricts the linear and angular motion between two entities.
/// Uses the average of the two entity positions for the anchor.
/// </summary>
/// <param name="connectionA">First entity of the constraint pair.</param>
/// <param name="connectionB">Second entity of the constraint pair.</param>
public WeldJoint(Entity connectionA, Entity connectionB)
{
if( connectionA == null )
connectionA = TwoEntityConstraint.WorldEntity;
if( connectionB == null )
connectionB = TwoEntityConstraint.WorldEntity;
Vector3 anchor; GetAnchorGuess( connectionA, connectionB, out anchor );
BallSocketJoint = new BallSocketJoint( connectionA, connectionB, ref anchor );
NoRotationJoint = new NoRotationJoint( connectionA, connectionB );
Add( BallSocketJoint );
Add( NoRotationJoint );
}
示例13: RevoluteJoint
/// <summary>
/// Constructs a new constraint which restricts three degrees of linear freedom and two degrees of angular freedom between two entities.
/// </summary>
/// <param name="connectionA">First entity of the constraint pair.</param>
/// <param name="connectionB">Second entity of the constraint pair.</param>
/// <param name="anchor">Point around which both entities rotate.</param>
/// <param name="freeAxis">Axis around which the hinge can rotate.</param>
public RevoluteJoint(Entity connectionA, Entity connectionB, System.Numerics.Vector3 anchor, System.Numerics.Vector3 freeAxis)
{
if (connectionA == null)
connectionA = TwoEntityConstraint.WorldEntity;
if (connectionB == null)
connectionB = TwoEntityConstraint.WorldEntity;
BallSocketJoint = new BallSocketJoint(connectionA, connectionB, anchor);
AngularJoint = new RevoluteAngularJoint(connectionA, connectionB, freeAxis);
Limit = new RevoluteLimit(connectionA, connectionB);
Motor = new RevoluteMotor(connectionA, connectionB, freeAxis);
Limit.IsActive = false;
Motor.IsActive = false;
//Ensure that the base and test direction is perpendicular to the free axis.
System.Numerics.Vector3 baseAxis = anchor - connectionA.position;
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon) //anchor and connection a in same spot, so try the other way.
baseAxis = connectionB.position - anchor;
baseAxis -= Vector3Ex.Dot(baseAxis, freeAxis) * freeAxis;
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
//However, if the free axis is totally aligned (like in an axis constraint), pick another reasonable direction.
baseAxis = System.Numerics.Vector3.Cross(freeAxis, Vector3Ex.Up);
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
baseAxis = System.Numerics.Vector3.Cross(freeAxis, Vector3Ex.Right);
}
}
Limit.Basis.SetWorldAxes(freeAxis, baseAxis, connectionA.orientationMatrix);
Motor.Basis.SetWorldAxes(freeAxis, baseAxis, connectionA.orientationMatrix);
baseAxis = connectionB.position - anchor;
baseAxis -= Vector3Ex.Dot(baseAxis, freeAxis) * freeAxis;
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
//However, if the free axis is totally aligned (like in an axis constraint), pick another reasonable direction.
baseAxis = System.Numerics.Vector3.Cross(freeAxis, Vector3Ex.Up);
if (baseAxis.LengthSquared() < Toolbox.BigEpsilon)
{
baseAxis = System.Numerics.Vector3.Cross(freeAxis, Vector3Ex.Right);
}
}
Limit.TestAxis = baseAxis;
Motor.TestAxis = baseAxis;
Add(BallSocketJoint);
Add(AngularJoint);
Add(Limit);
Add(Motor);
}
示例14: CalculateImpulse
/// <summary>
/// Calculates the impulse to apply to the center of mass of physically simulated bodies within the field.
/// </summary>
/// <param name="e">Target of the impulse.</param>
/// <param name="dt">Time since the last frame in simulation seconds.</param>
/// <param name="impulse">Force to apply at the given position.</param>
protected override void CalculateImpulse(Entity e, float dt, out Vector3 impulse)
{
if (MaximumPushSpeed > 0)
{
//Current velocity along the tangent direction.
float dot = Vector3.Dot(e.LinearVelocity, forceDirection);
//Compute the velocity difference between the current and the maximum
dot = MaximumPushSpeed - dot;
//Compute the force needed to reach the maximum, but clamp it to the amount of force that the field can apply
//Also, don't apply a force that would slow an object down.
dot = MathHelper.Clamp(dot * e.Mass, 0, forceMagnitude * dt);
Vector3.Multiply(ref forceDirection, dot, out impulse);
}
else
impulse = Force * dt;
}
示例15: EntityModel
/// <summary>
/// Creates a new EntityModel.
/// </summary>
/// <param name="entity">Entity to attach the graphical representation to.</param>
/// <param name="model">Graphical representation to use for the entity.</param>
/// <param name="transform">Base transformation to apply to the model before moving to the entity.</param>
/// <param name="game">Game to which this component will belong.</param>
public EntityModel(Entity entity, Model model, Matrix transform, Game game, Player player)
: base(game)
{
this.entity = entity;
this.model = model;
Transform = transform;
Player = player;
//Collect any bone transformations in the model itself.
//The default cube model doesn't have any, but this allows the EntityModel to work with more complicated shapes.
boneTransforms = new Matrix[model.Bones.Count];
foreach (var effect in model.Meshes.SelectMany(mesh => mesh.Effects).Cast<BasicEffect>())
{
effect.EnableDefaultLighting();
}
}