/** * @brief Write the neutral mob data back to a file. */ void NeutralMob::writeToFile( QFile &unitFile ) { QTextStream unitStream(&unitFile); if ( (dirty() > 0) || (rawData() == Q_NULLPTR) ) { // dirty = 0 means not dirty, dirty < 0 means uneditable, dirty > 0 means we can probably edit this entry without issue unitStream << type() << "/" << posX() << "/" << posY() << "/" << posZ() << "/" << rotation() << "/"; // Write all the unknown floats for (int i=0; i<4; i++) { unitStream << unknown_float(i) << "/"; } // Write all the options for (int i=0; i<3; i++) { unitStream << QString(option(i)?"True":"False") << "/"; } } else { unitStream << rawData(); } unitStream << endl; unitStream.flush(); }
Cube::Cube(const position_type &where, std::shared_ptr<Texture> texture ) : Object3D(where) { // 8 points, 6 surfaces position_type blf(-1.0, -1.0, 1.0) // front rectangle , brf(1.0, -1.0, 1.0) , trf(1.0, 1.0, 1.0) , tlf(-1.0, 1.0, 1.0) , blr(-1.0, -1.0, -1.0) // rear rectangle , brr(1.0, -1.0, -1.0) , trr(1.0, 1.0, -1.0) , tlr(-1.0, 1.0, -1.0); position_type negZ(0.0, 0.0, -1.0) , posZ(0.0, 0.0, 1.0) , negY(0.0, -1.0, 0.0) , posY(0.0, 1.0, 0.0) , negX(-1.0, 0.0, 0.0) , posX(1.0, 0.0, 0.0); // if changing the order, make sure to change accessors so they grab the correct object this->add_child(new Rectangle(POSITION_INHERIT, { blf, blr, brr, brf }, { negY, negY, negY, negY }, texture)); // bottom negY this->add_child(new Rectangle(POSITION_INHERIT, { trr, brr, blr, tlr }, { negZ, negZ, negZ, negZ }, texture)); // rear negZ this->add_child(new Rectangle(POSITION_INHERIT, { trf, brf, brr, trr }, { posX, posX, posX, posX }, texture)); // right posX this->add_child(new Rectangle(POSITION_INHERIT, { tlr, blr, blf, tlf }, { negX, negX, negX, negX }, texture)); // left negX this->add_child(new Rectangle(POSITION_INHERIT, { tlf, blf, brf, trf }, { posZ, posZ, posZ, posZ }, texture)); // front posZ this->add_child(new Rectangle(POSITION_INHERIT, { tlr, tlf, trf, trr }, { posY, posY, posY, posY }, texture)); // top posY } // Cube
void NeutralMob::print() { qDebug() << type() << "x" << posX() << "y" << posY() << "z" << posZ() << "rotation" << rotation(); }
void Point2D::draw() { glTranslatef(posX(), posY(), posZ()); glColor3fv(color); glBegin(GL_POINTS); glVertex2f(0.5f, 0.5f); glEnd(); glLoadIdentity(); }
QVariant NeutralMob::data(int role) const { switch(role) { case IdRole: return (unsigned int)id(); case FilterStringRole: return filterString(); case TypeRole: return type(); case PosXRole: return posX(); case PosYRole: return posY(); case PosZRole: return posZ(); case RotationRole: return rotation(); default: return QVariant(); } }
Cube::Cube( const position_type &where, Texture::pointer_type texture ) : Object( where, texture ) { glm::vec3 blf( -1.0, -1.0, 1.0 ) // front rectangle , brf( 1.0, -1.0, 1.0 ) , trf( 1.0, 1.0, 1.0 ) , tlf( -1.0, 1.0, 1.0 ) , blr( -1.0, -1.0, -1.0 ) // rear rectangle , brr( 1.0, -1.0, -1.0 ) , trr( 1.0, 1.0, -1.0 ) , tlr( -1.0, 1.0, -1.0 ) ; glm::vec3 negZ( 0.0, 0.0, -1.0 ) , posZ( 0.0, 0.0, 1.0 ) , negY( 0.0, -1.0, 0.0 ) , posY( 0.0, 1.0, 0.0 ) , negX( -1.0, 0.0, 0.0 ) , posX( 1.0, 0.0, 0.0 ) ; // gl_triangle strip // for ccw winding: top left, bottom left, top right, bottom right auto add_components = [ &]( const std::vector<Component::pointer_type>& vec ) { for ( auto& v : vec ) this->components.emplace_back( v ); }; add_components( Triangle::from_quad( std::vector<glm::vec3>( { blf, blr, brf, brr } ), negY, texture ) ); // bottom add_components( Triangle::from_quad( std::vector<glm::vec3>( { trr, brr, tlr, blr } ), negZ, texture ) ); // rear add_components( Triangle::from_quad( std::vector<glm::vec3>( { trf, brf, trr, brr } ), posX, texture ) ); // right posX add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlr, blr, tlf, blf } ), negX, texture ) ); // left negX add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlf, blf, trf, brf } ), posZ, texture ) ); // front posZ add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlr, tlf, trr, trf } ), posY, texture ) ); // top posY }
void osgMain::createPipe(osg::Vec3 & pt1, osg::Vec3 & pt2, osg::Vec3 & pt3, osg::Vec3Array* shape,bool startPt,osg::ref_ptr<osg::Geode> & currentLine) { __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe"); //shape must be at xy plane if(shape->size()<3) { __android_log_print(ANDROID_LOG_ERROR,"jni server","create pipe NOOOO"); return ; } //currentLine->addDrawable(new osg::ShapeDrawable(new osg::Sphere(pt3,1.0f))); //return; osg::Vec3 v12=(pt1-pt2); v12.normalize(); osg::Vec3 v32=(pt3-pt2); v32.normalize(); osg::ref_ptr<osg::Vec3Array> startShape; osg::Vec3 center(0,0,0); for(int i=0;i<shape->size();i++) center=center+shape->at(i); center=center/(float)shape->size(); __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe OK1"); if(startPt) { __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe OK2"); startShape=new osg::Vec3Array; osg::Vec3 posZ(0.0,0.0,1.0); osg::Vec3 rotAxis=posZ^(-v12); if(rotAxis.length2()<0.01f) return ; float rotAngle=(float)acos((double)(posZ*(-v12))); osg::Matrixd mat; mat.makeRotate(rotAngle,rotAxis); for(int i=0;i<shape->size();i++) startShape->push_back(mat.preMult(shape->at(i)-center)+pt1); __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe OK3"); } else startShape=shape; osg::Vec3 p2Dir; osg::Vec3 half=(v12+v32)/2.0f; half.normalize(); osg::Vec3 p2DirOrtho=v12^half; p2DirOrtho.normalize(); p2Dir=p2DirOrtho^half; p2Dir.normalize(); osg::Vec3 shapeDir=(startShape->at(2)-startShape->at(1))^(startShape->at(0)-startShape->at(1)); shapeDir.normalize(); if(shapeDir*(-v12)<0.0) shapeDir=-shapeDir; __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe OK3"); osg::ref_ptr<osg::Vec3Array> p2Shape=new osg::Vec3Array; osg::Vec3 rotAxis=shapeDir^p2Dir; float rotAngle=(float)acos((double)(shapeDir*p2Dir)); osg::Matrixd mat; mat.makeRotate(rotAngle,rotAxis); osg::Vec3 trans=pt2-pt1; center.set(0,0,0); for(int i=0;i<startShape->size();i++) center=center+startShape->at(i); center=center/(float)startShape->size(); for(int i=0;i<startShape->size();i++) p2Shape->push_back(mat.preMult(startShape->at(i)-center)+center+trans); __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe OK4"); osg::ref_ptr<osg::Geometry> pipe=new osg::Geometry; osg::ref_ptr<osg::Vec3Array> allVerts=new osg::Vec3Array; int numVerts=p2Shape->size(); for(unsigned int i=0;i<numVerts;i++) { allVerts->push_back(startShape->at(i)); allVerts->push_back(startShape->at((i+1)%numVerts)); allVerts->push_back(p2Shape->at(i)); allVerts->push_back(startShape->at((i+1)%numVerts)); allVerts->push_back(p2Shape->at((i+1)%numVerts)); allVerts->push_back(p2Shape->at(i)); } __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe OK5"); pipe->setVertexArray(allVerts.get()); osg::ref_ptr<osg::DrawArrays> array=new osg::DrawArrays(GL_TRIANGLES,0,allVerts->size()); pipe->addPrimitiveSet(array); osgUtil::SmoothingVisitor::smooth(*pipe); for(int i=0;i<numVerts;i++) shape->at(i)=p2Shape->at(i); __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe OK6"); if(startPt) { //currentLine=new osg::Geode(); currentLine->addDrawable(pipe); } else { osgUtil::Optimizer::MergeGeometryVisitor::mergeGeometry(*currentLine->getDrawable(0)->asGeometry(),*pipe); } //return pipe.release(); __android_log_print(ANDROID_LOG_ERROR,"jni client","create pipe finish"); }
int main(int argc, char *argv[]) { # include "setRootCase.H" # include "createTime.H" instantList Times = runTime.times(); # include "checkTimeOptions.H" runTime.setTime(Times[startTime],startTime); # include "createMesh.H" typedef VectorSpace<Vector<scalar>,scalar,4> quad; typedef VectorSpace<Vector<scalar>,scalar,6> hex; //read setDiscreteFieldsDictionary IOdictionary setDiscreteFieldsDict ( IOobject ( "setDiscreteFieldsDict", runTime.system(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ) ); // read pointer lists of each "Fields" PtrList<entry> parts=setDiscreteFieldsDict.lookup("Fields"); forAll(parts,partI) { const dictionary &part=parts[partI].dict(); Info <<part <<endl; // "field" ,"type", and "profile" are required in setDiscreteFieldsDict word field=part["field"]; word type=part["type"]; // "direction", "internal", and "patchNames" are option string direction="x"; if (part.found("direction")) { direction=part["direction"]; } bool internal=true; if (part.found("internal")) { internal=readBool(part["internal"]); } wordList patchNames; if (part.found("patchNames")){ patchNames=wordList(part.lookup("patchNames")); } const string &time = runTime.timeName(); Info <<"time " <<time <<"\n"; // for scalar field if(type=="scalar"){ Info << "set " <<field <<endl; // read profile List<quad> profile(part.lookup("profile")); scalarField posX(profile.size()); scalarField posY(profile.size()); scalarField posZ(profile.size()); scalarField fX(profile.size()); forAll(profile,i) { posX[i]=profile[i][0]; posY[i]=profile[i][1]; posZ[i]=profile[i][2]; fX[i]=profile[i][3]; } // read target field (scalar) volScalarField tmpField ( IOobject ( field, time, mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); //read cellCenter of targetMesh volVectorField center=tmpField.mesh().C(); //internalField if(internal){ scalarField &Ifield = tmpField.internalField(); scalarField Icenter(Ifield.size()); scalarField newIField(Ifield.size()); if(direction=="x"){ Icenter = center.internalField().component(vector::X); newIField = interpolateXY(Icenter,posX,fX); } else if(direction=="y"){ Icenter = center.internalField().component(vector::Y); newIField = interpolateXY(Icenter,posY,fX); } else if(direction=="z"){ Icenter = center.internalField().component(vector::Z); newIField = interpolateXY(Icenter,posZ,fX); } Ifield = newIField; } //patch forAll(patchNames,patchNameI) { label patchID=mesh.boundaryMesh().findPatchID(patchNames[patchNameI]); scalarField &Pfield = tmpField.boundaryField()[patchID]; scalarField newPField(Pfield.size()); scalarField Pcenter(Pfield.size()); if(direction=="x"){ Pcenter = center.boundaryField()[patchID].component(vector::X); newPField = interpolateXY(Pcenter,posX,fX); } else if(direction=="y"){ Pcenter = center.boundaryField()[patchID].component(vector::Y); newPField = interpolateXY(Pcenter,posY,fX); } else if(direction=="z"){ Pcenter = center.boundaryField()[patchID].component(vector::Z); newPField = interpolateXY(Pcenter,posZ,fX); } Pfield = newPField; }
QVariant Human::data(int role) const { switch(role) { case IdRole: return (unsigned int)id(); case FilterStringRole: return filterString(); case ProfessionRole: return profession(); case PosXRole: return posX(); case PosYRole: return posY(); case PosZRole: return posZ(); case NameRole: return name(); case ArcherLevelRole: return archerLevel(); case BlacksmithLevelRole: return blacksmithLevel(); case BuilderLevelRole: return builderLevel(); case CarpenterLevelRole: return carpenterLevel(); case EngineerLeveRole: return engineerLevel(); case FarmerLevelRole: return farmerLevel(); case FishermanLevelRole: return fishermanLevel(); case ForagerLevelRole: return foragerLevel(); case InfantryLevelRole: return infantryLevel(); case MinerLevelRole: return minerLevel(); case StoneMasonLevelRole: return stoneMasonLevel(); case WoodChopperLevelRole: return woodChopperLevel(); case TailorLevelRole: return tailorLevel(); case TraderLevelRole: return traderLevel(); case HerderLevelRole: return herderLevel(); case AdventurerLevelRole: return adventurerLevel(); case Unknown1Role: return unknown1Level(); case Unknown2Role: return unknown2Level(); case Unknown3Role: return unknown3Level(); case Unknown4Role: return unknown4Level(); case ExperienceRole: return experience(); case AutoChopTreesRole: return autoChop(); case GatherBerriesRole: return gatherBerries(); case HuntChickenRole: return huntChicken(); case HuntBoarRole: return huntBoar(); case ShowBowRangeRole: return showBowRange(); case TrainNearTargetRole: return trainNearTarget(); case RotationRole: return rotation(); case EquipHandRole: return equipHand(); case EquipOffhandRole: return equipOffhand(); case EquipHeadRole: return equipHead(); case EquipBodyRole: return equipBody(); case EquipFeetRole: return equipFeet(); case HealthRole: return health(); case MoraleRole: return morale(); case FatigueRole: return fatigue(); case HungerRole: return hunger(); default: return QVariant(); } }
/** * @brief Write the Human data back to a file. */ void Human::writeToFile( QFile &unitFile ) { QTextStream unitStream(&unitFile); unitStream << profession() << "/" << QString("%1").arg(posX(),0,'g',8) << "/" << QString("%1").arg(posY(),0,'g',8) << "/" << QString("%1").arg(posZ(),0,'g',8) << "/" << name() << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(archerLevel())); unitFile.write(Utils::toBinary(blacksmithLevel())); unitFile.write(Utils::toBinary(builderLevel())); unitFile.write(Utils::toBinary(carpenterLevel()).constData()); unitFile.write(Utils::toBinary(engineerLevel()).constData()); unitFile.write(Utils::toBinary(farmerLevel()).constData()); unitFile.write(Utils::toBinary(fishermanLevel()).constData()); unitFile.write(Utils::toBinary(foragerLevel()).constData()); unitFile.write(Utils::toBinary(infantryLevel()).constData()); unitFile.write(Utils::toBinary(minerLevel()).constData()); unitFile.write(Utils::toBinary(stoneMasonLevel()).constData()); unitFile.write(Utils::toBinary(woodChopperLevel()).constData()); unitFile.write(Utils::toBinary(tailorLevel()).constData()); unitFile.write(Utils::toBinary(traderLevel()).constData()); unitFile.write(Utils::toBinary(herderLevel()).constData()); unitFile.write(Utils::toBinary(adventurerLevel()).constData()); unitFile.write(Utils::toBinary(unknown1Level()).constData()); unitFile.write(Utils::toBinary(unknown2Level()).constData()); unitFile.write(Utils::toBinary(unknown3Level()).constData()); unitFile.write(Utils::toBinary(unknown4Level()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(experience()).constData()); unitStream << "/"; unitStream.flush(); unitStream << QString(autoChop()?"True":"False") << "/" << QString(gatherBerries()?"True":"False") << "/" << QString(huntChicken()?"True":"False") << "/" << QString(huntBoar()?"True":"False") << "/" << QString(showBowRange()?"True":"False") << "/"; unitStream << QString(trainNearTarget()?"True":"False") << "/"; unitStream << QString("%1").arg(rotation(),0,'g',8) << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipHand()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipOffhand()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipHead()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipBody()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipFeet()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(health()).constData()); unitStream << "/"; unitStream.flush(); // Dump some of the options in the file. for (unsigned int i = 0; i<52; i++) { unitStream << QString(option(i)?"True":"False") << "/"; } unitStream << timeToEat() << "/" << morale() << "/" << fatigue() << "/" << hunger() << "/"; // Dump more options in the file. for (unsigned int i = 52; i<52+12; i++) { unitStream << QString(option(i)?"True":"False") << "/"; } // Inventory Preferences for (int i = 0; i<inventoryPreferences()->length(); i++) { unitStream << inventoryPreferences()->at(i) << "/"; } // Inventory Items unitStream << inventoryItems()->length() << "/"; for (int i = 0; i<inventoryItems()->length(); i++) { unitStream << inventoryItems()->at(i) << "/"; } // Spare Inventory unitStream << spareInventory()->length() << "/"; for (int i = 0; i<spareInventory()->length(); i++) { unitStream << spareInventory()->at(i) << "/"; } // Patrol unitStream << patrolSetpoints()->length() << "/"; for (int i = 0; i<patrolSetpoints()->length(); i++) { unitStream << patrolSetpoints()->at(i) << "/"; } unitStream << patrolIndex() << "/"; unitStream << guardedUnit() << "/"; // Profession Experience for (int i = 0; i<professionEXP()->length(); i++) { unitStream << professionEXP()->at(i) << "/"; } unitStream << maxWeight() << "/"; unitStream << endl; unitStream.flush(); }