diff --git a/Fields.xcodeproj/project.pbxproj b/Fields.xcodeproj/project.pbxproj index 635a162..9cca835 100644 --- a/Fields.xcodeproj/project.pbxproj +++ b/Fields.xcodeproj/project.pbxproj @@ -7,24 +7,44 @@ objects = { /* Begin PBXBuildFile section */ + 9227913421D266F2009DB236 /* wav.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9227913321D266F2009DB236 /* wav.cpp */; }; 92B75C4021C24AB600DA2DF9 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 92B75C3F21C24AB600DA2DF9 /* main.cpp */; }; + 92B75C4821C2513C00DA2DF9 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92B75C4721C2513C00DA2DF9 /* GLUT.framework */; }; + 92B75C4A21C2514200DA2DF9 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92B75C4921C2514200DA2DF9 /* OpenGL.framework */; }; + 92B75C4D21C2602000DA2DF9 /* graphs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 92B75C4C21C2602000DA2DF9 /* graphs.cpp */; }; + 92B75C5021C2B69100DA2DF9 /* fields.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 92B75C4E21C2B69100DA2DF9 /* fields.cpp */; }; + 92B75C5221C2CCC700DA2DF9 /* libfreetype.6.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 92B75C5121C2CCC700DA2DF9 /* libfreetype.6.dylib */; }; + 92B75C5921C2D21E00DA2DF9 /* libglm_static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 92B75C5821C2D21E00DA2DF9 /* libglm_static.a */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ - 92B75C3A21C24AB600DA2DF9 /* CopyFiles */ = { + 92B75C3A21C24AB600DA2DF9 /* Copy Files */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = /usr/share/man/man1/; dstSubfolderSpec = 0; files = ( ); + name = "Copy Files"; runOnlyForDeploymentPostprocessing = 1; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 9227913221D266DE009DB236 /* wav.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = wav.hpp; sourceTree = ""; }; + 9227913321D266F2009DB236 /* wav.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wav.cpp; sourceTree = ""; }; + 9227913521D269C1009DB236 /* type.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = type.hpp; sourceTree = ""; }; 92B75C3C21C24AB600DA2DF9 /* Fields */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Fields; sourceTree = BUILT_PRODUCTS_DIR; }; 92B75C3F21C24AB600DA2DF9 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 92B75C4721C2513C00DA2DF9 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; }; + 92B75C4921C2514200DA2DF9 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; + 92B75C4B21C2602000DA2DF9 /* graphs.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = graphs.hpp; sourceTree = ""; }; + 92B75C4C21C2602000DA2DF9 /* graphs.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = graphs.cpp; sourceTree = ""; }; + 92B75C4E21C2B69100DA2DF9 /* fields.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = fields.cpp; sourceTree = ""; }; + 92B75C4F21C2B69100DA2DF9 /* fields.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = fields.hpp; sourceTree = ""; }; + 92B75C5121C2CCC700DA2DF9 /* libfreetype.6.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libfreetype.6.dylib; path = ../../../../../usr/local/lib/libfreetype.6.dylib; sourceTree = ""; }; + 92B75C5621C2D1E500DA2DF9 /* libglm_shared.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libglm_shared.dylib; path = ../../../../../usr/local/include/glm/libglm_shared.dylib; sourceTree = ""; }; + 92B75C5821C2D21E00DA2DF9 /* libglm_static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglm_static.a; path = ../../../../../usr/local/include/glm/libglm_static.a; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -32,17 +52,43 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 92B75C5221C2CCC700DA2DF9 /* libfreetype.6.dylib in Frameworks */, + 92B75C4A21C2514200DA2DF9 /* OpenGL.framework in Frameworks */, + 92B75C5921C2D21E00DA2DF9 /* libglm_static.a in Frameworks */, + 92B75C4821C2513C00DA2DF9 /* GLUT.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 9227913021D2660B009DB236 /* unix */ = { + isa = PBXGroup; + children = ( + 92B75C3F21C24AB600DA2DF9 /* main.cpp */, + ); + path = unix; + sourceTree = ""; + }; + 9227913121D26676009DB236 /* include */ = { + isa = PBXGroup; + children = ( + 92B75C4F21C2B69100DA2DF9 /* fields.hpp */, + 92B75C4B21C2602000DA2DF9 /* graphs.hpp */, + 9227913221D266DE009DB236 /* wav.hpp */, + 9227913521D269C1009DB236 /* type.hpp */, + ); + path = include; + sourceTree = ""; + }; 92B75C3321C24AB600DA2DF9 = { isa = PBXGroup; children = ( - 92B75C3E21C24AB600DA2DF9 /* Fields */, + 9227913121D26676009DB236 /* include */, + 9227913021D2660B009DB236 /* unix */, + 92B75C3E21C24AB600DA2DF9 /* src */, 92B75C3D21C24AB600DA2DF9 /* Products */, + 92B75C4621C2513C00DA2DF9 /* Frameworks */, ); sourceTree = ""; }; @@ -54,12 +100,26 @@ name = Products; sourceTree = ""; }; - 92B75C3E21C24AB600DA2DF9 /* Fields */ = { + 92B75C3E21C24AB600DA2DF9 /* src */ = { isa = PBXGroup; children = ( - 92B75C3F21C24AB600DA2DF9 /* main.cpp */, + 9227913321D266F2009DB236 /* wav.cpp */, + 92B75C4E21C2B69100DA2DF9 /* fields.cpp */, + 92B75C4C21C2602000DA2DF9 /* graphs.cpp */, ); - path = Fields; + path = src; + sourceTree = ""; + }; + 92B75C4621C2513C00DA2DF9 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 92B75C5821C2D21E00DA2DF9 /* libglm_static.a */, + 92B75C5621C2D1E500DA2DF9 /* libglm_shared.dylib */, + 92B75C5121C2CCC700DA2DF9 /* libfreetype.6.dylib */, + 92B75C4921C2514200DA2DF9 /* OpenGL.framework */, + 92B75C4721C2513C00DA2DF9 /* GLUT.framework */, + ); + name = Frameworks; sourceTree = ""; }; /* End PBXGroup section */ @@ -71,7 +131,7 @@ buildPhases = ( 92B75C3821C24AB600DA2DF9 /* Sources */, 92B75C3921C24AB600DA2DF9 /* Frameworks */, - 92B75C3A21C24AB600DA2DF9 /* CopyFiles */, + 92B75C3A21C24AB600DA2DF9 /* Copy Files */, ); buildRules = ( ); @@ -118,7 +178,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 92B75C4D21C2602000DA2DF9 /* graphs.cpp in Sources */, 92B75C4021C24AB600DA2DF9 /* main.cpp in Sources */, + 9227913421D266F2009DB236 /* wav.cpp in Sources */, + 92B75C5021C2B69100DA2DF9 /* fields.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -240,6 +303,22 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; + HEADER_SEARCH_PATHS = ( + "/usr/local/include/freetype2/**", + "/usr/local/include/glm/**", + "/usr/local/Cellar/glew/2.1.0/**", + "/usr/local/Cellar/glfw/3.2.1/**", + "\"$(SRCROOT)/include\"", + ); + LIBRARY_SEARCH_PATHS = ( + /usr/local/lib, + /usr/local/include/glm, + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-Wno-deprecated-declarations", + "-v", + ); PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -248,6 +327,22 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; + HEADER_SEARCH_PATHS = ( + "/usr/local/include/freetype2/**", + "/usr/local/include/glm/**", + "/usr/local/Cellar/glew/2.1.0/**", + "/usr/local/Cellar/glfw/3.2.1/**", + "\"$(SRCROOT)/include\"", + ); + LIBRARY_SEARCH_PATHS = ( + /usr/local/lib, + /usr/local/include/glm, + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-Wno-deprecated-declarations", + "-v", + ); PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/Fields/main.cpp b/Fields/main.cpp deleted file mode 100644 index 3ad3e9c..0000000 --- a/Fields/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// -// main.cpp -// Fields -// -// Created by 胡一兵 on 2018/12/13. -// Copyright © 2018年 Bakantu. All rights reserved. -// - -#include - -int main(int argc, const char * argv[]) { - // insert code here... - std::cout << "Hello, World!\n"; - return 0; -} diff --git a/include/fields.hpp b/include/fields.hpp new file mode 100644 index 0000000..e210211 --- /dev/null +++ b/include/fields.hpp @@ -0,0 +1,19 @@ +#ifndef fields_hpp +#define fields_hpp + +#include +#include + +class Field:public Shape{ + +public: + double people; + Field():people(0),Shape(){ + setRetangle({{0,0,0},{0,0,0}}); + } + Field(pair pos){ + setRetangle(pos); + } +}; + +#endif /* fields_hpp */ diff --git a/include/graphs.hpp b/include/graphs.hpp new file mode 100644 index 0000000..e839e00 --- /dev/null +++ b/include/graphs.hpp @@ -0,0 +1,228 @@ +#ifndef graphs_h +#define graphs_h + +#include + +#define DRAW_TIMER 1 +#define FRESH_TIMER 20 + +typedef std::pair Size; +typedef std::pair Point; +typedef std::vector Point3; +typedef std::vector RawColor; + +using std::string; +using std::vector; +using std::list; +using std::pair; +using std::map; + +class Field; + +unsigned long fresh_screen(int signal); +void draw_fields(int signal); + +class Color{ +public: + double red, green, blue; + Color():red(1.0),blue(1.0),green(1.0){ + } + Color(RawColor color){ + red = color[0]/255; + blue = color[1]/255; + green = color[2]/255; + } + Color(const Color &color){ + red = color.red; + blue = color.blue; + green = color.green; + } + void setColor(RawColor color){ + red = color[0]/255; + green = color[1]/255; + blue = color[2]/255; + } + void setColor(Color color){ + red = color.red; + blue = color.blue; + green = color.green; + } + void brighter(void){ + red = sqrt(red); + blue = sqrt(blue); + green = sqrt(green); + } +}; + +class Shape{ +public: + GLenum type; + GLfloat point_size, line_size; + vector points; + Color color; + void flesh(void){ + if(point_size != 1.0f) + glPointSize(point_size); + else if(line_size != 1.0f) + glLineWidth(line_size); + glColor3f(color.red, color.blue, color.green); + } + void setColor(RawColor color){ + this->color.setColor(color); + } + void setColor(Color color){ + this->color.setColor(color); + } + Shape():type(GL_POINTS),point_size(2.0f),line_size(2.0f),color({255,255,255}){ + } + + void setRetangle(const pair pos){ + double fx = pos.first[0],fy = pos.first[1]; + double sx = pos.second[0], sy = pos.second[1]; + setPolygon({{fx,fy,0},{sx,fy,0},{sx,sy,0},{fx,sy,0}}); + } + + void setPolygon(const vector pos){ + type = GL_POLYGON; + for(auto i = pos.begin(); i != pos.end(); i++){ + points.push_back(*i); + } + } + +}; + + +class View2D { +public: + Point pos; + vector shapes; + +}; + + +class Bar:public View2D { +public: + Bar(Point, GLint width){ + Shape *p_shape = new Shape(); + } +}; + +class Window { + +public: + static list shapes; + static map menus; + Window(int argc, char **argv){ + glutInit(&argc, argv); + } + void playMode(int Mode){ + glutInitDisplayMode(Mode); + } + void size(Size sizexy){ + glutInitWindowSize(static_cast(sizexy.first), static_cast(sizexy.second)); + } + void position(Point positionxy){ + glutPositionWindow(positionxy.first, positionxy.second); + } + void create(string name = "No Name",void (*func)() = Window::displayEngine){ + glutCreateWindow(name.data()); + glutDisplayFunc(func); + glutMouseFunc(mouseListener); + glutTimerFunc(DRAW_TIMER, draw_fields, 1); + glutTimerFunc(FRESH_TIMER, rendEngine, 1); + + } + void setColor(Color color){ + glClearColor(color.red, color.blue, color.green, 1.0f); + } + void show(void){ + glutMainLoop(); + } + + static void rendShape(Shape *shape){ + if(shape->point_size != 1.0f) + glPointSize(shape->point_size); + else if(shape->line_size != 1.0f) + glLineWidth(shape->line_size); + glColor3f(shape->color.red, shape->color.blue, shape->color.green); + glBegin(shape->type); + for(auto k = shape->points.begin(); k != shape->points.end();k++){ + glVertex3f((*k)[0],(*k)[1],(*k)[2]); + } + glEnd(); + } + + static void displayEngine(void){ + glClear(GL_COLOR_BUFFER_BIT); + for(auto i = shapes.begin(); i != shapes.end(); i++) + rendShape(*i); + //for(auto i = menus.begin(); i != menus.end(); i++) + //rendShape((*i).second); + glutSwapBuffers(); + } + static void mouseListener(int button,int state,int x,int y){ + } + + static void rendEngine(int value){ + unsigned long ms = fresh_screen(0); + unsigned int now_fresh = (unsigned int)(FRESH_TIMER - ms); + if(now_fresh < 0 || now_fresh > FRESH_TIMER) now_fresh = 0; + glutTimerFunc(now_fresh, rendEngine, 1); + } + + void draw_triangle(vector pos, RawColor color={255, 255, 255}){ + Shape *p_shape = new Shape; + p_shape->type = GL_TRIANGLES; + p_shape->setColor(color); + for(auto i = pos.begin(); i != pos.end(); i++){ + p_shape->points.push_back(*i); + } + draw_shape(p_shape); + } + + void draw_point(Point3 pos, GLfloat size = 1.0f, RawColor color={255, 255, 255}){ + Shape *p_shape = new Shape; + p_shape->type = GL_POINTS; + p_shape->point_size = size; + p_shape->setColor(color); + p_shape->points.push_back(pos); + draw_shape(p_shape); + } + + void draw_polygon(vector pos, RawColor color={255,255,255}){ + Shape *p_shape = new Shape; + p_shape->type = GL_POLYGON; + p_shape->setColor(color); + p_shape->setPolygon(pos); + draw_shape(p_shape); + } + + void draw_line(pair pos, GLfloat size = 1.0f, RawColor color={255,255,255}){ + Shape *p_shape = new Shape; + p_shape->type = GL_LINES; + p_shape->line_size = size; + p_shape->setColor(color); + p_shape->points.push_back(pos.first); + p_shape->points.push_back(pos.second); + draw_shape(p_shape); + } + + void draw_retangle(pair pos, RawColor color={255,255,255}){ + double fx = pos.first[0],fy = pos.first[1]; + double sx = pos.second[0], sy = pos.second[1]; + draw_polygon({{fx,fy},{sx,fy},{sx,sy},{fx,sy}},color); + } + + void draw_shape(Shape *shape){ + shapes.insert(shapes.end(),shape); + } + + void add_menu(string name, View2D *view){ + menus.insert({name,view}); + } + +}; + + + +#endif /* graphs_h */ diff --git a/include/type.hpp b/include/type.hpp new file mode 100644 index 0000000..82f0aba --- /dev/null +++ b/include/type.hpp @@ -0,0 +1,21 @@ +#ifndef type_h +#define type_h + +#include +#include +#include +#include + +#ifdef __APPLE__ +#include +#include +#include +#include +#endif + + +#include +#include +#include + +#endif /* type_h */ diff --git a/src/fields.cpp b/src/fields.cpp new file mode 100644 index 0000000..4d06c1c --- /dev/null +++ b/src/fields.cpp @@ -0,0 +1,9 @@ +// +// fields.cpp +// Fields +// +// Created by 胡一兵 on 2018/12/13. +// Copyright © 2018年 Bakantu. All rights reserved. +// + +#include diff --git a/src/wav.cpp b/src/wav.cpp new file mode 100644 index 0000000..74c96a4 --- /dev/null +++ b/src/wav.cpp @@ -0,0 +1,10 @@ +#include + +FILE * readWAVInfo(void){ + FILE *fp = NULL; + struct WAV_Format wav; + fp = fopen("test.wav", "rb"); + fread(&wav, 1, sizeof(struct WAV_Format), fp); + + return fp; +} diff --git a/unix/main.cpp b/unix/main.cpp new file mode 100644 index 0000000..63f73ae --- /dev/null +++ b/unix/main.cpp @@ -0,0 +1,47 @@ +// +// main.cpp +// Fields +// +// Created by 胡一兵 on 2018/12/13. +// Copyright © 2018年 Bakantu. All rights reserved. +// + +#include +#include +#include +#include + +int if_fresh = 1, if_draw = 0; +list Window::shapes = {}; +map Window::menus = {}; +vector fields; +Window *p_nwd = NULL; +WAV twav("test.wav"); +Shape *p_avg = new Shape(); + +int main(int argc, char * argv[]) { + Window nwd(argc,argv); + p_nwd = &nwd; + + nwd.playMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); + nwd.size({700,700}); + nwd.position({200,100}); + twav.getInfo(); + twav.setTimer(20); + int hw = sqrt(twav.m_pss.step); + nwd.create("Fields"); + p_avg->setRetangle({{0.98,-0.98},{0.85,-0.85}}); + nwd.draw_shape(p_avg); + for(int y = 0; y < hw; y++){ + for(int x = 0; x < hw; x++){ + double dx = x/16.8, dy = y/16.8; + Field *p_field = new Field({{-0.9+dx,0.9-dy,0},{-(0.848)+dx,(0.848)-dy,0}}); + nwd.draw_shape(p_field); + fields.push_back(p_field); + } + } + + fields[0]->color.setColor({0,0,0}); + nwd.show(); + return 0; +}