public static void rotateMotor(int rotationByteCode) { //calulate the number of millis it will take to rotate to specific angle int totalRotationAngle = mappedAngleRotation(rotationByteCode); stepCountRequired = (int)(totalRotationAngle / motorStepAngle); stepDifference = stepCountRequired - currentStep; currentStep += stepDifference; Debug.Log(stepDifference); //Debug.Log (totalRotationAngle); int totalMillisTime = Mathf.Abs(stepDifference) * singleStepTime; //start motor rotation //Debug.Log (rotationByteCode); sp.Write(new byte[] { (byte)rotationByteCode }, 0, 1); if (stepDifference != 0) { //set a time for the above millis with a callback that sets the angle of model to specified displacement ModelRotation.rotateModel(totalRotationAngle, totalMillisTime); } //startModel rotation immidiately, preferably by coroutine //mr.startModelRotation (totalRotationAngle, totalMillisTime); }
public Player(ContentManager cm, string modelName) { contentManager = cm; PlayerID = Globals.ThisPlayerID; AnimatedModels = new Dictionary <int, AnimatedModel>(); ModelName = modelName; Globals.MsgDispatcher.SendMessage(Message.MessageType.PlayerPosition.ToString() + ":" + ModelPosition.X.ToString() + ";" + ModelPosition.Y.ToString() + ";" + ModelPosition.Z.ToString() + ";." + Message.MessageType.PlayerRotation.ToString() + ":" + ModelRotation.ToString() + ";." + Message.MessageType.PlayerVelocity.ToString() + ":" + ModelVelocity.X.ToString() + ";" + ModelVelocity.Y.ToString() + ";" + ModelVelocity.Z.ToString() + ";." + Message.MessageType.NPC.ToString() + ":" + modelName + ";."); Globals.MsgReceiver.AskForReceive(ProcessLoadPlayerMessage); }
internal void Update(GameTime gameTime, Camera camera, Viewport viewport) { KeyboardState ks = Keyboard.GetState(); if (AnimatedModels.Keys.Contains(ShowAction)) { AnimatedModels[ShowAction].Update(gameTime); } Vector3 modelVelocityAdd = Vector3.Zero; bool modelChanged = false; if (ks.IsKeyDown(Keys.A)) { ModelRotation += 1 * 0.025f; modelChanged = true; } else if (ks.IsKeyDown(Keys.D)) { ModelRotation -= 1 * 0.025f; modelChanged = true; } if (ks.IsKeyDown(Keys.W)) { modelVelocityAdd.X = (float)Math.Sin(ModelRotation); modelVelocityAdd.Z = (float)Math.Cos(ModelRotation); modelVelocityAdd *= 2; ModelPosition += modelVelocityAdd; modelChanged = true; } if (ks.IsKeyDown(Keys.Escape)) { ModelPosition = Vector3.Zero; ModelVelocity = Vector3.Zero; ModelRotation = 0.0f; modelChanged = true; } MouseState ms = Mouse.GetState(); if (ms.LeftButton == ButtonState.Pressed) { leftMouseButtonDown = true; } if (leftMouseButtonDown && ms.LeftButton == ButtonState.Released) { leftMouseButtonDown = false; Vector3 nearPoint = new Vector3(ms.X, ms.Y, 0); Vector3 farPoint = new Vector3(ms.X, ms.Y, 1); nearPoint = viewport.Unproject(nearPoint, camera.Projection, camera.View, Matrix.Identity); farPoint = viewport.Unproject(farPoint, camera.Projection, camera.View, Matrix.Identity); Vector3 direction = farPoint - nearPoint; direction.Normalize(); Ray ray = new Ray(nearPoint, direction); if (ray.Intersects(new BoundingBox(ModelPosition, new Vector3(ModelPosition.X + 50, ModelPosition.Y + 200, ModelPosition.Z + 100))) > 0) { if (showNPCNamePlate) { showNPCNamePlate = false; } else { showNPCNamePlate = true; } } } Vector3 screenSpace = viewport.Project(Vector3.Zero, camera.Projection, camera.View, Matrix.CreateTranslation(ModelPosition)); textPosition.X = screenSpace.X; textPosition.Y = screenSpace.Y; if (modelChanged) { Globals.MsgDispatcher.SendMessage("PlayerPosition:" + ModelPosition.X.ToString() + ";" + ModelPosition.Y.ToString() + ";" + ModelPosition.Z.ToString() + ";.PlayerRotation:" + ModelRotation.ToString() + ";.PlayerVelocity:" + ModelVelocity.X.ToString() + ";" + ModelVelocity.Y.ToString() + ";" + ModelVelocity.Z.ToString() + ";."); } }