Cube rotation DX10

Posted by German on Game Development See other posts from Game Development or by German
Published on 2012-11-30T16:18:54Z Indexed on 2012/11/30 17:21 UTC
Read the original article Hit count: 216

Filed under:
|
|

Well I'm reading the Frank's Luna DirectX10 book and, while I'm trying to understand the first demo, I found something that's not very clear at least for me. In the updateScene method, when I press A, S, W or D, the angles mTheta and mPhi change, but after that, there are three lines of code that I don't understand exactly what they do:

// Convert Spherical to Cartesian coordinates: mPhi measured from +y
// and mTheta measured counterclockwise from -z.
float x = 5.0f*sinf(mPhi)*sinf(mTheta);
float z = -5.0f*sinf(mPhi)*cosf(mTheta);
float y = 5.0f*cosf(mPhi);

I mean, this explains that they do, it says that it converts the spherical coordinates to cartesian coordinates, but, mathematically, why? why the x value is calculated by the product of the sins of both angles? And the z by the product of the sine and cosine? and why the y just uses the cosine? After that, those values (x, y and z) are used to build the view matrix.

The book doesn't explain (mathematically) why those values are calculated like that (and I didn't find anything to help me to understand it at the first Part of the book: "Mathematical prerequisites"), so it would be good if someone could explain me what exactly happen in those code lines or just give me a link that helps me to understand the math part.

Thanks in advance!

© Game Development or respective owner

Related posts about c++

Related posts about math