本文整理汇总了C#中HkMassProperties类的典型用法代码示例。如果您正苦于以下问题:C# HkMassProperties类的具体用法?C# HkMassProperties怎么用?C# HkMassProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HkMassProperties类属于命名空间,在下文中一共展示了HkMassProperties类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ScalePhysicsShape
public virtual void ScalePhysicsShape(ref HkMassProperties massProperties)
{
var debriModel = Entity.Render.GetModel();
HkShape shape;
if (debriModel.HavokCollisionShapes != null && debriModel.HavokCollisionShapes.Length > 0)
{
shape = debriModel.HavokCollisionShapes[0];
Vector4 min, max;
shape.GetLocalAABB(0.1f, out min, out max);
Vector3 he = new Vector3((max - min) * 0.5f);
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(he, he.Volume * 50);
massProperties.CenterOfMass = new Vector3((min + max) * 0.5f);
}
else
{
var transformShape = (HkTransformShape)RigidBody.GetShape();
var boxShape = (HkBoxShape)transformShape.ChildShape;
boxShape.HalfExtents = ((debriModel.BoundingBox.Max - debriModel.BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value;
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, boxShape.HalfExtents.Volume * 0.5f);
massProperties.CenterOfMass = transformShape.Transform.Translation;
shape = transformShape;
}
RigidBody.SetShape(shape);
RigidBody.SetMassProperties(ref massProperties);
RigidBody.UpdateShape();
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:26,代码来源:MyDebrisBase.cs
示例2: AllocateForDefinition
public void AllocateForDefinition(string model, MyPhysicalModelDefinition definition, int count)
{
if (string.IsNullOrEmpty(model))
return;
ProfilerShort.Begin("Clone");
var data = MyModels.GetModelOnlyData(model);
if (MyFakes.LAZY_LOAD_DESTRUCTION && data.HavokBreakableShapes == null)
{
MyDestructionData.Static.LoadModelDestruction(model, definition, data.BoundingBoxSize);
}
if (data.HavokBreakableShapes != null && data.HavokBreakableShapes.Length > 0)
{
if (!m_pools.ContainsKey(definition.Id))
m_pools[definition.Id] = new Dictionary<string, ConcurrentQueue<HkdBreakableShape>>();
if(!m_pools[definition.Id].ContainsKey(model))
m_pools[definition.Id][model] = new ConcurrentQueue<HkdBreakableShape>();
var queue = m_pools[definition.Id][model];
for (int i = 0; i < count; i++)
{
var shape = data.HavokBreakableShapes[0].Clone();
queue.Enqueue(shape);
if (i == 0)
{
var mp = new HkMassProperties();
shape.BuildMassProperties(ref mp);
if (!mp.InertiaTensor.IsValid())
{
MyLog.Default.WriteLine(string.Format("Block with wrong destruction! (q.isOk): {0}", definition.Model));
break;
}
}
}
}
ProfilerShort.End();
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:35,代码来源:MyBreakableShapeManager.cs
示例3: CreatePhysicsShape
public override void CreatePhysicsShape(out HkShape shape, ref HkMassProperties massProperties)
{
var sphereShape = new HkSphereShape(((MyEntity)Entity).Render.GetModel().BoundingSphere.Radius * Entity.PositionComp.Scale.Value);
shape = sphereShape;
var mass = SphereMass(sphereShape.Radius, VoxelDensity);
massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(sphereShape.Radius, mass);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:7,代码来源:MyDebrisVoxel.cs
示例4: CreatePhysicsShape
public virtual void CreatePhysicsShape(out HkShape shape, ref HkMassProperties massProperties)
{
var boxShape = new HkBoxShape(((((MyEntity)Entity).Render.GetModel().BoundingBox.Max - ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value);
var pos = ((((MyEntity)Entity).Render.GetModel().BoundingBox.Max + ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2);
shape = new HkTransformShape(boxShape, ref pos, ref Quaternion.Identity);
//shape = boxShape;
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, boxShape.HalfExtents.Volume * 0.5f);
massProperties.CenterOfMass = pos;
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:9,代码来源:MyDebrisBase.cs
示例5: UpdateMassProps
internal void UpdateMassProps(HkRigidBody rb)
{
var mp = new HkMassProperties();
mp.InertiaTensor = rb.InertiaTensor;
mp.Mass = rb.Mass;
mp.CenterOfMass = rb.CenterOfMassLocal;
MassElement = new HkMassElement();
MassElement.Properties = mp;
MassElement.Tranform = Transform;
//MassElement.Tranform.Translation = Vector3.Transform(rb.CenterOfMassLocal, Transform);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:11,代码来源:MyPhysicsBody.Welding.cs
示例6: ScalePhysicsShape
public override void ScalePhysicsShape(ref HkMassProperties massProperties)
{
var shape = RigidBody.GetShape();
var sphereShape = (HkSphereShape)shape;
sphereShape.Radius = ((MyEntity)Entity).Render.GetModel().BoundingSphere.Radius * Entity.PositionComp.Scale.Value;
massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(sphereShape.Radius, 1);
RigidBody.SetShape(sphereShape);
RigidBody.SetMassProperties(ref massProperties);
RigidBody.UpdateShape();
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:11,代码来源:MyDebrisVoxel.cs
示例7: ScalePhysicsShape
public virtual void ScalePhysicsShape(ref HkMassProperties massProperties)
{
var shape = RigidBody.GetShape();
var boxShape = (HkBoxShape)shape;
boxShape.HalfExtents = ((((MyEntity)Entity).Render.GetModel().BoundingBox.Max - ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value;
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, massProperties.Mass);
RigidBody.SetShape(boxShape);
RigidBody.SetMassProperties(ref massProperties);
RigidBody.UpdateShape();
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:11,代码来源:MyDebrisBase.cs
示例8: CreatePhysicsShape
public virtual void CreatePhysicsShape(out HkShape shape, ref HkMassProperties massProperties)
{
var boxShape = new HkBoxShape(((((MyEntity)Entity).Render.GetModel().BoundingBox.Max - ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value);
shape = boxShape;
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, massProperties.Mass);
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:6,代码来源:MyDebrisBase.cs
示例9: Init
/// <summary>
/// One time initialization for debris entity. These are settings that do not change
/// when this debris entity is pulled from the pool.
/// Also note that this is the only way Debris should be initialized. It calls other Init methods with
/// correct arguments.
/// </summary>
public virtual void Init(MyDebrisBaseDescription desc)
{
base.Init(null, desc.Model, null, 1.0f);
m_randomScale = MyUtils.GetRandomFloat(desc.ScaleMin, desc.ScaleMax);
Container.Entity.PositionComp.Scale = m_randomScale;
m_lifespanInMiliseconds = MyUtils.GetRandomInt(desc.LifespanMinInMiliseconds, desc.LifespanMaxInMiliseconds);
HkShape shape;
m_massProperties = new HkMassProperties();
m_massProperties.Mass = 50;
Container.Entity.Physics = GetPhysics(RigidBodyFlag.RBF_DEBRIS);
(Container.Entity.Physics as MyDebrisPhysics).CreatePhysicsShape(out shape, ref m_massProperties);
(Container.Entity.Physics as MyDebrisPhysics).CreateFromCollisionObject(shape, Vector3.Zero, MatrixD.Identity, m_massProperties, MyPhysics.DebrisCollisionLayer);
Container.Entity.Physics.Enabled = false;
shape.RemoveReference();
m_entity.Save = false;
Container.Entity.Physics.PlayCollisionCueEnabled = true;
NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
m_onCloseCallback = desc.OnCloseAction;
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:27,代码来源:MyDebrisBase.cs
示例10: FindFractureComponentBlocks
/// <summary>
/// Searches for blocks which will create fracture components from cached m_fracturedSlimBlocksShapes
/// </summary>
private void FindFractureComponentBlocks()
{
Debug.Assert(MyFakes.ENABLE_FRACTURE_COMPONENT);
foreach (var pair in m_fracturedSlimBlocksShapes)
{
var slimBlock = pair.Key;
var shapeList = pair.Value;
if (slimBlock.FatBlock.Components.Has<MyFractureComponentBase>())
{
// Block has fracture component - ignore
continue;
}
else
{
int totalBreakableShapesCountForModel = slimBlock.GetTotalBreakableShapeChildrenCount();
Debug.Assert(shapeList.Count <= totalBreakableShapesCountForModel);
// No removed pieces? Then ignore.
if (slimBlock.BlockDefinition.CreateFracturedPieces && totalBreakableShapesCountForModel == shapeList.Count)
continue;
foreach (var s in shapeList)
{
s.SetTransform(ref Matrix.Identity);
}
ProfilerShort.Begin("CreateShapeComponent");
HkdBreakableShape compound = new HkdCompoundBreakableShape(null, shapeList);
((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
var mp = new HkMassProperties();
compound.BuildMassProperties(ref mp);
HkdBreakableShape shape = compound;
var sh = compound.GetShape();
shape = new HkdBreakableShape(sh, ref mp);
//shape.SetMassProperties(mp); //important! pass mp to constructor
foreach (var si in shapeList)
{
var siRef = si;
shape.AddShape(ref siRef);
}
compound.RemoveReference();
ProfilerShort.BeginNextBlock("Connect");
//shape.SetChildrenParent(shape);
ConnectPiecesInBlock(shape, shapeList);
MyFractureComponentBase.Info info = new MyFractureComponentBase.Info()
{
Entity = slimBlock.FatBlock,
Shape = shape,
Compound = true
};
m_fractureBlockComponentsCache.Add(info);
ProfilerShort.End();
}
}
m_fracturedSlimBlocksShapes.Clear();
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:64,代码来源:MyGridPhysics.Destruction.cs
示例11: FindFracturedBlocks
private void FindFracturedBlocks(HkdBreakableBodyInfo b)
{
ProfilerShort.Begin("DBHelper");
var dbHelper = new HkdBreakableBodyHelper(b);
ProfilerShort.BeginNextBlock("GetRBMatrix");
var bodyMatrix = dbHelper.GetRigidBodyMatrix();
ProfilerShort.BeginNextBlock("SearchChildren");
dbHelper.GetChildren(m_children);
foreach (var child in m_children)
{
if (!child.IsFracturePiece())
continue;
//var blockPosWorld = ClusterToWorld(Vector3.Transform(child.GetTransform().Translation, bodyMatrix));
var bShape = child.Shape;
HkVec3IProperty pProp = bShape.GetProperty(HkdBreakableShape.PROPERTY_GRID_POSITION);
var blockPos = pProp.Value; //Vector3I.Round(child.GetTransform().Translation / m_grid.GridSize);
if (!m_grid.CubeExists(blockPos))
{
//Debug.Fail("FindFracturedBlocks:Fracture piece missing block");//safe to ignore
continue;
}
if (MyFakes.ENABLE_FRACTURE_COMPONENT)
{
var block = m_grid.GetCubeBlock(blockPos);
if (block == null)
continue;
if (!FindFractureComponentBlocks(block, child))
continue;
}
else
{
if (!m_fracturedBlocksShapes.ContainsKey(blockPos))
m_fracturedBlocksShapes[blockPos] = new List<HkdShapeInstanceInfo>();
m_fracturedBlocksShapes[blockPos].Add(child);
}
}
ProfilerShort.BeginNextBlock("CreateFreacturedBlocks");
if (!MyFakes.ENABLE_FRACTURE_COMPONENT)
{
foreach (var key in m_fracturedBlocksShapes.Keys)
{
HkdBreakableShape shape;
var shapeList = m_fracturedBlocksShapes[key];
foreach (var s in shapeList)
{
var matrix = s.GetTransform();
matrix.Translation = Vector3.Zero;
s.SetTransform(ref matrix);
}
ProfilerShort.Begin("CreateShape");
HkdBreakableShape compound = new HkdCompoundBreakableShape(null, shapeList);
((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
var mp = new HkMassProperties();
compound.BuildMassProperties(ref mp);
shape = compound;
var sh = compound.GetShape();
shape = new HkdBreakableShape(sh, ref mp);
//shape.SetMassProperties(mp); //important! pass mp to constructor
foreach (var si in shapeList)
{
var siRef = si;
shape.AddShape(ref siRef);
}
compound.RemoveReference();
ProfilerShort.BeginNextBlock("Connect");
//shape.SetChildrenParent(shape);
ConnectPiecesInBlock(shape, shapeList);
ProfilerShort.End();
var info = new MyFracturedBlock.Info()
{
Shape = shape,
Position = key,
Compound = true,
};
var originalBlock = m_grid.GetCubeBlock(key);
if (originalBlock == null)
{
//Debug.Fail("Missing fracture piece original block.");//safe to ignore
shape.RemoveReference();
continue;
}
Debug.Assert(originalBlock != null);
if (originalBlock.FatBlock is MyFracturedBlock)
{
var fractured = originalBlock.FatBlock as MyFracturedBlock;
info.OriginalBlocks = fractured.OriginalBlocks;
info.Orientations = fractured.Orientations;
info.MultiBlocks = fractured.MultiBlocks;
}
else if (originalBlock.FatBlock is MyCompoundCubeBlock)
{
info.OriginalBlocks = new List<MyDefinitionId>();
info.Orientations = new List<MyBlockOrientation>();
MyCompoundCubeBlock compoundBlock = originalBlock.FatBlock as MyCompoundCubeBlock;
bool hasMultiBlockPart = false;
var blocksInCompound = compoundBlock.GetBlocks();
foreach (var block in blocksInCompound)
//.........这里部分代码省略.........
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridPhysics.Destruction.cs
示例12: CreateBlockShape
private HkdBreakableShape? CreateBlockShape(Sandbox.Game.Entities.Cube.MySlimBlock b, out Matrix blockTransform)
{
ProfilerShort.Begin("CreateBlockShape");
blockTransform = Matrix.Identity;
if (b.FatBlock == null)
{
Debug.Fail("Armor blocks are not allowed in medieval");
ProfilerShort.End();
return null;
}
HkdBreakableShape breakableShape;
Matrix compoundChildTransform = Matrix.Identity;
if (b.FatBlock is MyCompoundCubeBlock)
{
ProfilerShort.Begin("Cmpnd");
blockTransform.Translation = b.FatBlock.PositionComp.LocalMatrix.Translation;
var cb = b.FatBlock as MyCompoundCubeBlock;
if (cb.GetBlocksCount() == 1)
{
ProfilerShort.Begin("SingleBlock");
var block = cb.GetBlocks()[0];
var defId = block.FatBlock.BlockDefinition;
Matrix m;
var model = block.CalculateCurrentModel(out m);
if (MyFakes.LAZY_LOAD_DESTRUCTION || HasBreakableShape(model, defId))
{
ProfilerShort.Begin("Clone");
breakableShape = GetBreakableShape(model, defId);
ProfilerShort.End();
}
block.Orientation.GetMatrix(out compoundChildTransform);
blockTransform = compoundChildTransform * blockTransform;
ProfilerShort.End();
}
else
{
var pos = b.Position * m_grid.GridSize;
float mass = 0;
ProfilerShort.Begin("GetBlocks");
foreach (var block in cb.GetBlocks())
{
block.Orientation.GetMatrix(out compoundChildTransform);
compoundChildTransform.Translation = Vector3.Zero;
var blockDef = block.BlockDefinition;
Matrix m;
var model = block.CalculateCurrentModel(out m);
if (MyFakes.LAZY_LOAD_DESTRUCTION || HasBreakableShape(model, blockDef))
{
ProfilerShort.Begin("Clone");
breakableShape = GetBreakableShape(model, blockDef);
breakableShape.UserObject |= (uint)HkdBreakableShape.Flags.FRACTURE_PIECE;
System.Diagnostics.Debug.Assert(breakableShape.IsValid(), "Invalid breakableShape");
ProfilerShort.End();
mass += blockDef.Mass;
m_shapeInfosList2.Add(new HkdShapeInstanceInfo(breakableShape, compoundChildTransform));
}
}
if (m_shapeInfosList2.Count == 0)
{
ProfilerShort.End();
return null;
}
ProfilerShort.BeginNextBlock("CreateCompoundBlockShape");
//HkShape hkpShape = new HkListShape(m_khpShapeList.ToArray(), m_khpShapeList.Count, HkReferencePolicy.None);
//m_khpShapeList.Clear();
HkdBreakableShape compound = new HkdCompoundBreakableShape(null, m_shapeInfosList2);
((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
var mp = new HkMassProperties();
compound.BuildMassProperties(ref mp);
breakableShape = new HkdBreakableShape(compound.GetShape(), ref mp);
compound.RemoveReference();
foreach (var si in m_shapeInfosList2)
{
var siRef = si;
breakableShape.AddShape(ref siRef);
}
ProfilerShort.BeginNextBlock("Connect");
//slow slow slow
//breakableShape.AutoConnect(MyDestructionData.Static.TemporaryWorld);
//slow wrong
//breakableShape.ConnectSemiAccurate(MyDestructionData.Static.TemporaryWorld);
//fast frong
for (int i = 0; i < m_shapeInfosList2.Count; i++)
{
for (int j = 0; j < m_shapeInfosList2.Count; j++)
{
if (i != j)
{
ConnectShapesWithChildren(breakableShape, m_shapeInfosList2[i].Shape, m_shapeInfosList2[j].Shape);
}
}
//.........这里部分代码省略.........
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridShape.cs
示例13: CreateBody
protected virtual void CreateBody(ref HkShape shape, HkMassProperties? massProperties)
{
ProfilerShort.Begin("CreateBody");
HkRigidBodyCinfo rbInfo = new HkRigidBodyCinfo();
rbInfo.AngularDamping = m_angularDamping;
rbInfo.LinearDamping = m_linearDamping;
rbInfo.Shape = shape;
rbInfo.SolverDeactivation = InitialSolverDeactivation;
rbInfo.ContactPointCallbackDelay = ContactPointDelay;
if (massProperties.HasValue)
{
rbInfo.SetMassProperties(massProperties.Value);
}
GetInfoFromFlags(rbInfo, Flags);
RigidBody = new HkRigidBody(rbInfo);
ProfilerShort.End();
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:22,代码来源:MyPhysicsBody.cs
示例14: CheckVolumeMassRec
private bool CheckVolumeMassRec(HkdBreakableShape bShape, float minVolume, float minMass)
{
if (bShape.Name.Contains("Fake"))
return true;
if (bShape.Volume <= minVolume)
return false;
HkMassProperties mp = new HkMassProperties();
bShape.BuildMassProperties(ref mp);
if (mp.Mass <= minMass)
return false;
if (mp.InertiaTensor.M11 == 0 || mp.InertiaTensor.M22 == 0 || mp.InertiaTensor.M33 == 0)
return false;
for (int i = 0; i < bShape.GetChildrenCount(); i++)
{
if (!CheckVolumeMassRec(bShape.GetChildShape(i), minVolume, minMass))
return false;
}
return true;
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:19,代码来源:MyDestructionData.cs
示例15: GetPhysicsShape
// Don't call remove reference on this, this shape is pooled
protected virtual HkShape GetPhysicsShape(HkMassProperties massProperties, float mass, float scale)
{
const bool SimpleShape = false;
Vector3 halfExtents = (Entity.Render.GetModel().BoundingBox.Max - Entity.Render.GetModel().BoundingBox.Min) / 2;
HkShapeType shapeType;
if (VoxelMaterial != null)
{
shapeType = HkShapeType.Sphere;
massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(Entity.Render.GetModel().BoundingSphere.Radius * scale, mass);
}
else
{
shapeType = HkShapeType.Box;
massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(halfExtents, mass);
}
return MyDebris.Static.GetDebrisShape(Entity.Render.GetModel(), SimpleShape ? shapeType : HkShapeType.ConvexVertices);
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:21,代码来源:MyMeteor.cs
示例16: 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;
}
开发者ID:martejj,项目名称:SpaceEngineers,代码行数:68,代码来源:MyFloatingObject.cs
示例17: CreateBody
protected override void CreateBody(ref HkShape shape, HkMassProperties? massProperties)
{
if (MyPerGameSettings.Destruction)// && shape.ShapeType == HkShapeType.StaticCompound)
{
ProfilerShort.Begin("CreateGridBody");
HkdBreakableShape breakable;
HkMassProperties massProps = massProperties.HasValue ? massProperties.Value : new HkMassProperties();
if (!Shape.BreakableShape.IsValid())
Shape.CreateBreakableShape();
breakable = Shape.BreakableShape;
if (!breakable.IsValid())
{
breakable = new HkdBreakableShape(shape);
if (massProperties.HasValue)
{
var mp = massProperties.Value;
breakable.SetMassProperties(ref mp);
}
else
breakable.SetMassRecursively(50);
}
else
breakable.BuildMassProperties(ref massProps);
shape = breakable.GetShape(); //doesnt add reference
HkRigidBodyCinfo rbInfo = new HkRigidBodyCinfo();
rbInfo.AngularDamping = m_angularDamping;
rbInfo.LinearDamping = m_linearDamping;
rbInfo.SolverDeactivation = m_grid.IsStatic ? InitialSolverDeactivation : HkSolverDeactivation.Low;
rbInfo.ContactPointCallbackDelay = ContactPointDelay;
rbInfo.Shape = shape;
rbInfo.SetMassProperties(massProps);
//rbInfo.Position = Entity.PositionComp.GetPosition(); //obsolete with large worlds?
GetInfoFromFlags(rbInfo, Flags);
HkRigidBody rb = new HkRigidBody(rbInfo);
rb.EnableDeactivation = true;
BreakableBody = new HkdBreakableBody(breakable, rb, MyPhysics.SingleWorld.DestructionWorld, Matrix.Identity);
//DestructionBody.ConnectToWorld(HavokWorld, 0.05f);
BreakableBody.AfterReplaceBody += FracturedBody_AfterReplaceBody;
//RigidBody.SetWorldMatrix(Entity.PositionComp.WorldMatrix);
//breakable.Dispose();
ProfilerShort.End();
}
else
{
base.CreateBody(ref shape, massProperties);
}
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:55,代码来源:MyGridPhysics.cs
示例18: InitRagdoll
/// <summary>
/// Loads Ragdoll data
/// </summary>
/// <param name="ragDollFile"></param>
public bool InitRagdoll()
{
if (MyFakes.ENABLE_RAGDOLL_DEBUG) Debug.WriteLine("RagdollComponent.InitRagdoll");
if (Character.Physics.Ragdoll != null)
{
Character.Physics.CloseRagdollMode();
Character.Physics.Ragdoll.ResetToRigPose();
Character.Physics.Ragdoll.SetToKeyframed();
return true;
}
Character.Physics.Ragdoll = new HkRagdoll();
bool dataLoaded = false;
if (Character.Model.HavokData != null && Character.Model.HavokData.Length > 0)
{
try
{
dataLoaded = Character.Physics.Ragdoll.LoadRagdollFromBuffer(Character.Model.HavokData);
}
catch (Exception e)
{
Debug.Fail("Error loading ragdoll from buffer: " + e.Message);
Character.Physics.CloseRagdoll();
Character.Physics.Ragdoll = null;
}
}
else if (Character.Definition.RagdollDataFile != null)
{
String ragDollFile = System.IO.Path.Combine(MyFileSystem.ContentPath, Character.Definition.RagdollDataFile);
if (System.IO.File.Exists(ragDollFile))
{
dataLoaded = Character.Physics.Ragdoll.LoadRagdollFromFile(ragDollFile);
}
else
{
System.Diagnostics.Debug.Fail("Cannot find ragdoll file: " + ragDollFile);
}
}
if (Character.Definition.RagdollRootBody != String.Empty)
{
if (!Character.Physics.Ragdoll.SetRootBody(Character.Definition.RagdollRootBody))
{
Debug.Fail("Can not set root body with name: " + Character.Definition.RagdollRootBody + " on model " + Character.ModelName + ". Please check your definitions.");
}
}
if (!dataLoaded)
{
Character.Physics.Ragdoll.Dispose();
Character.Physics.Ragdoll = null;
}
foreach (var body in Character.Physics.Ragdoll.RigidBodies)
body.UserObject = Character;
if (Character.Physics.Ragdoll != null && MyPerGameSettings.Destruction) //scaling weights and IT
{
Character.Physics.Ragdoll.SetToDynamic();
var mp = new HkMassProperties();
foreach (var body in Character.Physics.Ragdoll.RigidBodies)
{
mp.Mass = MyDestructionHelper.MassToHavok(body.Mass);
mp.InertiaTensor = Matrix.CreateScale(1.0f / 25.0f) * body.InertiaTensor;
body.SetMassProperties(ref mp);
}
Character.Physics.Ragdoll.SetToKeyframed();
}
if (Character.Physics.Ragdoll != null && MyFakes.ENABLE_RAGDOLL_DEFAULT_PROPERTIES)
{
Character.Physics.SetRagdollDefaults();
}
return dataLoaded;
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:83,代码来源:MyCharacterRagdollComponent.cs
示例19: PrepareItemsPhysics
/// <summary>
/// Prepares data for renderer and physics. Must be called after all items has been added.
/// </summary>
public void PrepareItemsPhysics(HkStaticCompoundShape sectorRootShape, ref BoundingBoxD aabbWorld)
{
PositionComp.WorldAABB = aabbWorld;
if (sectorRootShape.InstanceCount > 0)
{
Debug.Assert(m_physicsShapeInstanceIdToLocalId.Count > 0);
Physics = new Sandbox.Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_STATIC)
{
MaterialType = m_definition.Material,
AngularDamping = MyPerGameSettings.DefaultAngularDamping,
LinearDamping = MyPerGameSettings.DefaultLinearDamping,
IsStaticForCluster = true,
};
sectorRootShape.Bake();
HkMassProperties massProperties = new HkMassProperties();
MatrixD matrix = MatrixD.CreateTranslation(CellsOffset);
Physics.CreateFromCollisionObject((HkShape)sectorRootShape, Vector3.Zero, matrix, massProperties);
Physics.ContactPointCallback += Physics_ContactPointCallback;
Physics.RigidBody.ContactPointCallbackEnabled = true;
sectorRootShape.Base.RemoveReference();
Physics.Enabled = true;
}
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:32,代码来源:MyEnvironmentItems.cs
示例20: RecreateShape
//.........这里部分代码省略.........
if (blockDef.BuildProgressModels != null)
{
foreach (var progress in blockDef.BuildProgressModels)
{
model = progress.File;
if (VRage.Game.Models.MyModels.GetModelOnlyData(model).HavokBreakableShapes == null)
MyDestructionData.Static.LoadModelDestruction(model, blockDef, Vector3.One);
shape = VRage.Game.Models.MyModels.GetModelOnlyData(model).HavokBreakableShapes[0];
si = new HkdShapeInstanceInfo(shape, null, null);
removeRefsList.Add(si);
m_tmpChildren.Add(si);
shape.GetChildren(m_tmpChildren);
}
}
}
Debug.Assert(m_tmpShapeListInit.Count == 0);
m_tmpShapeListInit.Clear();
m_tmpShapeListInit.AddList(shapeList);
for (int i = 0; i < m_tmpChildren.Count; i++)
{
var child = m_tmpChildren[i];
var result = m_tmpShapeListInit.Where(s => s.Name == child.ShapeName);
if (result.Count() > 0)
{
var found = result.First();
var si = new HkdShapeInstanceInfo(child.Shape.Clone(), Matrix.Identity);
if (found.Fixed)
si.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
removeRefsList.Add(si);
m_tmpShapeInfos.Add(si);
m_tmpShapeListInit.Remove(found);
}
else
{
child.GetChildren(m_tmpChildren);
}
}
m_tmpShapeListInit.Clear();
if (shapeList.Count > 0 && m_tmpShapeInfos.Count == 0)
{
ProfilerShort.End();
m_tmpChildren.Clear();
Debug.Fail("No relevant shape was found for fractured block. It was probably reexported and names changed. Block definition: " + Block.BlockDefinition.Id.ToString());
throw new Exception("No relevant shape was found for fractured block. It was probably reexported and names changed. Block definition: " + Block.BlockDefinition.Id.ToString());
}
if (render != null)
{
foreach (var shape in m_tmpShapeInfos)
{
if (!string.IsNullOrEmpty(shape.Shape.Name))
render.AddPiece(shape.Shape.Name, Matrix.Identity);
}
render.UpdateRenderObject(true);
}
m_tmpChildren.Clear();
if (Block.CubeGrid.CreatePhysics)
{
HkdBreakableShape compound = new HkdCompoundBreakableShape(null, m_tmpShapeInfos);
((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
var mp = new HkMassProperties();
compound.BuildMas
|
请发表评论