Merge remote-tracking branch 'refs/remotes/origin/master'

Conflicts:
	include/type.hpp
This commit is contained in:
Saturneic 2018-12-27 10:13:54 +08:00
commit bab388b4b5
9 changed files with 246 additions and 89 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

View File

@ -16,6 +16,8 @@ unsigned long fresh_screen(int signal);
//计算函数声明 //计算函数声明
void draw_fields(int signal); void draw_fields(int signal);
int create_fields(int hw);
/************************************************ /************************************************
***/ ***/

View File

@ -1,6 +1,7 @@
#ifndef type_h #ifndef type_h
#define type_h #define type_h
#include <iostream> #include <iostream>
#include <stdint.h> #include <stdint.h>
#include <cmath> #include <cmath>
@ -11,7 +12,16 @@
#include <GLUT/GLUT.h> #include <GLUT/GLUT.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#define _CRT_SECURE_NO_WARNINGS
#endif #endif
#ifdef WIN32
#include <Windows.h>
#include <glut.h>
#pragma warning(disable:4996)
#endif
#include <vector> #include <vector>
#include <list> #include <list>
#include <map> #include <map>

View File

@ -9,6 +9,7 @@ using std::string;
using std::vector; using std::vector;
FILE * readWAVInfo(void); FILE * readWAVInfo(void);
int init_test_wav(int);
struct WAV_Format{ struct WAV_Format{
uint32_t ChunkID; /* "RIFF" */ uint32_t ChunkID; /* "RIFF" */

View File

@ -1 +1,4 @@
#include <fields.hpp> #include <fields.hpp>

View File

@ -3,12 +3,34 @@
#include <wav.hpp> #include <wav.hpp>
extern int if_fresh, if_draw; extern int if_fresh, if_draw;
extern vector<Field*> fields; extern vector<Field*> fields;
extern Window *p_nwd; extern Window *p_nwd;
extern WAV twav; extern WAV twav;
extern Shape *p_avg; extern Shape *p_avg;
#ifdef WIN32
int gettimeofday(struct timeval *tp, void *tzp)
{
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm.tm_isdst = -1;
clock = mktime(&tm);
tp->tv_sec = clock;
tp->tv_usec = wtm.wMilliseconds * 1000;
return (0);
}
#endif
void draw_fields(int signal){ void draw_fields(int signal){
if (if_fresh == 1 && if_draw == 0){ if (if_fresh == 1 && if_draw == 0){
timeval timer_a, timer_b; timeval timer_a, timer_b;
@ -57,3 +79,17 @@ unsigned long fresh_screen(int signal){
return -1; return -1;
} }
int create_fields(int hw) {
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} });
p_nwd->draw_shape(p_field);
fields.push_back(p_field);
}
}
fields[0]->color.setColor({ 0,0,0 });
p_avg->setRetangle({ {0.98,-0.98},{0.85,-0.85} });
p_nwd->draw_shape(p_avg);
return 0;
}

View File

@ -2,112 +2,114 @@
#include <graphs.hpp> #include <graphs.hpp>
#include <hsv.hpp> #include <hsv.hpp>
hsv rgb2hsv(rgb in) hsv rgb2hsv(rgb in)
{ {
hsv out; hsv out;
double min, max, delta; double min, max, delta;
min = in.r < in.g ? in.r : in.g; min = in.r < in.g ? in.r : in.g;
min = min < in.b ? min : in.b; min = min < in.b ? min : in.b;
max = in.r > in.g ? in.r : in.g; max = in.r > in.g ? in.r : in.g;
max = max > in.b ? max : in.b; max = max > in.b ? max : in.b;
out.v = max; // v out.v = max; // v
delta = max - min; delta = max - min;
if (delta < 0.00001) if (delta < 0.00001)
{ {
out.s = 0; out.s = 0;
out.h = 0; // undefined, maybe nan? out.h = 0; // undefined, maybe nan?
return out; return out;
} }
if (max > 0.0) { // NOTE: if Max is == 0, this divide would cause a crash if (max > 0.0) { // NOTE: if Max is == 0, this divide would cause a crash
out.s = (delta / max); // s out.s = (delta / max); // s
} }
else { else {
// if max is 0, then r = g = b = 0 // if max is 0, then r = g = b = 0
// s = 0, h is undefined // s = 0, h is undefined
out.s = 0.0; out.s = 0.0;
out.h = NAN; // its now undefined out.h = NAN; // its now undefined
return out; return out;
} }
if (in.r >= max) // > is bogus, just keeps compilor happy if (in.r >= max) // > is bogus, just keeps compilor happy
out.h = (in.g - in.b) / delta; // between yellow & magenta out.h = (in.g - in.b) / delta; // between yellow & magenta
else else
if (in.g >= max) if (in.g >= max)
out.h = 2.0 + (in.b - in.r) / delta; // between cyan & yellow out.h = 2.0 + (in.b - in.r) / delta; // between cyan & yellow
else else
out.h = 4.0 + (in.r - in.g) / delta; // between magenta & cyan out.h = 4.0 + (in.r - in.g) / delta; // between magenta & cyan
out.h *= 60.0; // degrees out.h *= 60.0; // degrees
if (out.h < 0.0) if (out.h < 0.0)
out.h += 360.0; out.h += 360.0;
return out; return out;
} }
rgb hsv2rgb(hsv in) rgb hsv2rgb(hsv in)
{ {
double hh, p, q, t, ff; double hh, p, q, t, ff;
long i; long i;
rgb out; rgb out;
if (in.s <= 0.0) { // < is bogus, just shuts up warnings if (in.s <= 0.0) { // < is bogus, just shuts up warnings
out.r = in.v; out.r = in.v;
out.g = in.v; out.g = in.v;
out.b = in.v; out.b = in.v;
return out; return out;
} }
hh = in.h; hh = in.h;
if (hh >= 360.0) hh = 0.0; if (hh >= 360.0) hh = 0.0;
hh /= 60.0; hh /= 60.0;
i = (long)hh; i = (long)hh;
ff = hh - i; ff = hh - i;
p = in.v * (1.0 - in.s); p = in.v * (1.0 - in.s);
q = in.v * (1.0 - (in.s * ff)); q = in.v * (1.0 - (in.s * ff));
t = in.v * (1.0 - (in.s * (1.0 - ff))); t = in.v * (1.0 - (in.s * (1.0 - ff)));
switch (i) { switch (i) {
case 0: case 0:
out.r = in.v; out.r = in.v;
out.g = t; out.g = t;
out.b = p; out.b = p;
break; break;
case 1: case 1:
out.r = q; out.r = q;
out.g = in.v; out.g = in.v;
out.b = p; out.b = p;
break; break;
case 2: case 2:
out.r = p; out.r = p;
out.g = in.v; out.g = in.v;
out.b = t; out.b = t;
break; break;
case 3: case 3:
out.r = p; out.r = p;
out.g = q; out.g = q;
out.b = in.v; out.b = in.v;
break; break;
case 4: case 4:
out.r = t; out.r = t;
out.g = p; out.g = p;
out.b = in.v; out.b = in.v;
break; break;
case 5: case 5:
default: default:
out.r = in.v; out.r = in.v;
out.g = p; out.g = p;
out.b = q; out.b = q;
break; break;
} }
return out; return out;
} }
/* /*
void addsaturation(hsv &in) { void addsaturation(hsv &in) {
in.s += 0.1; in.s += 0.1;
in.s > 1 ? 1 : 1; in.s > 1 ? 1 : 1;
return; return;
}*/ }*/

View File

@ -1,5 +1,7 @@
#include <wav.hpp> #include <wav.hpp>
extern WAV twav;
FILE * readWAVInfo(void){ FILE * readWAVInfo(void){
FILE *fp = NULL; FILE *fp = NULL;
struct WAV_Format wav; struct WAV_Format wav;
@ -8,3 +10,10 @@ FILE * readWAVInfo(void){
return fp; return fp;
} }
int init_test_wav(int ms) {
twav.getInfo();
twav.setTimer(ms);
return sqrt(twav.m_pss.step);
}

31
windows/main.cpp Normal file
View File

@ -0,0 +1,31 @@
#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;
unsigned long fresh_screen(int signal);
FILE *fp;
Window *p_nwd = NULL;
WAV twav("data/test.wav");
Shape *p_avg = new Shape();
int main(int argc, char * argv[]) {
Window nwd(argc, argv);
p_nwd = &nwd;
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(700, 700);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
int hw = init_test_wav(60);
create_fields(hw);
nwd.create("Fields");
nwd.show();
return 0;
}