For starters... you want to avoid calling trig functions. They're computationally expensive. You want to call them only when needed.
is a terrible way to square a number.
should be preferred.
You also do not want to do this:
if(theta > 3.1415 * 2) theta = 0;
If you must reduce the numbers (which may not even be necessary... as sin/cos wrap as you'd expect anyway) you should subtract 2*pi, not reset to zero. After all if the user rotates to 3*pi, and you reset to 0, their new direction will be 0 instead of pi like it should be.
Same problem with your other if.
All of that said... this can probably be simplified.
Assuming this works like a normal, modern 3D game (X,Y axis control movement/strafe and Z axis controls which way the user is facing)...
Your angle theta should be calculated based on the direction the player is currently facing. From this angle, you should form a 2x2 rotation matrix used for movement:
However, for your pursposes, you don't need to fully implement a matrix... you can just shortcut it with this formula:
x2 = x*cos(theta) + z*sin(theta)
z2 = -x*sin(theta) + z*cos(theta)
Now since movement is going to occur more frequently than the player reorienting themself, you should keep track of sin(theta) and cos(theta) separately so they do not need to be calucated as much.
// whenever 'theta' changes
sinTheta = sin(theta);
cosTheta = cos(theta);
Now on playermovement, you have everything you need to push the player in the right direction. You simply take their movement vector (your joystick input) and run it through the rotation matrix (previously given):
playerX = /* -1.0 to 1.0 depending on joystick input */;
playerZ = /* -1.0 to 1.0 depending on joystick input */;
pos.x += playerX*cosTheta + playerZ*sinTheta;
pos.z += -playerX*sinTheta + playerZ*cosTheta;
EDIT: fixed they're / their