Hello World

master
exsersewo 7 years ago
commit 233dceb002
  1. 1
      .gitignore
  2. 25
      CMakeLists.txt
  3. 1
      README.md
  4. 30
      build-vs2015.bat
  5. 30
      build-vs2017.bat
  6. 15
      conanfile.txt
  7. 179
      src/main.cpp

1
.gitignore vendored

@ -0,0 +1 @@
[Bb]in/

@ -0,0 +1,25 @@
#Set the project name
project(LorenzAttractor)
#Set the CMake version
cmake_minimum_required(VERSION 3.0)
#Use Conan
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
#Import all source files
file(GLOB src_files "src/*.c" "src/*.cpp" )
#Make a project, link in libraries from conan
ADD_EXECUTABLE(LorenzAttractor ${src_files})
TARGET_LINK_LIBRARIES(LorenzAttractor ${CONAN_LIBS})
#Set the C++ version
set (CMAKE_CXX_STANDARD 11)
#Set the project for VS to use.
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT "LorenzAttractor")
#Perform prebuild
add_custom_command(TARGET LorenzAttractor PRE_BUILD COMMAND "pre_build_Script.bat")

@ -0,0 +1 @@
# Lorenz Attractor

@ -0,0 +1,30 @@
@echo off
:start
if exist src goto changetobin
if exist .\CMakeLists.txt xcopy /q /i /e /y .\CMakeLists.txt .\bin\CMakeLists.txt
if exist .\conanfile.txt xcopy /q /i /e /y .\conanfile.txt .\bin\conanfile.txt
:conan
conan install --build missing
goto cmake
:cmake
cmake .. -G "Visual Studio 14 2015 Win64"
goto end
:changetobin
cd bin
goto start
:end
if exist bin goto quit
cd ..
goto quit
:quit
echo.
echo.
echo INFO: Conan and CMake ran successfully. Open up your solution file (listed below) to open your project.
echo.
dir /b *.sln

@ -0,0 +1,30 @@
@echo off
:start
if exist src goto changetobin
if exist .\CMakeLists.txt xcopy /q /i /e /y .\CMakeLists.txt .\bin\CMakeLists.txt
if exist .\conanfile.txt xcopy /q /i /e /y .\conanfile.txt .\bin\conanfile.txt
:conan
conan install --build missing
goto cmake
:cmake
cmake .. -G "Visual Studio 15 2017 Win64"
goto end
:changetobin
cd bin
goto start
:end
if exist bin goto quit
cd ..
goto quit
:quit
echo.
echo.
echo INFO: Conan and CMake ran successfully. Open up your solution file (listed below) to open your project.
echo.
dir /b *.sln

@ -0,0 +1,15 @@
[requires]
SDL2/2.0.5@dotfloat/stable
glew/2.0.0@coding3d/stable
glm/0.9.7.6@dlarudgus20/stable
[options]
SDL2:shared=True
glew:shared=False
[generators]
cmake
[imports]
bin, *.dll -> ./bin # Copies all dll files from packages bin folder to my "bin" folder
lib, *.dylib* -> ./bin # Copies all dylib files from packages lib folder to my "bin" folder

@ -0,0 +1,179 @@
#pragma once
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <ctime>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <stdexcept>
#include <map>
//GLEW
#include <GL/glew.h>
#include "windows.h"
//OGL Maths
#define GLM_FORCE_RADIANS // use radians
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "SDL.h"
#undef main
SDL_Window* win;
SDL_GLContext context;
GLenum glew;
std::vector<glm::vec3> points;
std::vector<glm::vec4> colors;
//constants
const float sigma = 10;
const float beta = 8.0 / 3.0;
const float rho = 28;
const float dt = 0.02;
bool run = true;
SDL_DisplayMode DM;
float x, y, z;
float r = 0, g = 0, b = 0;
bool rotate = false;
int init()
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
printf("%s\n", SDL_GetError());
system("pause");
return 1;
}
SDL_GetDesktopDisplayMode(0, &DM);
win = SDL_CreateWindow("Lorenz Attractor", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, DM.w/2, DM.h/2, SDL_WINDOW_OPENGL);
if (win == nullptr)
{
printf("%s\n", SDL_GetError());
system("pause");
return 1;
}
glew = glewInit();
context = SDL_GL_CreateContext(win);
points.push_back({ 1.0, 1.0, 1.0 });
float scalesize = 0.015;
glScalef(scalesize,scalesize,scalesize);
//glPointSize(2.5);
return 0;
}
float amount = 0.01;
glm::vec3 getCol()
{
r += amount;
if (r > 1)
{
r = 1;
g += amount;
if (g > 1)
{
g = 0;
b += amount;
if (b > 1)
{
r = 0;
g = 0;
b = 0;
}
}
}
return { r, g, b };
}
void process()
{
SDL_Event evnt;
if (SDL_PollEvent(&evnt))
{
if (evnt.type == SDL_QUIT)
{
run = false;
}
if (evnt.type == SDL_KEYDOWN)
{
if (evnt.key.keysym.sym == SDLK_SPACE)
{
if (rotate)
rotate = false;
else
rotate = true;
}
}
}
}
void update()
{
glm::vec3 point = points.back();
float dx = (sigma * (point.y - point.x)) * dt;
float dy = (point.x * (rho - point.z) - point.y) * dt;
float dz = (point.x * point.y - beta * point.z) * dt;
x = x + dx;
y = y + dy;
z = z + dz;
glm::vec3 col = getCol();
points.push_back(glm::vec3(x,y,z));
colors.push_back(glm::vec4(col, 1));
printf("x: %f , y: %f, z: %f , r: %f , g: %f , b: %f", x, y, z, col.x, col.y, col.z);
printf("\n");
}
void draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &points[0]);
glColorPointer(4, GL_FLOAT, 0, &colors[0]);
glDrawArrays(GL_LINE_LOOP, 0, points.capacity());
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
if(rotate)
glRotatef(1, 0, 1, 0);
SDL_GL_SwapWindow(win);
}
int main()
{
if (init() != 0)
return 1;
while (run)
{
process();
update();
draw();
}
SDL_GL_DeleteContext(context);
SDL_Quit();
return 0;
}
Loading…
Cancel
Save