GDB Adventures
This commit is contained in:
74
src/lorenz.c
74
src/lorenz.c
@@ -13,22 +13,30 @@ float pos[3] = {0.0f, 0.0f, 0.0f};
|
|||||||
float rho=28.0;
|
float rho=28.0;
|
||||||
float sigma=10.0;
|
float sigma=10.0;
|
||||||
float beta=8.0/3.0;
|
float beta=8.0/3.0;
|
||||||
|
void lorenzStep(float next[3], vec3 prev, float dt) {
|
||||||
|
float x, y, z, dx, dy, dz;
|
||||||
|
x = prev[0];
|
||||||
|
y = prev[1];
|
||||||
|
z = prev[2];
|
||||||
|
|
||||||
|
dx = (sigma * (y-x))*dt;
|
||||||
|
dy = (x * (rho - z) -y)*dt;
|
||||||
|
dz = (x*y - beta*z)*dt;
|
||||||
|
|
||||||
|
next[0] = prev[0] + dx;
|
||||||
|
next[1] = prev[1] + dy;
|
||||||
|
next[2] = prev[2] + dz;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
window = initOpenGL();
|
window = initOpenGL();
|
||||||
glfwSetKeyCallback(window, &key_pressed);
|
glfwSetKeyCallback(window, &key_pressed);
|
||||||
|
|
||||||
|
|
||||||
// CreateShader
|
// CreateShader
|
||||||
char* vertex = "assets/shaders/vertex.glsl\0";
|
|
||||||
char* fragment = "assets/shaders/fragment.glsl\0";
|
|
||||||
unsigned int shader1;
|
unsigned int shader1;
|
||||||
shader1 = createShader(vertex, fragment);
|
shader1 = createShader("assets/shaders/vertex.glsl\0", "assets/shaders/fragment.glsl\0");
|
||||||
|
|
||||||
int projectionLoc = glGetUniformLocation(shader1, "proj");
|
|
||||||
|
|
||||||
// Initialise VBO and VAO
|
// Initialise VBO and VAO
|
||||||
unsigned int VAO, VBO;
|
unsigned int VAO, VBO;
|
||||||
@@ -37,50 +45,42 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vec3), NULL, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, 3000* sizeof(vec3), NULL, GL_STREAM_DRAW);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
vec3 vertices[3000];
|
|
||||||
int i=0;
|
|
||||||
float dx, dy, dz, dt=0.001;
|
|
||||||
vertices[0][0]=0.01;
|
|
||||||
vertices[0][1]=0.01;
|
|
||||||
vertices[0][2]=0.01;
|
|
||||||
|
|
||||||
|
|
||||||
|
// Projection Matrix
|
||||||
mat4x4 proj;
|
mat4x4 proj;
|
||||||
|
mat4x4_identity(proj);
|
||||||
mat4x4_ortho(proj, 0.0, 400.0, 0.0, 400.0, 0.1, 100.0);
|
mat4x4_ortho(proj, 0.0, 400.0, 0.0, 400.0, 0.1, 100.0);
|
||||||
|
|
||||||
|
// Uniform Projection Matrix
|
||||||
|
glUseProgram(shader1);
|
||||||
|
int projectionLoc = glGetUniformLocation(shader1, "proj");
|
||||||
|
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, *proj);
|
||||||
|
|
||||||
|
vec3* lorenzPoints = malloc(3000 * sizeof(vec3));
|
||||||
|
memset(lorenzPoints, 0, 3000 * sizeof(vec3));
|
||||||
|
vec3 initial = {0.1f, 0.1f, 0.1f};
|
||||||
|
memcpy(lorenzPoints, initial, sizeof(vec3));
|
||||||
|
|
||||||
|
int i=1;
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(shader1);
|
glUseProgram(shader1);
|
||||||
|
|
||||||
|
float increment = 0.1* (float)i;
|
||||||
|
float next[3] = {increment, increment, increment};
|
||||||
|
//lorenzStep(next, lorenzPoints[i], 0.01f);
|
||||||
|
memcpy(lorenzPoints[i++], next, sizeof(vec3));
|
||||||
|
|
||||||
//glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, *proj);
|
|
||||||
|
|
||||||
if(i<3000) {
|
float* buff = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||||
float x, y, z;
|
memcpy(buff, lorenzPoints, i * sizeof(vec3));
|
||||||
x = vertices[i][0];
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||||
y = vertices[i][1];
|
|
||||||
z = vertices[i][2];
|
|
||||||
|
|
||||||
printf("%i %f %f %f\n", i, x, y, z);
|
|
||||||
|
|
||||||
dx = (sigma * (y-x))*dt;
|
glDrawArrays(GL_LINE_STRIP, 0, i);
|
||||||
dy = (x * (rho - z) -y)*dt;
|
|
||||||
dz = (x*y - beta*z)*dt;
|
|
||||||
|
|
||||||
i++;
|
|
||||||
vertices[i][0] = x+dx;
|
|
||||||
vertices[i][1] = y+dy;
|
|
||||||
vertices[i][2] = z+dz;
|
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3), vertices[i]);
|
|
||||||
}
|
|
||||||
glDrawArrays(GL_POINTS, 0, 1);
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
processInput();
|
processInput();
|
||||||
|
|||||||
Reference in New Issue
Block a user