本文整理汇总了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)
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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));
}
示例10: Vec2D
DirArrayGen::DirArrayGen( Vec2D const& d )
{
difPos = Vec2D(0,0);
dir = ( 1.0f / sqrtf( d.length2() ) ) * d;
num = 1;
offset = 2;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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));
}