Jump to content
  • Advertisement
Sign in to follow this  

Sine wave

This topic is 4865 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

Does anyone know how I could plot a sine wave in OpenGL, I've been trying to mkae it work by glBegin(GL_LINE_STRIP); for (x = 0; x <= 100; x += 10) glVertex2f(x, sin(x)); end glEnd() but I end up with a slightly slanted line

Share this post

Link to post
Share on other sites
The sin function takes its argument in radians, so I'm not sure that a step of 10 radians is what you want there. Why don't you try a smaller step and see if that works?

 for (x = 0; x <= 100; x += 0.1) 

(I'm assuming x is a float or double)

Also, you might need to stick a multiplier in front of the sin(x), as the function will only provide you values between -1 and 1. Then again, depending on how you set up your camera, that might be what you want.

Hopefully that will be of some help!

Share this post

Link to post
Share on other sites
Ok I got it to work already, now I'm trying to wrap that sine wave around a sphere?
How can I do that?

Here's what I'm trying to do

Share this post

Link to post
Share on other sites
You have to go from 2D vertex to 3D vertex, and adapt two of the dimensions.
Something like this wraps a sine curve to a circle:

float phase;
float periods = 5.0f; // how many periods the sine curve shows around the circle
float twoPi = 6.2831853f;
float delta = twoPi/32*periods; // defines in how many steps the sine curve is rendered
float sphereRadius = 5.0f; // is the radius of the circle the sine curve is wrapped around
float magnitude = 3.0f; // is the magnitude of the sine curve
for(phase=0; phase<twoPi; phase += delta) {

EDIT: Other variations, e.g. sloping the sine to the center of the circle, are possible by choosing other combinations of the co-ordinates.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!