/// <summary> /// We've been sent some steering control data because we are the ROOT cell of /// an organism that is currently the camera ship. /// </summary> /// <param name="tiller">the joystick/keyboard data relevent to steering camera ships</param> /// <param name="elapsedTime">elapsed time this frame, in case motion/animation needs to be proportional</param> public override void Steer(TillerData tiller, float elapsedTime) { // pan and tilt change at a speed determined by joystick position pan -= tiller.Joystick.X * elapsedTime * 0.1f; if (pan < 0) pan = 0; else if (pan > 1) pan = 1; tilt -= tiller.Joystick.Y * elapsedTime * 0.1f; if (tilt < 0) tilt = 0; else if (tilt > 1) tilt = 1; //owner.ConsoleMessage("pan rate:"+tiller.Joystick.X); }
/// <summary> /// We've been sent some steering control data because we are the ROOT cell of /// an organism that is currently the camera ship. /// </summary> /// <param name="tiller">the joystick/keyboard data relavent to steering camera ships</param> /// <param name="elapsedTime">elapsed time this frame, in case motion/animation needs to be proportional</param> public override void Steer(TillerData tiller, float elapsedTime) { // Clamp pan and tilt change at a speed determined by joystick position pan += tiller.Joystick.Y * elapsedTime * 0.3f; if (pan < 0) pan = 0; else if (pan > 1) pan = 1; tilt += tiller.Joystick.X * elapsedTime * 0.3f; if (tilt < 0) tilt = 0; else if (tilt > 1) tilt = 1; }
/// <summary> /// We are acting as the camera mount and therefore have been sent steering and thrust data /// so that the user can control our position. If we're just hosting a creatures-eye-view /// then we aren't steerable (although the camera itself might plausibly be). But if we're a /// legitimate camera ship then we must respond to the controls. /// Send the control data to our ROOT cell's physiology. NOTE: this is probably NOT the cell /// on which the camera is actually mounted, but it makes sense for the steering data to go /// to the root, which can pass signals on to its other cells via nerves as appropriate. /// </summary> /// <param name="tiller"></param> public void Steer(TillerData tiller) { if (cameraMount!=null) rootCell.Physiology.Steer(tiller, Scene.ElapsedTime); // send the command to the ROOT cell }
/// <summary> /// Pass user control inputs to the current camera ship. /// The command ripples through to the correct cell and from there to the cell's physiology, /// where it is responded to /// </summary> /// <param name="tiller">Navigational commands</param> public static void SteerShip(TillerData tiller) { cameraShip[currentShip].Steer(tiller); }
/// <summary> /// We've been sent some steering control data because we are the ROOT cell of /// an organism that is currently the camera ship. /// </summary> /// <param name="tiller">the joystick/keyboard data relevant to steering camera ships</param> /// <param name="elapsedTime">elapsed time this frame, in case motion/animation needs to be proportional</param> public override void Steer(TillerData tiller, float elapsedTime) { // in panel 1, the joystick controls the pilot's head (camera), to look around the scene from the observation bubble if (owner.CurrentPanel() == 1) { pan -= tiller.Joystick.Y * elapsedTime * 0.3f; if (pan < 0) pan = 0; else if (pan > 1) pan = 1; tilt -= tiller.Joystick.X * elapsedTime * 0.3f; if (tilt < 0) tilt = 0; else if (tilt > 1) tilt = 1; } // In panel 0, the joystick controls the thrusters else { // Convert the joystick xy into four steering thrust values for right, left, top, bottom fans bot = tiller.Joystick.Y * 0.25f; top = -bot; left = tiller.Joystick.X * 0.25f; right = -left; // add main thrust equally to all (NOTE: total of steering + thrust must be in range +/-1 at this point) float thrust = tiller.Thrust * 0.5f; top += thrust; bot += thrust; left += thrust; right += thrust; // supply a bit of the left/right thrust to the downward facing jets to add some roll to the turn leftDown = tiller.Joystick.X * 0.15f; rightDown = -leftDown; // pump the thrust values into the nervous system (as unsigned values, where 0.5 is neutral) Output(2, left / 2f + 0.5f); Output(1, right / 2f + 0.5f); Output(4, bot / 2f + 0.5f); Output(3, top / 2f + 0.5f); Output(6, leftDown / 2f + 0.5f); Output(5, rightDown / 2f + 0.5f); } }
/// <summary> /// We've been sent some steering control data because we are the ROOT cell of /// an organism that is currently the camera ship. /// Overload this method if you are a camera ship and move/steer accordingly. /// The default is to ignore this data - we may have been sent it because we are /// acting as a creatures-eye-view, and proper creatures can't be steered by the user. /// </summary> /// <param name="tiller">the joystick/keyboard data relavent to steering camera ships</param> /// <param name="elapsedTime">elapsed time this frame, in case motion/animation needs to be proportional</param> public virtual void Steer(TillerData tiller, float elapsedTime) { }
private static void ProcessInput() { // Assemble camera control commands and send them to the current camera ship TillerData tiller = new TillerData(); tiller.Joystick = ReadJoystick(); // reads joystick, or mouse/kbd emulation if (leftButton) // if left mouse btn down, full thrust tiller.Thrust = 1.0f; else if ((joystick!=null)&& (joystickState.GetButtons())[joyThrust]!=0) // or if main joystick button, full thrust tiller.Thrust = 1.0f; CameraShip.SteerShip(tiller); // send data to the current camera ship }