bool QLCInputSource::isValid() const { if (universe() != invalidUniverse && channel() != invalidChannel) return true; else return false; }
/*! @todo Ne pas passer par le chargement de TestDemonstration mais faire un copier coller de son contenu dans le setup + une destruction dans le tearDown puis executer les commandes d'accès diverses */ void TestDemonstration::testBuild() { Model::init() ; Model::load("TestDemonstration") ; Object* observer(Model::getObject("Observer")) ; CPPUNIT_ASSERT_MESSAGE("no Observer object",observer) ; Kernel::Log::InformationMessage(std::string("sizeof(Object)=") + toString(sizeof(Object))) ; CPPUNIT_ASSERT_MESSAGE("Observer has no Observer trait", observer->getTrait<Observer>()) ; Kernel::Log::InternalMessage("Testing Observer has Positionned trait") ; CPPUNIT_ASSERT_MESSAGE("Observer has no Positionned trait", observer->getTrait<Positionned>()) ; CPPUNIT_ASSERT_MESSAGE("Observer has Universe trait", observer->getTrait<Universe>()==NULL) ; Kernel::Log::InternalMessage("Testing Observer has Universe ancestor") ; Universe* universe(observer->getParent<Universe>()) ; CPPUNIT_ASSERT_MESSAGE("Observer has no Universe ancestor", universe) ; Kernel::Log::InternalMessage("Testing Universe has object") ; Object* universe_object = universe->getObject() ; CPPUNIT_ASSERT_MESSAGE("universe has no object", universe_object) ; Kernel::Log::InternalMessage("Testing Universe has Universe trait") ; CPPUNIT_ASSERT_MESSAGE("universe has no Universe trait", universe->getObject()->getTrait<Universe>()) ; Kernel::Log::InternalMessage("Testing Observer has StellarSystem ancestor") ; StellarSystem* system(observer->getParent<StellarSystem>()) ; CPPUNIT_ASSERT_MESSAGE("Observer has no StellarSystem ancestor", system) ; Kernel::Log::InformationMessage(std::string("sizeof(StellarSystem)=") + toString(sizeof(StellarSystem))) ; Kernel::Log::InformationMessage(std::string("sizeof(Positionned)=") + toString(sizeof(Positionned))) ; CPPUNIT_ASSERT_MESSAGE("Observer has no Positionned root", observer->getRoot<Positionned>()) ; Model::close() ; }
void test_08() { /// Tries to draw text in different way int universeWidth = 720; int universeHeight = 480; int AmountOfObjects = 3; double pixRatio = 50; Universe universe(universeWidth/pixRatio, universeHeight/pixRatio); Window window = Window(&universe, pixRatio); glClearColor(0.2, 0.2, 0.3, 1.0); addRandomObjects(universe,1,AmountOfObjects); std::string filename = "Courier New Bold.ttf"; std::string text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."; GLuint shader = LoadShaders("shaders/text.glvs", "shaders/text.glfs"); FontTexHandler myFont = FontTexHandler(filename, 32, shader, window.windowSize()); glm::vec3 colour = glm::vec3(1.0, 0.0, 0.0); CircleShader myCircle; do{ // Clear the buffers to set values (in our case only colour buffer needs to be cleared) glClear(GL_COLOR_BUFFER_BIT); myFont.renderText(text, -300.0, 0, 0.8, colour); // Draw the universe's objects on top of that window.drawObjectList(universe.objects,&myCircle); // Do a physics iteration universe.physics_runtime_iteration(); window.pace_frame(); // Swap buffers glfwSwapBuffers(window.GLFWpointer); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window.GLFWpointer, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window.GLFWpointer) == 0 ); // Close OpenGL window and terminate GLFW glfwTerminate(); }
void Device::saveToFile(QFile &file) { QString s; QString t; // Comment s = QString("# Device Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Device") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + name() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Manufacturer s = QString("Manufacturer = ") + deviceClass()->manufacturer() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Model s = QString("Model = ") + deviceClass()->model() + QString("\n"); file.writeBlock((const char*) s, s.length()); // ID t.setNum(m_id); s = QString("ID = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Address t.setNum(address()); s = QString("Address = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Universe t.setNum(universe()); s = QString("Universe = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); }
QString Fixture::status() { QPalette pal; QString info; QString t; // HTML header info += QString("<HTML>"); info += QString("<HEAD>"); info += QString("<TITLE>Fixture Information</TITLE>"); info += QString("</HEAD>"); info += QString("<BODY>"); // Fixture title info += QString("<TABLE COLS=\"1\" WIDTH=\"100%\">"); info += QString("<TR>"); info += QString("<TD BGCOLOR=\""); info += pal.color(QPalette::Highlight).name(); info += QString("\">"); info += QString("<FONT COLOR=\""); info += pal.color(QPalette::HighlightedText).name(); info += QString("\" SIZE=\"5\">"); info += name(); info += QString("</FONT>"); info += QString("</TD>"); info += QString("</TR>"); info += QString("</TABLE>"); // Manufacturer info += QString("<TABLE COLS=\"2\" WIDTH=\"100%\">"); info += QString("<TR>"); info += QString("<TD>"); info += QString("<B>Manufacturer</B>"); info += QString("</TD>"); info += QString("<TD>"); if (m_fixtureDef != NULL) info += m_fixtureDef->manufacturer(); else info += KXMLFixtureGeneric; info += QString("</TD>"); info += QString("</TR>"); // Model info += QString("<TR>"); info += QString("<TD>"); info += QString("<B>Model</B>"); info += QString("</TD>"); info += QString("<TD>"); if (m_fixtureDef != NULL) info += m_fixtureDef->model(); else info += KXMLFixtureGeneric; info += QString("</TD>"); info += QString("</TR>"); // Mode info += QString("<TR>"); info += QString("<TD>"); info += QString("<B>Mode</B>"); info += QString("</TD>"); info += QString("<TD>"); if (m_fixtureDef != NULL && m_fixtureMode != NULL) info += m_fixtureMode->name(); else info += KXMLFixtureGeneric; info += QString("</TD>"); info += QString("</TR>"); // Type info += QString("<TR>"); info += QString("<TD>"); info += QString("<B>Type</B>"); info += QString("</TD>"); info += QString("<TD>"); if (m_fixtureDef != NULL && m_fixtureMode != NULL) info += m_fixtureDef->type(); else info += KXMLFixtureDimmer; info += QString("</TD>"); info += QString("</TR>"); // Universe info += QString("<TR>"); info += QString("<TD>"); info += QString("<B>Universe</B>"); info += QString("</TD>"); info += QString("<TD>"); info += t.sprintf("%d", universe() + 1); info += QString("</TD>"); info += QString("</TR>"); // Address info += QString("<TR>"); info += QString("<TD>"); info += QString("<B>Address space</B>"); info += QString("</TD>"); info += QString("<TD>"); info += t.sprintf("%d - %d", address() + 1, address() + channels()); info += QString("</TD>"); info += QString("</TR>"); info += QString("</TABLE>"); // // Channels // info += QString("<TABLE COLS=\"3\" WIDTH=\"100%\">"); info += QString("<TR>"); // Relative channel column title info += QString("<TD BGCOLOR=\""); info += pal.color(QPalette::Highlight).name(); info += QString("\">"); info += QString("<FONT COLOR=\""); info += pal.color(QPalette::HighlightedText).name(); info += QString("\">"); info += QString("<B>Channel</B>"); info += QString("</FONT>"); info += QString("</TD>"); // DMX channel column title info += QString("<TD BGCOLOR=\""); info += pal.color(QPalette::Highlight).name(); info += QString("\">"); info += QString("<FONT COLOR=\""); info += pal.color(QPalette::HighlightedText).name(); info += QString("\">"); info += QString("<B>DMX</B>"); info += QString("</FONT>"); info += QString("</TD>"); // Channel name column title info += QString("<TD BGCOLOR=\""); info += pal.color(QPalette::Highlight).name(); info += QString("\">"); info += QString("<FONT COLOR=\""); info += pal.color(QPalette::HighlightedText).name(); info += QString("\" SIZE=\"3\">"); info += QString("<B>Name</B>"); info += QString("</FONT>"); info += QString("</TD>"); info += QString("</TR>"); // Fill table with the fixture's channels for (t_channel ch = 0; ch < channels(); ch++) { info += QString("<TR>"); // Relative channel info += QString("<TD>"); info += t.setNum(ch + 1); info += QString("</TD>"); // DMX channel info += QString("<TD>"); info += t.setNum(address() + ch + 1); info += QString("</TD>"); // Channel name info += QString("<TD>"); if (m_fixtureDef != NULL && m_fixtureMode != NULL) info += channel(ch)->name(); else info += "Level"; info += QString("</TD>"); } info += QString("</TR>"); info += QString("</TABLE>"); info += QString("</BODY>"); info += QString("</HTML>"); return info; }
bool Fixture::saveXML(QDomDocument* doc, QDomElement* wksp_root) { QDomElement root; QDomElement tag; QDomText text; QString str; Q_ASSERT(doc != NULL); /* Fixture Instance entry */ root = doc->createElement(KXMLFixture); wksp_root->appendChild(root); /* Manufacturer */ tag = doc->createElement(KXMLQLCFixtureDefManufacturer); root.appendChild(tag); if (m_fixtureDef != NULL) text = doc->createTextNode(m_fixtureDef->manufacturer()); else text = doc->createTextNode(KXMLFixtureGeneric); tag.appendChild(text); /* Model */ tag = doc->createElement(KXMLQLCFixtureDefModel); root.appendChild(tag); if (m_fixtureDef != NULL) text = doc->createTextNode(m_fixtureDef->model()); else text = doc->createTextNode(KXMLFixtureGeneric); tag.appendChild(text); /* Fixture mode */ tag = doc->createElement(KXMLQLCFixtureMode); root.appendChild(tag); if (m_fixtureMode != NULL) text = doc->createTextNode(m_fixtureMode->name()); else text = doc->createTextNode(KXMLFixtureGeneric); tag.appendChild(text); /* ID */ tag = doc->createElement(KXMLFixtureID); root.appendChild(tag); str.setNum(id()); text = doc->createTextNode(str); tag.appendChild(text); /* Name */ tag = doc->createElement(KXMLFixtureName); root.appendChild(tag); text = doc->createTextNode(m_name); tag.appendChild(text); /* Universe */ tag = doc->createElement(KXMLFixtureUniverse); root.appendChild(tag); str.setNum(universe()); text = doc->createTextNode(str); tag.appendChild(text); /* Address */ tag = doc->createElement(KXMLFixtureAddress); root.appendChild(tag); str.setNum(address()); text = doc->createTextNode(str); tag.appendChild(text); /* Channel count */ tag = doc->createElement(KXMLFixtureChannels); root.appendChild(tag); str.setNum(channels()); text = doc->createTextNode(str); tag.appendChild(text); return true; }
bool Fixture::saveXML(QDomDocument* doc, QDomElement* wksp_root) const { QDomElement root; QDomElement tag; QDomText text; QString str; Q_ASSERT(doc != NULL); /* Fixture Instance entry */ root = doc->createElement(KXMLFixture); wksp_root->appendChild(root); /* Manufacturer */ tag = doc->createElement(KXMLQLCFixtureDefManufacturer); root.appendChild(tag); if (m_fixtureDef != NULL) text = doc->createTextNode(m_fixtureDef->manufacturer()); else text = doc->createTextNode(KXMLFixtureGeneric); tag.appendChild(text); /* Model */ tag = doc->createElement(KXMLQLCFixtureDefModel); root.appendChild(tag); if (m_fixtureDef != NULL) text = doc->createTextNode(m_fixtureDef->model()); else text = doc->createTextNode(KXMLFixtureGeneric); tag.appendChild(text); /* Fixture mode */ tag = doc->createElement(KXMLQLCFixtureMode); root.appendChild(tag); if (m_fixtureMode != NULL) text = doc->createTextNode(m_fixtureMode->name()); else text = doc->createTextNode(KXMLFixtureGeneric); tag.appendChild(text); /* RGB Panel physical dimensions */ if (m_fixtureDef != NULL && m_fixtureDef->model() == KXMLFixtureRGBPanel && m_fixtureMode != NULL) { tag = doc->createElement(KXMLQLCPhysicalDimensionsWeight); root.appendChild(tag); text = doc->createTextNode(QString::number(m_fixtureMode->physical().width())); tag.appendChild(text); tag = doc->createElement(KXMLQLCPhysicalDimensionsHeight); root.appendChild(tag); text = doc->createTextNode(QString::number(m_fixtureMode->physical().height())); tag.appendChild(text); } /* ID */ tag = doc->createElement(KXMLFixtureID); root.appendChild(tag); str.setNum(id()); text = doc->createTextNode(str); tag.appendChild(text); /* Name */ tag = doc->createElement(KXMLFixtureName); root.appendChild(tag); text = doc->createTextNode(m_name); tag.appendChild(text); /* Universe */ tag = doc->createElement(KXMLFixtureUniverse); root.appendChild(tag); str.setNum(universe()); text = doc->createTextNode(str); tag.appendChild(text); /* Address */ tag = doc->createElement(KXMLFixtureAddress); root.appendChild(tag); str.setNum(address()); text = doc->createTextNode(str); tag.appendChild(text); /* Channel count */ tag = doc->createElement(KXMLFixtureChannels); root.appendChild(tag); str.setNum(channels()); text = doc->createTextNode(str); tag.appendChild(text); if (m_excludeFadeIndices.count() > 0) { tag = doc->createElement(KXMLFixtureExcludeFade); root.appendChild(tag); QString list; for (int i = 0; i < m_excludeFadeIndices.count(); i++) { if (list.isEmpty() == false) list.append(QString(",")); list.append(QString("%1").arg(m_excludeFadeIndices.at(i))); } text = doc->createTextNode(list); tag.appendChild(text); } if (m_forcedHTPIndices.count() > 0) { tag = doc->createElement(KXMLFixtureForcedHTP); root.appendChild(tag); QString list; for (int i = 0; i < m_forcedHTPIndices.count(); i++) { if (list.isEmpty() == false) list.append(QString(",")); list.append(QString("%1").arg(m_forcedHTPIndices.at(i))); } text = doc->createTextNode(list); tag.appendChild(text); } if (m_forcedLTPIndices.count() > 0) { tag = doc->createElement(KXMLFixtureForcedLTP); root.appendChild(tag); QString list; for (int i = 0; i < m_forcedLTPIndices.count(); i++) { if (list.isEmpty() == false) list.append(QString(",")); list.append(QString("%1").arg(m_forcedLTPIndices.at(i))); } text = doc->createTextNode(list); tag.appendChild(text); } if (m_channelModifiers.isEmpty() == false) { QHashIterator<quint32, ChannelModifier *> it(m_channelModifiers); while (it.hasNext()) { it.next(); quint32 ch = it.key(); ChannelModifier *mod = it.value(); if (mod != NULL) { tag = doc->createElement(KXMLFixtureChannelModifier); tag.setAttribute(KXMLFixtureChannelIndex, ch); tag.setAttribute(KXMLFixtureModifierName, mod->name()); root.appendChild(tag); } } } return true; }
QString Fixture::status() const { QString info; QString t; QString title("<TR><TD CLASS='hilite' COLSPAN='3'>%1</TD></TR>"); QString subTitle("<TR><TD CLASS='subhi' COLSPAN='3'>%1</TD></TR>"); QString genInfo("<TR><TD CLASS='emphasis'>%1</TD><TD COLSPAN='2'>%2</TD></TR>"); /******************************************************************** * General info ********************************************************************/ info += "<TABLE COLS='3' WIDTH='100%'>"; // Fixture title info += title.arg(name()); // Manufacturer if (isDimmer() == false) { info += genInfo.arg(tr("Manufacturer")).arg(m_fixtureDef->manufacturer()); info += genInfo.arg(tr("Model")).arg(m_fixtureDef->model()); info += genInfo.arg(tr("Mode")).arg(m_fixtureMode->name()); info += genInfo.arg(tr("Type")).arg(m_fixtureDef->type()); } else { info += genInfo.arg(tr("Type")).arg(tr("Generic Dimmer")); } // Universe info += genInfo.arg(tr("Universe")).arg(universe() + 1); // Address QString range = QString("%1 - %2").arg(address() + 1).arg(address() + channels()); info += genInfo.arg(tr("Address Range")).arg(range); // Channels info += genInfo.arg(tr("Channels")).arg(channels()); // Binary address QString binaryStr = QString("%1").arg(address() + 1, 10, 2, QChar('0')); QString dipTable("<TABLE COLS='33' cellspacing='0'><TR><TD COLSPAN='33'><IMG SRC=\"" ":/ds_top.png\"></TD></TR>"); dipTable += "<TR><TD><IMG SRC=\"" ":/ds_border.png\"></TD><TD><IMG SRC=\"" ":/ds_border.png\"></TD>"; for (int i = 9; i >= 0; i--) { if (binaryStr.at(i) == '0') dipTable += "<TD COLSPAN='3'><IMG SRC=\"" ":/ds_off.png\"></TD>"; else dipTable += "<TD COLSPAN='3'><IMG SRC=\"" ":/ds_on.png\"></TD>"; } dipTable += "<TD><IMG SRC=\"" ":/ds_border.png\"></TD></TR>"; dipTable += "<TR><TD COLSPAN='33'><IMG SRC=\"" ":/ds_bottom.png\"></TD></TR>"; dipTable += "</TABLE>"; info += genInfo.arg(tr("Binary Address (DIP)")) .arg(QString("%1").arg(dipTable)); /******************************************************************** * Channels ********************************************************************/ // Title row info += QString("<TR><TD CLASS='subhi'>%1</TD>").arg(tr("Channel")); info += QString("<TD CLASS='subhi'>%1</TD>").arg(tr("DMX")); info += QString("<TD CLASS='subhi'>%1</TD></TR>").arg(tr("Name")); // Fill table with the fixture's channels for (quint32 ch = 0; ch < channels(); ch++) { QString chInfo("<TR><TD>%1</TD><TD>%2</TD><TD>%3</TD></TR>"); info += chInfo.arg(ch + 1).arg(address() + ch + 1) .arg(channel(ch)->name()); } /******************************************************************** * Extended device information for non-dimmers ********************************************************************/ if (isDimmer() == false) { QLCPhysical physical = m_fixtureMode->physical(); info += title.arg(tr("Physical")); float mmInch = 0.0393700787; float kgLbs = 2.20462262; QString mm("%1mm (%2\")"); QString kg("%1kg (%2 lbs)"); QString W("%1W"); info += genInfo.arg(tr("Width")).arg(mm.arg(physical.width())) .arg(physical.width() * mmInch, 0, 'g', 4); info += genInfo.arg(tr("Height")).arg(mm.arg(physical.height())) .arg(physical.height() * mmInch, 0, 'g', 4); info += genInfo.arg(tr("Depth")).arg(mm.arg(physical.depth())) .arg(physical.depth() * mmInch, 0, 'g', 4); info += genInfo.arg(tr("Weight")).arg(kg.arg(physical.weight())) .arg(physical.weight() * kgLbs, 0, 'g', 4); info += genInfo.arg(tr("Power consumption")).arg(W.arg(physical.powerConsumption())); info += genInfo.arg(tr("DMX Connector")).arg(physical.dmxConnector()); // Bulb QString K("%1K"); QString lm("%1lm"); info += subTitle.arg(tr("Bulb")); info += genInfo.arg(tr("Type")).arg(physical.bulbType()); info += genInfo.arg(tr("Luminous Flux")).arg(lm.arg(physical.bulbLumens())); info += genInfo.arg(tr("Colour Temperature")).arg(K.arg(physical.bulbColourTemperature())); // Lens QString angle1("%1°"); QString angle2("%1° – %2°"); info += subTitle.arg(tr("Lens")); info += genInfo.arg(tr("Name")).arg(physical.lensName()); if (physical.lensDegreesMin() == physical.lensDegreesMax()) { info += genInfo.arg(tr("Beam Angle")) .arg(angle1.arg(physical.lensDegreesMin())); } else { info += genInfo.arg(tr("Beam Angle")) .arg(angle2.arg(physical.lensDegreesMin()) .arg(physical.lensDegreesMax())); } // Focus QString range("%1°"); info += subTitle.arg(tr("Focus")); info += genInfo.arg(tr("Type")).arg(physical.focusType()); info += genInfo.arg(tr("Pan Range")).arg(range.arg(physical.focusPanMax())); info += genInfo.arg(tr("Tilt Range")).arg(range.arg(physical.focusTiltMax())); } // HTML document & table closure info += "</TABLE>"; if (isDimmer() == false) { info += "<HR>"; info += "<DIV CLASS='author' ALIGN='right'>"; info += tr("Fixture definition author: ") + fixtureDef()->author(); info += "</DIV>"; } return info; }
void test_10(){ ////Test most basic Texturing int universeWidth = 720; int universeHeight = 480; int AmountOfObjects = 3; double pixRatio = 50; glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); Universe universe(universeWidth/pixRatio, universeHeight/pixRatio); Window window = Window(&universe, pixRatio); addRandomObjects(universe,1,AmountOfObjects); glClearColor(0.2, 0.2, 0.3, 1.0); GLuint Texture = loadDDS("Asteroid.DDS"); TextureShader myShader(Texture); GLuint programID = myShader.programID; // Get a handle for our "MVP" uniform glm::vec4 colour = {1.0f, 0.0f,0.0f,1.0f}; CircleShader myCircle(colour); //myCircle.colour=colour; double size; double step = 0.001; double phi = 0.003; const GLfloat c = cos(phi); const GLfloat s = sin(phi); glm::mat3 rot = { c, -s, 0, s, c, 0, 0, 0, 1 }; do{ size = cos(step+=0.01); myCircle.tMatrixReset(); myCircle.tMatrixTranslate({size,0.0}); myCircle.tMatrixScale({size,size}); myShader.transformationMatrix *= rot; // Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); myShader.draw(); myCircle.draw(); // Swap buffers glfwSwapBuffers(window.GLFWpointer); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window.GLFWpointer, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window.GLFWpointer) == 0 ); // Close OpenGL window and terminate GLFW glfwTerminate(); }
void test_09(){ //// Most basic colouring shaders int universeWidth = 720; int universeHeight = 480; int AmountOfObjects = 3; double pixRatio = 50; Universe universe(universeWidth/pixRatio, universeHeight/pixRatio); Window window = Window(&universe, pixRatio); addRandomObjects(universe,1,AmountOfObjects); glClearColor(0.2, 0.2, 0.3, 1.0); GLuint shader = LoadShaders("shaders/test.glvs", "shaders/test.glfs"); GLuint vertexPosLocation = glGetAttribLocation(shader, "VertexPos" ); GLuint textColorLocation = glGetUniformLocation(shader, "textColor"); GLuint circleShader = LoadShaders("shaders/circle.glvs", "shaders/circle.glfs"); GLuint discColor = glGetAttribLocation(circleShader, "disc_color" ); GLuint VertexArrayID; glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); static const GLfloat g_vertex_buffer_data[] = { -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, }; GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); glm::vec3 color = {1,0,0}; float colorStep =0.001; do{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(color.x >= 1.0 && color.y < 1.0){ if(color.z > 0){ color.z -= colorStep; }else{ color.y += colorStep; } }else if(color.y >= 1.0 && color.z < 1.0){ if(color.x > 0){ color.x -= colorStep; }else{ color.z += colorStep; } }else if(color.z >= 1 && color.x < 1.0){ if(color.y > 0){ color.y -= colorStep; }else{ color.x += colorStep; } } // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute 0. No particular reason for 0, but must match the layout in the shader. 4, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle glUseProgram(circleShader); glUniform4f(discColor, color.x, color.y, color.z, 1.0f); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); // Starting from vertex 0; 3 vertices total -> 1 triangle glDisableVertexAttribArray(0); //shader.use(); //glUniform3f(textColorLocation, color.x, color.y, color.z); //window.drawObjectList(universe.objects); //universe.physics_runtime_iteration(); glfwSwapBuffers(window.GLFWpointer); glfwPollEvents(); }while ( glfwGetKey(window.GLFWpointer, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window.GLFWpointer) == 0 ); // Close OpenGL window and terminate GLFW glfwTerminate(); }
void test_07() { //// WRITES SYSTEM ENERGY TO FILE int width = 600; int height = 400; Object* A = new Player; Object* B = new Object; Object* C = new Object; Object* D = new Object; Window window = Window(width,height,NULL,30,vis::AUTO_SIZE_UNIVERSE); // Set them apart, and on a collision course A->set_position(2, 0); A->set_velocity(0,0); A->set_radius(0.5); A->set_mass(5); A->bouncyness = 1; B->set_position(2, 2); B->set_velocity(0, -1); B->set_mass(2); //B->bouncyness = 0.7; C->set_position(-2, -2); C->set_mass(2); //C->bouncyness = 0.7; D->set_position(-4, -4); D->set_mass(2); //D->bouncyness = 0.7; // Generate a universe Universe universe(width/window.pixRatio, height/window.pixRatio); window.bindUniverse(&universe); // Add them to the universe universe.add_object(A); universe.add_object(B); universe.add_object(C); universe.add_object(D); vec2d posA; vec2d posB; std::ofstream outputfile; outputfile.open("test_07.csv"); Universe* uni = &universe; do{ for(int ii = 0; ii < universe.objects.size(); ii++){ double vel2 = len_squared(universe.objects[ii]->get_velocity()); outputfile << 0.5*universe.objects[ii]->get_mass()*vel2 << ","; double ener = 0; for (int qq = 0; qq < universe.objects.size(); ++qq ) { // Make sure you are not calculating yourself if (qq == ii) { // This is myself, skip this loop iteration continue; } // Here add up the contribution to the acceleration ener += potentialEnergy(universe.objects[ii], universe.objects[qq],uni); } //// Made the potential energy per object only store half, as for each potential between 2 objects 2 objects store it but there is only one potential. if(ii == universe.objects.size()-1){ outputfile << ener/2 << ";" << std::endl; }else{ outputfile << ener/2 << ","; } } // Clear the buffers to set values (in our case only colour buffer needs to be cleared) glClear(GL_COLOR_BUFFER_BIT); // Draw the universe's objects on top of that window.drawObjectList(universe.objects); // Do a physics iteration universe.simulate_one_time_unit(window.fps); // Swap buffers glfwSwapBuffers(window.GLFWpointer); glfwPollEvents(); window.pace_frame(); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window.GLFWpointer, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window.GLFWpointer) == 0 ); outputfile.close(); // Close OpenGL window and terminate GLFW glfwTerminate(); }
void test_06() { ////// Press Z to zoom // Window dimensions [px] int width = 720; int height = 480; // universe dimensions [px] int universeWidth = 900; int universeHeight = 700; int AmountOfObjects = 800; // window already makes GLFWpointer currentContext so no need to call it again later on. // set ration of [px/m] double pixRatio = 25; Object* A = new Object; Object* B = new Object; // Set them apart, and on a collision course //A->set_position(-2, -2); //A->set_velocity(2,0); //A->set_mass(0.5); //A->bouncyness = 1; //B->set_position(2, 2); //B->set_velocity(0, 1); //B->set_mass(0.5); //B->set_radius(1); // Generate a universe Universe universe(universeWidth/pixRatio, universeHeight/pixRatio); Window window = Window(&universe, pixRatio); //// Look in the addRandomObjects function to find the parameter range of objects addRandomObjects(universe,0,AmountOfObjects); CircleShader myCircleShader; // Add them to the universe //universe.add_object(A); //universe.add_object(B); //vec2d posA; //vec2d posB; // Set the buffer clear color to: glClearColor(0.2, 0.2, 0.3, 1.0); bool HOLDZ = false; do{ // Clear the buffers to set values (in our case only colour buffer needs to be cleared) glClear(GL_COLOR_BUFFER_BIT); // Draw a grid with m/div //window.drawGrid(window.pixRatio); // Draw the universe's objects on top of that window.drawObjectList(universe.objects,&myCircleShader); // Draw A box on the boundaries of the universe //window.drawBox(universe.width, universe.height); // Do a physics iteration universe.physics_runtime_iteration(); //posA = A->get_position(); //posB = B->get_position(); // std::cout << "Position of A: " << posA[0] << "," << posA[1] << " Position of B: " << posB[0] << "," << posB[1] << ";" << std::endl; window.pace_frame(); // Swap buffers glfwSwapBuffers(window.GLFWpointer); glfwPollEvents(); // This makes you zoom between 25 and 50 pixels per m if(glfwGetKey(window.GLFWpointer, GLFW_KEY_Z) == GLFW_PRESS){ if(!HOLDZ){ HOLDZ = true; window.changeResizeFlag(vis::ZOOM_UNIVERSE); } }else{ HOLDZ = false; } } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window.GLFWpointer, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window.GLFWpointer) == 0 ); // Close OpenGL window and terminate GLFW glfwTerminate(); }
void test_01() { // Test collision detection std::cout.setf(std::ios::boolalpha); // make the stream interpret booleans as true/false instead of 1/0 std::cout << "Running test_01..." << std::endl << std::endl; // Generate a few objects Object* A = new Object; Object* B = new Object; // Set positions and velocities A->set_position(50, 20); B->set_position(49.2, 19.2); A->set_velocity(-2,-1); B->set_velocity(1,1); // Generate a universe Universe universe(720.0, 480.0); // check if size print worked. std::cout << "Universe size: " << universe.width << "x" << universe.height << std::endl; // Add the objects to the universe universe.add_object(A); universe.add_object(B); //// COLLISION DETECTION // Print initial conditions std::cout << "Collision detection scenario 1:" << std::endl; debug_display_world(universe); // Collision of objects moving toward each other and overlapping std::cout << "Collision between object A and B is: " << universe.physics.check_collision(A, B) <<"\n" << std::endl; A->set_velocity(2,2); B->set_velocity(1,1); std::cout << "Collision detection scenario 2:" << std::endl; debug_display_world(universe); // Collision of objects moving just away from each other and overlapping std::cout << "Collision between object A and B is: " << universe.physics.check_collision(A, B) <<"\n" << std::endl; A->set_velocity(-2,-1); B->set_velocity(1,1); A->set_position(50,20); B->set_position(48,18); std::cout << "Collision detection scenario 3:" << std::endl; debug_display_world(universe); // Collision of objects moving toward each other and not overlapping std::cout << "Collision between object A and B is: " << universe.physics.check_collision(A, B) <<"\n" << std::endl; ////// COLLISION RESOLVING std::cout << "Collision resolving scenario:" << std::endl; A->set_velocity(-2,-1); B->set_velocity(1,1); A->set_position(50,20); B->set_position(49.2,19.2); debug_display_world(universe); if(universe.physics.check_collision(A,B)){ std::cout << "Collision between object A and B is: " << true <<". Resolving collision..." << std::endl; universe.physics.resolve_collision(A,B); std::cout << "Scenario after collision: " << std::endl; debug_display_world(universe); } }
bool Fixture::saveXML(QXmlStreamWriter *doc) const { Q_ASSERT(doc != NULL); /* Fixture Instance entry */ doc->writeStartElement(KXMLFixture); /* Manufacturer */ if (m_fixtureDef != NULL) doc->writeTextElement(KXMLQLCFixtureDefManufacturer, m_fixtureDef->manufacturer()); else doc->writeTextElement(KXMLQLCFixtureDefManufacturer, KXMLFixtureGeneric); /* Model */ if (m_fixtureDef != NULL) doc->writeTextElement(KXMLQLCFixtureDefModel, m_fixtureDef->model()); else doc->writeTextElement(KXMLQLCFixtureDefModel, KXMLFixtureGeneric); /* Fixture mode */ if (m_fixtureMode != NULL) doc->writeTextElement(KXMLQLCFixtureMode, m_fixtureMode->name()); else doc->writeTextElement(KXMLQLCFixtureMode, KXMLFixtureGeneric); /* RGB Panel physical dimensions */ if (m_fixtureDef != NULL && m_fixtureDef->model() == KXMLFixtureRGBPanel && m_fixtureMode != NULL) { doc->writeTextElement(KXMLQLCPhysicalDimensionsWeight, QString::number(m_fixtureMode->physical().width())); doc->writeTextElement(KXMLQLCPhysicalDimensionsHeight, QString::number(m_fixtureMode->physical().height())); } /* ID */ doc->writeTextElement(KXMLFixtureID, QString::number(id())); /* Name */ doc->writeTextElement(KXMLFixtureName, m_name); /* Universe */ doc->writeTextElement(KXMLFixtureUniverse, QString::number(universe())); /* Address */ doc->writeTextElement(KXMLFixtureAddress, QString::number(address())); /* Channel count */ doc->writeTextElement(KXMLFixtureChannels, QString::number(channels())); if (m_excludeFadeIndices.count() > 0) { QString list; for (int i = 0; i < m_excludeFadeIndices.count(); i++) { if (list.isEmpty() == false) list.append(QString(",")); list.append(QString("%1").arg(m_excludeFadeIndices.at(i))); } doc->writeTextElement(KXMLFixtureExcludeFade, list); } if (m_forcedHTPIndices.count() > 0) { QString list; for (int i = 0; i < m_forcedHTPIndices.count(); i++) { if (list.isEmpty() == false) list.append(QString(",")); list.append(QString("%1").arg(m_forcedHTPIndices.at(i))); } doc->writeTextElement(KXMLFixtureForcedHTP, list); } if (m_forcedLTPIndices.count() > 0) { QString list; for (int i = 0; i < m_forcedLTPIndices.count(); i++) { if (list.isEmpty() == false) list.append(QString(",")); list.append(QString("%1").arg(m_forcedLTPIndices.at(i))); } doc->writeTextElement(KXMLFixtureForcedLTP, list); } if (m_channelModifiers.isEmpty() == false) { QHashIterator<quint32, ChannelModifier *> it(m_channelModifiers); while (it.hasNext()) { it.next(); quint32 ch = it.key(); ChannelModifier *mod = it.value(); if (mod != NULL) { doc->writeStartElement(KXMLFixtureChannelModifier); doc->writeAttribute(KXMLFixtureChannelIndex, QString::number(ch)); doc->writeAttribute(KXMLFixtureModifierName, mod->name()); doc->writeEndElement(); } } } /* End the <Fixture> tag */ doc->writeEndElement(); return true; }
QString Device::infoText() { assert(m_deviceClass); QString t; QString str = QString::null; // // General Info // str += QString("<HTML><HEAD><TITLE>Device Info</TITLE></HEAD><BODY>"); str += QString("<TABLE COLS=\"1\" WIDTH=\"100%\">"); str += QString("<TR><TD BGCOLOR=\"darkblue\"><FONT COLOR=\"white\" SIZE=5>"); str += name() + QString("</FONT></TD></TR></TABLE>"); str += QString("<TABLE COLS=\"2\" WIDTH=\"100%\">"); str += QString("<TR>\n"); str += QString("<TD><B>Manufacturer</B></TD>"); str += QString("<TD>") + m_deviceClass->manufacturer() + QString("</TD>"); str += QString("</TR>"); str += QString("<TR>"); str += QString("<TD><B>Model</B></TD>"); str += QString("<TD>") + m_deviceClass->model() + QString("</TD>"); str += QString("</TR>"); str += QString("<TR>"); str += QString("<TD><B>Type</B></TD>"); str += QString("<TD>") + m_deviceClass->type() + QString("</TD>"); str += QString("</TR>"); str += QString("<TR>"); str += QString("<TD><B>Universe</B></TD>"); t.sprintf("%d", universe() + 1); str += QString("<TD>") + t + QString("</TD>"); str += QString("</TR>"); str += QString("<TR>"); str += QString("<TD><B>Address space</B></TD>"); t.sprintf("%d - %d", address() + 1, address() + m_deviceClass->channels()->count()); str += QString("<TD>") + t + QString("</TD>"); str += QString("</TR>"); str += QString("</TABLE>"); // // Channels // str += QString("<TABLE COLS=\"3\" WIDTH=\"100%\">"); str += QString("<TR>"); str += QString("<TD BGCOLOR=\"darkblue\">"); str += QString("<FONT COLOR=\"white\" SIZE=\"3\">Channel</FONT>"); str += QString("</TD>"); str += QString("<TD BGCOLOR=\"darkblue\">"); str += QString("<FONT COLOR=\"white\" SIZE=\"3\">DMX</FONT>"); str += QString("</TD>"); str += QString("</TR>"); str += QString("<TD BGCOLOR=\"darkblue\">"); str += QString("<FONT COLOR=\"white\" SIZE=\"3\">Name</FONT>"); str += QString("</TD>"); str += QString("</TR>"); for (t_channel ch = 0; ch < (t_channel) m_deviceClass->channels()->count(); ch++) { t.setNum(ch + 1); str += QString("<TR>"); str += QString("<TD>" + t + "</TD>"); t.setNum(address() + ch + 1); str += QString("<TD>" + t + "</TD>"); str += QString("<TD>"); str += m_deviceClass->channels()->at(ch)->name(); str += QString("</TD>"); } str += QString("</TR>"); str += QString("</TABLE>"); str += QString("</BODY></HTML>"); return str; }