Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

DirectInput to Torque (c#)

This topic is 5189 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to take some direct input an convert it to torque acting on a rigid body. I''m pretty sure my physics update method is correct, based on other threads I read here:
		public override void UpdatePhysics(float dt)
			Vector3 accel,aAccel;
			Matrix rotation;

			accel = netForce * (1/mass);
			aAccel = Vector3.TransformCoordinate(netTorque, InvInertia);

			currentPosition += currentVelocity * dt + accel * dt*dt*0.5f;

			currentAngularVelocity.Add(aAccel * dt);
			currentAngularVelocity.X = currentAngularVelocity.X < 0 ? Math.Max(currentAngularVelocity.X, -maxRotationalVelocity[0]) : Math.Min(currentAngularVelocity.X, maxRotationalVelocity[0]);
			currentAngularVelocity.Y = currentAngularVelocity.Y < 0 ? Math.Max(currentAngularVelocity.Y, -maxRotationalVelocity[1]) : Math.Min(currentAngularVelocity.Y, maxRotationalVelocity[1]);
			currentAngularVelocity.Z = currentAngularVelocity.Z < 0 ? Math.Max(currentAngularVelocity.Z, -maxRotationalVelocity[2]) : Math.Min(currentAngularVelocity.Z, maxRotationalVelocity[2]);

			currentOrientation += Quaternion.RotationYawPitchRoll(currentAngularVelocity.X * 0.5f * dt, currentAngularVelocity.Y * 0.5f * dt, currentAngularVelocity.Z * 0.5f * dt) * currentOrientation;

			currentVelocity += accel * dt;

			rotation = Matrix.RotationQuaternion(currentOrientation);
			invInertia = rotation * Matrix.Invert(inertiaTensor) * Matrix.Invert(rotation);

			Runtime.Listener.WriteLine(String.Format("Throttle: {9}; Position: {0} {1} {2}; Velocity: {3} {4} {5} km/s; AngularVelocity: {6} {7} {8}", currentPosition.X, currentPosition.Y, currentPosition.Z, currentVelocity.X, currentVelocity.Y, currentVelocity.Z, currentAngularVelocity.X, currentAngularVelocity.Y, currentAngularVelocity.Z, CurrentThrottle), Runtime.Listener.ListenLevel.Screen);

			netTorque = netForce = Vector3.Empty;
To move the ship about a particular axis, first I loop through each engine, which has a function... pitch, roll, forward, etc:
		public void Pitch(int inputState)
			foreach (Engine e in engines)
				if (e.direction == EngineDirection.Pitch)
					float force;
					force  = e.maxThrust * inputState/(float)ActionFormat.AxisMax; // inputState is a number between -ActionFormat.AxisMax and ActionFormat.AxisMax

					netTorque.Add(Vector3.Cross(e.offset, new Vector3(0, force, 0))); // I assume the force vector to pitch the ship is going up / down the y axis

I was always a crappy math/physics student unfortunately... any ideas? =P

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!