本文整理汇总了C#中HkContactPointEvent类的典型用法代码示例。如果您正苦于以下问题:C# HkContactPointEvent类的具体用法?C# HkContactPointEvent怎么用?C# HkContactPointEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HkContactPointEvent类属于命名空间,在下文中一共展示了HkContactPointEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MyGridContactInfo
public MyGridContactInfo(ref HkContactPointEvent evnt, MyCubeGrid grid)
{
Event = evnt;
ContactPosition = grid.Physics.ClusterToWorld(evnt.ContactPoint.Position);
m_currentEntity = grid;
m_collidingEntity = Event.GetOtherEntity(grid) as MyEntity;
m_currentBlock = null;
m_otherBlock = null;
ImpulseMultiplier = 1;
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:10,代码来源:MyGridContactInfo.cs
示例2: RigidBody_ContactPointCallback_Destruction
void RigidBody_ContactPointCallback_Destruction(ref HkContactPointEvent value)
{
ProfilerShort.Begin("Grid Contact counter");
ProfilerShort.End();
MyGridContactInfo info = new MyGridContactInfo(ref value, m_grid);
if (info.IsKnown)
return;
var myEntity = info.CurrentEntity;//value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA.GetEntity() : value.Base.BodyB.GetEntity();
if (myEntity == null || myEntity.Physics == null || myEntity.Physics.RigidBody == null)
{
return;
}
var myBody = myEntity.Physics.RigidBody;
// CH: DEBUG
var physicsBody1 = value.GetPhysicsBody(0);
var physicsBody2 = value.GetPhysicsBody(1);
if (physicsBody1 == null || physicsBody2 == null)
return;
var entity1 = physicsBody1.Entity;
var entity2 = physicsBody2.Entity;
if (entity1 == null || entity2 == null || entity1.Physics == null || entity2.Physics == null)
return;
if (entity1 is MyFracturedPiece && entity2 is MyFracturedPiece)
return;
var rigidBody1 = value.Base.BodyA;
var rigidBody2 = value.Base.BodyB;
info.HandleEvents();
if (rigidBody1.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT) || rigidBody2.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT))
return;
if (info.CollidingEntity is Sandbox.Game.Entities.Character.MyCharacter || info.CollidingEntity == null || info.CollidingEntity.MarkedForClose)
return;
var grid1 = entity1 as MyCubeGrid;
var grid2 = entity2 as MyCubeGrid;
// CH: TODO: This is a hack Instead, the IMyDestroyableObject should be used and the subpart DoDamage code could delegate it to the grid
// The thing is, this approach would probably need a rewrite of this whole method...
if (grid2 == null && entity2 is MyEntitySubpart)
{
while (entity2 != null && !(entity2 is MyCubeGrid))
{
entity2 = entity2.Parent;
}
if (entity2 != null)
{
physicsBody2 = entity2.Physics as MyPhysicsBody;
rigidBody2 = physicsBody2.RigidBody;
grid2 = entity2 as MyCubeGrid;
}
}
if (grid1 != null && grid2 != null && (MyCubeGridGroups.Static.Physical.GetGroup(grid1) == MyCubeGridGroups.Static.Physical.GetGroup(grid2)))
return;
ProfilerShort.Begin("Grid contact point callback");
{
var vel = Math.Abs(value.SeparatingVelocity);
bool enoughSpeed = vel > 3;
//float dot = Vector3.Dot(Vector3.Normalize(LinearVelocity), Vector3.Normalize(info.CollidingEntity.Physics.LinearVelocity));
Vector3 velocity1 = rigidBody1.GetVelocityAtPoint(info.Event.ContactPoint.Position);
Vector3 velocity2 = rigidBody2.GetVelocityAtPoint(info.Event.ContactPoint.Position);
float speed1 = velocity1.Length();
float speed2 = velocity2.Length();
Vector3 dir1 = speed1 > 0 ? Vector3.Normalize(velocity1) : Vector3.Zero;
Vector3 dir2 = speed2 > 0 ? Vector3.Normalize(velocity2) : Vector3.Zero;
float mass1 = MyDestructionHelper.MassFromHavok(rigidBody1.Mass);
float mass2 = MyDestructionHelper.MassFromHavok(rigidBody2.Mass);
float impact1 = speed1 * mass1;
float impact2 = speed2 * mass2;
float dot1withNormal = speed1 > 0 ? Vector3.Dot(dir1, value.ContactPoint.Normal) : 0;
float dot2withNormal = speed2 > 0 ? Vector3.Dot(dir2, value.ContactPoint.Normal) : 0;
speed1 *= Math.Abs(dot1withNormal);
speed2 *= Math.Abs(dot2withNormal);
bool is1Static = mass1 == 0;
bool is2Static = mass2 == 0;
bool is1Small = entity1 is MyFracturedPiece || (grid1 != null && grid1.GridSizeEnum == MyCubeSize.Small);
bool is2Small = entity2 is MyFracturedPiece || (grid2 != null && grid2.GridSizeEnum == MyCubeSize.Small);
float dot = Vector3.Dot(dir1, dir2);
//.........这里部分代码省略.........
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridPhysics.Destruction.cs
示例3: GetOtherEntity
protected Sandbox.ModAPI.IMyEntity GetOtherEntity(ref HkContactPointEvent value)
{
if (value.Base.BodyA.GetEntity() == this)
return value.Base.BodyB.GetEntity();
else
return value.Base.BodyA.GetEntity();
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:7,代码来源:MyShipConnector.cs
示例4: PlayContactSound
public void PlayContactSound(HkContactPointEvent value, float volume = 0)
{
ProfilerShort.Begin("PlayContactSound");
var bodyA = value.Base.BodyA.GetBody();
var bodyB = value.Base.BodyB.GetBody();
if (bodyA == null || bodyB == null)
{
ProfilerShort.End();
return;
}
ProfilerShort.BeginNextBlock("GetMaterial");
var worldPos = ClusterToWorld(value.ContactPoint.Position);
var materialA = bodyA.GetMaterialAt(worldPos + value.ContactPoint.Normal * 0.1f);
var materialB = bodyB.GetMaterialAt(worldPos - value.ContactPoint.Normal * 0.1f);
/*if (materialA == m_character || materialB == m_character)
{
ProfilerShort.End();
return;
}*/
ProfilerShort.Begin("Lambdas");
var colision = value.Base;
Func<bool> canHear = () =>
{
if (MySession.Static.ControlledEntity != null)
{
var entity = MySession.Static.ControlledEntity.Entity.GetTopMostParent();
return (entity == value.GetPhysicsBody(0).Entity || entity == value.GetPhysicsBody(1).Entity);
}
return false;
};
Func<bool> shouldPlay2D = () => MySession.Static.ControlledEntity != null && MySession.Static.ControlledEntity.Entity is MyCharacter && (
MySession.Static.ControlledEntity.Entity.Components == value.GetPhysicsBody(0).Entity || MySession.Static.ControlledEntity.Entity.Components == value.GetPhysicsBody(1).Entity);
ProfilerShort.BeginNextBlock("Volume");
if (volume == 0)
{
//var vel = value.Base.BodyA.LinearVelocity - value.Base.BodyB.LinearVelocity;
//if (System.Math.Abs(Vector3.Normalize(vel).Dot(value.ContactPoint.Normal)) < 0.7f)\
//var val = System.Math.Abs(Vector3.Normalize(vel).Dot(value.ContactPoint.Normal)) * vel.Length();
//var mass = value.Base.BodyA.Mass;
//var massB = value.Base.BodyB.Mass;
//mass = mass == 0 ? massB : massB == 0 ? mass : mass < massB ? mass : massB; // select smaller mass > 0
//mass /= 40; //reference mass
//val *= mass;
if (Math.Abs(value.SeparatingVelocity) < 10f)
volume = 0.5f + Math.Abs(value.SeparatingVelocity) / 20f;
else
volume = 1f;
}
ProfilerShort.BeginNextBlock("PlaySound");
bool firstOneIsLighter = bodyB.Entity is MyVoxelBase || bodyB.Entity.Physics == null;
if (firstOneIsLighter == false && bodyA.Entity.Physics != null && bodyA.Entity.Physics.IsStatic == false && (bodyB.Entity.Physics.IsStatic || bodyA.Entity.Physics.Mass < bodyB.Entity.Physics.Mass))
firstOneIsLighter = true;
if (firstOneIsLighter)
MyAudioComponent.PlayContactSound(bodyA.Entity.EntityId, m_startCue, worldPos, materialA, materialB, volume, canHear, surfaceEntity: (MyEntity)bodyB.Entity, separatingVelocity: Math.Abs(value.SeparatingVelocity));
else
MyAudioComponent.PlayContactSound(bodyB.Entity.EntityId, m_startCue, worldPos, materialB, materialA, volume, canHear, surfaceEntity: (MyEntity)bodyA.Entity, separatingVelocity: Math.Abs(value.SeparatingVelocity));
ProfilerShort.End();
ProfilerShort.End();
}
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:62,代码来源:MyPhysicsBody.cs
示例5: OnContactPointCallback
//Vector3 GetVelocityAtPoint(Vector3D worldPos)
//{
// return LinearVelocity + AngularVelocity.Cross(worldPos - CenterOfMassWorld);
//}
void OnContactPointCallback(ref HkContactPointEvent e)
{
ProfilerShort.Begin("PhysicsBody.OnContacPointCallback");
if (ContactPointCallback != null)
{
var offset = MyPhysics.Clusters.GetObjectOffset(ClusterObjectID);
MyPhysics.MyContactPointEvent ce = new MyPhysics.MyContactPointEvent()
{
ContactPointEvent = e,
Position = e.ContactPoint.Position + offset
};
ContactPointCallback(ref ce);
}
ProfilerShort.End();
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:22,代码来源:MyPhysicsBody.cs
示例6: RigidBody_ContactPointCallback
//isnt used
void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
{
if (!Sync.IsServer)
return;
var entity = value.GetOtherEntity(this);
if (entity is MyFloatingObject)
{
m_entitiesToTake.Add(entity as MyFloatingObject);
NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
}
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:12,代码来源:MyCollector.cs
示例7: GetDamageFromHit
private DamageImpactEnum GetDamageFromHit(HkRigidBody collidingBody, MyEntity collidingEntity, ref HkContactPointEvent value)
{
if (collidingBody.LinearVelocity.Length() < MyPerGameSettings.CharacterDamageHitObjectMinVelocity) return DamageImpactEnum.NoDamage;
if (collidingEntity == ManipulatedEntity) return DamageImpactEnum.NoDamage;
if (collidingBody.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT)) return DamageImpactEnum.NoDamage;
var mass = (MyPerGameSettings.Destruction ? MyDestructionHelper.MassFromHavok(collidingBody.Mass) : collidingBody.Mass);
if (mass < MyPerGameSettings.CharacterDamageHitObjectMinMass) return DamageImpactEnum.NoDamage;
// Get the objects energies to calculate the damage - must be higher above treshold
float objectEnergy = Math.Abs(value.SeparatingVelocity) * mass;
if (objectEnergy > MyPerGameSettings.CharacterDamageHitObjectDeadlyEnergy) return DamageImpactEnum.DeadlyDamage;
if (objectEnergy > MyPerGameSettings.CharacterDamageHitObjectCriticalEnergy) return DamageImpactEnum.CriticalDamage;
if (objectEnergy > MyPerGameSettings.CharacterDamageHitObjectMediumEnergy) return DamageImpactEnum.MediumDamage;
if (objectEnergy > MyPerGameSettings.CharacterDamageHitObjectSmallEnergy) return DamageImpactEnum.SmallDamage;
return DamageImpactEnum.NoDamage;
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:21,代码来源:MyCharacter.cs
示例8: CalculateDamageAfterCollision
private void CalculateDamageAfterCollision(ref HkContactPointEvent value)
{
// Are bodies moving one to another? if not we do not apply damage
if (value.SeparatingVelocity < 0)
{
if (!Sync.IsServer) return;
DamageImpactEnum damageImpact = DamageImpactEnum.NoDamage;
// Get the colliding object and skip collisions between characters
HkRigidBody collidingBody;
int collidingBodyIdx = 0;
if (value.Base.BodyA == Physics.CharacterProxy.GetHitRigidBody())
{
collidingBody = value.Base.BodyB;
collidingBodyIdx = 1;
}
else
collidingBody = value.Base.BodyA;
MyEntity collidingEntity = value.GetPhysicsBody(collidingBodyIdx).Entity as MyEntity;
if (collidingEntity == null || collidingEntity is MyCharacter) return;
if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_SHOW_DAMAGE)
{
MatrixD worldMatrix = collidingEntity.Physics.GetWorldMatrix();
int index = 0;
MyPhysicsDebugDraw.DrawCollisionShape(collidingBody.GetShape(), worldMatrix, 1, ref index, "hit");
}
damageImpact = GetDamageFromFall(collidingBody, collidingEntity, ref value);
if (damageImpact != DamageImpactEnum.NoDamage) ApplyDamage(damageImpact, MyDamageType.Fall);
damageImpact = GetDamageFromHit(collidingBody, collidingEntity, ref value);
if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_SHOW_DAMAGE)
{
if (damageImpact != DamageImpactEnum.NoDamage)
{
MatrixD worldMatrix = collidingEntity.Physics.GetWorldMatrix();
VRageRender.MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, collidingBody.Mass, Color.Red, 1, false);
VRageRender.MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, "MASS: " + collidingBody.Mass, Color.Red, 1, false);
}
}
if (damageImpact != DamageImpactEnum.NoDamage) ApplyDamage(damageImpact, MyDamageType.Environment);
damageImpact = GetDamageFromSqueeze(collidingBody, collidingEntity, ref value);
if (damageImpact != DamageImpactEnum.NoDamage) ApplyDamage(damageImpact, MyDamageType.Squeez);
}
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:53,代码来源:MyCharacter.cs
示例9: TrySpawnWalkingParticles
internal void TrySpawnWalkingParticles(ref HkContactPointEvent value)
{
if (!MyFakes.ENABLE_WALKING_PARTICLES)
return;
var oldCheckTime = m_lastWalkParticleCheckTime;
m_lastWalkParticleCheckTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
m_walkParticleSpawnCounterMs -= m_lastWalkParticleCheckTime - oldCheckTime;
if (m_walkParticleSpawnCounterMs > 0)
return;
var naturalGravityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(Entity.PositionComp.WorldMatrix.Translation);
if (naturalGravityMultiplier <= 0f)
{
m_walkParticleSpawnCounterMs = m_walkParticleGravityDelay;
return;
}
var character = Entity as MyCharacter;
if (character.JetpackComp != null && character.JetpackComp.Running)
{
m_walkParticleSpawnCounterMs = m_walkParticleJetpackOffDelay;
return;
}
var currentMovementState = character.GetCurrentMovementState();
if (currentMovementState.GetDirection() == MyCharacterMovement.NoDirection || currentMovementState == MyCharacterMovementEnum.Falling)
{
m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
return;
}
var otherPhysicsBody = value.GetOtherEntity(character).Physics as MyVoxelPhysicsBody;//value.Base.BodyA.UserObject == character.Physics ? value.Base.BodyB.UserObject : value.Base.BodyA.UserObject)) as MyVoxelPhysicsBody;
if (otherPhysicsBody == null)
return;
MyStringId movementType;
const int walkParticleWalkDelay = 500;
const int walkParticleRunDelay = 275;
const int walkParticleSprintDelay = 250;
switch (currentMovementState.GetSpeed())
{
case MyCharacterMovement.NormalSpeed:
movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
m_walkParticleSpawnCounterMs = walkParticleWalkDelay;
break;
case MyCharacterMovement.Fast:
movementType = MyMaterialPropertiesHelper.CollisionType.Run;
m_walkParticleSpawnCounterMs = walkParticleRunDelay;
break;
case MyCharacterMovement.VeryFast:
movementType = MyMaterialPropertiesHelper.CollisionType.Sprint;
m_walkParticleSpawnCounterMs = walkParticleSprintDelay;
break;
default:
movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
break;
}
var spawnPosition = otherPhysicsBody.ClusterToWorld(value.ContactPoint.Position);
MyVoxelMaterialDefinition voxelMaterialDefinition = otherPhysicsBody.m_voxelMap.GetMaterialAt(ref spawnPosition);
if (voxelMaterialDefinition == null)
return;
MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(
movementType,
spawnPosition,
value.ContactPoint.Normal,
m_characterMaterial,
MyStringHash.GetOrCompute(voxelMaterialDefinition.MaterialTypeName));
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:75,代码来源:MyRenderComponentCharacter.cs
示例10: RigidBody_ContactPointCallback
void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
{
ProfilerShort.Begin("Grid Contact counter");
ProfilerShort.End();
var otherEntity = value.GetOtherEntity(m_grid);
var otherPhysicsBody = value.GetPhysicsBody(0);
var thisEntity = m_grid;
if (otherEntity == null || thisEntity == null)
return;
//DA used to stop appliyng force when there is planet/ship collisions to increase performance after ship crashes on planet
if ((Math.Abs(value.SeparatingVelocity) < 0.3f) && (otherEntity is MyTrees || otherEntity is MyVoxelPhysics))
{
return;
}
MyGridContactInfo info = new MyGridContactInfo(ref value, m_grid);
var myBody = RigidBody;// value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA : value.Base.BodyB;
if (info.CollidingEntity is Sandbox.Game.Entities.Character.MyCharacter || info.CollidingEntity.MarkedForClose)
return;
if (MyFakes.LANDING_GEAR_IGNORE_DAMAGE_CONTACTS && MyCubeGridGroups.Static.NoContactDamage.HasSameGroupAndIsGrid(otherEntity, thisEntity))
return;
ProfilerShort.Begin("Grid contact point callback");
bool hitVoxel = info.CollidingEntity is MyVoxelMap || info.CollidingEntity is MyVoxelPhysics;
if(hitVoxel && m_grid.Render != null) {
m_grid.Render.ResetLastVoxelContactTimer();
}
bool doSparks = MyPerGameSettings.EnableCollisionSparksEffect && (info.CollidingEntity is MyCubeGrid || hitVoxel);
// According to Petr, WasUsed does not work everytime
//if (value.ContactProperties.WasUsed)
{
// Handle callbacks here
info.HandleEvents();
}
if(MyDebugDrawSettings.DEBUG_DRAW_FRICTION)
{
var pos = ClusterToWorld(value.ContactPoint.Position);
var vel = -GetVelocityAtPoint(pos);
vel *= 0.1f;
var fn = Math.Abs(Gravity.Dot(value.ContactPoint.Normal) * value.ContactProperties.Friction);
if (vel.Length() > 0.5f)
{
vel.Normalize();
MyRenderProxy.DebugDrawArrow3D(pos, pos + fn * vel, Color.Gray, Color.Gray, false);
}
}
if (doSparks && Math.Abs(value.SeparatingVelocity) > 2.0f && value.ContactProperties.WasUsed && !m_lastContacts.ContainsKey(value.ContactPointId) && info.EnableParticles)
{
ProfilerShort.Begin("AddCollisionEffect");
m_lastContacts[value.ContactPointId] = MySandboxGame.TotalGamePlayTimeInMilliseconds;
AddCollisionEffect(info.ContactPosition, value.ContactPoint.Normal);
ProfilerShort.End();
}
ProfilerShort.Begin("Dust");
bool doDust = MyPerGameSettings.EnableCollisionSparksEffect && hitVoxel;
float force = Math.Abs(value.SeparatingVelocity * (Mass / 100000));
if (doDust && force > 0.25f && info.EnableParticles)
{
float scale = MathHelper.Clamp(force / 10.0f, 0.2f, 4.0f);
AddDustEffect(info.ContactPosition, scale);
}
ProfilerShort.End();
// Large dynamic ships colliding with floating objects
// When low separating velocity or deformation performed, disable contact point
// Floating object will still collide with kinematic part of ship and won't push it
if (m_grid.GridSizeEnum == MyCubeSize.Large && !myBody.IsFixedOrKeyframed && info.CollidingEntity is MyFloatingObject && (Math.Abs(value.SeparatingVelocity) < 0.2f))
{
var prop = value.ContactProperties;
prop.IsDisabled = true;
}
ProfilerShort.End();
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:84,代码来源:MyGridPhysics.cs
示例11: RegisterObstacleContact
public void RegisterObstacleContact(ref HkContactPointEvent e)
{
if (m_obstacleContact == false && m_fallSoundShouldPlay.Value == true && (DateTime.UtcNow - m_soundStart).TotalSeconds >= 1f)
{
m_obstacleContact = true;
}
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:7,代码来源:MyFracturedPiece.cs
示例12: RigidBody_ContactPointCallback
void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
{
if (Physics.CharacterProxy == null)
return;
if (!MySession.Static.Ready)
return;
if (value.Base.BodyA == null || value.Base.BodyB == null)
return;
if (value.Base.BodyA.UserObject == null || value.Base.BodyB.UserObject == null)
return;
if (value.Base.BodyA.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT) || value.Base.BodyB.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT))
return;
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:17,代码来源:MyGhostCharacter.cs
示例13: RigidBody_ContactPointCallback
void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
{
if (ContactPointCallback != null)
ContactPointCallback(ref value);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:5,代码来源:MyCharacterProxy.cs
示例14: PlayContactSound
public void PlayContactSound(HkContactPointEvent value, float volume = 0)
{
ProfilerShort.Begin("PlayContactSound");
var bodyA = value.Base.BodyA.GetBody();
var bodyB = value.Base.BodyB.GetBody();
if (bodyA == null || bodyB == null)
{
ProfilerShort.End();
return;
}
var colision = value.Base;
Func<bool> canHear = () =>
{
if (MySession.ControlledEntity != null)
{
var entity = MySession.ControlledEntity.Entity.GetTopMostParent();
return (entity == value.GetPhysicsBody(0).Entity || entity == value.GetPhysicsBody(1).Entity);
}
return false;
};
Func<bool> shouldPlay2D = () => MySession.ControlledEntity != null && MySession.ControlledEntity.Entity is MyCharacter && (
MySession.ControlledEntity.Entity.Components == value.GetPhysicsBody(0).Entity || MySession.ControlledEntity.Entity.Components == value.GetPhysicsBody(1).Entity);
if (volume == 0)
{
var vel = value.Base.BodyA.LinearVelocity - value.Base.BodyB.LinearVelocity;
//if (System.Math.Abs(Vector3.Normalize(vel).Dot(value.ContactPoint.Normal)) < 0.7f)\
var val = System.Math.Abs(Vector3.Normalize(vel).Dot(value.ContactPoint.Normal)) * vel.Length();
//var mass = value.Base.BodyA.Mass;
//var massB = value.Base.BodyB.Mass;
//mass = mass == 0 ? massB : massB == 0 ? mass : mass < massB ? mass : massB; // select smaller mass > 0
//mass /= 40; //reference mass
//val *= mass;
if (val < 10)
volume = val / 10;
else
volume = 1;
}
var worldPos = ClusterToWorld(value.ContactPoint.Position);
var materialA = bodyA.GetMaterialAt(worldPos + value.ContactPoint.Normal * 0.1f);
var materialB = bodyB.GetMaterialAt(worldPos - value.ContactPoint.Normal * 0.1f);
MyAudioComponent.PlayContactSound(Entity.EntityId, worldPos, materialA, materialB, volume, canHear);
ProfilerShort.End();
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:50,代码来源:MyPhysicsBody.cs
示例15: GetOtherEntity
protected IMyEntity GetOtherEntity(ref HkContactPointEvent value)
{
if (value.Base.BodyA.GetEntity() == Entity)
return value.Base.BodyB.GetEntity();
else
return value.Base.BodyA.GetEntity();
}
开发者ID:notten,项目名称:SpaceEngineers,代码行数:7,代码来源:MyMeteor.cs
示例16: RigidBody_ContactPointCallback
void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
{
if (IsDead || Sync.IsServer == false)
return;
if (Physics.CharacterProxy == null)
return;
if (!MySession.Static.Ready)
return;
if (value.Base.BodyA == null || value.Base.BodyB == null)
return;
if (value.Base.BodyA.UserObject == null || value.Base.BodyB.UserObject == null)
return;
if (value.Base.BodyA.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT) || value.Base.BodyB.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT))
return;
//MyCharacter charA = null;//((MyPhysicsBody)value.Base.BodyA.UserObject).Entity as MyCharacter;
//MyCharacter charB = null;//((MyPhysicsBody)value.Base.BodyB.UserObject).Entity as MyCharacter;
//if (charA != null && charA.AIMode)
// return;
//if (charB != null && charB.AIMode)
// return;
Render.TrySpawnWalkingParticles(ref value);
// DAMAGE COMPUTATION TO THE CHARACTER
// GET THE OTHER COLLIDING BODY AND COMPUTE DAMAGE BASED ON BODIES MASS AND VELOCITIES
if (MyPerGameSettings.EnableCharacterCollisionDamage && !MyFakes.NEW_CHARACTER_DAMAGE)
{
CalculateDamageAfterCollision(ref value);
}
//// ORIGINAL DAMAGE COMPUTATION
else
{
float impact = 0;
if (MyFakes.NEW_CHARACTER_DAMAGE)
{
var normal = value.ContactPoint.Normal;
MyEntity other = value.GetPhysicsBody(0).Entity as MyEntity;
HkRigidBody otherRb = value.Base.BodyA;
if (other == this)
{
other = value.GetPhysicsBody(1).Entity as MyEntity;
otherRb = value.Base.BodyB;
normal = -normal;
}
var otherChar = (other as MyCharacter);
if (otherChar != null)
{
if (otherChar.IsDead)
{
if (otherChar.Physics.Ragdoll != null && otherChar.Physics.Ragdoll.GetRootRigidBody().HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT))
return;
}
else
{
if (Physics.CharacterProxy.Supported && otherChar.Physics.CharacterProxy.Supported)
return;
}
}
if (Math.Abs(value.SeparatingVelocity) < 3)
{
return;
}
Vector3 velocity1 = Physics.LinearVelocity;
Vector3 difference = velocity1 - m_previousLinearVelocity;
float lenght = difference.Length();
if (lenght > 10)
{
//strange angle / magnitude force mismatch
return;
}
Vector3 velocity2 = otherRb.GetVelocityAtPoint(value.ContactPoint.Position);
float velocity = velocity1.Length();
float speed1 = Math.Max(velocity - (MyFakes.ENABLE_CUSTOM_CHARACTER_IMPACT ? 12.6f : 17.0f), 0);//treshold for falling dmg
float speed2 = velocity2.Length() - 2.0f;
Vector3 dir1 = speed1 > 0 ? Vector3.Normalize(velocity1) : Vector3.Zero;
Vector3 dir2 = speed2 > 0 ? Vector3.Normalize(velocity2) : Vector3.Zero;
float dot1withNormal = speed1 > 0 ? Vector3.Dot(dir1, normal) : 0;
float dot2withNormal = speed2 > 0 ? -Vector3.Dot(dir2, normal) : 0;
//.........这里部分代码省略.........
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:101,代码来源:MyCharacter.cs
示例17: RigidBody_ContactPointCallback
void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
{
ProfilerShort.Begin("Grid Contact counter");
ProfilerShort.End();
var entity1 = value.Base.BodyA.GetEntity();
var entity2 = value.Base.BodyB.GetEntity();
if (entity1 == null || entity2 == null)
return;
//DA used to stop appliyng force when there is planet/ship collisions to increase performance after ship crashes on planet
if ((Math.Abs(value.SeparatingVelocity) < 0.3f) && (entity1 is MyTrees || entity1 is MyVoxelPhysics || entity2 is MyVoxelPhysics || entity2 is MyTrees))
{
return;
}
MyGridContactInfo info = new MyGridContactInfo(ref value, m_grid);
var myBody = value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA : value.Base.BodyB;
// CH: DEBUG
if (info.CollidingEntity is Sandbox.Game.Entities.Character.MyCharacter || info.CollidingEntity.MarkedForClose)
return;
if (MyFakes.LANDING_GEAR_IGNORE_DAMAGE_CONTACTS && MyCubeGridGroups.Static.NoContactDamage.HasSameGroupAndIsGrid(entity1, entity2))
return;
ProfilerShort.Begin("Grid contact point callback");
bool doSparks = MyPerGameSettings.EnableCollisionSparksEffect && (info.CollidingEntity is MyCubeGrid || info.CollidingEntity is MyVoxelMap);
// According to Petr, WasUsed does not work everytime
//if (value.ContactProperties.WasUsed)
{
// Handle callbacks here
info.HandleEvents();
}
bool deformationPerformed = false;
if (Sync.IsServer && value.ContactProperties.ImpulseApplied > MyGridShape.BreakImpulse && info.CollidingEntity != null && info.EnableDeformation && m_grid.BlocksDestructionEnabled)
{
float deformation = value.SeparatingVelocity;
if (info.RubberDeformation)
{
deformation /= 5;
}
HkBreakOffPointInfo breakInfo = CreateBreakOffPoint(value, info.ContactPosition, MyGridShape.BreakImpulse);
PerformDeformation(ref breakInfo, false, value.SeparatingVelocity);
deformationPerformed = true;
}
else if (doSparks && value.SeparatingVelocity > 2.0f && value.ContactProperties.WasUsed && !m_lastContacts.ContainsKey(value.ContactPointId) && info.EnableParticles)
{
m_lastContacts[value.ContactPointId] = MySandboxGame.TotalGamePlayTimeInMilliseconds;
AddCollisionEffect(info.ContactPosition, value.ContactPoint.Normal);
}
// Large dynamic ships colliding with floating objects
// When low separating velocity or deformation performed, disable contact point
// Floating object will still collide with kinematic part of ship and won't push it
if (m_grid.GridSizeEnum == MyCubeSize.Large && !myBody.IsFixedOrKeyframed && info.CollidingEntity is MyFloatingObject && (Math.Abs(value.SeparatingVelocity) < 0.2f || deformationPerformed))
{
var prop = value.ContactProperties;
prop.IsDisabled = true;
}
ProfilerShort.End();
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:70,代码来源:MyGridPhysics.cs
示例18: GetDamageFromSqueeze
private DamageImpactEnum GetDamageFromSqueeze(HkRigidBody collidingBody, MyEntity collidingEntity, ref HkContactPointEvent value)
{
if (collidingBody.IsFixed || collidingBody.Mass < MyPerGameSettings.CharacterSqueezeMinMass) return DamageImpactEnum.NoDamage;
if (value.ContactProperties.IsNew) return DamageImpactEnum.NoDamage;
// the object has to be moving towards the character even slowly and that also the character is not moving away from it
Vector3 direction = Physics.CharacterProxy.GetHitRigidBody().Position - collidingBody.Position;
Vector3 gravity = MyGravityProviderSystem.CalculateTotalGravityInPoint(PositionComp.WorldAABB.Center) + Physics.HavokWorld.Gravity;
direction.Normalize();
gravity.Normalize();
float resultToPlayer = Vector3.Dot(direction, gravity);
if (resultToPlayer < 0.5f) return DamageImpactEnum.NoDamage;
if (m_squeezeDamageTimer > 0)
{
m_squeezeDamageTimer -= VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
return DamageImpactEnum.NoDamage;
}
m_squeezeDamageTimer = MyPerGameSettings.CharacterSqueezeDamageDelay;
if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_SHOW_DAMAGE)
{
MatrixD worldMatrix = collidingEntity.Physics.GetWorldMatrix();
int index = 2;
MyPhysicsDebugDraw.DrawCollisionShape(collidingBody.GetShape(), worldMatrix, 1, ref index);
VRageRender.MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, "SQUEEZE, MASS:" + collidingBody.Mass, Color.Yellow, 2, false);
}
if (collidingBody.Mass > MyPerGameSettings.CharacterSqueezeDeadlyDamageMass) return DamageImpactEnum.DeadlyDamage;
if (collidingBody.Mass > MyPerGameSettings.CharacterSqueezeCriticalDamageMass) return DamageImpactEnum.CriticalDamage;
if (collidingBody.Mass > MyPerGameSettings.CharacterSqueezeMediumDamageMass) return DamageImpactEnum.MediumDamage;
return DamageImpactEnum.SmallDamage;
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:39,代码来源:MyCharacter.cs
示例19: RigidBody_ContactPointCallback_Destruction
void RigidBody_ContactPointCallback_Destruction(ref HkContactPointEvent value)
{
ProfilerShort.Begin("Grid Contact counter");
ProfilerShort.End();
MyGridContactInfo info = new MyGridContactInfo(ref value, m_grid);
if (info.IsKnown)
return;
var myBody = info.CurrentEntity.Physics.RigidBody;//value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA : value.Base.BodyB;
var myEntity = info.CurrentEntity;//value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA.GetEntity() : value.Base.BodyB.GetEntity();
// CH: DEBUG
var entity1 = value.Base.BodyA.GetEntity();
var entity2 = value.Base.BodyB.GetEntity();
var rigidBody1 = value.Base.BodyA;
var rigidBody2 = value.Base.BodyB;
if (entity1 == null || entity2 == null || entity1.Physics == null || entity2.Physics == null)
return;
if (entity1 is MyFracturedPiece && entity2 is MyFracturedPiece)
return;
info.HandleEvents();
if (rigidBody1.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT) || rigidBody2.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT))
return;
if (info.CollidingEntity is Sandbox.Game.Entities.Character.MyCharacter || info.CollidingEntity == null || info.CollidingEntity.MarkedForClose)
return;
if (MyFakes.ENABLE_CHARACTER_VIRTUAL_PHYSICS)
{
MyCharacter character = MySession.ControlledEntity as MyCharacter;
if (character != null && character.VirtualPhysics != null)
{
foreach (var constraint in character.VirtualPhysics.Constraints)
{
IMyEntity cstrEntityA = constraint.RigidBodyA.GetEntity();
IMyEntity cstrEntityB = constraint.RigidBodyB.GetEntity();
if (info.CurrentEntity == cstrEntityA || info.CurrentEntity == cstrEntityB || info.CollidingEntity == cstrEntityA || info.CollidingEntity == cstrEntityB)
return;
}
}
}
var grid1 = entity1 as MyCubeGrid;
var grid2 = entity2 as MyCubeGrid;
if (grid1 != null && grid2 != null && (MyCubeGridGroups.Static.Physical.GetGroup(grid1) == MyCubeGridGroups.Static.Physical.G
|
请发表评论