本文整理汇总了C++中math::Vector2类的典型用法代码示例。如果您正苦于以下问题:C++ Vector2类的具体用法?C++ Vector2怎么用?C++ Vector2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: values
void
MeshBase::setVertex(int i, const Math::Vector2 &v)
{
if (!m_vdata->set(i, v.x(), v.y()))
MMWARNING("Failed to assign values (%f, %f) to vertex %d",
v.x(), v.y(), i);
}
示例2: draw_point
void RendererPlplot::draw_point(const math::Vector2 &v, const Rgb &rgb, enum PointStyle s)
{
int code;
_pls->col0(get_color_id(rgb));
switch (s)
{
default:
case PointStyleDot:
code = 1;
break;
case PointStyleCross:
code = 2;
break;
case PointStyleRound:
code = 4;
break;
case PointStyleSquare:
code = 6;
break;
case PointStyleTriangle:
code = 11;
break;
}
PLFLT x = v.x(), y = v.y();
_pls->poin(1, &x, &y, code);
}
示例3: Error
Containers::Array<char> StbPngImageConverter::doExportToData(const ImageView2D& image) {
#ifndef MAGNUM_TARGET_GLES
if(image.storage().swapBytes()) {
Error() << "Trade::StbPngImageConverter::exportToData(): pixel byte swap is not supported";
return nullptr;
}
#endif
if(image.type() != PixelType::UnsignedByte) {
Error() << "Trade::StbPngImageConverter::exportToData(): unsupported pixel type" << image.type();
return nullptr;
}
Int components;
switch(image.format()) {
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
case PixelFormat::Red:
#endif
#ifdef MAGNUM_TARGET_GLES2
case PixelFormat::Luminance:
#endif
components = 1;
break;
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
case PixelFormat::RG:
#endif
#ifdef MAGNUM_TARGET_GLES2
case PixelFormat::LuminanceAlpha:
#endif
components = 2;
break;
case PixelFormat::RGB: components = 3; break;
case PixelFormat::RGBA: components = 4; break;
default:
Error() << "Trade::StbPngImageConverter::exportToData(): unsupported pixel format" << image.format();
return nullptr;
}
/* Data properties */
std::size_t offset;
Math::Vector2<std::size_t> dataSize;
std::tie(offset, dataSize, std::ignore) = image.dataProperties();
/* Reverse rows in image data */
Containers::Array<unsigned char> reversedData{image.data().size()};
for(Int y = 0; y != image.size().y(); ++y) {
std::copy(image.data<unsigned char>() + offset + y*dataSize.x(), image.data<unsigned char>() + offset + (y + 1)*dataSize.x(), reversedData + (image.size().y() - y - 1)*dataSize.x());
}
Int size;
unsigned char* const data = stbi_write_png_to_mem(reversedData, dataSize.x(), image.size().x(), image.size().y(), components, &size);
CORRADE_INTERNAL_ASSERT(data);
/* Wrap the data in an array with custom deleter (we can't use delete[]) */
Containers::Array<char> fileData{reinterpret_cast<char*>(data), std::size_t(size),
[](char* data, std::size_t) { std::free(data); }};
return fileData;
}
示例4: draw_circle
void RendererPlplot::draw_circle(const math::Vector2 &c, double r,
const Rgb &rgb, bool filled)
{
_pls->col0(get_color_id(rgb));
std::cout << "draw_circle was not tested (added 8th parameter to compile" << std::endl;
exit(-1);
_pls->arc(c.x(), c.y(), r, r, 0., 360., 360., filled);
}
示例5: cos
Math::VectorPair2 TRegularPolygon::get_edge(const Math::Vector2 &point) const
{
// find sector start angle
double a = Math::lp_floor(atan2(point.y(), point.x()) - _angle, (double)_edge_cnt / (2.0 * M_PI));
// find sector edge coordinates
return Math::VectorPair2(_radius * cos(_angle + a), _radius * sin(_angle + a),
_radius * cos(_angle + a + _a_step), _radius * sin(_angle + a + _a_step));
}
示例6: normal
void TCurveBase::normal(Math::Vector3 &normal, const Math::Vector3 &point) const
{
Math::Vector2 d;
derivative(point.project_xy(), d);
normal = Math::Vector3(d.x(), d.y(), -1.0);
normal.normalize();
}
示例7: Draw
void Block::Draw(sf::RenderTarget& renderTarget) {
MATH::Vector2 position = GetPosition();
if(_highlight) {
_blockSprite.SetColor(_color + sf::Color(255, 255, 255, 255 * sinf(_highlightPhase)));
position -= MATH::Vector2(0.0f, 5.0f * sinf(_highlightPhase));
}
_blockSprite.SetPosition(position.sfVec());
renderTarget.Draw(_blockSprite);
}
示例8: draw_text
void RendererPlplot::draw_text(const math::Vector2 &c, const math::Vector2 &dir,
const std::string &str, TextAlignMask a, int size, const Rgb &rgb)
{
double j = .5;
if (a & TextAlignLeft)
j = 0.;
else if (a & TextAlignRight)
j = 1.;
_pls->schr(size/3., 1.);
_pls->col0(get_color_id(rgb));
_pls->ptex(c.x(), c.y(), dir.x(), dir.y(), j, str.c_str());
}
示例9: movement
bool
BounceColliderComponent::collision(ColliderComponent &c, float d, const CollisionData &data)
{
MMUNUSED(c);
MMUNUSED(d);
MMUNUSED(data);
const Math::Vector2 &l_vel = movement()->velocity();
const float l_mag = l_vel.magnitude();
const Math::Vector2 l_normal = l_vel.normalized(l_mag);
Math::Vector2 l_pvel = (l_normal * (2.f * l_normal.dot(l_vel * -1.f)) + l_vel);
movement()->velocity() = l_pvel.normalize(l_pvel.magnitude()) * l_mag;
return(true);
}
示例10: SetEnemyEyeSight
void EnemyAIBase::SetEnemyEyeSight( math::Vector2 eye )
{
if( m_enemyMine ){
eye.Normalize();
m_enemyMine->m_eye = eye;
}
}
示例11: inside
bool TRegularPolygon::inside(const Math::Vector2 &point) const
{
double d = Math::square(point.x()) + Math::square(point.y());
// check against circumscribed circle
if (d > Math::square(_radius))
return false;
// check against inscribed circle
if (d < Math::square(_i_radius))
return true;
Math::VectorPair2 e(get_edge(point));
return ((point.y() - e.y0()) * (e.x1() - e.x0()) -
(point.x() - e.x0()) * (e.y1() - e.y0()) > 0);
}
示例12: aspectRatioFix
template<UnsignedInt dimensions, class T> typename DimensionTraits<dimensions, T>::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) {
/* Don't divide by zero / don't preserve anything */
if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved)
return {};
Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale;
/* Extend on larger side = scale larger side down
Clip on smaller side = scale smaller side up */
return Camera<dimensions, T>::aspectRatioScale(
(relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ?
Vector2(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1.0)) :
Vector2(T(1.0), relativeAspectRatio.x()/relativeAspectRatio.y()));
}
示例13: aspectRatioFix
template<UnsignedInt dimensions, class T> MatrixTypeFor<dimensions, T> aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) {
/* Don't divide by zero / don't preserve anything */
if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved)
return {};
CORRADE_INTERNAL_ASSERT((projectionScale > Math::Vector2<T>(0)).all() && (viewport > Vector2i(0)).all());
Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale;
/* Extend on larger side = scale larger side down
Clip on smaller side = scale smaller side up */
return MatrixTypeFor<dimensions, T>::scaling(Math::Vector<dimensions, T>::pad(
(relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ?
Math::Vector2<T>(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1)) :
Math::Vector2<T>(T(1), relativeAspectRatio.x()/relativeAspectRatio.y()), T(1)));
}
示例14: offsetFix
bool GLVideo::DrawLine(const math::Vector2 &p1, const math::Vector2 &p2, const Color& color1, const Color& color2)
{
if (GetLineWidth() <= 0.0f)
return true;
if (p1 == p2)
return true;
static const math::Vector2 offsetFix(0.5f, 0.5f);
const math::Vector2 a(p1 + offsetFix), b(p2 + offsetFix);
const math::Vector2 v2Dir = a - b;
const float length = v2Dir.Length() + 0.5f;
const float angle = math::RadianToDegree(math::GetAngle(v2Dir));
DrawRectangle(a, math::Vector2(GetLineWidth(), length),
color2, color2, color1, color1,
angle, Sprite::EO_CENTER_BOTTOM);
return true;
}
示例15: derivative
void TCurveBase::derivative(const Math::Vector2 & xy, Math::Vector2 & dxdy) const
{
double abserr;
struct curve_gsl_params_s params;
gsl_function gsl_func;
gsl_func.params = ¶ms;
params.c = this;
params.x = xy.x();
params.y = xy.y();
gsl_func.function = gsl_func_sagitta_x;
gsl_deriv_central(&gsl_func, xy.x(), 1e-6, &dxdy.x(), &abserr);
gsl_func.function = gsl_func_sagitta_y;
gsl_deriv_central(&gsl_func, xy.y(), 1e-6, &dxdy.y(), &abserr);
}