void Creature::toXml(QDomDocument& xml, QDomElement * parent) const { QDomElement creature = xml.createElement("Creature"); // creature.setAttribute("id", getId()); creature.setAttribute("name", QString(getName().c_str())); // creature.setAttribute("type", QString::number(getType())); creature.setAttribute("body-parts", getNumberOfBodyParts()); creature.setAttribute("constraints", getNumberOfConstraints()); creature.setAttribute("hidden-layers", getNeuralNetwork().getNumberOfLayers() - 2); creature.setAttribute("neurons-per-layer", getNeuralNetwork().getLayer(1).getNumberOfNeurons()); creature.setAttribute("initial-position", QString(( TO_STRING(getInitialPosition().x()) + " ; " + TO_STRING(getInitialPosition().y()) + " ; " + TO_STRING(getInitialPosition().z())).c_str())); creature.setAttribute("final-position", QString(( TO_STRING(getFinalPosition().x()) + " ; " + TO_STRING(getFinalPosition().y()) + " ; " + TO_STRING(getFinalPosition().z())).c_str())); creature.setAttribute("fitness", getFitness()); for (int i = 0; i < getNumberOfBodyParts(); ++i) { getBodyPart(i).toXml(xml, &creature); } for (int i = 0; i < getNumberOfConstraints(); ++i) { getConstraint(i).toXml(xml, &creature); } getNeuralNetwork().toXml(xml, &creature); if (parent) { parent->appendChild(creature); } else { xml.appendChild(creature); } }
//============================================================================== bool Joint::checkSanity(bool _printWarnings) const { bool sane = true; for(std::size_t i=0; i < getNumDofs(); ++i) { if(getInitialPosition(i) < getPositionLowerLimit(i) || getPositionUpperLimit(i) < getInitialPosition(i)) { if(_printWarnings) { dtwarn << "[Joint::checkSanity] Initial position of index " << i << " [" << getDofName(i) << "] in Joint [" << getName() << "] is " << "outside of its position limits\n" << " -- Initial Position: " << getInitialPosition(i) << "\n" << " -- Limits: [" << getPositionLowerLimit(i) << ", " << getPositionUpperLimit(i) << "]\n"; } else { return false; } sane = false; } if(getInitialVelocity(i) < getVelocityLowerLimit(i) || getVelocityUpperLimit(i) < getInitialVelocity(i)) { if(_printWarnings) { dtwarn << "[Joint::checkSanity] Initial velocity of index " << i << " [" << getDofName(i) << "] is Joint [" << getName() << "] is " << "outside of its velocity limits\n" << " -- Initial Velocity: " << getInitialVelocity(i) << "\n" << " -- Limits: [" << getVelocityLowerLimit(i) << ", " << getVelocityUpperLimit(i) << "]\n"; } else { return false; } sane = false; } } return sane; }
int main(int argc, char **argv) { DEBUG_START; if (argc < 3) { printUsage(argv[0]); DEBUG_END; return EXIT_FAILURE; } const char *pathPolyhedron = argv[1]; const char *pathEdgesData = argv[2]; PolyhedronPtr p(new Polyhedron()); if (!p->fscan_default_1_2(pathPolyhedron)) { printf("Failed to read polyhedron data!\n"); printUsage(argv[0]); DEBUG_END; return EXIT_FAILURE; } std::cout << "Number of vertices (custom): " << p->numVertices << std::endl; globalPCLDumper.setNameBase(pathPolyhedron); globalPCLDumper.enableVerboseMode(); Polyhedron_3 initP(p); globalPCLDumper(PCL_DUMPER_LEVEL_DEBUG, "init-polyhedron.ply") << initP; std::cout << "Successfully read the polyhedron..." << std::endl; std::vector<EdgeInfo> data; if (!readEdgeInfoFile(pathEdgesData, data)) { printf("Failed to read edge info data!\n"); printUsage(argv[0]); DEBUG_END; return EXIT_FAILURE; } if (!getInitialPosition(initP, data)) { printf("Failed to initialize edges!\n"); DEBUG_END; return EXIT_FAILURE; } std::cout << "Successfully read the edge info data..." << std::endl; std::vector<Plane_3> planes; for (auto I = initP.planes_begin(), E = initP.planes_end(); I != E; ++I) planes.push_back(normalizePlane(*I)); std::vector<Plane_3> resultingPlanes = correctPlanes(planes, data); dumpResult(planes, resultingPlanes, getCenter(initP)); DEBUG_END; return EXIT_SUCCESS; }
int main() { unsigned char pos = getInitialPosition(); int arr[256]; while(1) { arr[pos] = getNextValue(); arr[pos + 1] = getNextValue(); pos += 2; } return 0; }
Creature * Creature::clone() const { Creature* result = new Creature(getNumberOfBodyParts(), getNumberOfConstraints(), getNeuralNetwork()); for (int i = 0; i < result->getNumberOfBodyParts(); ++i) { result->setBodyPart(i, getBodyPart(i).clone()); } for (int i = 0; i < result->getNumberOfConstraints(); ++i) { result->setConstraint(i, getConstraint(i).clone()); } result->setFinalPosition(getFinalPosition()); result->setInitialPosition(getInitialPosition()); result->setFitness(getFitness()); result->setName(getName()); return result; }
Rectangle::Rectangle() { id = counter; proportion = getRandomProportion(); // set it random color = getRandomColor(); // set it random among fixed values position = glm::vec4(0, 0, 0, 1); scaleMatrix = glm::scale(glm::mat4(1), glm::vec3(2, 2, 1)); rotationMatrix = glm::rotate(glm::mat4(1), 0.0f, glm::vec3(0, 0, 1)); translationMatrix = getInitialPosition(); // modelMatrix = translationMatrix * rotationMatrix * scaleMatrix; // TODO change next lines modelMatrix = translationMatrix * rotationMatrix * scaleMatrix * glm::mat4(1); // modelMatrix = translationMatrix * glm::mat4(1); isPinned = false; isDead = false; previousTime = glfwGetTime(); currentTime = glfwGetTime(); counter++; // rectangle's vertices (object space) [-1:1] float ratio = proportion.x / proportion.y; float scaleFactor = 0; if (ratio > 1) { scaleFactor = 2 / proportion.x; } else { scaleFactor = 2 / proportion.y; } float halfx = proportion.x / 2.0; float halfy = proportion.y / 2.0; float scaledHalfx = scaleFactor * halfx; float scaledHalfy = scaleFactor * halfy; // int zbuffer = static_cast<int>(std::rand() * 1.0 / RAND_MAX * 2 - 1); zbuffer = 0; vertexa = glm::vec4(-scaledHalfx, scaledHalfy, zbuffer, 1); vertexb = glm::vec4(scaledHalfx, scaledHalfy, zbuffer, 1); vertexc = glm::vec4(-scaledHalfx, -scaledHalfy, zbuffer, 1); vertexd = glm::vec4(scaledHalfx, -scaledHalfy, zbuffer, 1); }
void playGame() { Boolean loaded = FALSE; Boolean hasInit = FALSE; Player player; Cell board[BOARD_HEIGHT][BOARD_WIDTH]; char load[BUFFER_SIZE]; char *token; char *readin; playgame_menu(); initialiseBoard(board); printf("Please enter to continue...\n"); while(getchar() != '\n'); displayBoard(board, NULL); twoCommands_menu(); while(TRUE) { if(loaded && hasInit) { fourCommands_menu(); } else if (loaded) { threeCommands_menu(); } readin = fgets(load,80,stdin); load[strlen(readin) - 1] = '\0'; token = strtok(readin,DELIMS); if(strcmp(token,COMMAND_LOAD) == 0) { token = strtok(NULL,DELIMS); getBoard(board,token); loaded = TRUE; } else if(strcmp(token,COMMAND_INIT) == 0) { if(!loaded) { printf("INVALID INPUT.\n"); } else { getInitialPosition(board,&player,token); displayBoard(board,&player); hasInit = TRUE; } } else if (strcmp(token,COMMAND_QUIT) == 0) { int moves = (int) player.moves; printf("Total player moves : %d\n",moves); break; } else { getNextMove(board,token,&player); } } }