当前位置: 首页>>代码示例>>C++>>正文


C++ Vec2D类代码示例

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


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

示例1:

toxi::geom::Vec3D toxi::geom::Vec2D::bisect( Vec2D b )
{
	Vec2D diff = this->sub(b);
	Vec2D sum = this->add(b);
	float dot = diff.dot(sum);
	return Vec3D(diff.x, diff.y, -dot / 2)
}
开发者ID:AndySmile,项目名称:ofxToxiclibs,代码行数:7,代码来源:Vec2D.cpp

示例2: addVertices

void addVertices(vector<float>& vertices, vector<float>& colors,
                 Vec2D<float> point, Vec2D<float> v1, QColor color,
                 float z = 0.0) {
  Vec2D<float> normal = v1;
  swap(normal.x, normal.y);
  normal.x *= -1;
  normal.normalize();

  Vec2D<float> p1 = point + normal * LINE_WIDTH;
  Vec2D<float> p2 = point - normal * LINE_WIDTH;

  for (int i = 0; i < 2; i++) {
    colors.push_back(color.redF());
    colors.push_back(color.greenF());
    colors.push_back(color.blueF());
    colors.push_back( (color.greenF() + color.redF()) *0.3f  );
  }

  vertices.push_back(p1.x);
  vertices.push_back(p1.y);
  vertices.push_back(z);

  vertices.push_back(p2.x);
  vertices.push_back(p2.y);
  vertices.push_back(z);
}
开发者ID:te42kyfo,项目名称:Feldrand,代码行数:26,代码来源:DrawStreamlinesImplementation.cpp

示例3: getCentroid

toxi::geom::Polygon2D * toxi::geom::Polygon2D::smooth( const float & amount, const float & baseWeight )
{
	Vec2D centroid = getCentroid();
	int num = vertices.size();
	std::vector<Vec2D> filtered;
	for (int i = 0, j = num - 1, k = 1; i < num; i++) {
		Vec2D a = vertices.at(i);
		Vec2D dir = vertices.at(j).sub( a ).addSelf( vertices.at(k).sub( a ))
			.addSelf(a.sub( centroid).scaleSelf(baseWeight));
		filtered.push_back(a.add(dir.scaleSelf(amount)));
		j++;
		if (j == num) {
			j = 0;
		}
		k++;
		if (k == num) {
			k = 0;
		}
	}
	vertices.clear();

	for( auto it = filtered.begin(); it != filtered.end(); ++it ) 
	{
		vertices.push_back( *it );
	}

	return this;
}
开发者ID:Jornason,项目名称:ofxToxiclibs,代码行数:28,代码来源:Polygon2D.cpp

示例4: StringFrom

static SimpleString StringFrom(const Vec2D & v)
{
    SimpleString s = SimpleString();
    s += SimpleString("(");
    s += StringFrom(v.get_x());
    s += SimpleString(",");
    s += StringFrom(v.get_y());
    s += SimpleString(")");

    return s;
}
开发者ID:31415us,项目名称:beacons,代码行数:11,代码来源:positioning_test.cpp

示例5: updateCenterOfMass

	void updateCenterOfMass(Body body) {
		if (_mass == 0) {
			_mass = body.getMass();
			_centerOfMass = body.getPos();
		} else {
			double new_mass = _mass + body.getMass();
			double new_cen_x = ((_mass*_centerOfMass.getX()) + (body.getMass() * body.getXPos()))/new_mass;
			double new_cen_y = ((_mass*_centerOfMass.getY()) + (body.getMass() * body.getYPos()))/new_mass;
			_centerOfMass = Vec2D(new_cen_x, new_cen_y);
			_mass = new_mass;
		}
	}
开发者ID:zeeshanabid94,项目名称:Barnes-Hut-N-Body-Simulation,代码行数:12,代码来源:quadtree.cpp

示例6: add

toxi::geom::Polygon2D::Polygon2D( const Vec2D & baseA, const Vec2D & baseB, const int & res )
{
	double theta = -(toxi::math::MathUtils::PI - (toxi::math::MathUtils::PI * (res - 2) / res));
	Vec2D dir = baseB.sub( baseA);
	Vec2D prev = baseB;
	add( baseA );
	add( baseB );
	for (int i = 1; i < res - 1; i++) {
		Vec2D p = prev.add(dir.getRotated(theta * i));
		add(p);
		prev = p;
	}
}
开发者ID:Jornason,项目名称:ofxToxiclibs,代码行数:13,代码来源:Polygon2D.cpp

示例7: sqrtf

	void SimpleGen::generate( Weapon* weapon )
	{
		Object* owner = weapon->owner;
		Object* destObj = weapon->destObj;

		Vec2D dif = destObj->getPos() - owner->getPos();
		float s= sqrtf(dif.length2());
		Vec2D speed = ( weapon->bulletSpeed / s ) * dif;

		Object* bullet = weapon->createBullet();
		bullet->setVelocity( speed );
		spawnObject(bullet);
	}
开发者ID:uvbs,项目名称:GameProject,代码行数:13,代码来源:Weapon.cpp

示例8: calculateForceFromBody

	Force calculateForceFromBody(Body otherBody) {
		Vec2D distance = calculateDistanceFromBody(otherBody);
		Vec2D unit_distance = distance.getUnitVector();
		if (distance.getMagnitude() != 0) {
			double forceMagnitude= (GRAVITYCONST * otherBody.getMass() * getMass()) / (pow(distance.getMagnitude(), 2));

			double forceMagnitude_x = forceMagnitude * unit_distance.getX();
			double forceMagnitude_y = forceMagnitude * unit_distance.getY();
			return Force(forceMagnitude_x, forceMagnitude_y);
		} else {
			return Force(0,0);
		}
	}
开发者ID:zeeshanabid94,项目名称:Barnes-Hut-N-Body-Simulation,代码行数:13,代码来源:body.cpp

示例9: apply_hooks_law

void SchQ_Particle_System :: apply_hooks_law(Spring &s){
    Vec2D<double> pos0  = s.a->get_position(), pos1  = s.b->get_position(),
                  vel0  = s.a->get_velocity(), vel1  = s.b->get_velocity();
    double        dx    = pos0.x-pos1.x,       dy    = pos0.y-pos1.y,
                  dvdx  = vel0.x-vel1.x,       dvdy  = vel0.y-vel1.y,
                  dist  = pos0.distance(pos1), rdist  = dist != 0 ? 1.0/dist : 0;
    
    Vec2D<double> force  (-(s.stiffness*(dist-s.rest_length) +
                            s.dampening*(dvdx) * dx*rdist) * dx*rdist ,
                          -(s.stiffness*(dist-s.rest_length) +
                            s.dampening*(dvdy) * dy*rdist) * dy*rdist);
    
    s.a->add_force(force);
    s.b->add_force(force.multiply(-1));
}
开发者ID:schanq,项目名称:Particle-System,代码行数:15,代码来源:SchQ_Particle_System.cpp

示例10: Vec2D

	DirArrayGen::DirArrayGen( Vec2D const& d )
	{
		difPos = Vec2D(0,0);
		dir = ( 1.0f / sqrtf( d.length2() ) ) * d;
		num = 1;
		offset = 2;
	}
开发者ID:uvbs,项目名称:GameProject,代码行数:7,代码来源:Weapon.cpp

示例11: Vec2D

toxi::geom::Vec2D toxi::geom::Polygon2D::getClosestPointTo( Vec2D & p )
{
	float minD = FLT_MAX;
	Vec2D q = Vec2D();
	for (Line2D l : getEdges()) 
	{
		Vec2D c = l.closestPointTo(p);
		float d = static_cast< float > ( c.distanceToSquared( p ) );
		if (d < minD) 
		{
			q = c;
			minD = d;
		}
	}
	return q;
}
开发者ID:Jornason,项目名称:ofxToxiclibs,代码行数:16,代码来源:Polygon2D.cpp

示例12: delta

Vec2D Segment::intersectionPoint(Segment const& other) const
{
  Vec2D selfDelta = delta();
  Vec2D otherDelta = other.delta();

  if(selfDelta.cross(otherDelta) != 0)
  {
    float t = other.a.subtract(a).cross(otherDelta) / selfDelta.cross(otherDelta);
    float u = other.a.subtract(a).cross(selfDelta) / selfDelta.cross(otherDelta);
    if(t >= 0 && t <= 1 && u >= 0 && u <= 1)
    {
      return a.add(selfDelta.scale(t));
    }
  }

  return Vec2D(0, 0);
}
开发者ID:bzar,项目名称:2dshooter,代码行数:17,代码来源:segment.cpp

示例13: Q_ASSERT

Image BrushStrokerCustomBrush::drawDabImage(const TabletInputData &data, QRect *rect)
{
    Q_ASSERT(data.pressure > 0);

    Vec2D radiusVec;
    radiusVec.rx() = radiusBase() * data.pressure;
    radiusVec.ry() = radiusVec.x() * (1.0 - _setting.flattening);

    _lastMinorRadius = radiusVec.y();

    //qDebug() << "radius" << radiusVec.x << radiusVec.y;

    QPainterPath ellipse;
    ellipse.addEllipse(data.pos, radiusVec.x(), radiusVec.y());

    QRect dabRect;

    if (_setting.rotation)
    {
        QTransform rotation;
        rotation.rotate(_setting.rotation);
        ellipse = rotation.map(ellipse);

        dabRect = ellipse.boundingRect().toAlignedRect();
    }
    else
    {
        dabRect = QRectF(QPointF(data.pos - radiusVec), QSizeF(2.0 * radiusVec)).toAlignedRect();
    }

    Image dabImage(dabRect.size());
    dabImage.clear();

    Painter dabPainter(&dabImage);

    dabPainter.translateShape(-dabRect.topLeft());

    if (_setting.tableWidth == 1 && _setting.tableHeight == 1)
    {
        // no gradient
        dabPainter.setPixel(pixel());
    }
    else
    {
        ArgbGradient gradient;
        gradient.addStop(0, pixel());
        gradient.addStop(_setting.tableWidth, pixel() * _setting.tableHeight);
        gradient.addStop(1, Pixel(0));

        dabPainter.setBrush(Malachite::Brush::fromRadialGradient(gradient, data.pos, radiusVec));
    }

    dabPainter.drawPath(ellipse);

    dabPainter.end();

    *rect = dabRect;
    return dabImage;
}
开发者ID:pasberth,项目名称:PaintField,代码行数:59,代码来源:brushstrokercustombrush.cpp

示例14: circleLineIntersect

bool circleLineIntersect(Vec2D const& p, float const r, Vec2D const& l1, Vec2D const& l2, float const lr)
{
  Vec2D ld = l2 - l1;
  Vec2D ln = ld.normal();
  Vec2D l1p = p - l1;
  Vec2D l2p = p - l2;
  if(ln.cross(l1p) * ln.cross(l2p) < 0)
  {
    return l1p.projectioni(ln).lengthSquared() <= (r + lr) * (r + lr);
  }
  else if(l1p.lengthSquared() < l2p.lengthSquared())
  {
    return l1p.lengthSquared() <= (r + lr) * (r + lr);
  }
  else
  {
    return l2p.lengthSquared() <= (r + lr) * (r + lr);
  }
}
开发者ID:Cloudef,项目名称:spacerocks,代码行数:19,代码来源:util.cpp

示例15: getNormalized

float toxi::geom::Vec2D::angleBetween( Vec2D v, bool forceNormalize )
{
	double theta;
	if (forceNormalize) {
		theta = getNormalized().dot(v.getNormalized());
	} else {
		theta = dot(v);
	}
	return (float) std::acos(toxi::math::MathUtils::clipNormalized(theta));
}
开发者ID:AndySmile,项目名称:ofxToxiclibs,代码行数:10,代码来源:Vec2D.cpp


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