/** Try to find a point that lies within (or on) the object @param[out] point :: on exit set to the point value, if found @return 1 if point found, 0 otherwise */ int MeshObject::getPointInObject(Kernel::V3D &point) const { Kernel::V3D testPt(0, 0, 0); // Try centre of bounding box as initial guess, if we have one. const BoundingBox &boundingBox = getBoundingBox(); if (boundingBox.isNonNull()) { testPt = boundingBox.centrePoint(); if (searchForObject(testPt)) { point = testPt; return 1; } } return 0; }
void demoAnim::handleAnimStep(ofTag tag) { //------- set the default event type to "end" vMouseType vType=OF_VMOUSE_END; //------- variable declarations ofInterObj * object=0; double duration=0; double speed=0; int xint=0, yint=0; string type=tag.getAttribute("type"); if(type.length()){ if(type=="move") vType=OF_VMOUSE_MOVE_TO; else if(type=="clickDown") vType=OF_VMOUSE_CLICK_DOWN,xint=anim.x,yint=anim.y; else if(type=="clickUp") vType=OF_VMOUSE_CLICK_UP,xint=anim.x,yint=anim.y; else if(type=="select"){ } } //------- if we have a time attribute, set the duration var to that attribute string time=tag.getAttribute("time"); if(time.length()){ duration=ofToFloat(time); } //-------otherwise, we need to look for the speed at which we want to move, to be used later to determine time else { string spd=tag.getAttribute("speed"); if(spd.length()){ speed=ofToFloat(spd); } } //------- if there is a pos tag inside the current tag, push into it if(tag.getNumTags("pos")){ ofTag & tg=tag.getNode("pos"); //------- and look at the type of position tag it is string typ=tg.getAttribute("type"); if(typ=="obj") //-- if it is an object tag, search for the specified object using the searchForObject function object = searchForObject(tg,xint,yint); else if(typ=="coord"){ //-------if it is a coordinate, set xint and yint to the x and y attributes. xint=ofToInt(tg.getAttribute("x")); yint=ofToInt(tg.getAttribute("y")); } //-------if it is a mouse tag, set the xint and yint to the mouse coordinates else if(typ=="mouse") xint=ofGetAppPtr()->mouseX,yint=ofGetAppPtr()->mouseY; if(!duration){ //-- if we haven't yet set the duration, use the speed to determine duration int xtmp=((object)?object->x+xint:xint); int ytmp=((object)?object->y+yint:yint); double dist= sqrt(double((xtmp-anim.x)*(xtmp-anim.x)+(ytmp-anim.y)*(ytmp-anim.y))); duration=dist/speed; } //-- if we are following an object, the next event is called, referencing that object if(object) anim.nextEvent(vType,(*object),xint, yint,duration); else anim.nextEvent(vType,xint, yint,duration); //-- otherwise, it is called using only x and y } else { //-- if there is not a position tag inside, the next event takes place where the vMouse is currently located anim.nextEvent(vType,xint, yint,duration); } }