# How to rotate and move a model in the direction it is facing?

I am not using Unity or XNA. Eventually, I will probably use OpenTK for graphics. But for the concept of a game I'm writing, I am using the console for keyboard input and visual logging of events, etc.

I am also using a WPF window to display world and player data.

Update: I am using 0 deg as North. I understand that this may not be 'standard'. I don't mind switching to the standard where 0 deg is East if necessary.

The standard keys are W, A, D, S and Left/Right arrows.
W: move forward
A: move left
D: move right
S: move backward

L Arrow: rotate left 2.5 (degrees)
R Arrow: rotate right 2.5 (degrees)

I am new to the physics of movement within a 2D space (as if I am looking down from overhead). What I have is a World and Player model; each Player encapsulates an IEntityVector object.

Edit: added the conversion to radians in the following method. Seems to work more correctly as long as the orientation is 0, 90, 180, or 270 degrees.

Move Model:

  public static void MoveEntity (Guid EntityId, Direction Direction) {
var entityVector = default(IEntityVector);
var gameWorld = default(World);

if (entityRealms.TryGetValue(EntityId, out gameWorld)) {
if (gameWorld.entityVectors.TryGetValue(EntityId, out entityVector)) {

switch (Direction) {
case Direction.Forward:

break;
case Direction.Left:

break;
case Direction.Right:

break;
case Direction.Backward:

break;
default:
break;
}
}
}
}


Rotate Model:

  public static void RotateEntity (Guid EntityId, float Heading) {
var entityVector = default(IEntityVector);
var gameWorld = default(World);

if (entityRealms.TryGetValue(EntityId, out gameWorld)) {
if (gameWorld.entityVectors.TryGetValue(EntityId, out entityVector)) {
}
}
}


#1 I am trying to understand the rotation first of all. If Heading is increased or decreased by 2.5 per rt/lf arrow key press, how do I keep the resulting value as a true degree value?

#2 How can I use the Heading degrees as the facing to properly move the entity?

Btw, here are the AddMovement methods:

  public static void AddMovementX (this IEntityVector Vector, float X) {
var newPosition = Vector.Location.X + (X * Vector.Thrust);
Vector.Location = new Vector(newPosition, Vector.Location.Y);
}

public static void AddMovementY (this IEntityVector Vector, float Y) {
var newPosition = Vector.Location.Y + (Y * Vector.Thrust);
Vector.Location = new Vector(Vector.Location.X, newPosition);
}


After quite a headache and a lot of fumbling about, I have finally solved this using the WPF libraries - WindowsBase.dll, PresentationCore.dll - for vectors, rotation, translation, etc. Also some correction to handling facing:

  public static void MoveEntity (Guid EntityId, Direction Direction) {
var entityVector = default(IEntityVector);
var gameWorld = default(World);

if (entityRealms.TryGetValue(EntityId, out gameWorld)) {
if (gameWorld.entityVectors.TryGetValue(EntityId, out entityVector)) {

switch (Direction) {
case Direction.Forward:

break;
case Direction.Backward:

break;
case Direction.Right:

break;
case Direction.Left:

break;
default:
break;
}


Also, removed the methods AddMovementX and AddMovementY.