/// <summary> /// Tries to reset the robot /// </summary> public void ResetRobot() { if (Skeleton == null) { return; } List <BulletRigidNode> Wheels = new List <BulletRigidNode>(); foreach (RigidNode_Base node in Skeleton.ListAllNodes()) { BulletRigidNode bNode = (BulletRigidNode)node; if (bNode.BulletObject == null) { continue; } WheelDriverMeta wheel; if ((wheel = bNode.GetSkeletalJoint()?.cDriver?.GetInfo <WheelDriverMeta>()) != null) { Wheels.Add(bNode); } AuxFunctions.OrientRobot(Wheels, Skeleton.BulletObject); bNode.BulletObject.WorldTransform = Matrix4.CreateTranslation(0, 10, 0); bNode.BulletObject.InterpolationLinearVelocity = Vector3.Zero; bNode.BulletObject.InterpolationAngularVelocity = Vector3.Zero; } }
/// <summary> /// Default Constructor /// </summary> public Physics() { DantzigSolver mlcp = new DantzigSolver(); collisionConf = new SoftBodyRigidBodyCollisionConfiguration(); dispatcher = new CollisionDispatcher(new DefaultCollisionConfiguration()); solver = new DefaultSoftBodySolver(); ConstraintSolver cSolver = new MultiBodyConstraintSolver(); broadphase = new DbvtBroadphase(); World = new SoftRigidDynamicsWorld(dispatcher, broadphase, cSolver, collisionConf, solver); //Actual scaling is unknown, this gravity is probably not right World.Gravity = new Vector3(0, -98.1f, 0); World.SetInternalTickCallback(new DynamicsWorld.InternalTickCallback((w, f) => DriveJoints.UpdateAllMotors(Skeleton, cachedArgs))); //Roobit RigidNode_Base.NODE_FACTORY = (Guid guid) => new BulletRigidNode(guid); string RobotPath = @"C:\Program Files (x86)\Autodesk\Synthesis\Synthesis\Robots\"; string dir = RobotPath; GetFromDirectory(RobotPath, s => { Skeleton = (BulletRigidNode)BXDJSkeleton.ReadSkeleton(s + "skeleton.bxdj"); dir = s; }); List <RigidNode_Base> nodes = Skeleton.ListAllNodes(); for (int i = 0; i < nodes.Count; i++) { BulletRigidNode bNode = (BulletRigidNode)nodes[i]; bNode.CreateRigidBody(dir + bNode.ModelFileName); bNode.CreateJoint(); if (bNode.joint != null) { World.AddConstraint(bNode.joint, true); } World.AddCollisionObject(bNode.BulletObject); collisionShapes.Add(bNode.BulletObject.CollisionShape); } //Field string fieldPath = @"C:\Program Files (x86)\Autodesk\Synthesis\Synthesis\Fields\"; GetFromDirectory(fieldPath, s => f = BulletFieldDefinition.FromFile(s)); foreach (RigidBody b in f.Bodies) { World.AddRigidBody(b); collisionShapes.Add(b.CollisionShape); } }