I use the below method to get the position of where each game object should be rendered relative to the camera position (posX and posY).
Code: Select all
void CCamera::mapWorldToScreen(COutput & output, float worldX, float worldY, float* screenX, float* screenY)
{
*screenX = (worldX-posX)*zoom+output.getScreenX()/2;
*screenY = (worldY-posY)*zoom+output.getScreenY()/2;
}
Also note that the image rotation is done separately. It's the position on screen which which I want to map.
I am just not sure how to add this. If anyone could help me out, that would be great.
***EDIT***
Ok so I worked out the math (I think?) for the rotation transformation...
Find the distance to the current position:
hyp = sqrt(posX^2+posY^2)
Then get the new posX and posY like:
posX = cos(newAngle)*hyp
posY = sin(newAngle)*hyp
But I still don't know how to use this to map on to the screen?
***EDIT***
Finally after several hours of fucking around I finally managed to get a result, however the zoom scales disproportionately and i'm still not sure?
Code: Select all
void CCamera::mapWorldToScreen(COutput & output, float worldX, float worldY, float* screenX, float* screenY)
{
static float degToRad = 57.29577;
float sinAng = sin(rotation/degToRad);
float cosAng = cos(rotation/degToRad);
float thisX = worldX-posX;
float thisY = worldY-posY;
*screenX = (thisX * cosAng - thisY * sinAng)*zoom + output.getScreenX()/2;
*screenY = (thisX * sinAng + thisY * cosAng)*zoom + output.getScreenY()/2;
}