本文整理汇总了C#中Sandbox.Engine.Physics.MyPhysicsBody类的典型用法代码示例。如果您正苦于以下问题:C# MyPhysicsBody类的具体用法?C# MyPhysicsBody怎么用?C# MyPhysicsBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MyPhysicsBody类属于Sandbox.Engine.Physics命名空间,在下文中一共展示了MyPhysicsBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
{
ResourceSink = new MyResourceSinkComponent();
ResourceSink.Init(
BlockDefinition.ResourceSinkGroup,
BlockDefinition.RequiredPowerInput,
this.CalculateRequiredPowerInput);
base.Init(objectBuilder, cubeGrid);
ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
ResourceSink.Update();
if (Physics != null)
{
Physics.Close();
}
var detectorShape = new HkBoxShape(new Vector3(cubeGrid.GridSize / 3.0f));
var massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(detectorShape.HalfExtents, BlockDefinition.VirtualMass);
Physics = new Sandbox.Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
Physics.IsPhantom = false;
Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.CollisionLayers.VirtualMassLayer);
Physics.Enabled = IsWorking && cubeGrid.Physics != null && cubeGrid.Physics.Enabled;
Physics.RigidBody.Activate();
detectorShape.Base.RemoveReference();
UpdateText();
NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
}
示例2: MyCameraSpring
public MyCameraSpring(MyPhysicsBody attachedTo)
{
m_limitedVelocity = Vector3.Zero;
m_physics = attachedTo;
m_linearVelocity = Vector3.Zero;
m_localTranslation = Vector3.Zero;
}
示例3: Init
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
{
InitializeSinkComponent();
base.Init(objectBuilder, cubeGrid);
if (CubeGrid.CreatePhysics)
{
// Put on my fake, because it does performance issues
if (MyFakes.ENABLE_GRAVITY_PHANTOM)
{
var shape = CreateFieldShape();
Physics = new Sandbox.Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KINEMATIC);
Physics.IsPhantom = true;
Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center, WorldMatrix, null, Sandbox.Engine.Physics.MyPhysics.CollisionLayers.GravityPhantomLayer);
shape.Base.RemoveReference();
Physics.Enabled = IsWorking;
}
NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
ResourceSink.Update();
}
m_soundEmitter = new MyEntity3DSoundEmitter(this, true);
m_baseIdleSound.Init("BlockGravityGen");
}
示例4: SetInBodySpace
public static void SetInBodySpace(this HkFixedConstraintData data, Matrix pivotA, Matrix pivotB, MyPhysicsBody bodyA, MyPhysicsBody bodyB)
{
if (bodyA.IsWelded)
pivotA = pivotA * bodyA.WeldInfo.Transform;
if (bodyB.IsWelded)
pivotB = pivotB * bodyB.WeldInfo.Transform;
data.SetInBodySpaceInternal(ref pivotA, ref pivotB);
}
示例5: InitInternal
private void InitInternal()
{
base.Init(null, m_definition.Model, null, null);
Render.ColorMaskHsv = m_definition.ColorHSV;
Render.Transparency = 0.25f;
Render.AddRenderObjects();
List<MyTextureChange> textureChanges = new List<MyTextureChange>();
textureChanges.Add(new MyTextureChange { TextureName = m_definition.ColorMetalTexture, MaterialSlot = "ColorMetalTexture" });
textureChanges.Add(new MyTextureChange { TextureName = m_definition.AddMapsTexture, MaterialSlot = "AddMapsTexture" });
VRageRender.MyRenderProxy.ChangeMaterialTexture(Render.RenderObjectIDs[0], "BotFlag", textureChanges); // TODO: change the material name
m_localActivationMatrix = MatrixD.CreateScale(this.PositionComp.LocalAABB.HalfExtents * 2.0f) * MatrixD.CreateTranslation(this.PositionComp.LocalAABB.Center);
var shape = new HkBoxShape(m_localActivationMatrix.Scale);
Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DISABLE_COLLISION_RESPONSE);
Physics.CreateFromCollisionObject(shape, Vector3.Zero, WorldMatrix, null, MyPhysics.ObjectDetectionCollisionLayer);
Physics.Enabled = true;
Components.Add<MyPlaceArea>(new MySpherePlaceArea(10.0f, m_definition.Id.SubtypeId)); // TODO: Add radius to the definition
MyHud.LocationMarkers.RegisterMarker(this, new MyHudEntityParams() {
FlagsEnum = MyHudIndicatorFlagsEnum.SHOW_TEXT,
Text = m_definition.DisplayNameEnum.HasValue ? MyTexts.Get(m_definition.DisplayNameEnum.Value) : new StringBuilder(),
TargetMode = MyRelationsBetweenPlayerAndBlock.Neutral,
MaxDistance = 200.0f,
MustBeDirectlyVisible = true
} );
}
示例6: InitInternal
private void InitInternal()
{
// TODO: This will be fixed and made much more simple once ore models are done
// https://app.asana.com/0/6594565324126/10473934569658
var physicalItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content);
string model = physicalItem.Model;
VoxelMaterial = null;
float scale = 1.0f;
if (Item.Content is MyObjectBuilder_Ore)
{
string oreSubTypeId = physicalItem.Id.SubtypeId.ToString();
foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
{
if (oreSubTypeId == mat.MinedOre)
{
VoxelMaterial = mat;
model = MyDebris.GetRandomDebrisVoxel();
scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
break;
}
}
scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
}
if (scale < 0.05f)
Close();
else if (scale < 0.15f)
scale = 0.15f;
FormatDisplayName(m_displayedText, Item);
Init(m_displayedText, model, null, null, null);
PositionComp.Scale = scale; // Must be set after init
var massProperties = new HkMassProperties();
HkShape shape = GetPhysicsShape(physicalItem.Mass * (float)Item.Amount, scale, out massProperties);
var scaleMatrix = Matrix.CreateScale(scale);
if (Physics != null)
Physics.Close();
Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);
if (VoxelMaterial != null)
{
HkConvexTransformShape transform = new HkConvexTransformShape((HkConvexShape)shape, ref scaleMatrix, HkReferencePolicy.None);
Physics.CreateFromCollisionObject(transform, Vector3.Zero, MatrixD.Identity, massProperties, MyPhysics.FloatingObjectCollisionLayer);
Physics.Enabled = true;
transform.Base.RemoveReference();
}
else
{
Physics.CreateFromCollisionObject(shape, Vector3.Zero, MatrixD.Identity, massProperties, MyPhysics.FloatingObjectCollisionLayer);
Physics.Enabled = true;
}
Physics.MaterialType = VoxelMaterial != null ? MyMaterialType.ROCK : MyMaterialType.METAL;
Physics.PlayCollisionCueEnabled = true;
NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
}
示例7: IsCharacter
private static bool IsCharacter(HkRigidBody rb, MyPhysicsBody character)
{
if (character == null)
return false;
var c = character.Entity as MyCharacter;
if (c == null) return false;
if (c.Physics == null) return false; // Physics may have been already released / Entity removed from the world?
if (c.Physics.CharacterProxy != null)
return c.Physics.CharacterProxy.GetHitRigidBody() == rb;
return (c.Physics.RigidBody == rb); // Otherwise we do proper check
}
示例8: Weld
public void Weld(MyPhysicsBody other, bool recreateShape = true)
{
if (other.WeldInfo.Parent == this) //already welded to this
return;
if(other.IsWelded && !IsWelded)
{
other.Weld(this);
return;
}
if(IsWelded)
{
WeldInfo.Parent.Weld(other);
return;
}
HkShape thisShape;
if (WeldInfo.Children.Count == 0)
{
thisShape = RigidBody.GetShape();
HkShape.SetUserData(thisShape, RigidBody);
Entity.OnPhysicsChanged += WeldedEntity_OnPhysicsChanged;
//Entity.OnClose += Entity_OnClose;
}
else
thisShape = GetShape();
other.Deactivate();
var transform = other.RigidBody.GetRigidBodyMatrix() * Matrix.Invert(RigidBody.GetRigidBodyMatrix());
other.WeldInfo.Transform = transform;
other.WeldedRigidBody = other.RigidBody;
other.RigidBody = RigidBody;
other.WeldInfo.Parent = this;
WeldInfo.Children.Add(other);
if(recreateShape)
RecreateWeldedShape(thisShape);
other.Entity.OnPhysicsChanged += WeldedEntity_OnPhysicsChanged;
}
示例9: InitDeadBodyPhysics
private void InitDeadBodyPhysics()
{
Vector3 velocity = Vector3.Zero;
RadioBroadcaster.BroadcastRadius = 5;
if (Physics != null)
{
velocity = Physics.LinearVelocity;
Physics.Enabled = false;
Physics.Close();
Physics = null;
}
//if (Physics == null)
{
var massProperties = new HkMassProperties();
massProperties.Mass = 500;
HkShape shape;
// CH: Need to rethink this. It does not belong here, but I don't want to add "DeadCharacterBodyCenterOfMass" to the character definition either...
// MZ: See ticket "Correct dying for characters", https://app.asana.com/0/64822442925263/75411538582998
// dead body shape can now be specified in character's SBC
if (Definition.DeadBodyShape != null)
{
HkBoxShape bshape = new HkBoxShape(PositionComp.LocalAABB.HalfExtents * Definition.DeadBodyShape.BoxShapeScale);
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(bshape.HalfExtents, massProperties.Mass);
massProperties.CenterOfMass = bshape.HalfExtents * Definition.DeadBodyShape.RelativeCenterOfMass;
shape = bshape;
Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
Vector3D offset = PositionComp.LocalAABB.HalfExtents * Definition.DeadBodyShape.RelativeShapeTranslation;
MatrixD pos = MatrixD.CreateTranslation(offset);
Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center + offset, pos, massProperties, MyPhysics.CollisionLayers.FloatingObjectCollisionLayer);
Physics.Friction = Definition.DeadBodyShape.Friction;
Physics.RigidBody.MaxAngularVelocity = MathHelper.PiOver2;
Physics.LinearVelocity = velocity;
shape.RemoveReference();
Physics.Enabled = true;
}
else // no special definition => use AABB
{
HkBoxShape bshape = new HkBoxShape(PositionComp.LocalAABB.HalfExtents);
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(bshape.HalfExtents, massProperties.Mass);
massProperties.CenterOfMass = new Vector3(bshape.HalfExtents.X, 0, 0);
shape = bshape;
Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center, MatrixD.Identity, massProperties, MyPhysics.CollisionLayers.FloatingObjectCollisionLayer);
Physics.Friction = 0.5f;
Physics.RigidBody.MaxAngularVelocity = MathHelper.PiOver2;
Physics.LinearVelocity = velocity;
shape.RemoveReference();
Physics.Enabled = true;
}
}
NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
}
示例10: Components_ComponentAdded
void Components_ComponentAdded(Type t, MyEntityComponentBase c)
{
if (t == typeof(MyPhysicsComponentBase))
m_physics = c as MyPhysicsBody;
else if (t == typeof(MySyncComponentBase))
m_syncObject = c as MySyncComponentBase;
else if (t == typeof(MyGameLogicComponent))
m_gameLogic = c as MyGameLogicComponent;
else if (t == typeof(MyPositionComponentBase))
m_position = c as MyPositionComponentBase;
else if (t == typeof(MyHierarchyComponentBase))
m_hierarchy = c as MyHierarchyComponentBase;
else if (t == typeof(MyRenderComponentBase))
{
m_render = c as MyRenderComponentBase;
}
}
示例11: Init
//.........这里部分代码省略.........
{
var child = m_children[i];
Func<MyObjectBuilder_FracturedPiece.Shape, bool> x = s => s.Name == child.ShapeName;
var result = m_shapes.Where(x);
if (result.Count() > 0)
{
var found = result.First();
var m = Matrix.CreateFromQuaternion(found.Orientation);
if (!offset.HasValue && found.Name == m_shapes[0].Name)
{
offset = child.GetTransform().Translation;
shapeAtZero = m_shapeInfos.Count;
}
m.Translation = child.GetTransform().Translation;
var si = new HkdShapeInstanceInfo(child.Shape.Clone(), m);
if(found.Fixed)
si.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
m_shapeInfos.Add(si);
m_shapes.Remove(found);
}
else
{
child.GetChildren(m_children);
}
}
if (m_shapeInfos.Count == 0)
{
List<string> shapesToLoad = new List<string>();
foreach (var obShape in ob.Shapes)
shapesToLoad.Add(obShape.Name);
var shapesStr = shapesToLoad.Aggregate((str1, str2) => str1 + ", " + str2);
var blocksStr = OriginalBlocks.Aggregate("", (str, defId) => str + ", " + defId.ToString());
var failMsg = "No relevant shape was found for fractured piece. It was probably reexported and names changed. Shapes: " + shapesStr + ". Original blocks: " + shapesStr;
Debug.Fail(failMsg);
//HkdShapeInstanceInfo si = new HkdShapeInstanceInfo(new HkdBreakableShape((HkShape)new HkBoxShape(Vector3.One)), Matrix.Identity);
//m_shapeInfos.Add(si);
throw new Exception(failMsg);
}
if (offset.HasValue)
{
for (int i = 0; i < m_shapeInfos.Count; i++)
{
var m = m_shapeInfos[i].GetTransform();
m.Translation -= offset.Value;
m_shapeInfos[i].SetTransform(ref m);
}
{
var m = m_shapeInfos[shapeAtZero].GetTransform();
m.Translation = Vector3.Zero;
m_shapeInfos[shapeAtZero].SetTransform(ref m);
}
}
if (m_shapeInfos.Count > 0)
{
if (m_shapeInfos.Count == 1)
Shape = m_shapeInfos[0].Shape;
else
{
Shape = new HkdCompoundBreakableShape(null, m_shapeInfos);
((HkdCompoundBreakableShape)Shape).RecalcMassPropsFromChildren();
}
Shape.SetStrenght(MyDestructionConstants.STRENGTH);
var mp = new HkMassProperties();
Shape.BuildMassProperties(ref mp);
Shape.SetChildrenParent(Shape);
Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);
Physics.CanUpdateAccelerations = true;
Physics.InitialSolverDeactivation = HkSolverDeactivation.High;
Physics.CreateFromCollisionObject(Shape.GetShape(), Vector3.Zero, PositionComp.WorldMatrix, mp);
Physics.BreakableBody = new HkdBreakableBody(Shape, Physics.RigidBody, null, (Matrix)PositionComp.WorldMatrix);
Physics.BreakableBody.AfterReplaceBody += Physics.FracturedBody_AfterReplaceBody;
if (OriginalBlocks.Count > 0)
{
MyPhysicalModelDefinition def;
if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(OriginalBlocks[0], out def))
Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId;
}
var rigidBody = Physics.RigidBody;
bool isFixed = MyDestructionHelper.IsFixed(Physics.BreakableBody.BreakableShape);
if (isFixed)
{
rigidBody.UpdateMotionType(HkMotionType.Fixed);
rigidBody.LinearVelocity = Vector3.Zero;
rigidBody.AngularVelocity = Vector3.Zero;
}
Physics.Enabled = true;
}
m_children.Clear();
m_shapeInfos.Clear();
}
示例12: UpdateMassFromInventories
public void UpdateMassFromInventories(HashSet<MySlimBlock> blocks, MyPhysicsBody rb)
{
if (rb.RigidBody.IsFixedOrKeyframed)
return;
ProfilerShort.Begin("GridShape.UpdateMassFromInv");
Debug.Assert(BreakableShape.IsValid(), "This routine works with breakable shape mass properties.");
foreach (var block in blocks)
{
var owner = block.FatBlock as IMyInventoryOwner;
if (owner == null) continue;
float mass = 0;
for (int i = 0; i < owner.InventoryCount; i++)
{
mass += (float)owner.GetInventory(i).CurrentMass;
}
var size = (block.Max - block.Min + Vector3I.One) * block.CubeGrid.GridSize;
var center = (block.Min + block.Max) * 0.5f * block.CubeGrid.GridSize;
HkMassProperties massProperties = new HkMassProperties();
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(size / 2, mass);
m_tmpElements.Add(new HkMassElement() { Properties = massProperties, Tranform = Matrix.CreateTranslation(center) });
}
HkMassProperties originalMp = new HkMassProperties();
BreakableShape.BuildMassProperties(ref originalMp);
m_tmpElements.Add(new HkMassElement() { Properties = originalMp, Tranform = Matrix.Identity });
var mp = HkInertiaTensorComputer.CombineMassProperties(m_tmpElements);
m_tmpElements.Clear();
rb.RigidBody.SetMassProperties(ref mp);
if (!rb.RigidBody.IsActive)
rb.RigidBody.Activate();
ProfilerShort.End();
}
示例13: OnUnwelded
protected override void OnUnwelded(MyPhysicsBody other)
{
base.OnUnwelded(other);
Shape.RefreshMass();
m_grid.HavokSystemIDChanged(HavokCollisionSystemID);
}
示例14: AddObject
/// <summary>
/// Try add object to some subspace.
/// Create new subspace if allowed (!SingleCluster.HasValue) and needed (object is outside of existing subspaces).
/// If not allowed, mark object as left the world.
/// </summary>
/// <param name="bbox"></param>
/// <param name="velocity"></param>
/// <param name="activationHandler"></param>
/// <param name="customId"></param>
/// <returns></returns>
public static ulong AddObject(BoundingBoxD bbox, Vector3 velocity, MyPhysicsBody activationHandler, ulong? customId)
{
ulong tmp = Clusters.AddObject(bbox, velocity, activationHandler, customId);
if (tmp == MyHavokCluster.CLUSTERED_OBJECT_ID_UNITIALIZED)
{
HavokWorld_EntityLeftWorld(activationHandler.RigidBody);
return MyHavokCluster.CLUSTERED_OBJECT_ID_UNITIALIZED;
}
return tmp;
}
示例15: RefreshPhysicsBody
private void RefreshPhysicsBody()
{
if (CubeGrid.CreatePhysics)
{
if (Physics != null)
{
Physics.Close();
}
var detectorShape = new HkSphereShape(CubeGrid.GridSize * 0.5f);
var massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(detectorShape.Radius, VirtualMass != 0 ? VirtualMass : 0.01f);
Physics = new Sandbox.Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KEYFRAMED_REPORTING);
Physics.IsPhantom = false;
Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.CollisionLayers.VirtualMassLayer);
UpdateIsWorking();
Physics.Enabled = IsWorking && CubeGrid.Physics != null && CubeGrid.Physics.Enabled;
Physics.RigidBody.Activate();
detectorShape.Base.RemoveReference();
if (CubeGrid != null && CubeGrid.Physics != null && !CubeGrid.IsStatic)
CubeGrid.Physics.UpdateMass();
}
}