acoustic_vr_noimu.cpp
Go to the documentation of this file.
00001 /*===============================================================================================
00002  3D Demo Example
00003  Copyright (c), Firelight Technologies Pty, Ltd 2005-2011.
00004 
00005  Example to show occlusion
00006 ===============================================================================================*/
00007 #include <iostream>
00008 #include <fmod/fmod.hpp>
00009 #include <fmod/fmod_errors.h>
00010 #include <fmod/fmod_event.hpp>
00011 #include <fmod/fmod_event_net.hpp>
00012 #include <labust/xml/GyrosWriter.hpp>
00013 #include <moos/MoosConfig.hpp>
00014 #include <moos/GyrosMoosCommsInterface.h>
00015 //#include <windows.h>
00016 #include <boost/algorithm/string.hpp>
00017 
00018 #include <GL/glut.h>
00019 #include <SOIL/SOIL.h>
00020 
00021 #include <math.h>
00022 #include <string.h>
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <stack>
00026 #include <string>
00027 #include <fstream>
00028 #include <sstream>
00029 #include <JoystickReader.h>
00030 #include <time.h>
00031 
00032 //#include <crtdbg.h>
00033 
00034 LABUST::JoystickReader *joystick;
00035 LABUST::COMMUNICATION::GyrosMoosCommsInterface *comms;
00036 std::string filterMessageLabel;
00037 std::string rovMessageLabel;
00038 std::string dvlMessageLabel;
00039 std::string TARGETMessageLabel;
00040 namespace FMOD
00041 {
00042 
00043 //#define SHOW_GUI_DEBUG_TEXT
00044 #define GL_CLAMP_TO_EDGE 0x812F
00045 #define FMOD_INIT_DSOUND_HRTFFULL 0x00000800
00046 
00047 //time_t start_time;
00048 //time(&start_time);
00049 //std::ofstream file("C:/Documents and Settings/Toni/Desktop/Doktorski Logs/Log_Doc.txt");
00050 std::ofstream file("files/Log_Doc.txt");
00051 
00052 std::stringstream converter;
00053 float Head;
00054 float HeadIni=0.0f;
00055 
00056 unsigned char key1 =0;
00057 
00058 void ERRCHECK(FMOD_RESULT result)
00059 {
00060     if (result != FMOD_OK)
00061     {
00062         printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
00063         exit(-1);
00064     }
00065 }
00066 
00067 int INTERFACE_UPDATETIME = 15; // milliseconds
00068 
00069 int intMax = 32767;
00070 int r;
00071 int iDiter = 0;
00072 int KDiterTime = 1;
00073 float AmpDiter = 0.0f;
00074 float FreqDiter = 1.0f;
00075 float tDiter[13] ={10,15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70};
00076 float FiDiter[13] = {0, 15, -10, -25, 0, 5, -15, 15, -10, -3, -10, 5, 0};
00077 float ti=0;
00078 float Integral=0.0f;
00079 bool fullscreen = false;
00080 bool wait = false;
00081 
00082 float forw=0.0f;
00083 float InputStoh=0.0f;
00084 int InputStoh1=0;
00085 double lastObjectLong = 0.0;
00086 double zPos = 0.0;
00087 float aSQR = 1.0f;
00088 float bSQR = 0.0f;
00089 float cSQR = 0.0f;
00090 // varijable koje se trebaju primiti iz MOOSa
00091 float Altitude = 2.5f;
00092 float ROVLat = 43.5f;
00093 float ROVLong = 15.5f;
00094 float ROVHeading = 0.0f;
00095 float ROVRoll = 0.0f;
00096 float ROVPitch = 0.0f;
00097 float Depth = 0.0f;
00098 float VelVec = 0.0f;
00099 float HE = 0.0f;
00100 
00101 // varijable koje se upisu "Rucno"
00102 float AltitudeSetPoint = 10.0f;
00103 bool TrajectoryTracking = false;
00104 float ObjectLat = 43.5;
00105 float ObjectLong = 15.5;
00106 float ObjectDepth = 20.0f;
00107 float Doppler = 100.0f;
00108 float SilenceAngle = 0.00f;
00109 float VerbalAngle = 5.00f;
00110 float NonLinearCoeff = 1.0f;
00111 float NonLinearCoeffDist = 1.0f;
00112 float TransformAngle = 0.00f;
00113 float PathVelocity = 0.0f;
00114 float Ki = 0.0f;
00115 int Sound=0;
00116 int GuidanceMode = 1;
00117 int TaskMode = 1;
00118 int JoyStickMode=1;
00119 char SpeedProfile='C';
00120 float velAtitude = 0.0f;
00121 float lastvelAtitude = 0.0f;
00122 float PathStartX = 10.0f;
00123 float PathStartY = 10.0f;
00124 float PathStartX1 = 0.0f;
00125 float PathStartY1 = 0.0f;
00126 float PathX = 0.0f;
00127 float PathY = 0.0f;
00128 float DistanceToPath = 0.0f;
00129 float RabbitDistance = 0.0f;
00130 float RabbitNorth = 0;
00131 float RabbitNorth1 = 0;
00132 float RabbitNorth2 = 0;
00133 float RabbitNorthOld = 0;
00134 float RabbitEast = 0;
00135 float RabbitEastOld = 0;
00136 float HeadingErr = 0.0f;
00137 float TauX = 0.0f;
00138 float TauY = 0.0f;
00139 float TauZ = 0.0f;
00140 float TauK = 0.0f;
00141 float TauM = 0.0f;
00142 float TauN = 0.0f;
00143 float frwVelVector = 0.0f;
00144 float latVelVector = 0.0f;
00145 float zVelVector = 0.0f;
00146 
00147 // definiranje Way Pointa
00148 int NumberOfWP = 15;
00149 const int MaxNumberOfWP = 15;
00150 //int mode = 1;// za lawnmover mode, mode = 0
00151 int WPindex = 1;
00152 int ActualWPindex = 1;
00153 int ActualWPindexOld = 1;
00154 float WPnorth[MaxNumberOfWP];// ={43.823023f, 43.822942f, 43.823321f, 43.823023f};
00155 float WPeast[MaxNumberOfWP];// = {15.570909f, 15.570321f, 15.570435f,15.570909f};
00156 float WPz[MaxNumberOfWP];
00157 
00158 
00159 // window size
00160 int width = 500;
00161 int height = 500;
00162 
00163 // mouse control
00164 bool doRotate = false;
00165 int xMouse = 0;
00166 int yMouse = 0;
00167 
00168 // listener orientation
00169 float xRotation = 0.0f; // Roll
00170 float yRotation = 0.0f; //Heading
00171 float zRotation = 0.0f; //Pitch
00172 float lastyRotation = 0.0f;
00173 
00174 // listener position
00175 float xListenerPos = 0.0f;
00176 //TONI ustvari su y i z zamjenjeni
00177 float yListenerPos = 50.0f; //ovo je Z
00178 float zListenerPos = 20.0f; //ovo je Y
00179 float DirectionToTarget = 0.0f;
00180 float zListenerPosRel = 0.0f;
00181 float xListenerPosRel = 0.0f;
00182 
00183 // keyboard control
00184 bool moveForward    = false;
00185 bool moveBackward   = false;
00186 bool moveRotateClock    = false;
00187 bool moveRotateAntiClock   = false;
00188 bool moveLeft       = false;
00189 bool moveRight      = false;
00190 bool moveUp         = false;
00191 bool moveDown       = false;
00192 bool moveFast       = false;
00193 bool ambientVolUp   = false;
00194 bool ambientVolDown = false;
00195 bool masterVolUp    = false;
00196 bool masterVolDown  = false;
00197 
00198 #undef PI
00199 const float PI = 3.14159265f;
00200 
00201 float accumulatedTime = 0.0f;
00202 
00203 // textures
00204 GLuint texture;
00205 GLuint skyboxTexture[6];
00206 
00207 // sounds placement
00208 struct Object
00209 {
00210         float xPos;
00211         float yPos;
00212         float zPos;
00213         float intensity;
00214         int sound;
00215     FMOD::Event *event;
00216 };
00217 
00218 const int NUM_OBJECTS = 8;
00219 Object objects[NUM_OBJECTS] =
00220 {
00221         //{  -11.0f,    10.0f,    0.0f,    1.0f,    0,    0 },
00222         {   0.0f,     10.0f,    0.0f,    1.0f,    0,    0 }, //Toni: IZVOR ZVUKA JE ISHODISTE KOORDINATNOG SUSTAVA
00223         {   0.0f,    10.0f,    0.0f,    1.0f,    1,    0 },
00224         {   45.0f,    10.0f,    0.0f,    1.0f,    3,    0 },
00225         {  -30.0f,    1.0f,   21.0f,    1.0f,    2,    0 },
00226         {  -30.0f,    1.0f,  -21.0f,    1.0f,    3,    0 },
00227         {   12.0f,    1.0f,  -27.0f,    1.0f,    0,    0 },
00228         {    0.0f,    10.0f,   0.0f,    1.0f,    0,    0 },
00229         {    0.0f,    10.0f,   0.0f,    1.0f,    1,    0 },
00230 };
00231 
00232 // geometry structers for loading and drawing
00233 struct Polygon
00234 {
00235         int numVertices;
00236         int indicesOffset;
00237         float directOcclusion;
00238         float reverbOcclusion;
00239         FMOD_VECTOR normal;
00240 };
00241 
00242 struct Mesh
00243 {
00244         int numVertices;
00245         FMOD_VECTOR *vertices;
00246         float (*texcoords)[2];
00247         int numPolygons;
00248         Polygon* polygons;
00249         int numIndices;
00250         int *indices;
00251         FMOD::Geometry *geometry;
00252 };
00253 
00254 class GlutCloseClass
00255 {
00256   public:
00257     GlutCloseClass() {};
00258    ~GlutCloseClass();
00259 };
00260 
00261 
00262 GlutCloseClass gCloseObject;
00263 
00264 Mesh walls;
00265 Mesh rotatingMesh;
00266 
00267 // fmod sounds structures
00268 FMOD::EventSystem     *fmodEventSystem    = 0;
00269 FMOD::EventProject    *fmodEventProject   = 0;
00270 FMOD::EventGroup      *fmodEventGroup     = 0;
00271 FMOD::EventParameter  *fmodEventParameter = 0;
00272 FMOD::System          *fmodSystem         = 0;
00273 FMOD::Geometry        *geometry           = 0;
00274 FMOD::DSP             *global_lowpass     = 0;
00275 
00276 float   ambientVolume   = 0.2f;
00277 float   masterVolume;
00278 
00279 /*
00280     Global stack of strings to render
00281 */
00282 #ifdef SHOW_GUI_DEBUG_TEXT
00283 std::stack<std::string> debugText;
00284 std::stack<std::string> statusText;
00285 #endif
00286 
00287 GLenum  rendermode = GL_FILL;
00288 
00289 bool showdebug = false;
00290 bool showhelp = false;
00291 
00292 void outputText(int x, int y, std::string text)
00293 {
00294         int i;
00295         const char *txt = text.c_str();
00296 
00297         glRasterPos2f(x, y);
00298         for (i = 0; i < (int)text.length(); i++)
00299         {
00300                 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, txt[i]);
00301         }
00302 }
00303 
00304 #ifdef SHOW_GUI_DEBUG_TEXT
00305 void renderText(int x, int y, std::stack<std::string> *text)
00306 {
00307     glColor3f(1.0f, 1.0f, 1.0f);
00308     for (int count = 0; count < text->size(); count++)
00309     {
00310         outputText(x, y, text->top());
00311         text->pop();
00312 
00313         y -= 17;
00314     }
00315 }
00316 #endif
00317 
00318 void renderUiText()
00319 {
00320     /*
00321         Render help text
00322     */
00323     if (showhelp)
00324     {
00325         int x = 10;
00326         int y = height - 20;
00327 
00328         glColor3f(1.0f, 1.0f, 1.0f);
00329         outputText(x, y,     "F1   - Toggle help");
00330         outputText(x, y-=18, "F2   - Toggle fullscreen");
00331         outputText(x, y-=18, "F3   - Toggle wireframe rendering");
00332         outputText(x, y-=18, "F11  - Toggle debug info");
00333         outputText(x, y-=18, "--");
00334         outputText(x, y-=18, "w     - Move forward");
00335         outputText(x, y-=18, "s     - Move backward");
00336         outputText(x, y-=18, "a     - Move left");
00337         outputText(x, y-=18, "d     - Move right");
00338         outputText(x, y-=18, "space - Move up");
00339         outputText(x, y-=18, "c     - Move down");
00340         outputText(x, y-=18, "Mouse (hold left button) - look direction");
00341         outputText(x, y-=18, "--");
00342   //      outputText(x, y-=18, "V/v   - Master volume up/down");
00343         outputText(x, y-=18, "Z/z   - Ambient sound volume up/down");
00344     }
00345     else
00346     {
00347         glColor3f(1.0f, 1.0f, 1.0f);
00348         outputText(10, height - 20, "F1 - Help");
00349     }
00350 
00351     /*
00352         Render debug text
00353     */
00354 #ifdef SHOW_GUI_DEBUG_TEXT
00355     if (showdebug)
00356     {
00357         renderText(width - (width/2), height - 20, &debugText);
00358     }
00359     else
00360     {
00361         /*
00362             Otherwise just pop everything off the stack
00363         */
00364         for (int count = 0; count < debugText.size(); count++)
00365         {
00366             debugText.pop();
00367         }
00368     }
00369 
00370     /*
00371         Render status text
00372     */
00373     renderText(10, 20, &statusText);
00374 #endif
00375 }
00376 
00377 void initGeometry(const char* szFileName, Mesh& mesh, bool alter = false)
00378 {
00379         FMOD_RESULT result;
00380 
00381         FILE* file = fopen(szFileName, "rb");
00382         if (file)
00383         {
00384                 // read vertices
00385                 fread(&mesh.numVertices, sizeof (mesh.numVertices), 1, file);
00386                 mesh.vertices = new FMOD_VECTOR[mesh.numVertices];
00387                 mesh.texcoords = new float[mesh.numVertices][2];
00388                 fread(mesh.vertices, sizeof (float) * 3, mesh.numVertices, file);
00389                 fread(mesh.texcoords, sizeof (float) * 2, mesh.numVertices, file);
00390 
00391 
00392                 fread(&mesh.numIndices, sizeof (mesh.numIndices), 1, file);
00393                 mesh.indices = new int[mesh.numIndices];
00394                 fread(mesh.indices, sizeof (int), mesh.numIndices, file);
00395 
00396 
00397                 fread(&mesh.numPolygons, sizeof (mesh.numPolygons), 1, file);
00398                 mesh.polygons = new Polygon[mesh.numPolygons];
00399 
00400                 // read polygons
00401                 for (int poly = 0; poly < mesh.numPolygons; poly++)
00402                 {
00403                         Polygon* polygon = &mesh.polygons[poly];
00404 
00405 
00406                         fread(&polygon->numVertices, sizeof (polygon->numVertices), 1, file);
00407                         fread(&polygon->indicesOffset, sizeof (polygon->indicesOffset), 1, file);
00408                         fread(&polygon->directOcclusion, sizeof (polygon->directOcclusion), 1, file);
00409                         fread(&polygon->reverbOcclusion, sizeof (polygon->reverbOcclusion), 1, file);
00410 
00411                         int* indices = &mesh.indices[polygon->indicesOffset];
00412 
00413                         // calculate polygon normal
00414                         float xN = 0.0f;
00415                         float yN = 0.0f;
00416                         float zN = 0.0f;
00417                         // todo: return an error if a polygon has less then 3 vertices.
00418                         for (int vertex = 0; vertex < polygon->numVertices - 2; vertex++)
00419                         {
00420                                 float xA = mesh.vertices[indices[vertex + 1]].x -mesh.vertices[indices[0]].x;
00421                                 float yA = mesh.vertices[indices[vertex + 1]].y -mesh.vertices[indices[0]].y;
00422                                 float zA = mesh.vertices[indices[vertex + 1]].z -mesh.vertices[indices[0]].z;
00423                                 float xB = mesh.vertices[indices[vertex + 2]].x -mesh.vertices[indices[0]].x;
00424                                 float yB = mesh.vertices[indices[vertex + 2]].y -mesh.vertices[indices[0]].y;
00425                                 float zB = mesh.vertices[indices[vertex + 2]].z -mesh.vertices[indices[0]].z;
00426                                 // cross product
00427                                 xN += yA * zB - zA * yB;
00428                                 yN += zA * xB - xA * zB;
00429                                 zN += xA * yB - yA * xB;
00430                         }
00431                         float fMagnidued = (float)sqrt(xN * xN + yN * yN + zN * zN);
00432                         if (fMagnidued > 0.0f) // a tollerance here might be called for
00433                         {
00434                                 xN /= fMagnidued;
00435                                 yN /= fMagnidued;
00436                                 zN /= fMagnidued;
00437                         }
00438                         polygon->normal.x = xN;
00439                         polygon->normal.y = yN;
00440                         polygon->normal.z = zN;
00441                 }
00442                 fclose(file);
00443         }
00444 
00445         result = fmodSystem->createGeometry(mesh.numPolygons, mesh.numIndices, &mesh.geometry);
00446         ERRCHECK(result);
00447 
00448     /*
00449         Tell FMOD about the geometry
00450     */
00451         for (int poly = 0; poly < mesh.numPolygons; poly++)
00452         {
00453                 Polygon* polygon = &mesh.polygons[poly];
00454                 FMOD_VECTOR vertices[16];
00455                 for (int i = 0; i < polygon->numVertices; i++)
00456                         vertices[i] = mesh.vertices[mesh.indices[polygon->indicesOffset + i]];
00457                 int polygonIndex = 0;
00458 
00459         if (alter && polygon->directOcclusion == 0.85f)
00460         {
00461      //       polygon->directOcclusion = 0.95f;
00462         }
00463 
00464                 result = mesh.geometry->addPolygon(
00465                         polygon->directOcclusion,
00466                         polygon->reverbOcclusion,
00467                         false, // single sided
00468                         polygon->numVertices,
00469                         vertices,
00470                         &polygonIndex);
00471                 ERRCHECK(result);
00472         }
00473 }
00474 
00475 
00476 void freeGeometry(Mesh& mesh)
00477 {
00478     mesh.geometry->release();
00479 
00480     delete [] mesh.vertices;
00481         delete [] mesh.texcoords;
00482         delete [] mesh.polygons;
00483         delete [] mesh.indices;
00484 }
00485 
00486 
00487 void inWater()
00488 {
00489     FMOD_RESULT result;
00490     FMOD_REVERB_PROPERTIES reverbprops;
00491     static bool inwater = false;
00492 
00493     if (xListenerPos > -14.75f && xListenerPos < -7.6f
00494         && zListenerPos > -10.85f && zListenerPos < -3.75f
00495         && yListenerPos < 5.0f)
00496     {
00497         /*
00498             Use opengl fog to make it look like we are in water
00499         */
00500         if (!inwater)
00501         {
00502             glEnable(GL_FOG);
00503 
00504             result = fmodEventSystem->getReverbPreset("UnderWater", &reverbprops);
00505             ERRCHECK(result);
00506             result = fmodEventSystem->setReverbProperties(&reverbprops);
00507             ERRCHECK(result);
00508             result = global_lowpass->setBypass(false);
00509             ERRCHECK(result);
00510 
00511             inwater = true;
00512         }
00513     }
00514     else
00515     {
00516         /*
00517             Disable fog (water)
00518         */
00519         if (inwater)
00520         {
00521             glDisable(GL_FOG);
00522 
00523             result = fmodEventSystem->getReverbPreset("StdReverb", &reverbprops);
00524             ERRCHECK(result);
00525             result = fmodEventSystem->setReverbProperties(&reverbprops);
00526             ERRCHECK(result);
00527             if (global_lowpass)
00528             {
00529                 result = global_lowpass->setBypass(true);
00530                 ERRCHECK(result);
00531             }
00532 
00533             inwater = false;
00534         }
00535     }
00536 }
00537 
00538 
00539 void drawSkyBox()
00540 {
00541     glPushMatrix();
00542         glTranslatef(xListenerPos, 0.0f, yListenerPos);
00543         glDisable(GL_LIGHTING);
00544         /*
00545             Walls
00546         */
00547         glBindTexture(GL_TEXTURE_2D, skyboxTexture[0]);
00548         glBegin(GL_QUADS);
00549             glTexCoord2f(1.0f, 1.0f); glVertex3f(-150.0f, -150.0f, -150.0f);
00550             glTexCoord2f(1.0f, 0.0f); glVertex3f(-150.0f, 150.0f, -150.0f);
00551             glTexCoord2f(0.0f, 0.0f); glVertex3f(150.0f, 150.0f, -150.0f);
00552             glTexCoord2f(0.0f, 1.0f);  glVertex3f(150.0f, -150.0f, -150.0f);
00553         glEnd();
00554 
00555         glBindTexture(GL_TEXTURE_2D, skyboxTexture[1]);
00556         glBegin(GL_QUADS);
00557             glTexCoord2f(1.0f, 1.0f); glVertex3f(150.0f, -150.0f, -150.0f);
00558             glTexCoord2f(1.0f, 0.0f); glVertex3f(150.0f, 150.0f,-150.0f);
00559             glTexCoord2f(0.0f, 0.0f); glVertex3f(150.0f, 150.0f, 150.0f);
00560             glTexCoord2f(0.0f, 1.0f); glVertex3f(150.0f, -150.0f, 150.0f);
00561         glEnd();
00562 
00563         glBindTexture(GL_TEXTURE_2D, skyboxTexture[2]);
00564         glBegin(GL_QUADS);
00565             glTexCoord2f(0.0f, 1.0f); glVertex3f(-150.0f, -150.0f, 150.0f);
00566             glTexCoord2f(0.0f, 0.0f); glVertex3f(-150.0f, 150.0f, 150.0f);
00567             glTexCoord2f(1.0f, 0.0f); glVertex3f(150.0f, 150.0f, 150.0f);
00568             glTexCoord2f(1.0f, 1.0f); glVertex3f(150.0f, -150.0f, 150.0f);
00569         glEnd();
00570 
00571         glBindTexture(GL_TEXTURE_2D, skyboxTexture[3]);
00572         glBegin(GL_QUADS);
00573             glTexCoord2f(0.0f, 1.0f); glVertex3f(-150.0f, -150.0f, -150.0f);
00574             glTexCoord2f(0.0f, 0.0f); glVertex3f(-150.0f, 150.0f, -150.0f);
00575             glTexCoord2f(1.0f, 0.0f); glVertex3f(-150.0f, 150.0f, 150.0f);
00576             glTexCoord2f(1.0f, 1.0f); glVertex3f(-150.0f, -150.0f, 150.0f);
00577         glEnd();
00578 
00579         /*
00580             Top
00581         */
00582         glBindTexture(GL_TEXTURE_2D, skyboxTexture[4]);
00583         glBegin(GL_QUADS);
00584             glTexCoord2f(1.0f, 0.0f); glVertex3f(-150.0f, 150.0f, -150.0f);
00585             glTexCoord2f(1.0f, 1.0f); glVertex3f(150.0f, 150.0f, -150.0f);
00586             glTexCoord2f(0.0f, 1.0f); glVertex3f(150.0f, 150.0f, 150.0f);
00587             glTexCoord2f(0.0f, 0.0f); glVertex3f(-150.0f, 150.0f, 150.0f);
00588         glEnd();
00589 
00590         /*
00591             Bottom
00592         */
00593         glBindTexture(GL_TEXTURE_2D, skyboxTexture[5]);
00594         glBegin(GL_QUADS);
00595             glTexCoord2f(0.0f, 1.0f); glVertex3f(-150.0f, -150.0f, -150.0f);
00596             glTexCoord2f(0.0f, 0.0f); glVertex3f(150.0f, -150.0f, -150.0f);
00597             glTexCoord2f(1.0f, 0.0f); glVertex3f(150.0f, -150.0f, 150.0f);
00598             glTexCoord2f(1.0f, 1.0f); glVertex3f(-150.0f, -150.0f, 150.0f);
00599         glEnd();
00600 
00601         glEnable(GL_LIGHTING);
00602     glPopMatrix();
00603 }
00604 
00605 void drawWaterRoom()
00606 {
00607     glBlendFunc( GL_SRC_ALPHA, GL_ONE );
00608     glEnable(GL_BLEND);
00609 
00610     glPushMatrix();
00611         glColor4f(0.0f,0.1f,0.8f,1.0f);
00612         glDisable(GL_LIGHTING);
00613 
00614         glBegin(GL_QUADS);
00615             glVertex3f(-14.72f, 4.0f, -10.85f);
00616             glVertex3f(-7.68f, 4.0f, -10.85f);
00617             glVertex3f(-7.68f, 4.0f, -3.85f);
00618             glVertex3f(-14.72f, 4.0f, -3.85f);
00619         glEnd();
00620 
00621         glEnable(GL_LIGHTING);
00622     glPopMatrix();
00623 
00624     glDisable(GL_BLEND);
00625 }
00626 
00627 void drawGeometry(Mesh& mesh)
00628 {
00629         FMOD_RESULT result;
00630 
00631         FMOD_VECTOR pos;
00632         result = mesh.geometry->getPosition(&pos);
00633         ERRCHECK(result);
00634 
00635         glPushMatrix();
00636         // create matrix and set gl transformation for geometry
00637         glTranslatef(pos.x, pos.y, pos.z);
00638         FMOD_VECTOR forward;
00639         FMOD_VECTOR up;
00640         result = mesh.geometry->getRotation(&forward, &up);
00641         ERRCHECK(result);
00642         float matrix[16] =
00643         {
00644                 up.y * forward.z - up.z * forward.y,            up.x,           forward.x,              0.0f,
00645                 up.z * forward.x - up.x * forward.z,            up.y,           forward.y,              0.0f,
00646                 up.x * forward.y - up.y * forward.x,            up.z,           forward.z,              0.0f,
00647                 0.0f,                                                                           0.0f,           0.0f,                   1.0f,
00648         };
00649         glMultMatrixf(matrix);
00650 
00651         // draw all polygons in object
00652         glEnable(GL_LIGHTING);
00653         glPolygonMode(GL_FRONT_AND_BACK, rendermode);
00654         for (int poly = 0; poly < mesh.numPolygons; poly++)
00655         {
00656                 Polygon* polygon = &mesh.polygons[poly];
00657                 if (polygon->directOcclusion == 0.0f)
00658         {
00659                         continue; // don't draw because it is an open door way
00660         }
00661                 glBegin(GL_TRIANGLE_FAN);
00662                 glNormal3fv(&polygon->normal.x);
00663 
00664                 for (int i = 0; i < polygon->numVertices; i++)
00665                 {
00666                         int index = mesh.indices[polygon->indicesOffset + i];
00667                         glTexCoord2f(mesh.texcoords[index][0], mesh.texcoords[index][1]);
00668                         glVertex3fv(&mesh.vertices[index].x);
00669                 }
00670                 glEnd();
00671         }
00672         glPopMatrix();
00673 }
00674 
00675 void initObjects()
00676 {
00677     FMOD_RESULT result;
00678         // TONI pozivanje zvukova
00679     if (GuidanceMode < 3)
00680                 {if (Sound==0)
00681                 {result = fmodEventGroup->getEvent("PinkNew 500m", FMOD_EVENT_DEFAULT, &objects[0].event);
00682     ERRCHECK(result);
00683 
00684     result = fmodEventGroup->getEvent("Click1 500m", FMOD_EVENT_DEFAULT, &objects[1].event);
00685         ERRCHECK(result);}
00686                 else
00687                 {{result = fmodEventGroup->getEvent("PinkNew 500m", FMOD_EVENT_DEFAULT, &objects[1].event);
00688     ERRCHECK(result);
00689 
00690     result = fmodEventGroup->getEvent("Click1 500m", FMOD_EVENT_DEFAULT, &objects[0].event);
00691         ERRCHECK(result);}}
00692         }
00693 
00694     if (GuidanceMode > 1 && GuidanceMode < 4)
00695                 {
00696                         result = fmodEventGroup->getEvent("up", FMOD_EVENT_DEFAULT, &objects[2].event);
00697     ERRCHECK(result);
00698 
00699     result = fmodEventGroup->getEvent("down", FMOD_EVENT_DEFAULT, &objects[3].event);
00700     ERRCHECK(result);
00701         }
00702 
00703     if (GuidanceMode > 2)
00704                 {result = fmodEventGroup->getEvent("left", FMOD_EVENT_DEFAULT, &objects[4].event);
00705     ERRCHECK(result);
00706 
00707     result = fmodEventGroup->getEvent("right", FMOD_EVENT_DEFAULT, &objects[5].event);
00708     ERRCHECK(result);
00709         }
00710 
00711     if (TaskMode == 3)
00712                 {//result = fmodEventGroup->getEvent("3DSoundEmit", FMOD_EVENT_DEFAULT, &objects[6].event);
00713                         if (Sound==0)
00714                         {result = fmodEventGroup->getEvent("PinkNew", FMOD_EVENT_DEFAULT, &objects[6].event);
00715                 ERRCHECK(result);
00716                 result = fmodEventGroup->getEvent("Click1", FMOD_EVENT_DEFAULT, &objects[7].event);
00717                 ERRCHECK(result);}
00718                         else
00719                         {result = fmodEventGroup->getEvent("PinkNew", FMOD_EVENT_DEFAULT, &objects[7].event);
00720                 ERRCHECK(result);
00721                 result = fmodEventGroup->getEvent("Click1", FMOD_EVENT_DEFAULT, &objects[6].event);
00722                 ERRCHECK(result);}
00723         }
00724 
00725 
00726         for (int i=0; i < NUM_OBJECTS-1; i++)
00727         {
00728                 FMOD_VECTOR pos = { objects[i].xPos, objects[i].yPos, objects[i].zPos };
00729                 FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };
00730 
00731         if (objects[i].event)
00732         {
00733                     //TONI izgleda kao prerada zvuka u 3D na osnovu pozicije i velocity (brzina kretanja) izvora zvuka?
00734                         result = objects[i].event->set3DAttributes(&pos, &vel);
00735                     ERRCHECK(result);
00736 
00737                         //TONI izgleda kao pokretanje zvuka
00738                         result = objects[i].event->start();
00739             ERRCHECK(result);
00740         }
00741         }
00742 }
00743 
00744 
00745 void updateObjectSoundPos(Object* object)
00746 {
00747     FMOD_RESULT result;
00748 
00749     if (object->event)
00750     {
00751 
00752                 //TONI nova pozicija izvora zvuka
00753                 FMOD_VECTOR pos = { object->xPos, object->yPos, object->zPos };
00754             FMOD_VECTOR oldPos;
00755         object->event->get3DAttributes(&oldPos, 0);
00756 
00757                 //TONI racunanje brzine kretanja izvora zvuka
00758             FMOD_VECTOR vel;
00759             vel.x = 0;//(pos.x - oldPos.x) *  (1000.0f / (float)INTERFACE_UPDATETIME);
00760             vel.y = 0;//(pos.y - oldPos.y) *  (1000.0f / (float)INTERFACE_UPDATETIME);
00761             vel.z = 0;//(pos.z - oldPos.z) *  (1000.0f / (float)INTERFACE_UPDATETIME);
00762         result = object->event->set3DAttributes(&pos, &vel);
00763 
00764 //      ERRCHECK(result);
00765     }
00766 }
00767 
00768 
00769 void mouseFunc(int button, int state, int x, int y)
00770 {
00771         switch (button)
00772         {
00773         case GLUT_LEFT_BUTTON:
00774                 if (state == GLUT_DOWN)
00775                 {
00776                         doRotate = true;
00777                         xMouse = x;
00778                         yMouse = y;
00779                 }
00780                 else
00781                 if (state == GLUT_UP)
00782                 {
00783                         doRotate = false;
00784                 }
00785                 break;
00786 
00787         default:
00788                 break;
00789         }
00790 }
00791 
00792 void motionFunc(int x, int y)
00793 {
00794         //TONI s misom se moze rotirati a ne kretati naprijed-nazad
00795         std::string SingleLog;
00796         int test = 0;
00797 
00798         int dx = x - xMouse;
00799         int dy = y - yMouse;
00800 
00801         // view rotation about y-axis
00802         yRotation += (float)dx * 0.5f;
00803         if (yRotation > 180.0f)
00804                 yRotation -= 360.0f;
00805         else
00806         if (yRotation < -180.0f)
00807                 yRotation += 360.0f;
00808 
00809         // view rotation about x-axis
00810         const float xExtent = 88.0f;
00811         //TONI izmjena u redu ispod, da se ne mice gore-dolje vec samo lijevo-desno
00812         xRotation += 0.0f;//(float)dy * 0.5f;
00813         if (xRotation > xExtent)
00814                 xRotation = xExtent;
00815         else
00816         if (xRotation < -xExtent)
00817                 xRotation = -xExtent;
00818 
00819         converter<<dx;
00820         converter>>SingleLog;
00821         converter.clear();
00822         file<<SingleLog+' ';
00823         converter<<dy;
00824         converter>>SingleLog;
00825         converter.clear();
00826         file<<SingleLog+' ';
00827 
00828         xMouse = x;
00829         yMouse = y;
00830 }
00831 
00832 void doGeometryMovement()
00833 {
00834         FMOD_RESULT result;
00835 
00836         // example of moving individual polygon vertices
00837         int xGeometryWarpPos = -30.0f;
00838         int zGeometryWarpPos = -21.0f;
00839         int dx = xListenerPos - xGeometryWarpPos;
00840         int dz = zListenerPos - zGeometryWarpPos;
00841         if (dx * dx + dz * dz < 30.0f * 30.0f)
00842         {
00843                 if (sin(accumulatedTime * 1.0f) > 0.0f)
00844                 {
00845                         static FMOD_VECTOR lastOffset = { 0.0f, 0.0f, 0.0f };
00846                         FMOD_VECTOR offset = { sin(accumulatedTime * 2.0f), 0.0f, cos(accumulatedTime * 2.0f) };
00847                         for (int poly = 0; poly < walls.numPolygons; poly++)
00848                         {
00849                                 Polygon* polygon = &walls.polygons[poly];
00850                                 for (int i = 0; i < polygon->numVertices; i++)
00851                                 {
00852                                         FMOD_VECTOR& vertex = walls.vertices[walls.indices[polygon->indicesOffset + i]];
00853 
00854                                         dx = vertex.x - xGeometryWarpPos;
00855                                         dz = vertex.z - zGeometryWarpPos;
00856                                         if (dx * dx + dz * dz > 90.0f)
00857                                                 continue;
00858                                         vertex.x -= lastOffset.x;
00859                                         vertex.y -= lastOffset.y;
00860                                         vertex.z -= lastOffset.z;
00861 
00862                                         vertex.x += offset.x;
00863                                         vertex.y += offset.y;
00864                                         vertex.z += offset.z;
00865                                         result = walls.geometry->setPolygonVertex(poly, i, &vertex);
00866                                         ERRCHECK(result);
00867                                 }
00868                         }
00869                         lastOffset = offset;
00870                 }
00871         }
00872 
00873         // example of rotation and a geometry object
00874         FMOD_VECTOR up = { 0.0f, 1.0f, 0.0f };
00875         FMOD_VECTOR forward = { (float)sin(accumulatedTime * 0.5f), 0.0f, (float)cos(accumulatedTime * 0.5f) };
00876         result = rotatingMesh.geometry->setRotation(&forward, &up);
00877         ERRCHECK(result);
00878         FMOD_VECTOR pos;
00879         pos.x = 12.0f;
00880         pos.y = (float)sin(accumulatedTime) * 0.4f + 0.1f;
00881         pos.z = 0.0f;
00882         result = rotatingMesh.geometry->setPosition(&pos);
00883         ERRCHECK(result);
00884         drawGeometry(rotatingMesh);
00885 }
00886 
00887 void doSoundMovement()
00888 {
00889         //TONI micanje izvora zvuka
00890         //NonLinearCoeffDist is nonlineariti coeff for distance cue
00891         float azim = 0, DistanceErr = 0;
00892         float distance = sqrt((xListenerPos-RabbitEast)*(xListenerPos-RabbitEast)+(zListenerPos-RabbitNorth)*(zListenerPos-RabbitNorth)); //distance from target(rabbit) to the listener
00893         float TransformDistance=1.0f, NewDist=distance; //NewDist is supernormal distance, TransformDistance is realtionship betwean supernormal and real distance.
00894 
00895         //Nova distanca uzrokovana uvodjenjem nelinearnosti na isti nacin kao i za azimut
00896         DistanceErr = distance - 10;//RabbitDistance;
00897         if (ActualWPindex==1)
00898         {Integral=0;}
00899         else
00900         {Integral += DistanceErr*INTERFACE_UPDATETIME/1000;}
00901         NewDist = 10/PI*atan2((2*NonLinearCoeffDist*sin(2*(PI/2)*DistanceErr/10)),(1-NonLinearCoeffDist*NonLinearCoeffDist+(1+NonLinearCoeffDist*NonLinearCoeffDist)*cos(2*(PI/2)*DistanceErr/10)))+10;
00902         NewDist += Ki*Integral;
00903         //Nova supernormalna distanca sa mrtvom zonom +/-0.5 i linearno (promjenjeni koeficijent nagiba) u ostalom dijelu
00904         /*if (fabs(distance - RabbitDistance)>0.5)
00905         {
00906                 if (fabs(distance - RabbitDistance)<5)
00907                 {
00908                         if (distance<RabbitDistance)
00909                         {NewDist=5/NonLinearCoeffDist+(9.5-5/NonLinearCoeffDist)/4.5*(distance-5);}
00910                         else
00911                         {NewDist=10.5+(9.5-5/NonLinearCoeffDist)/4.5*(distance-10.5);}
00912                 }
00913                 else
00914                 {
00915                         if (distance<RabbitDistance)
00916                         {NewDist=distance/(5/NonLinearCoeffDist);}
00917                         else
00918                         {NewDist=distance+10.5+(9.5-5/NonLinearCoeffDist)-15;}
00919                 }
00920         }*/
00921         if (ActualWPindex==1)
00922                 {TransformDistance = RabbitDistance/distance;}
00923         else
00924                 {TransformDistance = NewDist/distance;}
00925 
00926         //InputStoh1 = (0*sin(2*PI*accumulatedTime)+ sin(PI/8*accumulatedTime)+ 1.5*sin(4*PI/8*accumulatedTime)+ 1.5*sin(7*PI/8*accumulatedTime)+ sin(10*PI/8*accumulatedTime)+ 0*sin(13*PI/8*accumulatedTime))/3;
00927         //InputStoh = 12*(r-1);//InputStoh1;
00928 
00929         // Slip angle - Pomak zbog vodjenja po vektoru brzine a ne headingu, za male brzine nepouzdan
00930         std::cout<<latVelVector<<","<<frwVelVector<<std::endl;
00931         VelVec = atan2(latVelVector,frwVelVector);
00932         if      (fabs(frwVelVector) < 0.3)
00933                 {VelVec = fabs(frwVelVector)/0.3*VelVec;}
00934         HeadingErr = DirectionToTarget - yRotation - VelVec*180/PI;
00935 
00936         if (HeadingErr<-180.0f)
00937         {HeadingErr = HeadingErr + 360;
00938         }
00939 
00940         //uvodjenje azimut pomaka rabbita zbog nelinearnosti heading skale i vodjenja po brzine a ne headingu
00941         HE = HeadingErr;
00942         azim = HE*PI/180;
00943         if (fabs(HeadingErr) < 90)// || HeadingErr > 270)
00944                 {
00945                         // uvodjenje nelinearnosti u heading skalu
00946                         TransformAngle = 0.5*atan2((2*NonLinearCoeff*sin(2*azim)),(1-NonLinearCoeff*NonLinearCoeff+(1+NonLinearCoeff*NonLinearCoeff)*cos(2*azim)));//-azim;// ovo nije novi kut vec kut degeneracije headingerrora zbog uvodjenja nelinearnosti
00947                 }
00948         else
00949                 {TransformAngle = azim;//0.0f;
00950                 }
00951 
00952         //std::cout<<180/PI*TransformAngle<<" "<<DirectionToTarget<<" "<<yRotation<<" "<<HeadingErr<<" "<<fabs(HE)<<" "<<zListenerPosRel<<" "<<xListenerPosRel<<std::endl;
00953 
00954 
00955 
00956         if (TaskMode == 1)
00957         {
00958         if ((accumulatedTime > KDiterTime * tDiter[iDiter]) && (iDiter < 12))
00959         {iDiter++;}
00960                 objects[0].xPos = xListenerPos*(1-cos(TransformAngle))+zListenerPos*sin(TransformAngle);//-25*(1-cos((FiDiter[iDiter]+AmpDiter*sin(accumulatedTime*2*PI*FreqDiter))*PI/180));
00961                 objects[0].zPos = zListenerPos*(1-cos(TransformAngle))-xListenerPos*sin(TransformAngle);//+25*sin((FiDiter[iDiter]+AmpDiter*sin(accumulatedTime*2*PI*FreqDiter))*PI/180);
00962                 objects[1].xPos = 0;
00963                 objects[1].zPos = 0;
00964         }
00965         else
00966                 {objects[0].xPos = xListenerPos + RabbitDistance*sin(TransformAngle + yRotation*PI/180 + VelVec);//RabbitEast+(xListenerPos-RabbitEast)*(1-cos(TransformAngle))+(zListenerPos-RabbitNorth)*sin(TransformAngle);
00967                 objects[0].zPos = zListenerPos - RabbitDistance*cos(TransformAngle + yRotation*PI/180 + VelVec);//RabbitNorth+(zListenerPos-RabbitNorth)*(1-cos(TransformAngle))-(xListenerPos-RabbitEast)*sin(TransformAngle);
00968                 objects[0].xPos = xListenerPos + (objects[0].xPos - xListenerPos)*TransformDistance;
00969                 objects[0].zPos = zListenerPos + (objects[0].zPos - zListenerPos)*TransformDistance;
00970                 objects[1].xPos = RabbitEast;
00971                 objects[1].zPos = RabbitNorth;
00972                 objects[6].xPos = objects[0].xPos;
00973                 objects[6].zPos = objects[0].zPos;
00974         }
00975 
00976 
00977 
00978         if (fabs(HeadingErr) < SilenceAngle)// || HeadingErr > 360-SilenceAngle)
00979         {
00980                 objects[0].yPos = yListenerPos + 5000;
00981                 objects[1].yPos = yListenerPos + 5000;
00982         }
00983         else
00984         {
00985                 if (TaskMode<3) // for target and path use sound source of long distance (500m)
00986                 {
00987                         objects[0].yPos = yListenerPos;// Toni: ovo znaci da je objekt (izvor zvuka) uvjek u ROV ravnini po z (dubini)
00988                         objects[6].yPos = yListenerPos + 5000;
00989                 }
00990                 else
00991                 {
00992                         objects[6].yPos = yListenerPos;
00993                         objects[0].yPos = yListenerPos + 5000;
00994                 }
00995                 objects[1].yPos = yListenerPos + 5000;
00996         }
00997 
00998         // target or last WP won
00999         if ((fabs(xListenerPos) < 2 && fabs(zListenerPos) < 2) || ((ActualWPindex == NumberOfWP + 1) && JoyStickMode==1))
01000                 {
01001                         objects[0].yPos = yListenerPos + 5000;
01002                         objects[6].yPos = yListenerPos + 5000;
01003                         objects[1].yPos = yListenerPos;
01004         }
01005 
01006         std::cout<<distance<<" "<<HE<<" "<<yRotation<<" "<<RabbitNorth<<" "<<RabbitEast<<" "<<ActualWPindex<<std::endl;
01007         std::cout<<std::endl;
01008         /*std::cout<<objects[0].xPos<<"  "<<xListenerPos<<std::endl;
01009         std::cout<<std::endl;
01010         std::cout<<objects[0].zPos<<"  "<<zListenerPos<<std::endl;
01011         std::cout<<std::endl;
01012         std::cout<<objects[0].yPos<<"  "<<yListenerPos<<std::endl;
01013         std::cout<<std::endl;*/
01014 
01015 
01016         updateObjectSoundPos(&objects[0]);
01017         updateObjectSoundPos(&objects[6]);
01018         updateObjectSoundPos(&objects[1]);
01019 
01020         //std::cout<<zListenerPosRel<<" "<<xListenerPosRel<<" "<<HE<<" "<<DirectionToTarget<<" "<<objects[0].zPos<<" "<<objects[0].xPos<<std::endl;
01021 
01022         // Upute gore-dolje
01023         if (Altitude < AltitudeSetPoint - 1.0f) //OVAJ RED UBACITI ZA TEREN UMJESTO REDA ISPOD
01024         //if (yListenerPos < AltitudeSetPoint - 0.5f)
01025         {
01026                 objects[2].xPos = xListenerPos;
01027                 objects[2].zPos = zListenerPos;
01028                 objects[2].yPos = yListenerPos + 5;
01029         }
01030         else
01031         {
01032                 objects[2].yPos = yListenerPos + 5000;
01033         }
01034         updateObjectSoundPos(&objects[2]);
01035         if (Altitude > AltitudeSetPoint + 1.0f) //OVAJ RED UBACITI ZA TEREN UMJESTO REDA ISPOD
01036         //if (yListenerPos > AltitudeSetPoint + 0.5f)
01037         {
01038                 objects[3].xPos = xListenerPos;
01039                 objects[3].zPos = zListenerPos;
01040                 objects[3].yPos = yListenerPos - 5;//listenerVector.x;// = ;//-22 + 8.0f * sin(accumulatedTime)
01041         }
01042                 else
01043         {
01044                 objects[3].yPos = yListenerPos + 5000;
01045         }
01046         updateObjectSoundPos(&objects[3]);
01047 
01048         // Upute lijevo-desno
01049 
01050 
01051                 if (HeadingErr > VerbalAngle && HeadingErr < 360-VerbalAngle && sin(HeadingErr*PI/180) < 0)
01052         {
01053                 objects[4].xPos = xListenerPos;
01054                 objects[4].zPos = zListenerPos;
01055                 objects[4].yPos = yListenerPos;
01056         }
01057                 else
01058         {
01059                 objects[4].yPos = yListenerPos + 5000;
01060         }
01061         updateObjectSoundPos(&objects[4]);
01062                 if (HeadingErr > VerbalAngle && HeadingErr < 360-VerbalAngle && sin(HeadingErr*PI/180) > 0)
01063         {
01064                 objects[5].xPos = xListenerPos;
01065                 objects[5].zPos = zListenerPos;
01066                 objects[5].yPos = yListenerPos;
01067         }
01068                 else
01069         {
01070                 objects[5].yPos = yListenerPos + 5000;
01071         }
01072         updateObjectSoundPos(&objects[5]);
01073 
01074 }
01075 
01076 void doListenerMovement()
01077 {
01078         // Update user movement
01079 
01080         std::string SingleLog;
01081         float step;
01082         const float MOVEMENT_SPEED = 0.1f;
01083         float forward = 0.0f;
01084         switch (SpeedProfile)
01085         {
01086                 case 'V':
01087                         step=(float)INTERFACE_UPDATETIME/1000*PathVelocity+0.3*(float)INTERFACE_UPDATETIME/1000*PathVelocity*(float)sin(accumulatedTime/3);
01088                         break;
01089                 case 'S':
01090                         if (xListenerPos>0)
01091                                 {step=(float)INTERFACE_UPDATETIME/1000*PathVelocity*1.2;}
01092                         else
01093                                 {step=(float)INTERFACE_UPDATETIME/1000*PathVelocity;}
01094                         break;
01095                 default:
01096                         step=(float)INTERFACE_UPDATETIME/1000*PathVelocity;
01097         }
01098 
01099 
01100         //r = rand();
01101         //koristenje joysticka
01102         LABUST::JoystickData joystickData;
01103 if (JoyStickMode==2)
01104         {
01105         joystickData = joystick->ReadJoystickData();
01106         std::cout<<joystickData.axes[0]<<" "<<joystickData.axes[1]<<std::endl;
01107 }
01108 
01109   Head = 0.0f;
01110 
01111         std::vector<labust::xml::GyrosReader> receivedData;
01112         comms->Receive(receivedData);
01113         static std::map<std::string,double> latLonMap,TARGETStatus;
01114         static std::map<std::string,float> rovStatus,dvlStatus;
01115         static std::map<std::string,std::string> rovStringifiedStatus;
01116 
01117         if(!receivedData.empty())
01118                 {
01119                         for(std::vector<labust::xml::GyrosReader>::iterator gyros = receivedData.begin(); gyros!=receivedData.end(); gyros++)
01120                         {
01121                                 std::string label = gyros->GetLabel();
01122 
01123                                 //std::cout<<"Labela:"<<label<<", "<<filterMessageLabel<<std::endl;
01124 
01125                                 try
01126                                 {
01127                                         if(boost::iequals(label,rovMessageLabel))
01128                                         {
01129                                                 rovStatus.clear();
01130                                                 gyros->dictionary(rovStatus);
01131                                                 gyros->dictionary(rovStringifiedStatus);
01132                                         //      dvlStatus = rovStatus;
01133                                         //      latLonMap = rovStatus;
01134                                         }
01135                                         //za fieldwork
01136                                         if(boost::iequals(label,dvlMessageLabel))
01137                                         {
01138                                                 dvlStatus.clear();
01139                                                 gyros->dictionary(dvlStatus);
01140                                         }
01141                                         if(boost::iequals(label,filterMessageLabel))
01142                                         {
01143                                                 latLonMap.clear();
01144                                                 gyros->dictionary(latLonMap);
01145                                         }
01146 
01147                                         if(boost::iequals(label,TARGETMessageLabel))
01148                                         {
01149                                                 TARGETStatus.clear();
01150                                                 gyros->dictionary(TARGETStatus);
01151                                         }
01152                                 }
01153                                 catch (std::exception &e)
01154                                 {
01155                                         std::cout<<"Error: "<<e.what()<<" "<<label<<" "<<std::endl;
01156                                 }
01157                         }
01158 
01159                         receivedData.clear();
01160                 }
01161 
01162 
01163 
01164 // OVAJ DIO TREBA UBACITI ZA TEREN
01165         //Pozicija ROVa (Listener-a) u metrima, ishodiste je u izvoru zvuka (cilja)
01166 
01167         ObjectLong = TARGETStatus["Northing"];
01168         ObjectLat = TARGETStatus["Easting"];
01169         ObjectDepth = TARGETStatus["Depth"];//xListenerPos = (latLonMap["LAT"] - ObjectLat) * 110000.0f;
01170         zPos = latLonMap["Northing"];
01171         if (JoyStickMode==2)
01172                 {yListenerPos = 20;}
01173         else
01174         {       zListenerPos = -(latLonMap["Northing"] - ObjectLong); //relative to the target
01175                 xListenerPos = (latLonMap["Easting"] - ObjectLat); //relative to the target
01176                 yListenerPos = rovStatus["Depth"];
01177         }
01178         zRotation = rovStatus["Roll"]; //sve je izmjesano z-naprijed, x-lateral, y-gore/dolje
01179         xRotation = rovStatus["Pitch"];
01180         if (JoyStickMode==1)
01181         {yRotation = rovStatus["Heading"];}
01182         //std::cout<<yRotation<<" "<<yListenerPos<<" "<<TaskMode<<" "<<GuidanceMode<<std::endl;
01183         TauX = rovStatus["TauX"];
01184         TauY = rovStatus["TauY"];
01185         TauZ = rovStatus["TauZ"];
01186         TauK = rovStatus["TauK"];
01187         TauM = rovStatus["TauM"];
01188         TauN = rovStatus["TauN"];
01189         frwVelVector = rovStatus["u"];
01190         latVelVector = rovStatus["v"];
01191 
01192         //Na pocetku upisivanje WPa u log file
01193         if (accumulatedTime < 0.01)
01194                 {std::string sname,strWPindex;
01195                 int WPindex;
01196 
01197                 // Inicijalizacija WPova iz MOOS stringa
01198                 for (WPindex=1; WPindex < NumberOfWP +2; WPindex++)
01199                         {
01200                         converter.clear();
01201                         converter<<WPindex-1;
01202                         converter>>strWPindex;
01203                         sname = rovStringifiedStatus["Waypoint"+strWPindex];
01204                         int index = 0;
01205                         index = sname.find(",");
01206                         sname = sname.substr(index + 1);//na pocetku WP poruke je greskom zarez pa ga moramo izbaciti
01207                         index = sname.find(",");
01208                         converter.clear();
01209                         SingleLog = sname.substr(0, index);
01210                         converter<<SingleLog;
01211                         converter>>WPnorth[WPindex];
01212                         if (WPnorth[WPindex]==0)
01213                         {NumberOfWP = WPindex -1;}
01214                         else
01215                         {WPnorth[WPindex] = -(WPnorth[WPindex]-ObjectLong);
01216                         sname = sname.substr(index + 1);
01217                         index = sname.find(",");
01218                         converter.clear();
01219                         SingleLog = sname.substr(0, index);
01220                         converter<<SingleLog;
01221                         converter>>WPeast[WPindex];
01222                         WPeast[WPindex] = (WPeast[WPindex]-ObjectLat);
01223                         sname = sname.substr(index + 1);
01224                         converter.clear();
01225                         SingleLog = sname.substr(0, index);
01226                         converter<<SingleLog;
01227                         converter>>WPz[WPindex];
01228                         }}
01229 
01230                 // upis vrijednosti WPa u log file
01231                 for (WPindex=1; WPindex < NumberOfWP +1; WPindex++)
01232                 {file<<WPnorth[WPindex];
01233                 file<<";";
01234                 file<<WPeast[WPindex];
01235                 file<<";";
01236                 file<<WPz[WPindex]<<std::endl;
01237                 file<<";";
01238                 //std::cout<<WPnorth[WPindex]<<" "<<WPeast[WPindex]<<" "<<WPz[WPindex]<<" "<<ObjectLong<<" "<<ObjectLat<<std::endl;
01239                 }
01240         }
01241         Altitude = dvlStatus["Altitude"];
01242         if (fabs(xListenerPos - WPeast[ActualWPindex]) < 3 && fabs(zListenerPos-WPnorth[ActualWPindex]) < 3)
01243         {ActualWPindex += 1;}
01244         if (TaskMode==3)
01245         {if (ActualWPindex == 1 && sqrt((xListenerPos - WPeast[ActualWPindex])*(xListenerPos - WPeast[ActualWPindex]) + (zListenerPos-WPnorth[ActualWPindex])*(zListenerPos-WPnorth[ActualWPindex])) < RabbitDistance)
01246                 {ActualWPindex += 1;}
01247         }
01248         else
01249         {if (ActualWPindex == 1 && sqrt((xListenerPos - WPeast[ActualWPindex])*(xListenerPos - WPeast[ActualWPindex]) + (zListenerPos-WPnorth[ActualWPindex])*(zListenerPos-WPnorth[ActualWPindex])) < 2)
01250                 {ActualWPindex += 1;}
01251         }
01252         // Set virtual target (rabbit) position
01253         /*
01254         PathX = PathStartX*(PathStartY * xListenerPos + PathStartX * zListenerPos)/(PathStartX * PathStartX + PathStartY * PathStartY);
01255         PathY = PathStartY*(PathStartY * xListenerPos + PathStartX * zListenerPos)/(PathStartX * PathStartX + PathStartY * PathStartY);
01256         DistanceToPath = sqrt((xListenerPos - PathY) * (xListenerPos - PathY) + (zListenerPos - PathX) * (zListenerPos - PathX));*/
01257         if (TaskMode>1 && ActualWPindex>1)
01258                 {PathStartY = WPeast[ActualWPindex-1] - WPeast[ActualWPindex];
01259                 PathStartX = WPnorth[ActualWPindex-1] - WPnorth[ActualWPindex];
01260                 }
01261         float kLine = PathStartY / PathStartX;
01262         float kLineAngle = atan2(PathStartY,PathStartX);
01263         aSQR = 1 + kLine*kLine;
01264 
01265         // PathX i Path Y su tocka projekcije ROV pozicije na path (pravi kut)
01266         if (TaskMode>1)
01267                 {if (PathStartX == 0)
01268                 {PathX = WPnorth[ActualWPindex];
01269                 PathY =xListenerPos;}
01270                 else
01271                 {PathX = (kLine*(xListenerPos - WPeast[ActualWPindex] + kLine*WPnorth[ActualWPindex]) + zListenerPos)/aSQR;//(1+kLine*kLine);
01272                 PathY = WPeast[ActualWPindex] + kLine*PathX - kLine*WPnorth[ActualWPindex];
01273                 //PathY = PathStartY + WPeast[ActualWPindex] + kLine*PathX - kLine*PathStartX - kLine*WPnorth[ActualWPindex];
01274                 }
01275         }
01276         else
01277                 {PathX = PathStartX*(PathStartY * xListenerPos + PathStartX * zListenerPos)/(PathStartX * PathStartX + PathStartY * PathStartY);
01278                 PathY = PathStartY*(PathStartY * xListenerPos + PathStartX * zListenerPos)/(PathStartX * PathStartX + PathStartY * PathStartY);
01279                 }
01280 
01281         DistanceToPath = sqrt((xListenerPos - PathY) * (xListenerPos - PathY) + (zListenerPos - PathX) * (zListenerPos - PathX));
01282 
01283 
01284         if ((TaskMode > 1 && sqrt((zListenerPos-WPnorth[NumberOfWP])*(zListenerPos-WPnorth[NumberOfWP]) + (xListenerPos-WPeast[NumberOfWP])*(xListenerPos-WPeast[NumberOfWP])) > RabbitDistance))
01285                 //Da li smo dosli do targeta, odnosno zadnjeg WPa
01286         {
01287         if (DistanceToPath > RabbitDistance)
01288                 {RabbitNorth = PathX;
01289                 RabbitEast = PathY;
01290                 RabbitNorthOld = RabbitNorth;
01291                 RabbitEastOld = RabbitEast;
01292                 }
01293         else
01294                 {if (TaskMode==3) //meaning trajectory tracking
01295                 {
01296                 if (ActualWPindex>2 && ActualWPindex>ActualWPindexOld) //if new WP
01297                 {
01298                         RabbitNorth = WPnorth[ActualWPindex-1] - cos(kLineAngle)*RabbitDistance;
01299                         RabbitEast = WPeast[ActualWPindex-1] - sin(kLineAngle)*RabbitDistance;
01300                         wait = true;
01301                 }
01302                 else
01303                 {
01304                         if (wait==false || (wait==true && fabs(HE)<10)) // if WP is cahnged recently, wait until heading is cca. inline with path segment
01305                         {
01306                                 RabbitNorth = RabbitNorthOld - cos(kLineAngle)*step;
01307                                 RabbitEast = RabbitEastOld - sin(kLineAngle)*step;
01308                                 wait=false;
01309                         }
01310                 }
01311                 RabbitNorthOld = RabbitNorth;
01312                 RabbitEastOld = RabbitEast;
01313                 ActualWPindexOld=ActualWPindex;
01314                 //std::cout<<kLineAngle*180/PI<<" "<<step<<" "<<sin(kLineAngle)*step<<" "<<RabbitEast<<" "<<ActualWPindex<<std::endl;
01315                 }
01316                 else
01317                         {if (PathStartX == 0)
01318                                 {RabbitNorth = WPnorth[ActualWPindex];
01319                                 if (PathStartY<0)
01320                                         {RabbitEast = xListenerPos + sqrt(RabbitDistance*RabbitDistance-(zListenerPos - RabbitNorth)*(zListenerPos - RabbitNorth));}
01321                                 else
01322                                         {RabbitEast = xListenerPos - sqrt(RabbitDistance*RabbitDistance-(zListenerPos - RabbitNorth)*(zListenerPos - RabbitNorth));}
01323                                 }
01324                         else
01325                                 {bSQR = -2*((PathX-WPnorth[ActualWPindex]) + kLine*(PathY-WPeast[ActualWPindex]));
01326                                 cSQR = (PathX-WPnorth[ActualWPindex])*(PathX-WPnorth[ActualWPindex])+(PathY-WPeast[ActualWPindex])*(PathY-WPeast[ActualWPindex])+DistanceToPath*DistanceToPath-RabbitDistance*RabbitDistance;
01327                                 RabbitNorth1 = (-bSQR+sqrt(bSQR*bSQR-4*aSQR*cSQR))/(2*aSQR);
01328                                 RabbitNorth2 = (-bSQR-sqrt(bSQR*bSQR-4*aSQR*cSQR))/(2*aSQR);
01329                                 if (abs(RabbitNorth1)<abs(RabbitNorth2))
01330                                         {RabbitNorth = RabbitNorth1 + WPnorth[ActualWPindex];
01331                                         RabbitEast = kLine * RabbitNorth1 + WPeast[ActualWPindex];}
01332                                 else
01333                                         {RabbitNorth= RabbitNorth2 + WPnorth[ActualWPindex];
01334                                         RabbitEast = kLine * RabbitNorth2 + WPeast[ActualWPindex];}
01335                                 }
01336                         }
01337                 }
01338         }
01339         else
01340         {RabbitNorth = WPnorth[ActualWPindex];
01341                 RabbitEast = WPeast[ActualWPindex];
01342         }
01343         if (TaskMode == 1) // if guidance to Target, rabbit is target
01344                 {RabbitNorth = 0.0f;
01345                 RabbitEast = 0.0f;
01346         }
01347         if (ActualWPindex == 1) //guidance to the first WP of the path
01348                 {RabbitNorth = WPnorth[1];
01349                 RabbitEast = WPeast[1];
01350                 RabbitNorthOld = RabbitNorth;
01351                 RabbitEastOld = RabbitEast;
01352         }
01353 
01354         ti += (float)INTERFACE_UPDATETIME / 1000.0f;
01355         if (ti > 2)
01356         {r = rand()%3;
01357         ti = 0.0f;}
01358         //std::cout<<r-1<<" "<<ti<<std::endl;//<<RabbitNorth<<" "<<RabbitEast<<" "<<PathX<<" "<<PathY<<" "<<PathStartX<<" "<<PathStartY<<" "<<ActualWPindex<<" "<<DistanceToPath<<" "<<zListenerPos<<" "<< xListenerPos<<std::endl;
01359 
01360         //std::cout<<latLonMap["Northing"]<<" "<<latLonMap["Easting"]<<" "<<rovStatus["Depth"]<<" "<<TARGETStatus["Northing"]<<" "<<TARGETStatus["Easting"]<<" "<<TARGETStatus["Depth"]<<" "<<rovStatus["Heading"]<<" "<<dvlStatus["Altitude"]<<" "<<AltitudeSetPoint<<std::endl;
01361         if (JoyStickMode==2)
01362                 {if (abs(joystickData.axes[1])>2000)
01363                         {forw = -0.1*joystickData.axes[1]/intMax;}
01364                 else
01365                 {forw = 0;}
01366         }
01367         if (JoyStickMode==2)
01368                 {
01369         if (abs(joystickData.axes[0])>2000)
01370                 {
01371                 yRotation += 1.0f*joystickData.axes[0]/intMax;
01372                 if (yRotation < 0)
01373                 {yRotation = yRotation + 360;}
01374                 else
01375                 {
01376                                 if (yRotation > 360)
01377                         {yRotation = yRotation - 360;}
01378                 }
01379         }
01380 
01381 }
01382 // OVAJ DIO TREBA IZBACITI ZA TEREN, OVO JE VOZNJA TIPKOVNICOM
01383         /*if (moveForward)
01384     {
01385                 forward += (MOVEMENT_SPEED * (moveFast ? 2.0f : 1.0f));
01386     }*/
01387 
01388         /*if (moveBackward)
01389     {
01390                 forward -= (MOVEMENT_SPEED * (moveFast ? 2.0f : 1.0f));
01391     }*/
01392         /*if (moveRotateClock)
01393     {
01394                 yRotation += 0.3f;
01395 
01396     }
01397         if (moveRotateAntiClock)
01398     {
01399                 yRotation += -0.3f;
01400     }*/
01401 
01402         /*
01403         float right = 0.0f;
01404         if (moveLeft)
01405     {
01406                 right -= (MOVEMENT_SPEED * (moveFast ? 2.0f : 1.0f));
01407     }
01408         if (moveRight)
01409     {
01410                 right += (MOVEMENT_SPEED * (moveFast ? 2.0f : 1.0f));
01411     }
01412         */
01413         float up = 0.0f;
01414         /*
01415         if (moveUp)
01416     {
01417                 up += (MOVEMENT_SPEED * 0.2f * (moveFast ? 2.0f : 1.0f));
01418     }
01419         if (moveDown)
01420     {
01421                 up -= (MOVEMENT_SPEED * 0.2f * (moveFast ? 2.0f : 1.0f));
01422     }
01423         float right = 0.0f;
01424 if (JoyStickMode==2)
01425         //Lateral movement, TONI: kada tipkama biras desno/lijevo, ovdje nije petljao sa pith-om i roll-om
01426         {float xRight = (float)cos(yRotation * (PI / 180.0f));
01427         float yRight = 0.0f;
01428         float zRight = (float)sin(yRotation * (PI / 180.0f));
01429 
01430         xListenerPos += xRight * right;
01431         yListenerPos += yRight * right;
01432         zListenerPos += zRight * right;
01433 
01434         //Forward-backward movement TONI: kada tipkama biras naprijed/nazad, ovdje je petljao sa pith-om i roll-om
01435         //float xForward = (float)sin(yRotation * (PI / 180.0f)) * cos(xRotation  * (PI / 180.0f));
01436         float xForward = (float)sin(yRotation * (PI / 180.0f)) * cos(zRotation  * (PI / 180.0f));
01437         float yForward = -(float)sin(xRotation  * (PI / 180.0f));
01438         float zForward = -(float)cos(yRotation * (PI / 180.0f)) * cos(xRotation  * (PI / 180.0f));
01439 
01440         xListenerPos += xForward * forward;
01441         yListenerPos += yForward * forward;
01442         zListenerPos += zForward * forward;}
01443         */
01444 // DO OVDJE TREBA IZBACITI ZA TEREN
01445 
01446 // OVO OSTAJE I ZA TEREN I ZA SIMULACIJU
01447         lastyRotation=yRotation; //Toni spremi stvarni heading
01448         // simulacija
01449 
01450         //Lateral movement, TONI: Isto kao gore samo sa ukljucenim pokretom glave
01451         float xRight = (float)cos(yRotation * (PI / 180.0f));
01452         float yRight = 0.0f;
01453         float zRight = (float)sin(yRotation * (PI / 180.0f));
01454 
01455         //Forward-backward movement TONI: Isto kao gore samo sa ukljucenim pokretom glave
01456         float xForward = (float)sin(yRotation * (PI / 180.0f)) * cos(xRotation  * (PI / 180.0f));
01457         float yForward = -(float)sin(xRotation  * (PI / 180.0f));
01458         float zForward = -(float)cos(yRotation * (PI / 180.0f)) * cos(xRotation  * (PI / 180.0f));
01459 
01460         if (JoyStickMode==2)
01461                 {xListenerPos += xForward * forw;
01462                 yListenerPos += yForward * forw;
01463                 zListenerPos += zForward * forw;}
01464 
01465         yRotation=lastyRotation; //Toni: vrati pravi heading
01466 
01467         //Up-Down movement simulacija
01468         /*yListenerPos += up;
01469 
01470         if (yListenerPos < 1.0f)
01471     {
01472                 yListenerPos = 1.0f;
01473     }*/
01474 
01475         if (yListenerPos < 0.0f)
01476     {
01477                 yListenerPos = 0.0f;
01478     }
01479 
01480         // cross product TONI????
01481         float xUp = yRight * zForward - zRight * yForward;
01482         float yUp = zRight * xForward - xRight * zForward;
01483         float zUp = xRight * yForward - yRight * xForward;
01484 
01485         /*std::cout<<xForward<<" "<<yForward<<" "<< zForward<<std::endl;
01486         std::cout<<std::endl;
01487         std::cout<<xUp<<" "<<yUp<<" "<< zUp<<std::endl;
01488         std::cout<<std::endl;*/
01489 
01490                 // Racunanje heading-a prema target-u ili rabbit-u
01491         if (TaskMode ==1)
01492         {       if (JoyStickMode == 1)
01493                         {zListenerPosRel = zListenerPos;
01494                         xListenerPosRel = xListenerPos;}
01495                 else
01496                 {zListenerPosRel = 0;//20*cos(PI/180*InputStoh);
01497                 xListenerPosRel = -25;//20*sin(PI/180*InputStoh);
01498         }
01499         }
01500         else
01501                 {zListenerPosRel = zListenerPos - RabbitNorth;
01502                 xListenerPosRel = xListenerPos - RabbitEast;}
01503 
01504         DirectionToTarget = atan2(-xListenerPosRel,zListenerPosRel)*180.0f/PI;
01505 
01506 //OVAJ DIO SE KORISTI I ZA TEREN I ZA SIMULACIJU
01507         // Update listener
01508         {
01509                 //TONI nova pozicija slusaca, koristi se i za Teren i simulaciju
01510                 FMOD_VECTOR listenerVector;
01511                 if (JoyStickMode==2)
01512                 {listenerVector.x = xListenerPosRel;
01513                 listenerVector.y = yListenerPos;
01514                 listenerVector.z = zListenerPosRel;}
01515                 else
01516                 {listenerVector.x = xListenerPos;
01517                 listenerVector.y = yListenerPos;
01518                 listenerVector.z = zListenerPos;}
01519 
01520                 static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
01521                 static bool bFirst = true;
01522 
01523                 FMOD_VECTOR forward;
01524                 FMOD_VECTOR up;
01525                 FMOD_VECTOR vel;
01526 
01527                 forward.x = xForward;
01528                 forward.y = yForward;
01529                 forward.z = zForward;
01530                 up.x = xUp;
01531                 up.y = yUp;
01532                 up.z = zUp;
01533 
01534                 // ********* NOTE ******* READ NEXT COMMENT!!!!!
01535                 // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
01536                 //TONI brzina slusaca
01537                 vel.x = (listenerVector.x - lastpos.x) * (Doppler * 1000.0f / (float)INTERFACE_UPDATETIME); // BRZINA UVECANA RADI UVODJENJA POJACANOG DOPPLERA
01538                 vel.y = (listenerVector.y - lastpos.y) * (Doppler * 1000.0f / (float)INTERFACE_UPDATETIME);
01539                 vel.z = (listenerVector.z - lastpos.z) * (Doppler * 1000.0f / (float)INTERFACE_UPDATETIME);
01540 
01541                 if (bFirst)
01542                 {
01543                         bFirst = false;
01544                         vel.x = 0;
01545                         vel.y = 0;
01546                         vel.z = 0;
01547                         HeadIni = Head;
01548                 }
01549                 if (vel.x==0 && vel.z==0)
01550                                         {velAtitude = lastvelAtitude;}
01551                 else
01552                 {
01553                         if (vel.z < 0.0f)
01554                                 {velAtitude = atan(-vel.x/vel.z);}
01555                         else
01556                         {
01557                                 if (vel.z == 0.0f)
01558                                 {
01559                                         if (vel.x < 0.0f)
01560                                                 {velAtitude = 1.5*PI;}
01561                                         else
01562                                                 {velAtitude = 0.5*PI;}
01563                                 }
01564                                 else
01565                                 {velAtitude = atan(-vel.x/vel.z)+PI;}
01566                         }
01567                 velAtitude = fmod(180*velAtitude/PI+360,360);
01568                 lastvelAtitude = velAtitude;
01569                 }
01570                 //std::cout<<yRotation<<" "<<forw<<" "<<zListenerPos<<" "<<xListenerPos<<" "<<std::endl;
01571 
01572                 /*static FMOD_VECTOR lastVel = { 0.0f, 0.0f, 0.0f };
01573                 // store pos and vel for next time
01574 
01575                 if (lastVel.x != 0.0f || lastVel.y != 0.0f || lastVel.z != 0.0f)
01576                 {
01577                         if (vel.x == 0.0f && vel.y == 0.0f && vel.z == 0.0f)
01578                         {
01579                                 int test = 0;
01580                         }
01581                 }
01582                 lastVel = vel;*/
01583                 lastpos = listenerVector;
01584                 lastObjectLong = zPos;
01585 
01586                 FMOD_RESULT result = fmodSystem->set3DListenerAttributes(0, &listenerVector, &vel, &forward, &up);
01587                 ERRCHECK(result);
01588 
01589                 file<<key1;
01590                 file<<';';
01591                 converter<<TauX;
01592                 converter>>SingleLog;
01593                 converter.clear();
01594                 file<<SingleLog+';';
01595                 converter<<TauY;
01596                 converter>>SingleLog;
01597                 converter.clear();
01598                 file<<SingleLog+';';
01599                 converter<<TauZ;
01600                 converter>>SingleLog;
01601                 converter.clear();
01602                 file<<SingleLog+';';
01603                 converter<<TauN;
01604                 converter>>SingleLog;
01605                 converter.clear();
01606                 file<<SingleLog+';';
01607                 converter<<listenerVector.z;
01608                 converter>>SingleLog;
01609                 converter.clear();
01610                 file<<SingleLog+';';
01611                 converter<<listenerVector.x;
01612                 converter>>SingleLog;
01613                 converter.clear();
01614                 file<<SingleLog+';';
01615                 converter<<listenerVector.y;
01616                 converter>>SingleLog;
01617                 converter.clear();
01618                 file<<SingleLog+';';
01619                 converter<<yRotation;
01620                 converter>>SingleLog;
01621                 converter.clear();
01622                 file<<SingleLog+';';
01623                 converter<<DistanceToPath;
01624                 converter>>SingleLog;
01625                 converter.clear();
01626                 file<<SingleLog+';';
01627                 converter<<Altitude;
01628                 converter>>SingleLog;
01629                 converter.clear();
01630                 file<<SingleLog+';';
01631                 converter<<objects[0].zPos;//ovo je ustvari x pozicija
01632                 converter>>SingleLog;
01633                 converter.clear();
01634                 file<<SingleLog+';';
01635                 converter<<objects[0].xPos; //ovo je ustvari y pozicija
01636                 converter>>SingleLog;
01637                 converter.clear();
01638                 file<<SingleLog+';';
01639                 converter<<objects[0].yPos;
01640                 converter>>SingleLog;
01641                 converter.clear();
01642                 file<<SingleLog+';';
01643                 converter<<Head-HeadIni; //pomak glave
01644                 converter>>SingleLog;
01645                 converter.clear();
01646                 file<<SingleLog+';';
01647                 converter<<DirectionToTarget; //
01648                 converter>>SingleLog;
01649                 converter.clear();
01650                 file<<SingleLog+';';
01651                 converter<<RabbitNorth;
01652                 converter>>SingleLog;
01653                 converter.clear();
01654                 file<<SingleLog+';';
01655                 converter<<RabbitEast;
01656                 converter>>SingleLog;
01657                 converter.clear();
01658                 file<<SingleLog+';';
01659 
01660         }
01661 }
01662 
01663 void doUpdateVolume()
01664 {
01665     //TONI pojacavanje i stisavanje zvuka tipke Z/z
01666         if (ambientVolUp)
01667     {
01668         char volumestring[64];
01669 
01670         ambientVolume += 0.025;
01671         if (ambientVolume > 1.0f)
01672         {
01673             ambientVolume = 1.0f;
01674         }
01675 
01676         sprintf(volumestring, "Ambient Volume: %0.3f", ambientVolume);
01677 
01678         #ifdef SHOW_GUI_DEBUG_TEXT
01679         statusText.push(volumestring);
01680         #endif
01681     }
01682     else if (ambientVolDown)
01683     {
01684         char volumestring[64];
01685 
01686         ambientVolume -= 0.025;
01687         if (ambientVolume < 0.0f)
01688         {
01689             ambientVolume = 0.0f;
01690         }
01691 
01692         sprintf(volumestring,"Ambient Volume: %0.3f", ambientVolume);
01693 
01694         #ifdef SHOW_GUI_DEBUG_TEXT
01695         statusText.push(volumestring);
01696         #endif
01697     }
01698 }
01699 
01700 void timerFunc(int nValue)
01701 {
01702     std::string TimeLog;
01703         static bool firsttime = true;
01704         FMOD_RESULT result;
01705 
01706         //doGeometryMovement();
01707 
01708         doSoundMovement();
01709         doListenerMovement();
01710     doUpdateVolume();
01711 
01712     result = FMOD::NetEventSystem_Update();
01713         ERRCHECK(result);
01714     result = fmodEventSystem->update();
01715         ERRCHECK(result);
01716 
01717         accumulatedTime += (float)INTERFACE_UPDATETIME / 1000.0f;
01718 
01719         converter<<accumulatedTime;
01720         converter>>TimeLog;
01721         converter.clear();
01722         file<<TimeLog+';'<<std::endl;
01723 
01724         glutPostRedisplay();
01725         glutTimerFunc(INTERFACE_UPDATETIME, timerFunc, 0);
01726 
01727 #if 0
01728     if (firsttime)
01729     {
01730         SetWindowPos(
01731           GetForegroundWindow(),    // handle to window
01732           HWND_TOPMOST,             // placement-order handle
01733           0,                        // horizontal position
01734           0,                        // vertical position
01735           width,                    // width
01736           height,                   // height
01737           SWP_NOMOVE
01738         );
01739         firsttime = false;
01740     }
01741 #endif
01742 }
01743 
01744 void keyboardFunc(unsigned char key, int x, int y)
01745 {
01746         key1 = key;
01747         switch (key)
01748         {
01749         case 'w':
01750                 moveForward = true;
01751                 break;
01752         case 's':
01753                 moveBackward = true;
01754                 break;
01755         case 'j':
01756                 moveRotateAntiClock = true;
01757                 break;
01758         case 'l':
01759                 moveRotateClock = true;
01760                 break;
01761         case 'a':
01762                 moveLeft = true;
01763                 break;
01764         case 'd':
01765                 moveRight = true;
01766                 break;
01767         case ' ':
01768                 moveUp = true;
01769                 break;
01770         case 'c':
01771                 moveDown = true;
01772         break;
01773     case 'z' :
01774         ambientVolDown = true;
01775         break;
01776     case 'Z' :
01777         ambientVolUp = true;
01778         break;
01779     case 'v':
01780         masterVolDown = true;
01781         break;
01782     case 'V':
01783         masterVolUp = true;
01784         break;
01785 
01786     case 'p':
01787         {
01788             float value;
01789 
01790             fmodEventParameter->getValue(&value);
01791 
01792             fmodEventParameter->setValue(value - 20.0f);
01793         }
01794         break;
01795 
01796     case 'P':
01797         {
01798             float value;
01799 
01800             fmodEventParameter->getValue(&value);
01801 
01802             fmodEventParameter->setValue(value + 20.0f);
01803         }
01804         break;
01805 
01806     case 'f':
01807         moveFast = true;
01808         break;
01809         }
01810 }
01811 
01812 void keyboardUpFunc(unsigned char key, int x, int y)
01813 {
01814         key1 = 0;
01815         switch (key)
01816         {
01817         case 'w':
01818                 moveForward = false;
01819                 break;
01820         case 's':
01821                 moveBackward = false;
01822                 break;
01823         case 'j':
01824                 moveRotateAntiClock = false;
01825                 break;
01826         case 'l':
01827                 moveRotateClock = false;
01828         case 'a':
01829                 moveLeft = false;
01830                 break;
01831         case 'd':
01832                 moveRight = false;
01833         break;
01834         case ' ':
01835                 moveUp = false;
01836                 break;
01837         case 'c':
01838                 moveDown = false;
01839         break;
01840     case 'z' :
01841         ambientVolDown = false;
01842         break;
01843     case 'Z' :
01844         ambientVolUp = false;
01845         break;
01846     case 'v':
01847         masterVolDown = false;
01848         break;
01849     case 'V':
01850         masterVolUp = false;
01851         break;
01852     case 'f':
01853         moveFast = false;
01854         break;
01855     case 27:
01856         exit(1);
01857         break;
01858         }
01859 }
01860 
01861 void specialKeyFunc(int key, int x, int y)
01862 {
01863   /*  switch (key)
01864     {
01865 
01866     }*/
01867 
01868     key = key;
01869 }
01870 
01871 void specialKeyUpFunc(int key, int x, int y)
01872 {
01873     switch (key)
01874     {
01875     case GLUT_KEY_F1:
01876         showhelp = !showhelp;
01877         break;
01878     case GLUT_KEY_F2:
01879         if(fullscreen)
01880         {
01881             glutPositionWindow(20,40);
01882             glutReshapeWindow(500,500);
01883             fullscreen = false;
01884         }
01885         else
01886         {
01887             glutFullScreen();
01888             fullscreen = true;
01889         }
01890         break;
01891     case GLUT_KEY_F3:
01892         rendermode = (rendermode == GL_LINE ? GL_FILL : GL_LINE);
01893         break;
01894     case GLUT_KEY_F11:
01895         showdebug = !showdebug;
01896         break;
01897     case GLUT_KEY_F8:
01898         rotatingMesh.geometry->setActive(false);
01899         walls.geometry->setActive(false);
01900         break;
01901     case GLUT_KEY_F9:
01902         rotatingMesh.geometry->setActive(true);
01903         walls.geometry->setActive(true);
01904         break;
01905     }
01906 }
01907 
01908 void display(void)
01909 {
01910     // Show listener position
01911     {
01912         char text[64];
01913 
01914         sprintf(text, "Listener Pos: (%.2f, %.2f, %.2f)", xListenerPos, yListenerPos, zListenerPos);
01915         #ifdef SHOW_GUI_DEBUG_TEXT
01916         debugText.push(std::string(text));
01917         #endif
01918     }
01919     // Show cpu usage position
01920     {
01921         char text[64];
01922         float dsp, stream, geometry, update, total;
01923 
01924         fmodSystem->getCPUUsage(&dsp, &stream, &geometry, &update, &total);
01925         sprintf(text, "CPU Usage : (%.2f, %.2f, %.2f, %.2f, %.2f)", dsp, stream, geometry, update, total);
01926         #ifdef SHOW_GUI_DEBUG_TEXT
01927         debugText.push(std::string(text));
01928         #endif
01929     }
01930 
01931     /*
01932         3D RENDERING
01933     */
01934 
01935         // update view
01936         glMatrixMode(GL_PROJECTION);
01937         glLoadIdentity();
01938         gluPerspective(
01939                 60.0,                                                           // fov
01940                 (float)width / (float)height,           // aspect
01941                 0.1,                                                            // near
01942                 500.0                                                           // far
01943                 );
01944 
01945 
01946         glRotatef(xRotation, 1.0f, 0.0f, 0.0f);
01947         glRotatef(yRotation, 0.0f, 1.0f, 0.0f);
01948         glTranslatef(-xListenerPosRel, -yListenerPos, -zListenerPosRel);
01949         glMatrixMode(GL_MODELVIEW);
01950         glLoadIdentity();
01951 
01952         // clear
01953         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01954         glClearColor(0.4, 0.6f, 1.0f, 0.0f);
01955 
01956         glEnable(GL_TEXTURE_2D);
01957         glBindTexture( GL_TEXTURE_2D, texture );
01958 
01959         // draw geometry
01960         drawGeometry(walls);
01961         drawGeometry(rotatingMesh);
01962 
01963     // draw skybox
01964     drawSkyBox();
01965 
01966         glDisable(GL_TEXTURE_2D);
01967 
01968         // draw sound objects
01969         int object;
01970         if (TaskMode == 3)
01971                 {object=6;}
01972         else
01973                 {object=0;}
01974         //for (object = 0; object < NUM_OBJECTS-6; object++)
01975         {
01976         char txt[256];
01977 
01978 
01979                 float directOcclusion = 1.0f;
01980                 float reverbOcclusion = 1.0f;
01981 
01982                 // set colour baced on direct occlusion
01983 //              objects[object].channel->getOcclusion(&directOcclusion, &reverbOcclusion);
01984                 float intensity = 1.0f;// - directOcclusion;
01985 
01986                 glPolygonMode(GL_FRONT_AND_BACK, rendermode);
01987                 glPushMatrix();
01988                 //glTranslatef(objects[object].xPos, objects[object].yPos, objects[object].zPos);
01989                 glTranslatef(0, objects[object].yPos, 0);
01990 
01991         sprintf(txt, "Sound object (%d): %.2f, %.2f, %.2f", object, objects[object].xPos, objects[object].yPos, objects[object].zPos);
01992         #ifdef SHOW_GUI_DEBUG_TEXT
01993         debugText.push(std::string(txt));
01994         #endif
01995 
01996                 glPushAttrib(GL_LIGHTING_BIT);
01997 
01998                 intensity *= 0.75f;
01999                 float color[4] = { intensity, intensity, 0.0f, 0.0f };
02000                 if(object == 0)
02001                 {//objekt broj 0 je ofarban crveno
02002                         color[1] = 0;
02003                         //std::cout<<objects[0].zPos<<"  "<<objects[0].xPos<<std::endl;
02004                         //std::cout<<std::endl;
02005                 }
02006                 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
02007                 intensity *= 0.5f;
02008                 float ambient[4] = { intensity, intensity, 0.0f, 0.0f };
02009                 if(object == 0)
02010                 {//objekt broj 0 je ofarban crveno
02011                         ambient[1] = 0;
02012                 }
02013 
02014                 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
02015 
02016 
02017                 glRotatef(accumulatedTime * 200.0f, 0.0f, 1.0f, 0.0f);
02018         {
02019             FMOD_VECTOR soundorientation;
02020             float rad = (accumulatedTime * 200.0f);
02021 
02022             rad *= 3.14159f;
02023             rad /= 180.0f;
02024 
02025             soundorientation.x = 0;//sinf(rad);
02026             soundorientation.y = 0;
02027             soundorientation.z = 0;//cosf(rad);
02028 
02029             objects[object].event->set3DAttributes(0, 0, &soundorientation);
02030         }
02031 
02032                 glutSolidTeapot(1.f);//SolidTorus(0.15f, 0.6f, 8, 16);
02033                 glPopAttrib();
02034                 glPopMatrix();
02035         }
02036 
02037     /*
02038         Draw blue transparent blue quads to entry to water room
02039     */
02040     drawWaterRoom();
02041 
02042     /*
02043         Do water effects if we are in the water room
02044     */
02045     inWater();
02046 
02047 
02048     /*
02049         2D RENDERING
02050     */
02051         glMatrixMode(GL_PROJECTION);
02052         glLoadIdentity();
02053         gluOrtho2D(0.0f, (GLsizei)width, 0.0f, (GLsizei)height);
02054         glMatrixMode(GL_MODELVIEW);
02055         glLoadIdentity();
02056 
02057         glDisable(GL_LIGHTING);
02058         glDisable(GL_NORMALIZE);
02059     glDisable(GL_DEPTH_TEST);
02060 
02061     /*
02062         Render text
02063     */
02064     renderUiText();
02065 
02066 
02067     glEnable(GL_DEPTH_TEST);
02068         glEnable(GL_LIGHTING);
02069         glEnable(GL_LIGHT0);
02070         glEnable(GL_NORMALIZE);
02071         glShadeModel(GL_SMOOTH);
02072         glPolygonMode(GL_FRONT_AND_BACK, rendermode);
02073 
02074         // finish
02075         glutSwapBuffers();
02076 }
02077 
02078 void reshapeFunc(int w, int h)
02079 {
02080         width = w;
02081         height = h;
02082         glViewport(0, 0, (GLsizei)w, (GLsizei)h);
02083 }
02084 
02085 GLuint loadTexturePNG(const char *filename)
02086 {
02087     GLuint texture = SOIL_load_OGL_texture(filename, 0, 0, 0);
02088     glBindTexture(GL_TEXTURE_2D, texture);
02089     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
02090     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
02091 
02092     return texture;
02093 }
02094 
02095 GLuint loadTexture(const char *filename)
02096 {
02097     GLuint texture;
02098     int width;
02099         int height;
02100     unsigned char *data;
02101     FILE *file;
02102 
02103     // open texture data
02104     file = fopen( filename, "rb" );
02105     if ( file == NULL )
02106                 return 0;
02107 
02108     width = 128;
02109     height = 128;
02110     data = (unsigned char*)malloc(width * height * 3);
02111 
02112     fread(data, width * height * 3, 1, file );
02113     fclose(file);
02114 
02115     glGenTextures(1, &texture);
02116     glBindTexture(GL_TEXTURE_2D, texture);
02117 
02118     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
02119     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
02120     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
02121     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
02122     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
02123 
02124     gluBuild2DMipmaps(
02125                 GL_TEXTURE_2D,
02126                 3,
02127                 width,
02128                 height,
02129         GL_RGB,
02130                 GL_UNSIGNED_BYTE,
02131                 data);
02132 
02133     free(data);
02134 
02135     return texture;
02136 }
02137 
02138 
02139 void init(void)
02140 {
02141     FMOD_RESULT      result;
02142     bool             listenerflag = true;
02143     FMOD_VECTOR      listenerpos  = { 0.0f, 0.0f, 0.0f };
02144     FMOD_SPEAKERMODE speakermode;
02145 
02146     printf("==================================================================\n");
02147     printf("3D example.  Copyright (c) Firelight Technologies 2004-2011.\n");
02148     printf("==================================================================\n\n");
02149 
02150     result = FMOD::EventSystem_Create(&fmodEventSystem);
02151     ERRCHECK(result);
02152     result = FMOD::NetEventSystem_Init(fmodEventSystem);
02153     ERRCHECK(result);
02154     result = fmodEventSystem->getSystemObject(&fmodSystem);
02155     ERRCHECK(result);
02156     result = fmodSystem->getDriverCaps(0,0,0,&speakermode);
02157     ERRCHECK(result);
02158     result = fmodSystem->setSpeakerMode(speakermode);
02159     ERRCHECK(result);
02160     //result = fmodEventSystem->init(32, FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_SOFTWARE_OCCLUSION | FMOD_INIT_SOFTWARE_HRTF, 0, FMOD_EVENT_INIT_NORMAL);
02161     result = fmodEventSystem->init(32, FMOD_INIT_3D_RIGHTHANDED, 0, FMOD_EVENT_INIT_NORMAL);
02162         //result = fmodEventSystem->init(32, FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_SOFTWARE_OCCLUSION | FMOD_INIT_SOFTWARE_HRTF | FMOD_INIT_DSOUND_HRTFFULL, 0, FMOD_EVENT_INIT_NORMAL);
02163     ERRCHECK(result);
02164     //result = fmodEventSystem->setMediaPath("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media1/");
02165     ERRCHECK(result);
02166     result = fmodEventSystem->load("examples1.fev", 0, &fmodEventProject);
02167     ERRCHECK(result);
02168     result = fmodEventProject->getGroup("FeatureDemonstration/3D Events", true, &fmodEventGroup);
02169     ERRCHECK(result);
02170 
02171     /*
02172         Create a programmer created lowpass filter to apply to everything.
02173     */
02174     result = fmodSystem->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &global_lowpass);
02175     ERRCHECK(result);
02176 
02177     result = global_lowpass->setParameter(FMOD_DSP_LOWPASS_CUTOFF, 1000);
02178     ERRCHECK(result);
02179 
02180     result = global_lowpass->setBypass(true);   // turn it off to start with.
02181     ERRCHECK(result);
02182 
02183     result = fmodSystem->addDSP(global_lowpass, 0);
02184     ERRCHECK(result);
02185 
02186 
02187         initObjects();
02188 
02189         result = fmodSystem->setGeometrySettings(200.0f);
02190     ERRCHECK(result);
02191 
02192     printf("Loading geometry...");
02193 
02194         // load objects
02195         //initGeometry("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/walls.bin", walls, true);
02196         //initGeometry("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/center.bin", rotatingMesh);
02197         initGeometry("files/walls.bin", walls, true);
02198         initGeometry("files/center.bin", rotatingMesh);
02199 
02200     printf("done.\n");
02201 
02202     /*
02203         Load textures
02204     */
02205     printf("Loading textures...\n");
02206 
02207         /*texture = loadTexture("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/texture.img");
02208     skyboxTexture[0] = loadTexturePNG("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/skybox/bluesky/front.png");
02209     skyboxTexture[1] = loadTexturePNG("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/skybox/bluesky/right.png");
02210     skyboxTexture[2] = loadTexturePNG("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/skybox/bluesky/back.png");
02211     skyboxTexture[3] = loadTexturePNG("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/skybox/bluesky/left.png");
02212     skyboxTexture[4] = loadTexturePNG("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/skybox/bluesky/top.png");
02213     skyboxTexture[5] = loadTexturePNG("C:/Program Files/FMOD SoundSystem/FMOD Programmers API Win32/fmoddesignerapi/examples/media/skybox/bluesky/bottom.png");
02214         */
02215         texture = loadTexture("files/texture.img");
02216     skyboxTexture[0] = loadTexturePNG("files/front.png");
02217     skyboxTexture[1] = loadTexturePNG("files/right.png");
02218     skyboxTexture[2] = loadTexturePNG("files/back.png");
02219     skyboxTexture[3] = loadTexturePNG("files/left.png");
02220     skyboxTexture[4] = loadTexturePNG("files/top.png");
02221     skyboxTexture[5] = loadTexturePNG("files/bottom.png");
02222 
02223 
02224     printf("done.\n");
02225 
02226         // setup lighting
02227         GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0};
02228         GLfloat lightPosition[] = {300.0, 1000.0, 400.0, 0.0};
02229         GLfloat lightAmbiant[] = {1.25, 1.25, 1.25, 1.0};
02230         glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
02231         glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
02232         glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbiant);
02233         glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0f);
02234         glEnable(GL_LIGHT0);
02235         glEnable(GL_LIGHTING);
02236 
02237     // setup fog(water)
02238     GLfloat     fogColor[4] = {0.0f,0.1f,0.9f,1.0f};
02239 
02240         glFogi(GL_FOG_MODE, GL_EXP);        // Fog Mode
02241         glFogfv(GL_FOG_COLOR, fogColor);    // Set Fog Color
02242         glFogf(GL_FOG_DENSITY, 0.15f);      // How Dense Will The Fog Be
02243         glHint(GL_FOG_HINT, GL_DONT_CARE);      // Fog Hint Value
02244         glFogf(GL_FOG_START, 0.0f);                     // Fog Start Depth
02245         glFogf(GL_FOG_END, 1.0f);                       // Fog End Depth
02246 
02247         glEnable(GL_DEPTH_TEST);
02248 
02249         glMatrixMode(GL_MODELVIEW);
02250         glLoadIdentity();
02251 }
02252 
02253 GlutCloseClass::~GlutCloseClass()
02254 {
02255     glDeleteTextures( 1, &texture );
02256 
02257         freeGeometry(walls);
02258         freeGeometry(rotatingMesh);
02259 
02260     fmodEventSystem->release();
02261     FMOD::NetEventSystem_Shutdown();
02262 
02263     //_CrtDumpMemoryLeaks();
02264 }
02265 }
02266 
02267 using namespace FMOD;
02268 
02269 int     main(int argc, char **argv)
02270 {
02271         try
02272         {
02273         //ako nema command line parametara, ppita se path do config fajla
02274         std::string path, configToUse;
02275                 if(argc < 2)
02276                 {
02277                         std::cout<<"Please enter path to config file for Audio experiment"<<std::endl;
02278                         std::cin>>path;
02279                 }
02280                 else
02281                 {//inace se prvi param uzme kao path
02282                         path = argv[1];
02283                 }
02284 
02285                 if(argc < 3)
02286                 {//
02287                         configToUse = "";
02288                 }
02289                 else
02290                 {//A drugi kao ime configa
02291                         configToUse = argv[2];
02292                 }
02293 
02294                 labust::xml::Reader reader(path, true);
02295                 //kreiraj xml citac
02296                 std::string configQuery;
02297                 if (configToUse.empty())
02298                 {
02299                         configQuery = "/configurations/config[@type='program']";
02300                 }
02301                 else
02302                 {
02303                         configQuery = "/configurations/config[@type='program' and @name='"+configToUse+"']";
02304                 }
02305 
02306                 _xmlNode* configNode = NULL;
02307                 int sampleParam;
02308                 if (reader.try_value(configQuery, &configNode))
02309                 {//pozicioniraj se u cvor koji ima config za moj program i ucitaj varijable za PROGRAM
02310                 reader.useNode(configNode);
02311                         reader.try_value("param[@name='FilterMessage']/@value", &filterMessageLabel);
02312                         reader.try_value("param[@name='RovMessage']/@value", &rovMessageLabel);
02313                         reader.try_value("param[@name='DvlMessage']/@value", &dvlMessageLabel);
02314                         reader.try_value("param[@name='TARGETMessage']/@value", &TARGETMessageLabel);
02315                         reader.try_value("param[@name='ObjectLat']/@value", &ObjectLat);
02316                         reader.try_value("param[@name='ObjectLong']/@value", &ObjectLong);
02317                         reader.try_value("param[@name='AltitudeSetPoint']/@value", &AltitudeSetPoint);
02318                         reader.try_value("param[@name='Doppler']/@value", &Doppler);
02319                         reader.try_value("param[@name='Silence_angle']/@value", &SilenceAngle);
02320                         reader.try_value("param[@name='Verbal_angle']/@value", &VerbalAngle);
02321                         reader.try_value("param[@name='NonLinear_coeff']/@value", &NonLinearCoeff);
02322                         reader.try_value("param[@name='Guidance_Mode']/@value", &GuidanceMode);
02323                         reader.try_value("param[@name='Task_Mode']/@value", &TaskMode);
02324                         reader.try_value("param[@name='K_Diter_Time']/@value", &KDiterTime);
02325                         reader.try_value("param[@name='AmpDiter']/@value", &AmpDiter);
02326                         reader.try_value("param[@name='FreqDiter']/@value", &FreqDiter);
02327                         reader.try_value("param[@name='JoyStick_Mode']/@value", &JoyStickMode);
02328                         reader.try_value("param[@name='PathVelocity']/@value", &PathVelocity);
02329                         reader.try_value("param[@name='SpeedProfile']/@value", &SpeedProfile);
02330                         reader.try_value("param[@name='NonLinear_coeff_distance']/@value", &NonLinearCoeffDist);
02331                         reader.try_value("param[@name='Kintegral']/@value", &Ki);
02332                         reader.try_value("param[@name='Sound']/@value", &Sound);
02333                         reader.try_value("param[@name='PathStartX']/@value", &PathStartX1);
02334                         reader.try_value("param[@name='PathStartY']/@value", &PathStartY1);
02335                         reader.try_value("param[@name='RabbitDistance']/@value", &RabbitDistance);
02336                 }
02337                 //vrati se u cvor i posalji config u moos comms interface
02338                 reader.useNode(configNode);
02339                 comms = new LABUST::COMMUNICATION::GyrosMoosCommsInterface(reader);
02340 
02341                 //reader.useNode(configNode);//,"PalicaMS"); //ovo ti je citac xml fajla
02342                 //LABUST::COMMUNICATION::GyrosMoosCommsInterface comms(reader, moosConfig);     
02343 
02344 
02345                 if (JoyStickMode==2)
02346                 {
02347                         std::string joystickConfig("PalicaMS");
02348                         reader.useNode(configNode);
02349                         joystick = new LABUST::JoystickReader(reader,joystickConfig);
02350                 }
02351 
02352 
02353 
02354 
02355                 // Inicijalizacija joysticka
02356 
02357         srand((unsigned)time(0));
02358 
02359         //Upisivanje zadanih parametara u Log_Doc file 
02360 
02361         file<<"ImuCom ;Doppler ;SilenceAngle ;VerbalAngle ;NonLinearCoeff ;GuidanceMode ;TaskMode ;RabbitDistance ;PathVelocity ;NonLinearCoeffDistance; PathStartX ;PathStartY"<<std::endl;
02362         file<<Doppler<<" ;"<<SilenceAngle<<" ;"<<VerbalAngle<<" ;"<<NonLinearCoeff<<" ;"<<GuidanceMode<<" ;"<<TaskMode<<" ;"<<RabbitDistance<<" ;"<<PathVelocity<<" ;"<<NonLinearCoeffDist<<" ;"<<PathStartX<<" ;"<<PathStartY<<" ;"<<std::endl;
02363         file<<"WayPointx;WayPointy;WayPointz"<<std::endl;
02364 
02365         //Upisivanje podataka u Header Log_Doc file
02366         file<<"Control_signal_field ;TauX ;TauY ;TauZ ;TauYaw ;ROV_N ;ROV_E ;ROV_Z ;Azimuth ;DistanceToPath ;Altitude ;TargetN ;TargetE ;TargetZ ;Head ;DirToTarget ;RabbitN ;RabbitE ;Time ;"<<std::endl;
02367 
02368 
02369         glutInit(&argc, argv);
02370 
02371         glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
02372         glutInitWindowSize(width, height);
02373         glutCreateWindow("Audio guidance");
02374         glutDisplayFunc(display);       
02375         glutReshapeFunc(reshapeFunc);
02376         glutMouseFunc(mouseFunc);
02377         glutMotionFunc(motionFunc);
02378         glutKeyboardFunc(keyboardFunc);
02379         glutKeyboardUpFunc(keyboardUpFunc);
02380     glutSpecialFunc(specialKeyFunc);
02381     glutSpecialUpFunc(specialKeyUpFunc);
02382 
02383         glutTimerFunc(INTERFACE_UPDATETIME, timerFunc, 0);
02384 
02385         init();
02386 
02387     usleep(1000*1000);
02388 
02389         glutMainLoop();
02390 
02391         }
02392         catch(std::exception &e)
02393         {
02394                 std::cout<<e.what()<<std::endl;
02395         }
02396         return 0;
02397 }


acoustic_vr
Author(s):
autogenerated on Fri Feb 7 2014 11:37:09