private void Timer_Elapsed(object sender, ElapsedEventArgs e) { offsetXByTime += 0.05f; int boxNumber = 0; for (float curX = fromX; curX < toX; curX += stepX) { int curXOffset = boxNumber / FunctionZWidth * functionDensity; for (int z = 0; z < FunctionZWidth; ++z) { RigidBody body = functionBoxes[boxNumber]; if (body == null) { continue; } Vector3 boxPos = new Vector3(curX + curXOffset, (float)Math.Sin(functionPeriod * (curX + offsetXByTime)) * functionAmplitude + functionOffsetY, z + z * 3); lock (body) { body.Activate(); body.ProceedToTransform(Matrix4.CreateTranslation(boxPos)); } boxNumber++; } } }
static void Main(string[] args) { { var world = new DiscreteDynamicsWorld(); world.Gravity = new Vector3(0.0f, -10.0f, 0.0f); var info0 = new RigidBodyConstructionInfo(); info0.Mass = 1.0f; info0.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One); info0.CenterOfMass = Vector3.Zero; var rb0 = new RigidBody(info0, OnGetTransform0, OnSetTransform0); var info1 = new RigidBodyConstructionInfo(); info1.Mass = 0.0f; info1.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One); info1.CenterOfMass = Vector3.Zero; var rb1 = new RigidBody(info1, OnGetTransform1, OnSetTransform1); world.AddRigidBody(rb0); world.AddRigidBody(rb1); for (int i = 0; i < 100; i++) { rb0.Activate(); world.StepSimulation(1.0f / 60.0f); } world.RemoveRigidBody(rb0); world.RemoveRigidBody(rb1); } GC.Collect(); GC.WaitForPendingFinalizers(); }
protected void ApplyCentralForce(Vector3 force) { rigidBody.ApplyCentralForce(force); rigidBody.Activate(); logger.Debug("{0} applied central force {1}", this, force); }
public void PhysicsPreStep(float timeStep) { float newSteering = 0.0f; float accelerator = 0.0f; // Read controls if (Controls.IsDown(CtrlLeft)) { newSteering = -1.0f; } if (Controls.IsDown(CtrlRight)) { newSteering = 1.0f; } if (Controls.IsDown(CtrlForward)) { accelerator = 1.0f; } if (Controls.IsDown(CtrlBack)) { accelerator = -0.5f; } // When steering, wake up the wheel rigidbodies so that their orientation is updated if (newSteering != 0.0f) { frontLeftBody.Activate(); frontRightBody.Activate(); steering = steering * 0.95f + newSteering * 0.05f; } else { steering = steering * 0.8f + newSteering * 0.2f; } // Set front wheel angles Quaternion steeringRot = new Quaternion(0, steering * MaxWheelAngle, 0); frontLeftAxis.SetOtherAxis(steeringRot * new Vector3(-1f, 0f, 0f)); frontRightAxis.SetOtherAxis(steeringRot * Vector3.UnitX); Quaternion hullRot = hullBody.Rotation; if (accelerator != 0.0f) { // Torques are applied in world space, so need to take the vehicle & wheel rotation into account Vector3 torqueVec = new Vector3(EnginePower * accelerator, 0.0f, 0.0f); frontLeftBody.ApplyTorque(hullRot * steeringRot * torqueVec); frontRightBody.ApplyTorque(hullRot * steeringRot * torqueVec); rearLeftBody.ApplyTorque(hullRot * torqueVec); rearRightBody.ApplyTorque(hullRot * torqueVec); } // Apply downforce proportional to velocity Vector3 localVelocity = Quaternion.Invert(hullRot) * hullBody.LinearVelocity; hullBody.ApplyForce(hullRot * new Vector3(0f, -1f, 0f) * Math.Abs(localVelocity.Z) * DownForce); }
public void AddTorque(Vector3 torque) { if (torque.LengthSquared > float.Epsilon) { RigidBody.Activate(true); RigidBody.ApplyTorque(torque.Cast()); } }
public void AddForce(Vector3 force) { if (force.LengthSquared > float.Epsilon) { RigidBody.Activate(true); RigidBody.ApplyForce(force.Cast(), BM.Vector3.Zero); } }
public void Evaluate(int SpreadMax) { for (int i = 0; i < SpreadMax; i++) { RigidBody rb = this.FInput[i]; if (rb != null && this.FActivate[i]) { rb.Activate(); } } }
// This static method is useful for the demo only. It's called by "void GhostObjectsDemo::clientMoveAndDisplay()". // Basically we must find a way to "display" the objects inside ghost objects to the user. // We choose to apply a vertical impulse to them (just because it's easier). // (The strength of the impulse is different depending on the type of ghost object) static void ProcessObectsInsideGhostObjects(ObjectArray <CollisionObject> objs, bool isPairCachingGhostObject) { foreach (CollisionObject co in objs) { RigidBody b = RigidBody.Upcast(co); if (b != null) { b.Activate(); IndexedVector3 impulse = isPairCachingGhostObject ? new IndexedVector3(0, 0.5f, 0) : new IndexedVector3(0, 0.25f, 0); b.ApplyCentralImpulse(ref impulse); } } }
private void SimpleMessage_Start(object sender, EventArgs e) { //switch to dynamic and awake the rigid body rigidBody.Type = RigidBodyTypes.Dynamic; rigidBody.Activate(true); //need to awake to object }
/// <summary> /// Updates the positions and rotations of each tracker's parent object according to the replay time. /// </summary> public override void Update() { if (dynamicCamera == null) { dynamicCamera = UnityEngine.Object.FindObjectOfType <DynamicCamera>(); camera = dynamicCamera.GetComponent <Camera>(); } if (InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)) { dynamicCamera.ToggleCameraState(dynamicCamera.cameraState); } if (firstFrame) { firstFrame = false; } else if (Input.GetKeyDown(KeyCode.Space)) { if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { rewindTime = Tracker.Lifetime; playbackMode = PlaybackMode.Play; } else { switch (playbackMode) { case PlaybackMode.Paused: if (rewindTime == 0f) { rewindTime = Tracker.Lifetime; } playbackMode = PlaybackMode.Play; break; case PlaybackMode.Play: case PlaybackMode.Rewind: playbackMode = PlaybackMode.Paused; break; } } } switch (playbackMode) { case PlaybackMode.Rewind: rewindTime += Time.smoothDeltaTime * playbackSpeed; break; case PlaybackMode.Play: rewindTime -= Time.smoothDeltaTime * playbackSpeed; break; } if (Input.GetKey(KeyCode.LeftArrow)) { rewindTime += Time.smoothDeltaTime * 0.25f; playbackMode = PlaybackMode.Paused; } if (Input.GetKey(KeyCode.RightArrow)) { rewindTime -= Time.smoothDeltaTime * 0.25f; playbackMode = PlaybackMode.Paused; } if (rewindTime < 0.0f) { rewindTime = 0.0f; playbackMode = PlaybackMode.Paused; } else if (rewindTime > Tracker.Lifetime) { rewindTime = Tracker.Lifetime; playbackMode = PlaybackMode.Paused; } foreach (Tracker t in trackers) { float replayTime = RewindFrame; int currentIndex = (int)Math.Floor(replayTime); StateDescriptor lowerState = t.States[currentIndex]; StateDescriptor upperState = currentIndex < t.States.Length - 1 ? t.States[currentIndex + 1] : lowerState; float percent = replayTime - currentIndex; RigidBody r = (RigidBody)t.GetComponent <BRigidBody>().GetCollisionObject(); if (!r.IsActive) { r.Activate(); } BulletSharp.Math.Matrix worldTransform = r.WorldTransform; worldTransform.Origin = BulletSharp.Math.Vector3.Lerp(lowerState.Position, upperState.Position, percent); worldTransform.Basis = BulletSharp.Math.Matrix.Lerp(lowerState.Rotation, upperState.Rotation, percent); r.WorldTransform = worldTransform; } if (Input.GetKeyDown(KeyCode.Tab)) { StateMachine.Instance.PopState(); } }