本文整理汇总了C++中vec2类的典型用法代码示例。如果您正苦于以下问题:C++ vec2类的具体用法?C++ vec2怎么用?C++ vec2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vec2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AngleBetween
float AngleBetween(const vec2 &a, const vec2 &b)
{
float dotProd = a.dotProduct(b);
float cosine = dotProd / (a.length() * b.length());
return RadToDeg(acos(cosine));
}
示例2: draw_pt
void
draw_pt(const vec2 &pt, float size, const vec4 &color)
{
gl::Uniform(m_pts_pos_loc, vec3(pt.x(), pt.y(), size));
gl::Uniform(m_pts_color_loc, color);
glDrawArrays(GL_POINTS, 0, 1);
}
示例3: globalAngle
inline static qreal globalAngle( const vec2 &v )
{
//assuming v is normalized
qreal cosa = v.x();
qreal sina = -v.y();
return sina >= 0.0 ? acosf(cosa) : 2.0*PI - acosf(cosa);
}
示例4: angle
float angle (const vec2& arg1, const vec2& arg2)
{
float skal = il_skal(arg1, arg2)/(arg1.length()*arg2.length());
skal = abs(acos(skal))*sgn(arg1, arg2);
return skal;
}
示例5:
inline vec2 operator*(const vec2& v, const mat2& m)
{
vec2 t;
t.x() = v.x()*m.e(0,0) + v.y()*m.e(0,1);
t.y() = v.x()*m.e(1,0) + v.y()*m.e(1,1);
return t;
}
示例6: wanted_direction
void Automan::OnTick() {
Parent::OnTick();
cure::ContextObject* car = manager_->GetObject(car_id_, true);
if (!car) {
manager_->PostKillObject(GetInstanceId());
return;
}
if (!car->IsLoaded()) {
return;
}
car->SetEnginePower(0, 1);
const vec2 wanted_direction(direction_.x, direction_.y);
const vec3 car_direction3d = car->GetOrientation()*vec3(0,1,0);
const vec2 car_direction(car_direction3d.x, car_direction3d.y);
const float angle = wanted_direction.GetAngle(car_direction);
car->SetEnginePower(1, angle);
if (car->GetVelocity().GetLengthSquared() < 1.0f) {
still_timer_.TryStart();
if (still_timer_.QueryTimeDiff() > 4.0f) {
cure::Health::Set(car, 0);
}
} else {
still_timer_.Stop();
}
}
示例7: build
void KDTree::build(const vec2& iLats, const vec2& iLons) {
mLats = iLats;
mLons = iLons;
if(iLats.size() != iLons.size())
Util::error("Cannot initialize KDTree, lats and lons not the same size");
size_t nLat = iLats.size();
if(nLat == 0)
Util::error("Cannot initialize KDTree, no valid locations");
size_t nLon = iLats[0].size();
if(nLon == 0)
Util::error("Cannot initialize KDTree, no valid locations");
indexdVec lons(nLon*nLat);
indexdVec::iterator currLon = lons.begin();
size_t to = -1;
for(size_t i = 0; i < iLats.size(); ++i) {
for(size_t j = 0; j < iLats[0].size(); ++j) {
if(Util::isValid(iLons[i][j]) && Util::isValid(iLats[i][j])) {
*(currLon++) = Indexed(iLons[i][j], iLats[i][j], i, j);
++to;
}
}
}
if(to == -1) {
Util::error("Cannot initialize KDTree, no valid locations");
}
if(to >= 0) subTree(lons, 0, to, true, NULL, mRoot);
}
示例8: x
bool operator<(const vec2& v) const
{
if (x() != v.x())
return x() < v.x();
else
return y() < v.y();
}
示例9: yaw_vector
void Launcher::GetBallisticData(const vec3& position1, const vec3& position2,
float pitch, float& guide_pitch, float& guide_yaw, float &time) const {
const vec3 delta = position1 - position2;
const vec2 yaw_vector(delta.x, delta.y);
guide_yaw = vec2(0, 1).GetAngle(yaw_vector);
const float h = delta.z;
const float v = game_->GetMuzzleVelocity();
const float vup = v * ::cos(pitch);
// g*t^2/2 - vup*t + h = 0
//
// Quaderatic formula:
// ax^2 + bx + c = 0
// =>
// -b +- sqrt(b^2 - 4ac)
// x = ---------------------
// 2a
const float a = +9.82f/2;
const float b = -vup;
const float c = +h;
const float b2 = b*b;
const float _4ac = 4*a*c;
if (b2 < _4ac) { // Does not compute.
guide_pitch = -PIF/4;
} else {
const float t = (-b + sqrt(b2 - _4ac)) / (2*a);
//deb_assert(t > 0);
time = t;
const float vfwd = yaw_vector.GetLength() / t;
guide_pitch = -::atan(vfwd/vup);
if (guide_pitch < pitch) { // Aiming downwards?
guide_pitch += (guide_pitch-pitch); // Tss! Homebrew... seems to be working somewhat! :)
}
}
}
示例10: parseTransform
bool esvg::Polyline::parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) {
// line must have a minimum size...
m_paint.strokeWidth = 1;
if (_element.exist() == false) {
return false;
}
parseTransform(_element);
parsePaintAttr(_element);
// add the property of the parrent modifications ...
m_transformMatrix *= _parentTrans;
std::string sss1 = _element.attributes["points"];
if (sss1.size() == 0) {
ESVG_ERROR("(l "<<_element.getPos()<<") polyline: missing points attribute");
return false;
}
_sizeMax.setValue(0,0);
ESVG_VERBOSE("Parse polyline : \"" << sss1 << "\"");
const char* sss = sss1.c_str();
while ('\0' != sss[0]) {
vec2 pos;
int32_t n;
if (sscanf(sss, "%f,%f %n", &pos.m_floats[0], &pos.m_floats[1], &n) == 2) {
m_listPoint.push_back(pos);
_sizeMax.setValue(std::max(_sizeMax.x(), pos.x()),
std::max(_sizeMax.y(), pos.y()));
sss += n;
} else {
break;
}
}
return true;
}
示例11: contains
bool Rectangle::contains(const vec2 &pt){
if(pt.x() > pts[0].x() &&pt.x() < pts[1].x()
&& pt.y() > pts[0].y() && pt.y()< pts[3].y()){
return true;
}
return false;
}
示例12:
void etk::Matrix2::scale(const vec2& _vect) {
m_mat[0] *= _vect.x();
m_mat[1] *= _vect.x();
m_mat[2] *= _vect.x();
m_mat[4] *= _vect.y();
m_mat[3] *= _vect.y();
m_mat[5] *= _vect.y();
}
示例13: SetCamera
void SetCamera ( vec2 corner1, vec2 corner2, float rotation )
{
matrix2x3 projection ( matrix2x3::Ortho(corner1.X(), corner2.X(), corner1.Y(), corner2.Y()) );
if (fabs(rotation) > 0.00004f)
projection *= matrix2x3::Rotation(rotation);
Matrices::SetProjectionMatrix(projection);
cameraCorner1 = corner1;
cameraCorner2 = corner2;
}
示例14: cmdUIDrawTexturedQuad
void cmdUIDrawTexturedQuad(struct Cmd* pCmd, UIManager* pUIManager, const vec2& position, const vec2& size, Texture* pTexture)
{
UNREF_PARAM(pCmd);
// the last variable can be used to create a border
TexVertex pVertices[] = { MAKETEXQUAD(position.getX(), position.getY(), position.getX() + size.getX(), position.getY() + size.getY(), 0) };
int nVertices = sizeof(pVertices) / sizeof(pVertices[0]);
float4 color = { 1.0f, 1.0f, 1.0f, 1.0f };
pUIManager->pUIRenderer->drawTextured(PRIMITIVE_TOPO_TRI_STRIP, pVertices, nVertices, pTexture, &color);
}
示例15: vec2
vec2 matrix2x3::operator* ( const vec2& srcv2 ) const
{
float ix, iy, ox, oy;
ix = srcv2.X();
iy = srcv2.Y();
ox = (ix * _m11) + (iy * _m12) + _tX;
oy = (ix * _m21) + (iy * _m22) + _tY;
return vec2(ox, oy);
}