Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

math question 2

Status
Not open for further replies.

slowATthought

Programmer
Dec 2, 2003
56
US
I am trying to make a camera turn in Direct3D. Because I need to specify what point for the camera to look at, it is prooving difficult. So far, I can calculate the slope of a the line the camera is facing, then change the slope to a new line, and the recalculate the point. However, I want to change the slope by 1 degree, and I don't know how to do this. So, the question is how do take a slope and subtract/add 1 degreee?
 
The slope is defined as Rise/Run which I will represent as 'y/x'. The rotation of a camera would produce as circle with a radius (which is fixed) equal to the distance between the pivot point and the lens of the camera which I will refer to as 'r'. The angle will need to be maintained and I will refer to it as 'a'. Given this the 'y' component can be defined as "r * Sin a" and the 'x' component can be defined as "r * Cos a" which allows the slope to be defined as "(r * Sin a)/(r * Cos a)". If you set a variable that represents the current angle 'a' you can calculate the required slope by the given formula and adding or subtracting 1 from the current angle 'a'.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
You can +/- the tangent of the desired angle to your slope value as the tangent gives the delta y/delta x value. Just remember that vb's trig functions work in radians (I think DX does as well) and you are probably thinking in degrees. To convert radians to degrees multiply by 180/pi.
 
Thank you both very much. Foada, thank you for the formula; I never would have figured that out myself. Thank you jges, I had forgotten that VB was in radians, and that post probably saved me from a lot of debugging :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top