This commit is contained in:
Saturneic 2018-12-25 21:41:30 +08:00
parent 88ef37994e
commit f7368d7ea5
8 changed files with 435 additions and 21 deletions

View File

@ -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 = "<group>"; };
9227913321D266F2009DB236 /* wav.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wav.cpp; sourceTree = "<group>"; };
9227913521D269C1009DB236 /* type.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = type.hpp; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
92B75C4C21C2602000DA2DF9 /* graphs.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = graphs.cpp; sourceTree = "<group>"; };
92B75C4E21C2B69100DA2DF9 /* fields.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = fields.cpp; sourceTree = "<group>"; };
92B75C4F21C2B69100DA2DF9 /* fields.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = fields.hpp; sourceTree = "<group>"; };
92B75C5121C2CCC700DA2DF9 /* libfreetype.6.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libfreetype.6.dylib; path = ../../../../../usr/local/lib/libfreetype.6.dylib; sourceTree = "<group>"; };
92B75C5621C2D1E500DA2DF9 /* libglm_shared.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libglm_shared.dylib; path = ../../../../../usr/local/include/glm/libglm_shared.dylib; sourceTree = "<group>"; };
92B75C5821C2D21E00DA2DF9 /* libglm_static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglm_static.a; path = ../../../../../usr/local/include/glm/libglm_static.a; sourceTree = "<group>"; };
/* 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 = "<group>";
};
9227913121D26676009DB236 /* include */ = {
isa = PBXGroup;
children = (
92B75C4F21C2B69100DA2DF9 /* fields.hpp */,
92B75C4B21C2602000DA2DF9 /* graphs.hpp */,
9227913221D266DE009DB236 /* wav.hpp */,
9227913521D269C1009DB236 /* type.hpp */,
);
path = include;
sourceTree = "<group>";
};
92B75C3321C24AB600DA2DF9 = {
isa = PBXGroup;
children = (
92B75C3E21C24AB600DA2DF9 /* Fields */,
9227913121D26676009DB236 /* include */,
9227913021D2660B009DB236 /* unix */,
92B75C3E21C24AB600DA2DF9 /* src */,
92B75C3D21C24AB600DA2DF9 /* Products */,
92B75C4621C2513C00DA2DF9 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -54,12 +100,26 @@
name = Products;
sourceTree = "<group>";
};
92B75C3E21C24AB600DA2DF9 /* Fields */ = {
92B75C3E21C24AB600DA2DF9 /* src */ = {
isa = PBXGroup;
children = (
92B75C3F21C24AB600DA2DF9 /* main.cpp */,
9227913321D266F2009DB236 /* wav.cpp */,
92B75C4E21C2B69100DA2DF9 /* fields.cpp */,
92B75C4C21C2602000DA2DF9 /* graphs.cpp */,
);
path = Fields;
path = src;
sourceTree = "<group>";
};
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 = "<group>";
};
/* 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;

View File

@ -1,15 +0,0 @@
//
// main.cpp
// Fields
//
// Created by 胡一兵 on 2018/12/13.
// Copyright © 2018年 Bakantu. All rights reserved.
//
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}

19
include/fields.hpp Normal file
View File

@ -0,0 +1,19 @@
#ifndef fields_hpp
#define fields_hpp
#include <type.hpp>
#include <graphs.hpp>
class Field:public Shape{
public:
double people;
Field():people(0),Shape(){
setRetangle({{0,0,0},{0,0,0}});
}
Field(pair<Point3,Point3> pos){
setRetangle(pos);
}
};
#endif /* fields_hpp */

228
include/graphs.hpp Normal file
View File

@ -0,0 +1,228 @@
#ifndef graphs_h
#define graphs_h
#include <type.hpp>
#define DRAW_TIMER 1
#define FRESH_TIMER 20
typedef std::pair<double, double> Size;
typedef std::pair<double, double> Point;
typedef std::vector<double> Point3;
typedef std::vector<double> 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<Point3> 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<Point3,Point3> 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<Point3> pos){
type = GL_POLYGON;
for(auto i = pos.begin(); i != pos.end(); i++){
points.push_back(*i);
}
}
};
class View2D {
public:
Point pos;
vector<Shape> shapes;
};
class Bar:public View2D {
public:
Bar(Point, GLint width){
Shape *p_shape = new Shape();
}
};
class Window {
public:
static list<Shape *> shapes;
static map<string,View2D *> menus;
Window(int argc, char **argv){
glutInit(&argc, argv);
}
void playMode(int Mode){
glutInitDisplayMode(Mode);
}
void size(Size sizexy){
glutInitWindowSize(static_cast<int>(sizexy.first), static_cast<int>(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<Point3> 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<Point3> 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<Point3,Point3> 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<Point3,Point3> 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 */

21
include/type.hpp Normal file
View File

@ -0,0 +1,21 @@
#ifndef type_h
#define type_h
#include <iostream>
#include <stdint.h>
#include <cmath>
#include <time.h>
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <vector>
#include <list>
#include <map>
#endif /* type_h */

9
src/fields.cpp Normal file
View File

@ -0,0 +1,9 @@
//
// fields.cpp
// Fields
//
// Created by 胡一兵 on 2018/12/13.
// Copyright © 2018年 Bakantu. All rights reserved.
//
#include <fields.hpp>

10
src/wav.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <wav.hpp>
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;
}

47
unix/main.cpp Normal file
View File

@ -0,0 +1,47 @@
//
// main.cpp
// Fields
//
// Created by 胡一兵 on 2018/12/13.
// Copyright © 2018年 Bakantu. All rights reserved.
//
#include <type.hpp>
#include <graphs.hpp>
#include <fields.hpp>
#include <wav.hpp>
int if_fresh = 1, if_draw = 0;
list<Shape *> Window::shapes = {};
map<string,View2D *> Window::menus = {};
vector<Field*> 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;
}