BANANAMAN
Resident Star Battle Expert.
- Reaction score
- 150
So I'm trying to create a sin wave that moves in OpenGL and so far I've gotten around 35 line segments to move up and down due to their Y value being determined by continuous computation as the program runs. Thing is how do I make it so that the Y value for each line to increase at different rates such as theta 1 = theta,theta 2 = theta + 10,and so on....until it creates a sin wave.
Is it also possible to build up from this code a simple gravity simulation?
Code:
#include <stdio.h>
#include <conio.h>
#include "GlutStarter.h"
//Add this to use the sine function
#include <math.h>
void Render();
double ConvertToRadian(double DegreeValue);
double t = 0.0; //time or angle for the sine function
int main(int argc, char** argv)
{
StartGlut(&argc, argv, "GL Simulation Environment",
Render, Render, 0,0,0,0,0,0,0,0);
return 0;
}
double ConvertToRadian(double DegreeValue)
{
double pi = 3.14159;
double RadianValue = DegreeValue * (pi/180.0);
return RadianValue;
}
void Render()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//compute the height of the platform
double y = 5 * sin(ConvertToRadian(t)); //t is for time
t++;
if (t>=360.0) t = 0.0;
//Render the platform using:
//Computed value
//Line
glBegin(GL_LINES);
for(int x = -1.0;x < 36;x++)
{
glVertex3d(x, y, 0.0);
}
glEnd();
glutSwapBuffers();
}
Is it also possible to build up from this code a simple gravity simulation?