Sign in to follow this  

Sine and Cosine - How to apply and understand it. Erm, heightmaps too. :-)

This topic is 4338 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

...I might seem to be a total idiot in OpenGL programming not being to even undertsand Sine and Cosine and how to apply it....because I am a noob, the sad truth. Can some one help? I mean, how does it make things rotate? That bewilders me. So how about it? Can I get a tutorial or an example? Nothing complecated like saphisticated mathematical formulas and theories, okay?A tutorial would be helpful though. #2. Heightmaps, how the heck do they work? @_@ Why use a greyscale? This all confuses me and makes me wonder why they are even needed in a landscape program. Thank yu all, and while your at it, check my sig to completely process my compacities with being a total newb in OpenGL.

Share this post


Link to post
Share on other sites
Quote:
Original post by Axesor
#2.
Heightmaps, how the heck do they work? @_@
Why use a greyscale?

This all confuses me and makes me wonder why they are even needed in a landscape program.


First a heightmap gives the height in a landscape.
Imagine a even grid with coordinates spread evenly along the x and z axis, a heightmap determines the position of the y axis of those coordinates.

You don't have to use a grayscale map, but it's better, because it takes up only a third of the memory required, and you could more easily use 16 bit rather than the standard of 8 bit.
it is possible to add displacement on the other axis also, but it's not advisable on the first try.

Regarding sine and cosine, they arn't directly used to rotate things, they are however used to create a rotation matrix, thats linear algebra (or matrix math) and it's a bit hard to explain.
so try these links.
http://www.math.miami.edu/~ec/book/
http://www.gamedev.net/reference/articles/article877.asp
http://www.gamedev.net/reference/list.asp?categoryid=28
hope this will help you

Share this post


Link to post
Share on other sites
Ok, mathematics is not my area so I will point you in the direction of the Maths and Physics Forum FAQ, as well as the first two links from a Google search for "sine cosine" which both look good: first link and second link.

As to heightmaps, they work by taking the colour value of a pixel in an image and using that value to represent a height on a mesh of triangles. The reason that grayscale is used is because it is easier to visualize the colours as height values: the blacker the pixel the lower the height and conversely the whiter the pixel the heigher the height. For example, if you had an image which was all black then you would have a flat mesh of triangles; if you had one pixel in the middle of the image which was white then this would look like a sharp 'spike' in the mesh:

=


=


Now if you fill in different shades of gray you can approximate hills (whiter areas) and valleys (blacker areas) as you have probably seen in other heightmaps:

=


The only other reason for using grayscale images other than the one I mentioned before is by nature of how they store their colours they occupy less disk space than a full colour image. It is perfectly legal and proper to use full colour images and use a modified height algorithm (how you convert a colour to a height) instead. For example, adding all three full colour components together (red, green and blue) to give yourself a greater range of values, 768 (256 * 3) as opposed to the 256 offered by a grayscale image. You could even scale each colour component differently if you so wished, although why anyone would want to is beyond me. I know this from experience [embarrass]:

=


Anyway, sorry for the mini-essay but I hope that helped [smile].

Edit: Curses, beaten to it [grin].

Share this post


Link to post
Share on other sites
Quote:
Original post by Axesor
...I might seem to be a total idiot in OpenGL programming not being to even undertsand Sine and Cosine and how to apply it....because I am a noob, the sad truth. Can some one help? I mean, how does it make things rotate? That bewilders me. So how about it? Can I get a tutorial or an example? Nothing complecated like saphisticated mathematical formulas and theories, okay?A tutorial would be helpful though.

A simple experience for understanding the sin and cos functions requires a piece of paper and a pencil.
Draw a unit circle, then choose a point on the circle.
This point will have an angle. Put the angle in a calculator and get sin/cos (take care some calcs use radians while others use degrees).
If you did it correctly you'll notice than sin=y and cos=x.
Get a 90° angle (such as from the paper's corner) and graphically rotate the point.
Get angle and sin/cos again... can you see the relationships?

Try again with different angles and radii. Another interesting thing is to try out (0,1) with various angles...

This is the real basics. The math involved from that is slightly more complicated but that's the idea behind it.
Is it complicated? Not really, but if you still think it is, you'll be glad in knowing most of the time it everything boils down to calling Rotate ;)

Share this post


Link to post
Share on other sites
Here's an explanation of the sine and cosine:

Lets say we have a triangle. *Tries to make one Ascii style* (EDIT: My beautiful triangle got spoiled :-(, the triangle has one corner with 90* and side A is the hypotenuse)

If you know the angle and one of the sides, which you of course wants to you has to use sine, cosine, or tangent, that is trigonometry by the way.

The cosine of an angle equals the side closest to it divided by the hypotenuse.
In this triangle at angle a: cos(a) = side C / side A

The sine of an angle equals the side opposite to it divided by the hypotenuse.
In this triangle at angle a: sin(a) = side B / side A

The tangent of an angle equals the side opposite to it divided by the side closest to it.
In this triangle at angle a: tan(a) = side B / side C


So this has nothing to do with OpenGL programming really, its pure math.

The Wazaa

Share this post


Link to post
Share on other sites

This topic is 4338 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this