internal RigidBody(GodotRigidBody rigidbody, Spatial sceneRoot) { _sceneRoot = sceneRoot; _rigidbody = rigidbody; // Read initial values Update(rigidbody); }
public static MRERigidBodyConstraints GetMRERigidBodyConstraints(this Godot.RigidBody rigidBody) { MRERigidBodyConstraints constraints = 0; if (rigidBody.AxisLockLinearX) { constraints |= MRERigidBodyConstraints.FreezePositionX; } if (rigidBody.AxisLockLinearY) { constraints |= MRERigidBodyConstraints.FreezePositionY; } if (rigidBody.AxisLockLinearZ) { constraints |= MRERigidBodyConstraints.FreezePositionZ; } if (rigidBody.AxisLockAngularX) { constraints |= MRERigidBodyConstraints.FreezeRotationX; } if (rigidBody.AxisLockAngularY) { constraints |= MRERigidBodyConstraints.FreezeRotationY; } if (rigidBody.AxisLockAngularZ) { constraints |= MRERigidBodyConstraints.FreezeRotationZ; } return(constraints); }
public void addRigidBody(Guid id, Godot.RigidBody rigidbody, Guid source, bool isKinematic) { Debug.Assert(!_rigidBodies.ContainsKey(id), "PhysicsBridge already has an entry for rigid body with specified ID."); bool isLocalSumulationAuthoritative = LocalUserId == source; var rb = new RigidBodyPhysicsBridgeInfo(id, rigidbody, isLocalSumulationAuthoritative); _rigidBodies.Add(id, rb); if (isLocalSumulationAuthoritative) { rb.IsKeyframed = isKinematic; if (isKinematic) { rigidbody.Mode = Godot.RigidBody.ModeEnum.Kinematic; } } else { rigidbody.Mode = Godot.RigidBody.ModeEnum.Kinematic; _snapshotManager.RegisterOrUpateRigidBody(id, source); } }
} // end of PredictAllRemoteBodiesWithOwnedBodies private Vector3 ClosestPointOnBounds(Godot.RigidBody from, Godot.RigidBody to) { var toCollisionShape = to.GetChild <CollisionShape>(1); var aabb = toCollisionShape.Shape.GetDebugMesh().GetAabb(); var aabbPosition = aabb.Position; var aabbEnd = aabb.End; Vector3[] collisionPoint = new Vector3[8]; collisionPoint[0] = aabbPosition; collisionPoint[1] = new Vector3(aabbPosition.x, aabbPosition.y, aabbEnd.z); collisionPoint[2] = new Vector3(aabbEnd.x, aabbPosition.y, aabbEnd.z); collisionPoint[3] = new Vector3(aabbEnd.x, aabbPosition.y, aabbPosition.z); collisionPoint[4] = new Vector3(aabbPosition.x, aabbEnd.y, aabbPosition.z); collisionPoint[5] = new Vector3(aabbPosition.x, aabbEnd.y, aabbEnd.z); collisionPoint[6] = new Vector3(aabbEnd.x, aabbEnd.y, aabbPosition.z); collisionPoint[7] = aabbEnd; var shortest = to.GlobalTransform.origin.DistanceSquaredTo(from.GlobalTransform.origin); Vector3 ret = Vector3.Zero; foreach (var point in collisionPoint.Select(x => x + to.GlobalTransform.origin)) { var distance = point.DistanceSquaredTo(from.GlobalTransform.origin); if (shortest > distance) { shortest = distance; ret = point; } } return(ret); }
public RigidBodyPhysicsBridgeInfo(Guid id, Godot.RigidBody rb, bool ownership) { Id = id; RigidBody = rb; Ownership = ownership; lastTimeKeyFramedUpdate = 0.0f; lastValidLinerVelocityOrPos = new Vector3(0.0f, 0.0f, 0.0f); lastValidAngularVelocityorAng = new Vector3(0.0f, 0.0f, 0.0f); numOfConsequentSleepingFrames = 0; IsKeyframed = false; }
internal void Update(GodotRigidBody rigidbody) { Velocity.FromGodotVector3(_sceneRoot.ToLocal(rigidbody.LinearVelocity)); AngularVelocity.FromGodotVector3(_sceneRoot.ToLocal(rigidbody.AngularVelocity)); // No need to read Position or Rotation. They're write-only from the patch to the component. Mass = rigidbody.Mass; DetectCollisions = !rigidbody.GetChild <CollisionShape>()?.Disabled ?? false; CollisionDetectionMode = rigidbody.ContinuousCd switch { true => MRECollisionDetectionMode.Continuous, false => MRECollisionDetectionMode.Discrete }; UseGravity = !Mathf.IsZeroApprox(rigidbody.GravityScale); ConstraintFlags = rigidbody.GetMRERigidBodyConstraints(); }
public static RigidBodyPatch GeneratePatch(MixedRealityExtension.Core.RigidBody _old, Godot.RigidBody _new, Spatial sceneRoot, bool addVelocities) { if (_old == null && _new != null) { return(new RigidBodyPatch(_new, sceneRoot)); } else if (_new == null) { return(null); } var patch = new RigidBodyPatch() { // Do not include Position or Rotation in the patch. // we add velocities only if there is an explicit subscription for it, since it might cause significant bandwidth Velocity = ((addVelocities) ? GeneratePatch(_old.Velocity, sceneRoot.ToLocal(_new.LinearVelocity)) : null), AngularVelocity = ((addVelocities) ? GeneratePatch(_old.AngularVelocity, sceneRoot.ToLocal(_new.AngularVelocity)) : null), CollisionDetectionMode = GeneratePatch( _old.CollisionDetectionMode, _new.ContinuousCd switch { true => MRECollisionDetectionMode.Continuous, false => MRECollisionDetectionMode.Discrete }),