world coords into camera local coords
BlitzMax Forums/BlitzMax Beginners Area/world coords into camera local coords
| ||
I've been trying to write some code to convert an objects position from world coordinates into the cameras local coordinates. the camera can rotate around x and y axes. This would then allow me to calculate pan and depth values for a sound coming from said object by just taking the x and z lengths. In pseudo code I have been doing this. newpos = object.pos - camera.pos object.rotatexyz(newpos,-camanglex,-camangley,-camanglez) However this doesn't work. What am I doing wrong? |
| ||
What you need to do is doing matrix operations: lposx = cos(angle)*posx + sin(angle)*posy - camx lposy = -sin(angle)*posx + cos(angle)*posy - camy This should be the correct equation when I'm not totally wrong. The first part is a matrix multiplication of world pos with rotation matrix of the camera and substraction of the cam position repositions the world origin into the one of the camera |
| ||
thats essentially what im doing and it ain't working.. |
| ||
What does your rotate method look like? With 3 dimensional transformations, it is essential to combine the matrices correctly (ie in the correct order) |
| ||
ah I think I have cracked it. By putting my opengl camera rotation instructions in the order z,y,x (they were in xyz before)and my "unrotations" in order x,y,z everything seems to work. Well thats 2 days i'll never see again. I hate these problems where one is basically looking in totally the wrong place for the problem.grrr Thanks Dreamora for your assistance anyway. |