• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Vec2d类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Vec2d的典型用法代码示例。如果您正苦于以下问题:C++ Vec2d类的具体用法?C++ Vec2d怎么用?C++ Vec2d使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Vec2d类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: while

bool Enemy::tick(){
    if(Game::enemiesRoute.size()<=_nextPositionIndex
    || _nextPositionIndex<0 || _distanceToEnd<=_velocity)
        return true;

    Vec2d p = Game::enemiesRoute[_nextPositionIndex];
    double toMove = _velocity;
    _distanceToEnd -= toMove;
    while(toMove>0.0){
        double d = _position.distance(p);
        if(d<=_velocity){
            _position = p;
            _nextPositionIndex += 1;
            /*if(Game::enemiesRoute.size()<=_nextPositionIndex){
                _nextPositionIndex = -1;
                return true;
            }*/
            toMove -= d;
            p = Game::enemiesRoute[_nextPositionIndex];
        }else{
            Vec2d t = p-_position;
            t.normalize();
            t *= _velocity;
            _position += t;
            toMove = 0.0;
        }
    }
    return false;
}
开发者ID:ivancea,项目名称:TowerDefense,代码行数:29,代码来源:Enemy.cpp


示例2: createPatch

Transform* PatchSet::createPatch(const std::string& filename, PatchOptions* poptions)
{
    Patch* patch = new Patch;
    patch->setPatchSet(this);
    Vec2d ll, ur;
    poptions->getPatchExtents(ll, ur);
    Vec2d range = (ur - ll);
    ref_ptr<Patch::Data> data = new Patch::Data;
    int patchDim = _resolution + 1;
    Vec3Array* verts = new Vec3Array(patchDim * patchDim);
    for (int j = 0; j < patchDim; ++j)
        for (int i = 0; i < patchDim; ++i)
            (*verts)[patchDim * j + i]
                = Vec3((ll.x() + i * range.x()
                        / static_cast<float>(_resolution)) * 81920.0,
                       (ll.y() + j * range.y()
                        / static_cast<float>(_resolution)) * 81920.0,
                       0.0);
    data->vertexData.array = verts;
    data->vertexData.binding = Geometry::BIND_PER_VERTEX;
    Vec3Array* norms = new Vec3Array(1);
    (*norms)[0] = Vec3d(0.0, 0.0, 1.0);
    data->normalData.array = norms;
    data->normalData.binding = Geometry::BIND_OVERALL;
    Vec4Array* colors = new Vec4Array(1);
    (*colors)[0] = Vec4(1.0, 1.0, 1.0, 1.0);
    data->colorData.array = colors;
    data->colorData.binding = Geometry::BIND_OVERALL;
    patch->setData(data);
    MatrixTransform* transform = new MatrixTransform;
    transform->addChild(patch);
    return transform;
}
开发者ID:2php,项目名称:osgearth,代码行数:33,代码来源:PatchSet.cpp


示例3: GetEdgeIntersection

void	Voronoi::CheckCircle(VParabola * b){

	VParabola * lp = VParabola::GetLeftParent (b);
	VParabola * rp = VParabola::GetRightParent(b);

	VParabola * a  = VParabola::GetLeftChild (lp);
	VParabola * c  = VParabola::GetRightChild(rp);

	if(!a || !c || a->site == c->site) return;

	Vec2d * s = 0;
	s = GetEdgeIntersection(lp->edge, rp->edge);
	if(s == 0) return;

	double dx = a->site->x - s->x;
	double dy = a->site->y - s->y;

	double d = std::sqrt( (dx * dx) + (dy * dy) );

	if(s->y - d >= ly) { return;}

    Vec2d * newv = new Vec2d(); newv->set( s->x,  s->y - d );
    VEvent * e = new VEvent( newv, false);
	//VEvent * e = new VEvent( new Vec2d(s->x, s->y - d), false);
	points.push_back(e->point);
	b->cEvent = e;
	e->arch = b;
	queue.push(e);

}
开发者ID:ProkopHapala,项目名称:SimpleSimulationEngine,代码行数:30,代码来源:Voronoi.cpp


示例4: sgn

//Add of Marie
bool VRWorkpieceElement::doesCollide(Vec3d position) {
    //position in argument is the lowest part of the worktool and the (0,0) point of the profile

    float py = this->position[1], px = this->position[0], pz = this->position[2];
    float sy = this->size[1], sx = this->size[0], sz = this->size[2];
    float ptooly = position[1], ptoolx = position[0], ptoolz = position[2];

    float profileLength = workpiece.cuttingProfile->getLength();

    if ((py + sy/2.0f > ptooly) && (py - sy/2.0f < ptooly + profileLength))
    {
        float maximum = workpiece.cuttingProfile->maxProfile(position, this->position, this->size);

        if ((ptoolz - maximum < pz + sz/2.0f) && (ptoolz + maximum > pz - sz/2.0) &&
            (ptoolx - maximum < px + sx/2.0f) && (ptoolx + maximum > px - sx/2.0))
        {
            float diffx = ptoolx - px, diffz = ptoolz - pz;
            if (std::abs(diffx) <= sx / 2.0f) return true;
            if (std::abs(diffz) <= sz / 2.0f) return true;

            float sgnx = sgn(diffx), sgnz = sgn(diffz);
            Vec2d vertex(px + sgnx * sx / 2.0f, pz + sgnz * sz / 2.0f);
            Vec2d toolMid(ptoolx, ptoolz);
            Vec2d distanceVertexTool = vertex - toolMid;
            if (distanceVertexTool.length() < maximum) {
                return true;
            }
        }
    }

    return false;
}
开发者ID:Victor-Haefner,项目名称:polyvr,代码行数:33,代码来源:VRMillingWorkPiece.cpp


示例5: draw

void draw() {

    //	draw Points
    glColor3f( 0.3,0.3,0.3 );
    for ( int i=0; i<n; i++ ) {
        draw_Vec2d( ps[i] );
    };
    //	draw map.points.hits
    for ( int i=0; i<map.points.capacity; i++ ) {
        draw_Segment2d( {-0.5+i*pixsz,-0.5}, { -0.5+i*pixsz, -0.5	+ map.points.hits[i] * 3*pixsz } );
    }

    Vec2d pmouse;
    pmouse.set( (mouseX-WIDTH_HALF)*pixsz, (HEIGHT_HALF-mouseY)*( pixsz*ASPECT_RATIO ) );
    int ix    = map.getIx( pmouse.x );
    int iy    = map.getIy( pmouse.y );
    int index = map.getBoxIndex( ix, iy );
    //colorHash( map.getBoxIndex( ix, iy )  );
    glColor3f( 0.9,0.7,0.8 );
    draw_Rect2d( { map.getX(ix), map.getY(iy) }, { map.getX(ix+1), map.getY(iy+1) } );
    //printf( " rect X Y %i %i %f %f \n", ix, iy, map.getX(ix), map.getY(iy) );
    //printf( " mouse X Y %i %i \n", mouseX, mouseY );
    paint_Vec2d( pmouse, 0.01 );
    int nloaded = map.loadPointsIn( pmouse );
    for ( int i=0; i<nloaded; i++ ) {
        int ii = map.tempi[i];
        Vec2d* pp = map.points.store[ ii ];
        paint_Vec2d( *pp, 0.0025 );
    };
    if( index != lastIndex ) printf( " ix iy index %i %i %i iters %i \n", ix, iy, index, map.points.DEBUG_counter  );
    lastIndex = index;

};
开发者ID:ProkopHapala,项目名称:cpp_arch,代码行数:33,代码来源:main.cpp


示例6: pickParticle

void NBodyWorldApp::pickParticle( Particle2D*& picked ){
    Particle2D* screenObjects[256];
    // mouse picking
    double rmax  = 2.0d;
    double r2max = rmax*rmax;
    Vec2d vmouse;
    vmouse.set( mouse_begin_x, mouse_begin_y );
    UINT mfound = world.map.getObjectsInRect( (float)(vmouse.x - rmax ), (float)(vmouse.y - rmax ), (float)(vmouse.x + rmax ), (float)(vmouse.y + rmax ), &(screenObjects[0]) );
    //printf( "mfound  %i \n", mfound );
    int imin = -1;
    double r2min = 1e+300;
    for( int i=0; i<mfound; i++ ){
        Particle2D* p = screenObjects[i];
        Vec2d d;
        d.set_sub( p->pos, vmouse );
        double r2 = d.norm2();
        if( r2 < r2max ){
            if( r2 < r2min ){  r2min = r2; imin = i; }
        }
        //printf( " r2 %3.3f r2max %3.3f r2min %3.3f imin %i \n", r2, r2max, r2min, imin );
    }
    if( imin >= 0 ){
        picked = screenObjects[imin];
    }else{
        picked = NULL;
    }
    //if( world.picked != NULL ) printf( " MOUSE picked (%f,%f) \n", world.picked->pos.x, world.picked->pos.y );
}
开发者ID:ProkopHapala,项目名称:SimpleSimulationEngine,代码行数:28,代码来源:main.cpp


示例7: mouseMotion

 bool mouseMotion(GLWindow *win, int x, int y, int buttons) {
     Vec2d pos = Vec2d(x - win->w / 2, -(y - win->h / 2)) / win->w;
     pos *= m_fieldWidth;
     m_mouseAngle = pos.getAngle();
     m_mouseIn = pos.mag() <= m_circleRad;
     m_pt = pos;
     return true;
 }
开发者ID:trbabb,项目名称:noodle,代码行数:8,代码来源:circle.cpp


示例8: CalcLineError

float netrule :: CalcLineError (int li, const Vec2d & v) const
{
  float dx = v.X() - linevecs.Get(li).X();
  float dy = v.Y() - linevecs.Get(li).Y();

  const threefloat * ltf = &linetolerances.Get(li);
  return ltf->f1 * dx * dx + ltf->f2 * dx * dy + ltf->f3 * dy * dy;
}
开发者ID:apieum,项目名称:netgen,代码行数:8,代码来源:netrule2.cpp


示例9: slope

double Algebra::slope( const Vec2d &b, const Vec2d &e )
{
   Vec2d dxdy;
   dxdy.diff(e, b);
   if (absolute(dxdy.x) < EPS)
      return PI_2;
   else
      return atan((double) dxdy.y / dxdy.x);
}
开发者ID:,项目名称:,代码行数:9,代码来源:


示例10: Angle

double Angle (const Vec2d & v)
{
  if (v.X() == 0 && v.Y() == 0)
    return 0;
    
  double ang = atan2 (v.Y(), v.X());
  if (ang < 0) ang+= 2 * M_PI;
  return ang;
}
开发者ID:SeregaGomen,项目名称:qng,代码行数:9,代码来源:geom2d.cpp


示例11: pickMol

int MoleculeWorldApp::pickMol( const Vec2d& mpos ){
    int    imin  = -1;
    double r2min = 1e+300;
    for(int i=0; i<world.nMols; i++){
        Vec2d d; d.set_sub( mpos, world.pos[i] );
        double r2 = d.norm2();
        if (r2<r2min){ r2min=r2; imin=i; }
    }
    return imin;
}
开发者ID:ProkopHapala,项目名称:SimpleSimulationEngine,代码行数:10,代码来源:test_GlobOpt2D.cpp


示例12: reloadDistanceToEnd

void Enemy::reloadDistanceToEnd(){
    if(_nextPositionIndex<0 || _nextPositionIndex>=Game::enemiesRoute.size()){
        _distanceToEnd = -1;
    }else{
        double d = 0;
        Vec2d p = _position;
        for(int i=_nextPositionIndex; i<Game::enemiesRoute.size(); i++)
            d += p.distance(Game::enemiesRoute[i]);
        _distanceToEnd = d;
    }
}
开发者ID:ivancea,项目名称:TowerDefense,代码行数:11,代码来源:Enemy.cpp


示例13: collidesWithQuads

bool World::collidesWithQuads(vector<Quad*>* quads) {
    for (auto quad : *quads) {
        for (int i = 0; i < quad->getVertexCount(); i++) {
            Vec2d* vertex = quad->getVertices()[i];
            if (vertex->getY() < 0 || vertex->getY() > bounds->getY() || vertex->getX() < 0 || vertex->getX() > bounds->getX()) {
                cout << "Collision with world " << vertex->toString() << endl;
                return true;
            }
        }
    }
    return false;
}
开发者ID:andystanton,项目名称:lana-tetris,代码行数:12,代码来源:World.cpp


示例14: Vec2d

bool World::resetTet(char letter) {
    TetrominoType* type = typeFactory->getType(letter);

    Vec2d* newCoords = new Vec2d(spawnPoint);
    int spawnOffset = type->getHeight();
    newCoords->setY(newCoords->getY() - spawnOffset);
    
    activeTet = tetFactory->getTetromino(type, newCoords)->withDirection(defaultDirection);
    nextTet = tetFactory->getTetromino(type, newCoords)->withDirection(defaultDirection);
    
    return !heap->collidesWithQuads(activeTet->getQuads());
}
开发者ID:andystanton,项目名称:lana-tetris,代码行数:12,代码来源:World.cpp


示例15: VParabola

void	Voronoi::InsertParabola(Vec2d * p){
	if(!root){root = new VParabola(p); return;}

	if(root->isLeaf && root->site->y - p->y < 1){ // degenerovaný pripad - obì spodní místa ve stejné výšce
		Vec2d * fp = root->site;
		root->isLeaf = false;
		root->SetLeft( new VParabola(fp) );
		root->SetRight(new VParabola(p)  );
		//Vec2d * s = new Vec2d( (p->x + fp->x)/2, height ); // zaèátek hrany uprostøed míst
		Vec2d * s = new Vec2d();   s->set( (p->x + fp->x)/2, height ); // zaèátek hrany uprostøed míst
		points.push_back(s);
		if(p->x > fp->x) root->edge = new VEdge(s, fp, p); // rozhodnu, který vlevo, který vpravo
		else root->edge = new VEdge(s, p, fp);
		edges->push_back(root->edge);
		return;
	}

	VParabola * par = GetParabolaByX(p->x);

	if(par->cEvent)	{
		deleted.insert(par->cEvent);
		par->cEvent = 0;
	}

	//Vec2d * start = new Vec2d(p->x, GetY(par->site, p->x));
    Vec2d * start = new Vec2d(); start->set( p->x, GetY(par->site, p->x) );
	points.push_back(start);

	VEdge * el = new VEdge(start, par->site, p);
	VEdge * er = new VEdge(start, p, par->site);

	el->neighbour = er;
	edges->push_back(el);

	// pøestavuju strom .. vkládám novou parabolu
	par->edge = er;
	par->isLeaf = false;

	VParabola * p0 = new VParabola(par->site);
	VParabola * p1 = new VParabola(p);
	VParabola * p2 = new VParabola(par->site);

	par->SetRight(p2);
	par->SetLeft(new VParabola());
	par->Left()->edge = el;

	par->Left()->SetLeft(p0);
	par->Left()->SetRight(p1);

	CheckCircle(p0);
	CheckCircle(p2);
}
开发者ID:ProkopHapala,项目名称:SimpleSimulationEngine,代码行数:52,代码来源:Voronoi.cpp


示例16: Vec2d

Vec2d MaiBody::resolveForce(const MaiBody &body) const
{
	if (this == &body) { return Vec2d(0, 0); } // no force is here.

	Vec2d r = (position_ - body.getPosition());
	float r_len = r.length();

	double GMm = Constants::kGaes * mass_ * body.getMass();

	return Vec2d(
		-GMm * (r.x / (r_len * r_len * r_len)),
		-GMm * (r.y / (r_len * r_len * r_len))
	);
}
开发者ID:dwmh,项目名称:maidemo,代码行数:14,代码来源:mai_body.cpp


示例17: Vec2d

void	Voronoi::FinishEdge(VParabola * n){
	if(n->isLeaf) {delete n; return;}
	double mx;
	if(n->edge->direction->x > 0.0){ mx = std::max(width, n->edge->start->x + 10 ); }
	else                           { mx = std::min(0.0,   n->edge->start->x - 10 ); }

	//Vec2d * end = new Vec2d(mx, mx * n->edge->f + n->edge->g);
	Vec2d * end = new Vec2d(); end->set( mx,  mx * n->edge->f + n->edge->g );
	n->edge->end = end;
	points.push_back(end);

	FinishEdge(n->Left() );
	FinishEdge(n->Right());
	delete n;
}
开发者ID:ProkopHapala,项目名称:SimpleSimulationEngine,代码行数:15,代码来源:Voronoi.cpp


示例18: make_one_period

static std::vector<Vec2d> make_one_period(double width, double scaleFactor, double z_cos, double z_sin, bool vertical, bool flip)
{
    std::vector<Vec2d> points;
    double dx = M_PI_4; // very coarse spacing to begin with
    double limit = std::min(2*M_PI, width);
    for (double x = 0.; x < limit + EPSILON; x += dx) {  // so the last point is there too
        x = std::min(x, limit);
        points.emplace_back(Vec2d(x,f(x, z_sin,z_cos, vertical, flip)));
    }

    // now we will check all internal points and in case some are too far from the line connecting its neighbours,
    // we will add one more point on each side:
    const double tolerance = .1;
    for (unsigned int i=1;i<points.size()-1;++i) {
        auto& lp = points[i-1]; // left point
        auto& tp = points[i];   // this point
        Vec2d lrv = tp - lp;
        auto& rp = points[i+1]; // right point
        // calculate distance of the point to the line:
        double dist_mm = unscale<double>(scaleFactor) * std::abs(cross2(rp, lp) - cross2(rp - lp, tp)) / lrv.norm();
        if (dist_mm > tolerance) {                               // if the difference from straight line is more than this
            double x = 0.5f * (points[i-1](0) + points[i](0));
            points.emplace_back(Vec2d(x, f(x, z_sin, z_cos, vertical, flip)));
            x = 0.5f * (points[i+1](0) + points[i](0));
            points.emplace_back(Vec2d(x, f(x, z_sin, z_cos, vertical, flip)));
            // we added the points to the end, but need them all in order
            std::sort(points.begin(), points.end(), [](const Vec2d &lhs, const Vec2d &rhs){ return lhs < rhs; });
            // decrement i so we also check the first newly added point
            --i;
        }
    }
    return points;
}
开发者ID:prusa3d,项目名称:Slic3r,代码行数:33,代码来源:FillGyroid.cpp


示例19: isInRange

 bool isInRange(Vec2d position, double minRange, double maxRange, Enemy* enemy){
     if(maxRange<0)
         return true;
     if(maxRange<minRange)
         return false;
     double d = position.distance(enemy->getPosition());
     return d<=maxRange && d>=minRange;
 }
开发者ID:ivancea,项目名称:TowerDefense,代码行数:8,代码来源:Game.cpp


示例20: update

		void Spatial::update()
		{
			double timeDelta = mTimeDelta.getElapsedTime().asSeconds();
			mSteeringForce.truncate(mMaxForce);

			Vec2d acceleration = mSteeringForce / mMass;
			mVelocity += acceleration * timeDelta;
			mVelocity.truncate(mMaxSpeed);
			mPos += mVelocity * timeDelta;

			if (mVelocity.lengthSq() > 0.00000001)
			{
				Vec2d velocityNorm = mVelocity;
				velocityNorm.normalize();
				setHeading(velocityNorm);
			}

			mTimeDelta.restart();
		}
开发者ID:DanWatkins,项目名称:glZombies,代码行数:19,代码来源:Spatial.cpp



注:本文中的Vec2d类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Vec2f类代码示例发布时间:2022-05-31
下一篇:
C++ Vec2D类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap