From: Thomas Pietrzak Date: Wed, 30 Mar 2011 20:30:19 +0000 (+0000) Subject: Portage windows + textures sur notes X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=9610b010735d18b7ab60dab77bf2ebe2cf5728e0;p=hapticmetronome.git Portage windows + textures sur notes git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@5 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/Haptic Metronome/Haptic Metronome.sln b/Haptic Metronome/Haptic Metronome.sln new file mode 100644 index 0000000..b695369 --- /dev/null +++ b/Haptic Metronome/Haptic Metronome.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Haptic Metronome", "Haptic Metronome\Haptic Metronome.vcxproj", "{46FB682E-53BE-41ED-8EF7-21FCD538023B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Debug|Win32.ActiveCfg = Debug|Win32 + {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Debug|Win32.Build.0 = Debug|Win32 + {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Release|Win32.ActiveCfg = Release|Win32 + {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Haptic Metronome/Haptic Metronome.suo b/Haptic Metronome/Haptic Metronome.suo new file mode 100644 index 0000000..66ff2c7 Binary files /dev/null and b/Haptic Metronome/Haptic Metronome.suo differ diff --git a/include/MIDIReader.hpp b/include/MIDIReader.hpp index a09c8a7..2e620f5 100644 --- a/include/MIDIReader.hpp +++ b/include/MIDIReader.hpp @@ -6,6 +6,7 @@ #include "Track.hpp" #include "String.hpp" #include "Tools.hpp" +#include class MIDIReader @@ -23,13 +24,13 @@ class MIDIReader MIDIReader(const MIDIReader &); FILE *_file; - uint16 _nbtracks; - uint16 _timedivision; + uint16_t _nbtracks; + uint16_t _timedivision; // unsigned long int _position; - uint8 readVariableLength(uint32 &); - void readBytes(void *, uint32); - void printBytes(uint8 *data, uint32 length); - uint32 _position; + uint8_t readVariableLength(uint32_t &); + void readBytes(void *, uint32_t); + void printBytes(uint8_t *data, uint32_t length); + uint32_t _position; }; #endif diff --git a/include/Mixer.hpp b/include/Mixer.hpp index 7725886..ed21914 100644 --- a/include/Mixer.hpp +++ b/include/Mixer.hpp @@ -28,6 +28,8 @@ #include "PrefixTree.hpp" #ifdef __APPLE__ #include +#elif WIN32 +#include #else #include #endif diff --git a/include/Texture.hpp b/include/Texture.hpp index ee7058a..e2a2ec3 100644 --- a/include/Texture.hpp +++ b/include/Texture.hpp @@ -22,7 +22,11 @@ #define __TEXTURE__ #include +#ifdef WIN32 +#include +#else #include +#endif // #include #include "String.hpp" diff --git a/include/Track.hpp b/include/Track.hpp index d9af107..9bfa783 100644 --- a/include/Track.hpp +++ b/include/Track.hpp @@ -30,7 +30,7 @@ class Track // void setTempo(uint32 t) { _currenttempo = t; } // uint32 beatsToTicks(uint32 time) { return (time * _currenttempo * 480) / 60000.0; } - uint32 beatsToTicks(uint32 time, uint32 tempo) { return (time * tempo * 480) / 60000.0; } + uint32 beatsToTicks(uint32 time, uint32 tempo) { return uint32((time * tempo * 480) / 60000.0); } uint32 ticksToBeats(uint32 time) { return 60000000 / time; } void displayTracks(); diff --git a/include/Vector2D.hpp b/include/Vector2D.hpp index 8ac544c..e004b52 100644 --- a/include/Vector2D.hpp +++ b/include/Vector2D.hpp @@ -22,8 +22,8 @@ #define __VECTOR2D__ #include "Pair.hpp" -/* -#include + +/*#include using namespace std;*/ template class Vector2D; @@ -65,19 +65,19 @@ class Vector2D: public Pair // const Vector2D & operator = (const Vector2D &s); // bool operator == (const Vector2D &s) const; - friend Vector2D operator + <>(const Vector2D &p1, const Vector2D &p2); - friend Vector2D operator + <>(const T &a, const Vector2D &p); - friend Vector2D operator + <>(const Vector2D &p1, const T &a); - friend Vector2D operator - <>(const Vector2D &p1, const Vector2D &p2); - friend Vector2D operator - <>(const T &a, const Vector2D &p); - friend Vector2D operator - <>(const Vector2D &p1, const T &a); + friend Vector2D operator + (const Vector2D &p1, const Vector2D &p2); + friend Vector2D operator + (const T &a, const Vector2D &p); + friend Vector2D operator + (const Vector2D &p1, const T &a); + friend Vector2D operator - (const Vector2D &p1, const Vector2D &p2); + friend Vector2D operator - (const T &a, const Vector2D &p); + friend Vector2D operator - (const Vector2D &p1, const T &a); Vector2D operator - (void); - friend Vector2D operator * <>(const Vector2D &p1, const Vector2D &p2); - friend Vector2D operator * <>(const T &a, const Vector2D &p); - friend Vector2D operator * <>(const Vector2D &p1, const T &a); - friend Vector2D operator / <>(const Vector2D &p1, const Vector2D &p2); - friend Vector2D operator / <>(const T &a, const Vector2D &p); - friend Vector2D operator / <>(const Vector2D &p1, const T &a); + friend Vector2D operator * (const Vector2D &p1, const Vector2D &p2); + friend Vector2D operator * (const T &a, const Vector2D &p); + friend Vector2D operator * (const Vector2D &p1, const T &a); + friend Vector2D operator / (const Vector2D &p1, const Vector2D &p2); + friend Vector2D operator / (const T &a, const Vector2D &p); + friend Vector2D operator / (const Vector2D &p1, const T &a); // // friend ostream &operator << <>(ostream &os, const Vector2D &s); diff --git a/include/Vector3D.hpp b/include/Vector3D.hpp index b6db366..f0de0cb 100644 --- a/include/Vector3D.hpp +++ b/include/Vector3D.hpp @@ -54,19 +54,19 @@ class Vector3D: public Triplet inline T &operator [] (const int &i); inline const T &operator [] (const int &i) const; - friend Vector3D operator + <>(const Vector3D &p1, const Vector3D &p2); - friend Vector3D operator + <>(const T &a, const Vector3D &p); - friend Vector3D operator + <>(const Vector3D &p1, const T &a); - friend Vector3D operator - <>(const Vector3D &p1, const Vector3D &p2); - friend Vector3D operator - <>(const T &a, const Vector3D &p); - friend Vector3D operator - <>(const Vector3D &p1, const T &a); + friend Vector3D operator + (const Vector3D &p1, const Vector3D &p2); + friend Vector3D operator + (const T &a, const Vector3D &p); + friend Vector3D operator + (const Vector3D &p1, const T &a); + friend Vector3D operator - (const Vector3D &p1, const Vector3D &p2); + friend Vector3D operator - (const T &a, const Vector3D &p); + friend Vector3D operator - (const Vector3D &p1, const T &a); Vector3D operator - (void); - friend Vector3D operator * <>(const Vector3D &p1, const Vector3D &p2); - friend Vector3D operator * <>(const T &a, const Vector3D &p); - friend Vector3D operator * <>(const Vector3D &p1, const T &a); - friend Vector3D operator / <>(const Vector3D &p1, const Vector3D &p2); - friend Vector3D operator / <>(const T &a, const Vector3D &p); - friend Vector3D operator / <>(const Vector3D &p1, const T &a); + friend Vector3D operator * (const Vector3D &p1, const Vector3D &p2); + friend Vector3D operator * (const T &a, const Vector3D &p); + friend Vector3D operator * (const Vector3D &p1, const T &a); + friend Vector3D operator / (const Vector3D &p1, const Vector3D &p2); + friend Vector3D operator / (const T &a, const Vector3D &p); + friend Vector3D operator / (const Vector3D &p1, const T &a); private: }; diff --git a/src/MIDIReader.cpp b/src/MIDIReader.cpp index 7ccb818..bc3f1c3 100644 --- a/src/MIDIReader.cpp +++ b/src/MIDIReader.cpp @@ -1,7 +1,7 @@ // For format explanation, see http://www.sonicspot.com/guide/midifiles.html #include -#include +//#include #include using namespace std; #include @@ -50,7 +50,7 @@ void MIDIReader::readHeader() if (!_file) return; - uint8 temp[4]; + uint8_t temp[4]; //read the chunk ID fread((void *)(temp), 1, 4, _file); @@ -61,12 +61,12 @@ void MIDIReader::readHeader() } //read the chunk size - uint32 chunksize; + uint32_t chunksize; readBytes(&chunksize, 4); cout << "Header size: " << chunksize << endl; //read the format - uint16 format; + uint16_t format; readBytes(&format, 2); cout << "Format type: " << format << endl; @@ -85,7 +85,7 @@ void MIDIReader::readHeader() void MIDIReader::skipTrack() { - uint8 temp[4]; + uint8_t temp[4]; //read the chunk ID fread((void *)(temp), 4, 1, _file); // cerr << temp << endl; @@ -96,7 +96,7 @@ void MIDIReader::skipTrack() } //read the chunk size - uint32 chunksize; + uint32_t chunksize; readBytes(&chunksize, 4); cout << "Chunk size: " << chunksize << endl; fseek(_file, chunksize, SEEK_CUR); @@ -105,7 +105,7 @@ void MIDIReader::skipTrack() void MIDIReader::readTrack(Track &tr) { - uint8 temp[4]; + uint8_t temp[4]; //read the chunk ID fread((void *)(temp), 4, 1, _file); // cerr << temp << endl; @@ -116,7 +116,7 @@ void MIDIReader::readTrack(Track &tr) } //read the chunk size - uint32 chunksize; + uint32_t chunksize; readBytes(&chunksize, 4); cout << "Chunk size: " << chunksize << endl; @@ -129,21 +129,21 @@ void MIDIReader::readTrack(Track &tr) // readBytes((char *)(&temp2),4); // printf("TEMP : %0x %0x %0x %0x\n", temp2[0], temp2[1], temp2[2], temp2[3]); bool end = false; - uint8 oldeventandchannel = 0; - uint32 timestamp = 0; + uint8_t oldeventandchannel = 0; + uint32_t timestamp = 0; // Track example; //Read the events while (_position < chunksize) { - uint32 delta; + uint32_t delta; //The delta is a variable-length stuff /*uint8 nblus = */readVariableLength(delta); timestamp += delta; - uint8 eventandchannel, tempevt; + uint8_t eventandchannel, tempevt; // 4 bits for event type, and 4 others for the channel readBytes(&tempevt, 1); fseek(_file, -1, SEEK_CUR); @@ -165,15 +165,15 @@ void MIDIReader::readTrack(Track &tr) { if (end) cerr << "EXTRA EVT "; - uint8 type; + uint8_t type; readBytes(&type, 1); - uint32 length; - /*uint8 nblus = */readVariableLength(length); + uint32_t length; + /*uint8_t nblus = */readVariableLength(length); - uint8 *data = new uint8[length]; + uint8_t *data = new uint8_t[length]; readBytes(data, length); - uint32 tempo = 0; + uint32_t tempo = 0; switch(type) { @@ -240,9 +240,9 @@ void MIDIReader::readTrack(Track &tr) else if ((eventandchannel & 0xf0) == 0xf0)// || (eventandchannel & 0xff) == 0xf7) { //May be something else - uint32 length; + uint32_t length; readVariableLength(length); - uint8 *data = new uint8[length]; + uint8_t *data = new uint8_t[length]; readBytes(data, length); printf("System data\n"); delete []data; @@ -251,7 +251,7 @@ void MIDIReader::readTrack(Track &tr) else { // printf("Evt : %x %x %x\n", eventandchannel & 0xf0, eventandchannel & 0x0f, eventandchannel); - uint8 par1, par2; + uint8_t par1, par2; // position += 2; // char *notenames[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; switch(eventandchannel & 0xf0) @@ -354,11 +354,11 @@ void MIDIReader::readTracks(Track &t)//, int &nb) cout << endl << "Total : " << total << endl; } -uint8 MIDIReader::readVariableLength(uint32 &nb) +uint8_t MIDIReader::readVariableLength(uint32_t &nb) { - uint8 nblus = 0; + uint8_t nblus = 0; nb = 0; - uint8 temp; + uint8_t temp; do { fread((void *)(&temp), 1, 1, _file); @@ -370,18 +370,19 @@ uint8 MIDIReader::readVariableLength(uint32 &nb) return nblus; } -void MIDIReader::readBytes(void *data, uint32 nb) +void MIDIReader::readBytes(void *data, uint32_t nb) { - uint8 temp[nb]; - fread((void *)(&temp), nb, 1, _file); - for (uint32 i=0 ; i using namespace std; +#ifdef WIN32 +#define snprintf _snprintf +#endif + String::String(const String &s) :string(strdup(s.string)) { @@ -38,9 +42,9 @@ String::String(const int &a) if (a == 0) string = (char *)malloc(2 * sizeof(char)); else if (a < 0) - string = (char *)malloc(int(log10(-a) + 3) * sizeof(char)); + string = (char *)malloc(int(log10(static_cast(-a)) + 3) * sizeof(char)); else - string = (char *)malloc(int(log10(a) + 2) * sizeof(char)); + string = (char *)malloc(int(log10(static_cast(a)) + 2) * sizeof(char)); sprintf(string, "%d", a); } diff --git a/src/Texture.cpp b/src/Texture.cpp index e3f9913..00d8cbe 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -24,6 +24,8 @@ // #include #ifdef __APPLE__ #include +#elif WIN32 +#include #else #include #endif diff --git a/src/Tools.cpp b/src/Tools.cpp index 79ce059..4b674a4 100644 --- a/src/Tools.cpp +++ b/src/Tools.cpp @@ -23,7 +23,9 @@ #include #include #include + #include + using namespace std; bool fileExists(const String &f) diff --git a/src/Track.cpp b/src/Track.cpp index e9173c5..a8405d1 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -1,15 +1,18 @@ #include "Track.hpp" #include "Mixer.hpp" +#include "Texture.hpp" #include double SECONDSIZE = 0.050; - +extern Texture* texturesteel; extern FILE *logfile; void drawCube(double pos, double size, double colorx, double colory, double colorz) { + glEnable(GL_TEXTURE_2D); + texturesteel->useTexture(); glBegin(GL_QUADS); glColor3f(colorx, colory, colorz); // Set The Color To Green /* @@ -20,29 +23,32 @@ void drawCube(double pos, double size, double colorx, double colory, double colo glVertex3f( size+pos,0,-size); // Bottom Right Of The Quad (Bottom) */ glNormal3f(0, 0.5, 0.5); - glVertex3f( size/2+pos, size/3, size/2); // Top Right Of The Quad (Front) - glVertex3f(-size/2+pos, size/3, size/2); // Top Left Of The Quad (Front) - glVertex3f(-size+pos,0, size); // Bottom Left Of The Quad (Front) - glVertex3f( size+pos,0, size); // Bottom Right Of The Quad (Front) + glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3, size/2); // Top Right Of The Quad (Front) + glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2); // Top Left Of The Quad (Front) + glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0, size); // Bottom Left Of The Quad (Front) + glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0, size); // Bottom Right Of The Quad (Front) glNormal3f(0, 0.5, -0.5); - glVertex3f( size+pos,0,-size); // Bottom Left Of The Quad (Back) - glVertex3f(-size+pos,0,-size); // Bottom Right Of The Quad (Back) - glVertex3f(-size/2+pos, size/3,-size/2); // Top Right Of The Quad (Back) - glVertex3f( size/2+pos, size/3,-size/2); // Top Left Of The Quad (Back) + glTexCoord2d(1.0, 0.0); glVertex3f( size+pos,0,-size); // Bottom Left Of The Quad (Back) + glTexCoord2d(0.0, 0.0); glVertex3f(-size+pos,0,-size); // Bottom Right Of The Quad (Back) + glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3,-size/2); // Top Right Of The Quad (Back) + glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3,-size/2); // Top Left Of The Quad (Back) glNormal3f(-0.5, 0.5, 0); - glVertex3f(-size/2+pos, size/3, size/2); // Top Right Of The Quad (Left) - glVertex3f(-size/2+pos, size/3,-size/2); // Top Left Of The Quad (Left) - glVertex3f(-size+pos,0,-size); // Bottom Left Of The Quad (Left) - glVertex3f(-size+pos,0, size); // Bottom Right Of The Quad (Left) + glTexCoord2d(1.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2); // Top Right Of The Quad (Left) + glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3,-size/2); // Top Left Of The Quad (Left) + glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0,-size); // Bottom Left Of The Quad (Left) + glTexCoord2d(1.0, 1.0); glVertex3f(-size+pos,0, size); // Bottom Right Of The Quad (Left) glNormal3f(0.5, 0.5, 0); - glVertex3f( size/2+pos, size/3,-size/2l); // Top Right Of The Quad (Right) - glVertex3f( size/2+pos, size/3, size/2); // Top Left Of The Quad (Right) - glVertex3f( size+pos,0, size); // Bottom Left Of The Quad (Right) - glVertex3f( size+pos,0,-size); // Bottom Right Of The Quad (Right) + glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3,-size/2l); // Top Right Of The Quad (Right) + glTexCoord2d(0.0, 0.0); glVertex3f( size/2+pos, size/3, size/2); // Top Left Of The Quad (Right) + glTexCoord2d(0.0, 1.0); glVertex3f( size+pos,0, size); // Bottom Left Of The Quad (Right) + glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0,-size); // Bottom Right Of The Quad (Right) + glEnd(); + glDisable(GL_TEXTURE_2D); + glBegin(GL_QUADS); glColor3f(1.0, 1.0, 1.0); // Set The Color To White glNormal3f(0, 1, 0); glVertex3f( size/2+pos, size/3,-size/2); // Top Right Of The Quad (Top) @@ -57,6 +63,8 @@ void drawCube(double pos, double size, double colorx, double colory, double colo void drawLong(double pos, double size, double length, double colorx, double colory, double colorz) { double l = length*SECONDSIZE; + glEnable(GL_TEXTURE_2D); + texturesteel->useTexture(); glBegin(GL_QUADS); glColor3f(colorx, colory, colorz); // Set The Color /* @@ -67,34 +75,34 @@ void drawLong(double pos, double size, double length, double colorx, double colo glVertex3f( size+pos,0,-size-l); // Bottom Right Of The Quad (Bottom) */ glNormal3f(0, 0.5, 0.5); - glVertex3f( size/2+pos, size/3, size/2); // Top Right Of The Quad (Front) - glVertex3f(-size/2+pos, size/3, size/2); // Top Left Of The Quad (Front) - glVertex3f(-size+pos,0, size); // Bottom Left Of The Quad (Front) - glVertex3f( size+pos,0, size); // Bottom Right Of The Quad (Front) + glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3, size/2); // Top Right Of The Quad (Front) + glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2); // Top Left Of The Quad (Front) + glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0, size); // Bottom Left Of The Quad (Front) + glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0, size); // Bottom Right Of The Quad (Front) glNormal3f(0, 0.5, -0.5); - glVertex3f( size+pos,0,-size); // Bottom Left Of The Quad (Back) - glVertex3f(-size+pos,0,-size); // Bottom Right Of The Quad (Back) - glVertex3f(-size/2+pos, size/3,-size/2-l); // Top Right Of The Quad (Back) - glVertex3f( size/2+pos, size/3,-size/2-l); // Top Left Of The Quad (Back) + glTexCoord2d(1.0, 0.0); glVertex3f( size+pos,0,-size); // Bottom Left Of The Quad (Back) + glTexCoord2d(0.0, 0.0); glVertex3f(-size+pos,0,-size); // Bottom Right Of The Quad (Back) + glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3,-size/2-l); // Top Right Of The Quad (Back) + glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3,-size/2-l); // Top Left Of The Quad (Back) glNormal3f(-0.5, 0.5, 0); - glVertex3f(-size/2+pos, size/3, size/2); // Top Right Of The Quad (Left) - glVertex3f(-size/2+pos, size/3,-size/2-l); // Top Left Of The Quad (Left) - glVertex3f(-size+pos,0,-size-l); // Bottom Left Of The Quad (Left) - glVertex3f(-size+pos,0, size); // Bottom Right Of The Quad (Left) + glTexCoord2d(1.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2); // Top Right Of The Quad (Left) + glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3,-size/2-l); // Top Left Of The Quad (Left) + glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0,-size-l); // Bottom Left Of The Quad (Left) + glTexCoord2d(1.0, 1.0); glVertex3f(-size+pos,0, size); // Bottom Right Of The Quad (Left) glNormal3f(0.5, 0.5, 0); - glVertex3f( size/2+pos, size/3,-size/2-l); // Top Right Of The Quad (Right) - glVertex3f( size/2+pos, size/3, size/2); // Top Left Of The Quad (Right) - glVertex3f( size+pos,0, size); // Bottom Left Of The Quad (Right) - glVertex3f( size+pos,0,-size-l); // Bottom Right Of The Quad (Right) + glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3,-size/2-l); // Top Right Of The Quad (Right) + glTexCoord2d(0.0, 0.0); glVertex3f( size/2+pos, size/3, size/2); // Top Left Of The Quad (Right) + glTexCoord2d(0.0, 1.0); glVertex3f( size+pos,0, size); // Bottom Left Of The Quad (Right) + glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0,-size-l); // Bottom Right Of The Quad (Right) glNormal3f(0, 1, 0); - glVertex3f( size/2+pos, size/3,-size/2-l); // Top Right Of The Quad (Top) - glVertex3f(-size/2+pos, size/3,-size/2-l); // Top Left Of The Quad (Top) - glVertex3f(-size/2+pos, size/3, size/2); // Bottom Left Of The Quad (Top) - glVertex3f( size/2+pos, size/3, size/2); // Bottom Right Of The Quad (Top) + glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3,-size/2-l); // Top Right Of The Quad (Top) + glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3,-size/2-l); // Top Left Of The Quad (Top) + glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3, size/2); // Bottom Left Of The Quad (Top) + glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3, size/2); // Bottom Right Of The Quad (Top) glEnd(); // Done Drawing The Quad } diff --git a/src/main.cpp b/src/main.cpp index f353f6b..0bf677c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,23 @@ #include "Texture.hpp" #include "Mixer.hpp" + +#include + +#ifdef WIN32 +#include + +#include +#include +#include +#else #include + +#include +#include +#include +#endif + #include /*#ifdef __APPLE__ #include @@ -13,17 +29,20 @@ #include #endif*/ -#include -#include -#include -#include extern double SECONDSIZE; #include "Wiimote.hpp" -double posx, posy, posz; -struct timeval start; -Texture *texturebois, *texturefond; +double posz=0.0; + +#ifdef WIN32 + struct { int tv_sec, tv_usec; } start; + DWORD t; +#else + struct timeval start; +#endif + +Texture *texturebois, *texturefond, *texturesteel; int resolution_x, resolution_y; Config fromKeyboard; @@ -45,8 +64,8 @@ void init() throw "Error while loading SDL"; //Initialize SDL_mixer - if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 ); -// throw String("Can't initialize sound"); + if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 ) + throw String("Can't initialize sound"); cout << "get video info" << endl; info = SDL_GetVideoInfo(); @@ -152,24 +171,34 @@ void init() texturebois = new Texture("wood.jpg", true); texturefond = new Texture("back.jpg"); - - posx=0.0; - posy=25.0; - posz=0.0; + texturesteel = new Texture("steel.jpg"); fromKeyboard.setPosition(-1); fromKeyboard.setEnd(-1); } +#define POSITION_HEIGHT 35 #define POSITION_EYE 45 -#define POSITION_CENTER (-80) -#define VIEWLENGTH 250 +#define POSITION_CENTER (-70) +#define VIEWLENGTH 250 void draw(Track &t, uint8 diff) { - struct timeval now; - gettimeofday(&now, NULL); +#ifdef WIN32 + struct { int tv_sec, tv_usec; } now; + DWORD tim; +#else + struct timeval now; +#endif + +#ifdef WIN32 + tim = timeGetTime (); + now.tv_sec = tim / 1000; + now.tv_usec = (tim % 1000) * 1000; +#else + gettimeofday(&now, NULL); +#endif double postime = (now.tv_sec - start.tv_sec) * 1000. + (now.tv_usec - start.tv_usec) / 1000.0; posz = -SECONDSIZE * postime; @@ -198,11 +227,11 @@ void draw(Track &t, uint8 diff) glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective( 45.0f, double(resolution_x) / double(resolution_y), POSITION_EYE+3, VIEWLENGTH ); + gluPerspective( 45.0f, double(resolution_x) / double(resolution_y), 1/*POSITION_EYE+3*/, VIEWLENGTH ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //cout << "posz=" << posz << endl; - gluLookAt(posx, posy, posz + POSITION_EYE, 0, 0, posz + POSITION_CENTER, 0.0,1.0,0.0); + gluLookAt(0, POSITION_HEIGHT, posz + POSITION_EYE, 0, 0, posz + POSITION_CENTER, 0.0,1.0,0.0); // gluLookAt(posx-50, posy, posz-POSITION, 0, 0,posz-POSITION, 0.0,1.0,0.0); GLfloat light_position[] = { 0.0, 10.0 , posz, 1.0 }; glLightfv(GL_LIGHT1, GL_POSITION, light_position); @@ -223,22 +252,26 @@ void draw(Track &t, uint8 diff) glEnd(); glDisable(GL_TEXTURE_2D); - //Draw the position bar - glMatrixMode(GL_MODELVIEW); + glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(0,0,posz); - glBegin(GL_QUADS); - glColor3f(0.8, 0.8, 0.8); - glNormal3f(0, 1, 0); - glVertex3f( NECKWIDTH,0, 1); - glVertex3f( NECKWIDTH,0.2, 0); - glVertex3f(-NECKWIDTH,0.2, 0); - glVertex3f(-NECKWIDTH,0, 1); - glVertex3f( NECKWIDTH,0.2, 0); - glVertex3f( NECKWIDTH,0, -1); - glVertex3f(-NECKWIDTH,0, -1); - glVertex3f(-NECKWIDTH,0.2, 0); - glEnd(); + //draw the strings + for (int i = 0 ; i < 5 ; i++) + { + glBegin(GL_QUADS); + glColor3f(0.2, 0.2, 0.2); + glNormal3f(0, 1, 0); + glVertex3f(NOTEDIST*(i-2), 0, 1); + glVertex3f(NOTEDIST*(i-2)+.1,0.2, 1); + glVertex3f(NOTEDIST*(i-2)+.1,0.2,-VIEWLENGTH); + glVertex3f(NOTEDIST*(i-2),0, -VIEWLENGTH); + glVertex3f(NOTEDIST*(i-2)+.1, 0.2, 1); + glVertex3f(NOTEDIST*(i-2)+.2,0, 1); + glVertex3f(NOTEDIST*(i-2)+.2,0,-VIEWLENGTH); + glVertex3f(NOTEDIST*(i-2)+.1,0.2, -VIEWLENGTH); + glEnd(); + } + //Draw the sides glBegin(GL_QUADS); glColor3f(0.8, 0.8, 0.8); glNormal3f(0, 1, 0); @@ -263,15 +296,33 @@ void draw(Track &t, uint8 diff) glVertex3f(-NECKWIDTH-.2,0,-VIEWLENGTH); glVertex3f(-NECKWIDTH-.1,0.2, -VIEWLENGTH); glEnd(); - fromKeyboard.display(); glPopMatrix(); - + //draw the frets t.drawFrets(postime); // Draw the notes t.drawNotes(postime, diff); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef(0,0,posz); + //Draw the position bar + glBegin(GL_QUADS); + glColor3f(0.8, 0.8, 0.8); + glNormal3f(0, 1, 0); + glVertex3f( NECKWIDTH,0.5, 10); + glVertex3f( NECKWIDTH,0.5, 0); + glVertex3f(-NECKWIDTH,0.5, 0); + glVertex3f(-NECKWIDTH,0.5, 10); + glVertex3f( NECKWIDTH,0.5, 0); + glVertex3f( NECKWIDTH,0, -1); + glVertex3f(-NECKWIDTH,0, -1); + glVertex3f(-NECKWIDTH,0.5, 0); + glEnd(); + fromKeyboard.display(); + glPopMatrix(); + SDL_GL_SwapBuffers(); } @@ -304,8 +355,21 @@ void handleKeyOff(keys k) if (fromKeyboard.getPosition() == -1) return; - struct timeval now; - gettimeofday(&now, NULL); +#ifdef WIN32 + struct { int tv_sec, tv_usec; } now; + DWORD t; +#else + struct timeval now; +#endif + +#ifdef WIN32 + t = timeGetTime (); + now.tv_sec = t / 1000; + now.tv_usec = (t % 1000) * 1000; +#else + gettimeofday(&now, NULL); +#endif + double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0; fromKeyboard.setEnd(postime); cout << fromKeyboard << endl; @@ -324,8 +388,21 @@ void handleKeys(bool a, bool b, bool c, bool d, bool e) void handleStrokeOn() { - struct timeval now; - gettimeofday(&now, NULL); +#ifdef WIN32 + struct { int tv_sec, tv_usec; } now; + DWORD t; +#else + struct timeval now; +#endif + +#ifdef WIN32 + t = timeGetTime (); + now.tv_sec = t / 1000; + now.tv_usec = (t % 1000) * 1000; +#else + gettimeofday(&now, NULL); +#endif + double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0; //cout << postime << endl; @@ -371,7 +448,7 @@ bool processEvents() case SDL_KEYDOWN: keystate = SDL_GetKeyState(NULL); - handleKeys(keystate[SDLK_a], keystate[SDLK_z], keystate[SDLK_e], keystate[SDLK_r], keystate[SDLK_t]); + handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]); switch(((SDL_KeyboardEvent *)(&event))->keysym.sym) { case SDLK_ESCAPE: @@ -382,12 +459,12 @@ bool processEvents() case SDLK_DOWN: SECONDSIZE -=1; break; - case SDLK_LEFT: +/* case SDLK_LEFT: posy +=1; break; case SDLK_RIGHT: posy -=1; - break; + break;*/ case SDLK_KP_PLUS: Mixer::getInstance()->setMusicVolume(Mixer::getInstance()->getMusicVolume() + 10); Mixer::getInstance()->setSoundVolume(Mixer::getInstance()->getSoundVolume() + 10); @@ -422,19 +499,19 @@ bool processEvents() case SDL_KEYUP: switch(((SDL_KeyboardEvent *)(&event))->keysym.sym) { - case SDLK_a: + case SDLK_F1: handleKeyOff(KEY0); break; - case SDLK_z: + case SDLK_F2: handleKeyOff(KEY1); break; - case SDLK_e: + case SDLK_F3: handleKeyOff(KEY2); break; - case SDLK_r: + case SDLK_F4: handleKeyOff(KEY3); break; - case SDLK_t: + case SDLK_F5: handleKeyOff(KEY4); break; case SDLK_SPACE: @@ -444,7 +521,7 @@ bool processEvents() break; } keystate = SDL_GetKeyState(NULL); - handleKeys(keystate[SDLK_a], keystate[SDLK_z], keystate[SDLK_e], keystate[SDLK_r], keystate[SDLK_t]); + handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]); break; default: // lasteventtype = OTHER; @@ -522,7 +599,14 @@ int main(int argc, char *argv[]) Mixer::getInstance()->playSound("guitar"); if (rhythm) Mixer::getInstance()->playSound("rhythm"); - gettimeofday(&start, NULL); + +#ifdef WIN32 + t = timeGetTime (); + start.tv_sec = t / 1000; + start.tv_usec = (t % 1000) * 1000; +#else + gettimeofday(&start, NULL); +#endif /* Sound music; cout << "Load sounds" << endl;