void MyLabel::updateFrame() { rect = tracker.update(frame); double pixNum = rect.y + rect.height - 288; double dist = 749800 * 1 / pixNum - 722.1; if (pixNum > 0) { emit setDistance(dist); } else emit setDistance(0); //this->mTimer.stop(); /*if (this->inited) if (tracker.update(frame, rect)) isRectFount = true; else { isRectFount = false; QMessageBox msbox; msbox.setText("frame update false, obj may loss"); msbox.exec(); }*/ //this->mTimer.start(); //double y = (rect.x + rect.width / 2 - 352); //double x = (576 - rect.y - rect.height); //double radio = y/x ; //int angle = atan(radio) * 180 / 3.1415926; int laserAngle = -((rect.x + rect.width / 2) / 704 * 50 - 25); emit requestDistance(laserAngle); }
void ShortestPath::reverse(function<double(Vec2)> entryFun, function<double(Vec2)> lengthFun, double mult, Vec2 from, int limit) { reversed = true; function<bool(Vec2, Vec2)> comparator = [=](Vec2 pos1, Vec2 pos2) { return this->getDistance(pos1) + lengthFun(from - pos1) > this->getDistance(pos2) + lengthFun(from - pos2); }; priority_queue<Vec2, vector<Vec2>, decltype(comparator)> q(comparator) ; for (Vec2 v : bounds) { double dist = getDistance(v); if (dist <= limit) { setDistance(v, mult * dist); q.push(v); } } int numPopped = 0; while (!q.empty()) { ++numPopped; Vec2 pos = q.top(); if (from == pos) { Debug() << "Rev shortest path from " << " from " << target << " " << numPopped << " visited"; constructPath(pos, true); return; } q.pop(); for (Vec2 dir : directions) if ((pos + dir).inRectangle(bounds)) { if (getDistance(pos + dir) > getDistance(pos) + entryFun(pos + dir) && getDistance(pos + dir) < 0) { setDistance(pos + dir, getDistance(pos) + entryFun(pos + dir)); q.push(pos + dir); } } } Debug() << "Rev shortest path from " << " from " << target << " " << numPopped << " visited"; }
void Collide::pointBoxCollide(const Body * point_, const Body * box) { Point *point = (Point*)point_; AABB *aabb = (AABB*)box; if (point->getPoint().GetX() > aabb->getMin().GetX() && point->getPoint().GetX() < aabb->getMax().GetX() && point->getPoint().GetY() > aabb->getMin().GetY() && point->getPoint().GetY() < aabb->getMax().GetY() && point->getPoint().GetZ() > aabb->getMin().GetZ() && point->getPoint().GetZ() < aabb->getMax().GetZ()) { setCollide(true); // haven't calculate the distance setDistance(-1); } else { setCollide(false); // haven't calculate the distance setDistance(1); } // compute the response vectors Vector3 responseObject1 = point_->getCenter() - box->getCenter(); Vector3 responseObject2 = box->getCenter() - point_->getCenter(); setResponseObject1(responseObject1); setResponseObject2(responseObject2); }
Vector3D::Vector3D(QColor color,unsigned char type,QNode*parent):QEntity(parent),flipped(type&FLIP){ addComponent(transform); QPhongMaterial*material=new QPhongMaterial(this);// material->setShareable(true); material->setAmbient(color); QEntity*tail=new QEntity(this); tail->addComponent(material); QCylinderMesh*tailMesh=new QCylinderMesh(tail); tailMesh->setLength(tailLength); tailMesh->setRadius(.01); tail->addComponent(tailMesh); tail->addComponent(tailTransform); if(type&AXIS){ tailMesh->setRadius(.009); tailMesh->setLength(9999); tailTransform->setTranslation(QVector3D(0,tailMesh->length()/2,0)); }else{ QEntity*head=new QEntity(this); head->addComponent(material); QConeMesh*headMesh=new QConeMesh(head); headMesh->setLength(headLength); headMesh->setBottomRadius(tailMesh->radius()*8); head->addComponent(headMesh); head->addComponent(headTransform); setDistance(); } }
void NDynamicObject::updateFromVision(VisionSense vs) { setDistance(vs.distanceToSelf); setLocalPos(vs.localPos); if (WM.CanLocalize()) setGlobalPos(WM.getVisionPerceptorMatrix()*pos_local); }
ShortestPath::ShortestPath(const Level* level, const Creature* creature, Vec2 to, Vec2 from, double mult, bool avoidEnemies) : target(to), directions(Vec2::directions8()), bounds(level->getBounds()) { CHECK(level->getBounds().getKX() <= maxSize && level->getBounds().getKY() <= maxSize); auto entryFun = [=](Vec2 pos) { if (level->getSquare(pos)->canEnter(creature) || creature->getPosition() == pos) return 1.0; if ((level->getSquare(pos)->canEnterEmpty(creature) || level->getSquare(pos)->canDestroy(creature)) && (!avoidEnemies || !level->getSquare(pos)->getCreature() || !level->getSquare(pos)->getCreature()->isEnemy(creature))) return 5.0; return infinity;}; CHECK(to.inRectangle(level->getBounds())); CHECK(from.inRectangle(level->getBounds())); if (mult == 0) { // Use a suboptimal, but faster pathfinding. init(entryFun, [](Vec2 v)->double { return 2 * v.lengthD(); }, target, from); } else { auto lengthFun = [](Vec2 v)->double { return v.length8(); }; bounds = bounds.intersection(Rectangle(min(to.x, from.x) - margin, min(to.y, from.y) - margin, max(to.x, from.x) + margin, max(to.y, from.y) + margin)); init(entryFun, lengthFun, target, Nothing(), revShortestLimit); setDistance(target, infinity); reverse(entryFun, lengthFun, mult, from, revShortestLimit); } }
// Initialization, happens every frame. void VisualCross::init() { width = 0; height = 0; setX(0); setY(0); centerX = 0; centerY = 0; angleX = 0; angleY = 0; focDist = 0; setDistance(0); setBearing(0); elevation = 0; switch (id) { case YELLOW_GOAL_CROSS: setPossibleCrosses(&ConcreteCross::yellowGoalCrossList); break; case BLUE_GOAL_CROSS: setPossibleCrosses(&ConcreteCross::blueGoalCrossList); break; case ABSTRACT_CROSS: setPossibleCrosses(&ConcreteCross::abstractCrossList); break; } }
//constructor Bullit :: Bullit(float xx, float yy,int dir,int ww, int hh){ setHealth(1); setDirectionGoing(dir); setSpeed(30); setNumOfVertices(3); setDistance(0); width = 50; height = 50; setXPos((xx+ww/2-width/2)-(xx+ww/2)); setYPos((yy+hh+height+10)-(yy+hh/2)); float dist=sqrt(pow(getXPos(),2)+pow(getYPos(),2)); setXPos(xx+ww/2-width/2+dist*cos(getDirectionGoing()*PI/180)); setYPos(yy+hh/2-height/2+dist*sin(getDirectionGoing()*PI/180)); x=xx; y=yy; w=ww; h=hh; setNumOfVertices(3); //define the bullit vertices[0] = getXPos(); //left x vertices[1] = getYPos(); //left y vertices[2] = getXPos()+width; //right x vertices[3] = getYPos(); //right y vertices[4] = getXPos()+width/2; //top x vertices[5] = getYPos()+height; //top y }
//Mouse press callback for Edit Mode void glfwEditMouse(GLFWwindow *window, int button, int action, int mods) { //If the left button is pressed if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) { //If game is paused if(isPaused()) { pauseorUnpause(); } //If in gui mode, call button presses if(eKeysPressed['G']) { GuiPressing(EDIT_MODE, lastCurPos.x, lastCurPos.y); } //If an entity is not selected and shift is held else if(areEntitiesSelected() == false && eKeysPressed[340] && eKeysPressed['G'] == 0) { deleteClosest(); } //If an entity is selected, add it else if(areEntitiesSelected() == true && eKeysPressed['G'] == 0) { placeSelectedEntity(); //Reset lookAtDistance previousLookAtDistance = getDistance(); setDistance(3.0); //Set shift to false to avoid undoing object just placed eKeysPressed[340] = 0; } } else if(button == GLFW_MOUSE_BUTTON_RIGHT && eKeysPressed['G'] == 0) { unselectEntity(); } }
void TagObject::initi(double x, double y) { //tag_id_ = tag_id; x_ = x; y_ = y; setDistance(); }
TFMarkerArrows::TFMarkerArrows(rviz::DisplayContext* context, Ogre::SceneNode* parentNode, TFMarker* parent, const Ogre::Quaternion& orientation, const Ogre::Vector3& scale, double distance) : TFMarkerControl(context, parentNode, parent, true, false, "<b>Left-Click:</b> Move."), positiveArrow(new rviz::Arrow(context->getSceneManager(), sceneNode)), negativeArrow(new rviz::Arrow(context->getSceneManager(), sceneNode)) { cursor = rviz::makeIconCursor("package://rviz/icons/move1d.svg"); positiveArrow->setOrientation(Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo( Ogre::Vector3::UNIT_X)); positiveArrow->set(0.5, 0.6, 0.5, 1.0); negativeArrow->setOrientation(Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo( Ogre::Vector3::NEGATIVE_UNIT_X)); negativeArrow->set(0.5, 0.6, 0.5, 1.0); setOrientation(orientation); setScale(scale); setDistance(distance); addMaterial(positiveArrow->getShaft()->getMaterial()); addMaterial(positiveArrow->getHead()->getMaterial()); addMaterial(negativeArrow->getShaft()->getMaterial()); addMaterial(negativeArrow->getHead()->getMaterial()); }
//CONSTRUCTORS Record::Record(int ev, int di, std::string ti, std::string da) { //set members that need no additional computing e = ev; d = di; time = ti; date = da; mins = 0; secs = 0; milis = 0; setStroke(e); setDistance (d); convertStringtoInts(ti); //set the time string from the converted integer values. time = ""; time = mins; time += ":"; time += secs; time += "."; time += milis; }
void offset(fwPlane& _plane, double _offset) { SLM_TRACE_FUNC(); double distance = getDistance(_plane); distance += _offset; setDistance(_plane, distance); }
void Camera::setup(int _camID) { camID = _camID; lookAtNode.setPosition(0, 0, 0); setDistance(100); minSecondsBeforeSwapping = 2; isReadyForSwap = false; }
void Collide::boxBoxCollide(const Body * box1, const Body * box2) { AABB *aabb1 = (AABB*)box1; AABB *aabb2 = (AABB*)box2; // float maxDistance = 0.0f; bool collide = false; // max > min min< max if (aabb1->getMax().GetX() < aabb2->getMin().GetX() && aabb1->getMin().GetX() > aabb2->getMax().GetX() && aabb1->getMax().GetY() > aabb2->getMin().GetY() && aabb1->getMin().GetY() < aabb2->getMax().GetY() && aabb1->getMax().GetZ() < aabb2->getMin().GetZ() && aabb1->getMin().GetZ() > aabb2->getMax().GetZ()) collide = true; setCollide(collide); setDistance(0.0f); /** SIMDVector3 dist1 = aabb2->getMin() - aabb1->getMax(); SIMDVector3 dist2 = aabb1->getMin() - aabb2->getMax(); // create the float array to store the maximum X, Y and Z float max[3]; // create a float to store the maximum float among the // values of float array max[3] maxDistance = max[0]; // here is the calculation to generate max[3] if (dist1.GetX() > dist2.GetX()) max[0] = dist1.GetX(); else max[0] = dist2.GetX(); if (dist1.GetY() > dist2.GetY()) max[1] = dist1.GetY(); else max[1] = dist1.GetY(); if (dist1.GetZ() > dist2.GetZ()) max[2] = dist1.GetZ(); else max[2] = dist1.GetZ(); // pick up the maximum value from max[3] for (int i = 1; i < 3; i++) { if (maxDistance < max[i]) maxDistance = max[i]; } setCollide(maxDistance < 0); setDistance(maxDistance); */ // compute the response vectors Vector3 responseObject1 = box1->getCenter() - box2->getCenter(); Vector3 responseObject2 = box2->getCenter() - box1->getCenter(); setResponseObject1(responseObject1.Normalize()); setResponseObject2(responseObject2.Normalize()); }
fwPlane getPlane(const fwVec3d& _normal,const fwVec3d& _point) { SLM_TRACE_FUNC(); fwPlane plane; fwVec3d normalVec = _normal; normalize(normalVec); setNormal(plane, normalVec); setDistance(plane, normalVec[0]*_point[0] +normalVec[1]*_point[1] + normalVec[2]*_point[2]); return plane; }
void ShortestPath::init(function<double(Vec2)> entryFun, function<double(Vec2)> lengthFun, Vec2 target, Optional<Vec2> from, Optional<int> limit) { reversed = false; ++counter; function<bool(Vec2, Vec2)> comparator; if (from) comparator = [=](Vec2 pos1, Vec2 pos2) { return this->getDistance(pos1) + lengthFun(*from - pos1) > this->getDistance(pos2) + lengthFun(*from - pos2); }; else comparator = [this](Vec2 pos1, Vec2 pos2) { return this->getDistance(pos1) > this->getDistance(pos2); }; priority_queue<Vec2, vector<Vec2>, decltype(comparator)> q(comparator) ; setDistance(target, 0); q.push(target); int numPopped = 0; while (!q.empty()) { ++numPopped; Vec2 pos = q.top(); // Debug() << "Popping " << pos << " " << distance[pos] << " " << (from ? (*from - pos).length4() : 0); if (from == pos || (limit && getDistance(pos) >= *limit)) { Debug() << "Shortest path from " << (from ? *from : Vec2(-1, -1)) << " to " << target << " " << numPopped << " visited distance " << getDistance(pos); constructPath(pos); return; } q.pop(); for (Vec2 dir : directions) { Vec2 next = pos + dir; if (next.inRectangle(bounds)) { double cdist = getDistance(pos); double ndist = getDistance(next); if (cdist < ndist) { double dist = cdist + entryFun(next); CHECK(dist > cdist) << "Entry fun non positive " << dist - cdist; if (dist < ndist) { setDistance(next, dist); q.push(next); } } } } } Debug() << "Shortest path exhausted, " << numPopped << " visited"; }
ShortestPath::ShortestPath(Rectangle a, function<double(Vec2)> entryFun, function<int(Vec2)> lengthFun, vector<Vec2> dir, Vec2 to, Vec2 from, double mult) : target(to), directions(dir), bounds(a) { CHECK(a.getKX() <= maxSize && a.getKY() <= maxSize && a.getPX() >= 0 && a.getPY() >= 0); if (mult == 0) init(entryFun, lengthFun, target, from); else { init(entryFun, lengthFun, target, Nothing(), revShortestLimit); setDistance(target, infinity); reverse(entryFun, lengthFun, mult, from, revShortestLimit); } }
int main(void){ setDistance(); getSquare(); while(1){ } return 0; }
//What's in doStuff right now is only for testing purpose. Lot of stuff to do here. void Elodie::doStuff(const EventHandler& event, const std::vector< std::vector<TileSprite*> >& tiles, EntityMap& entities, sf::Time animate) { //Compute the gravity computeGravity(animate); //Check the collisions, set the new distances and do the move Collide collideTiles = collideWithTiles(tiles, animate.asSeconds()); setDistance(collideTiles); move(animate.asSeconds()*(speed.x), animate.asSeconds()*speed.y); spriteCast->update(animate); //Change the sprite in accord with the speed changeAnimation(collideTiles); handleEvent(event, entities, collideTiles); if (0 == speed.x && !collideTiles.right["surface"]) { speed.x = moveSpeed; } float dist = cameraPos.x - spriteCast->getPosition().x; if (dist > 0 && !collideTiles.right["surface"] && !buffed) { buffed = true; speed.x = moveSpeed + dist; } buffed = !collideTiles.right["surface"]; if (buffed && dist <= 0) { buffed = false; speed.x = moveSpeed; } //Other stuff to do attackTimer += animate.asSeconds(); pvTimer += animate.asSeconds(); if (pvTimer > interRecoveryTime) { pvTimer = 0; immersionLevel = immersionLevel == 100 ? 100 : immersionLevel + 1; } if (damageCD) { --damageCD; } cameraPos.x += (moveSpeed)*animate.asSeconds(); cameraPos.y = spriteCast->getPosition().y; }
//---------------------------------------- void ofEasyFingerCam::reset() { rotationX = 0.0f; rotationY = 0.0f; rotationZ = 0.0f; targetXRot = 0.0f; targetYRot = 0.0f; targetZRot = 0.0f; target.resetTransform(); setDistance(lastDistance, false); rotation = ofQuaternion(0,0,0,1); distanceScaleVelocity = 0; }
void transform(fwPlane& _plane, const fwMatrix4x4& _matrix) { SLM_TRACE_FUNC(); fwVec3d normalVec = getNormal(_plane); fwVec3d beg = normalVec * getDistance(_plane); fwVec3d end = beg + normalVec; multVecMatrix(_matrix,beg,beg); multVecMatrix(_matrix,end,end); normalVec = end - beg; normalize(normalVec); setNormal(_plane, normalVec); setDistance(_plane, dot(normalVec, beg)); }
/****************************************************************************** * This method is called by the system when the modifier has been inserted * into a PipelineObject. ******************************************************************************/ void SliceModifier::initializeModifier(PipelineObject* pipeline, ModifierApplication* modApp) { ParticleModifier::initializeModifier(pipeline, modApp); // Get the input simulation cell to initially place the slicing plane in // the center of the cell. PipelineFlowState input = pipeline->evaluatePipeline(dataset()->animationSettings()->time(), modApp, false); SimulationCellObject* cell = input.findObject<SimulationCellObject>(); if(cell) { Point3 centerPoint = cell->cellMatrix() * Point3(0.5, 0.5, 0.5); FloatType centerDistance = normal().dot(centerPoint - Point3::Origin()); if(fabs(centerDistance) > FLOATTYPE_EPSILON) setDistance(centerDistance); } }
// Initialization, happens every frame. void VisualRobot::init() { width = 0; height = 0; setX(0); setY(0); centerX = 0; centerY = 0; angleX = 0; angleY = 0; setDistance(0); setBearing(0); elevation = 0; on = false; }
void Collide::boxSphereCollide(const Body * box, const Body * sphere) { AABB* m_box = (AABB*)box; Sphere* m_sphere = (Sphere*)sphere; float dMin = 0.0f; Vector3 sCenter = m_sphere->getCenter(); Vector3 bMin = m_box->getMin(); Vector3 bMax = m_box->getMax(); if (sCenter.GetX() > bMin.GetX()) dMin += pow(sCenter.GetX() - bMin.GetX(), 2); else if (sCenter.GetX() < bMax.GetX()) dMin += pow(sCenter.GetX() - bMax.GetX(), 2); if (sCenter.GetY() < bMin.GetY()) dMin += pow(sCenter.GetY() - bMin.GetY(), 2); else if (sCenter.GetY() > bMax.GetY()) dMin += pow(sCenter.GetY() - bMax.GetY(), 2); if (sCenter.GetZ() < bMin.GetZ()) dMin += pow(sCenter.GetZ() - bMin.GetZ(), 2); else if (sCenter.GetY() > bMax.GetY()) dMin += pow(sCenter.GetZ() - bMax.GetZ(), 2); if (dMin <= pow(m_sphere->getRadius(), 2)) { setCollide(true); setDistance(1); } else { setCollide(false); setDistance(-1); } }
bool ContactDistanceCalc<BasicTraits,BVOL,Metric>::Init () { Inherited::Init(); setDistance(getMaxDistance()); #ifdef GV_WITH_LINEGEOMETRY if (getLineGeometry() != NullFC) { beginEditCP(getLineGeometry()); for (u32 k=0; k<getLineGeometry()->size(); ++k) { getLineGeometry()->setValue(Pnt3f::Null, k); } endEditCP(getLineGeometry()); } #endif return true; }
void setValues(fwPlane& _plane, const fwVec3d & _point1, const fwVec3d & _point2, const fwVec3d & _point3) { SLM_TRACE_FUNC(); fwVec3d normalVec= cross(_point2 - _point1, _point3 -_point1); if((float)(vecLength(normalVec)) <= 0.0F) { normalVec[0] =0.0F; normalVec[1] =0.0F; normalVec[2] =1.0F; } normalize(normalVec); // Normal setNormal(_plane, normalVec); // Distance double distance = normalVec[0]*_point1[0] + normalVec[1]*_point1[1] + normalVec[2]*_point1[2]; setDistance(_plane, distance); }
//---------------------------------------- void ofEasyCam::update(ofEventArgs & args){ viewport = getViewport(this->viewport); if(!bDistanceSet && bAutoDistance){ setDistance(getImagePlaneDistance(viewport), true); } if(bMouseInputEnabled){ if(events->getMousePressed()) prevMouse = glm::vec2(events->getMouseX(),events->getMouseY()); if (bDoRotate) { updateRotation(); }else if (bDoTranslate || bDoScrollZoom || bIsBeingScrolled) { updateTranslation(); bDoScrollZoom = false; } } }
void Collide::pointSphereCollide(const Body * point_, const Body * sphere_) { Point *point = (Point*)point_; Sphere *sphere = (Sphere*)sphere_; float distance = 0.0f; distance = (point->getPoint() - sphere->getCenter()).Length(); setCollide(distance < sphere->getRadius()); setDistance(distance - sphere->getRadius()); // compute the response vectors Vector3 responseObject1 = point_->getCenter() - sphere_->getCenter(); Vector3 responseObject2 = sphere_->getCenter() - point_->getCenter(); setResponseObject1(responseObject1); setResponseObject2(responseObject2); }
//---------------------------------------- void ofEasyCam::update(ofEventArgs & args){ if(bMouseInputEnabled){ if(!bDistanceSet){ setDistance(getImagePlaneDistance(viewport), true); } rotationFactor = sensitivityRot * 180 / min(viewport.width, viewport.height); if (bMouseInputEnabled) { updateMouse(); } if (bDoRotate) { updateRotation(); }else if (bDoTranslate) { updateTranslation(); } } }