us-east-1

How to limit camera rotation

BlitzMax Forums/OpenGL Module/How to limit camera rotation

Warner(Posted 2011) [#1]
In response to a question:



Arska(Posted 2011) [#2]
What if i need my character entity to point another entity which is positioned to pickedx, pickedy and pickedz (camerapick). With 'pointentity' problem is that it points entity to another in all angles.

Maybe picture explains better:



Warner(Posted 2011) [#3]
So you want pointentity only at one axis? You could copy PointEntity from the engine to your main program, and take out two of the three angles to do that.

In maths, you would need to use atan2 to achieve this. These are 2D maths.
If you have two 2d coordinates, you can calculate the angle from point 1 to point 2 using atan2:

angle# = atan2( y2-y1, x2-x1 ) 'gives angle between (x1,y1) and (x2,z2)

The 3d scene could be seen as a 2d world lying down. Then, the y-coordinate is not important, and you only take x and z in account:

angle# = atan2( z2-z1, x2-x1 )

Here is a working sample:



Arska(Posted 2011) [#4]
Thanks! Now my program is working.