本文整理汇总了C++中Vector2::Magnitude方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2::Magnitude方法的具体用法?C++ Vector2::Magnitude怎么用?C++ Vector2::Magnitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2
的用法示例。
在下文中一共展示了Vector2::Magnitude方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: acos
double Vector2::AngleBetween(Vector2 v) {
if (this->Magnitude() == 0 || v.Magnitude() == 0) {
return 0;
}
else {
double dotProd = this->Dot(v);
dotProd /= this->Magnitude() * v.Magnitude();
return acos(dotProd);
}
}
示例2: Intersect
bool Intersect(const Circle& c, const Line& l)
{
Vector2 startToCenter = c.center - l.from;
Vector2 startToEnd = l.to - l.from;
float len = startToEnd.Magnitude();
Vector2 dir = startToEnd / len;
// Find the closest point to the line segment
float projection = Dot(startToCenter, dir);
Vector2 closestPoint;
if (projection > len)
{
closestPoint = l.to;
}
else if (projection < 0.0f)
{
closestPoint = l.from;
}
else
{
closestPoint = l.from + (dir * projection);
}
// Check if the closest point is within the circle
Vector2 closestToCenter = c.center - closestPoint;
if (closestToCenter.MagnitudeSqr() > c.radius * c.radius)
{
return false;
}
return true;
}
示例3: if
float Vector2::AngleBetween(Vector2 v) const {
if (this->Magnitude() == 0 || v.Magnitude() == 0) {
return 0;
}
Vector2 left = this->Normalize();
Vector2 right = v.Normalize();
if (left == right) {
return 0;
}
float dot = left.Dot(right);
// Floating points check
if (dot > 1.0f) {
dot = 1.0f;
}
else if (dot < -1.0f) {
dot = -1.0f;
}
float rot = acos(dot);
// http://stackoverflow.com/questions/11022446/direction-of-shortest-rotation-between-two-vectors
// Use cross vector3 to determine direction
Vector3 cross = Vector3(left.x, left.y).Cross(Vector3(right.x, right.y));
if (cross.z > 0) {
return -rot;
}
else {
return rot;
}
}
示例4: unitVec
void Vector2::RotateAround(Vector2 origin, double rotation) {
Vector2 fromMid = *this - origin;
Vector2 unitVec(1, 0);
double angleFrom0 = fromMid.AngleBetween(unitVec);
if (fromMid.y < 0) {
angleFrom0 *= -1;
}
angleFrom0 += rotation;
Vector2 endMove(cos(angleFrom0), sin(angleFrom0));
endMove *= fromMid.Magnitude();
endMove = origin + endMove;
*this = endMove;
}
示例5: unitVec
Vector2 Vector2::RotateAround(Vector2 origin, float rotation) const {
if (rotation == 0) {
return *this;
}
Vector2 fromMid = *this - origin;
Vector2 unitVec(1, 0);
float angleFrom0 = fromMid.AngleBetween(unitVec);
angleFrom0 -= rotation;
Vector2 endMove(cos(angleFrom0), sin(angleFrom0));
endMove *= fromMid.Magnitude();
endMove = origin + endMove;
return endMove;
}
示例6: MouseMotion
void GameManager::MouseMotion(int x, int y)
{
y = glutGet(GLUT_WINDOW_HEIGHT) - y;
Vector2 dirVector = Vector2(x,y) - Vector2(GameConfig::getInstance().ScreenWidth/2, GameConfig::getInstance().ScreenHeight/2);
float dirVectorMag = sqrtf((dirVector.x * dirVector.x) + (dirVector.y * dirVector.y));
mNormalizedDir = dirVector/dirVectorMag;
Vector2 shipUp(0,1);
float dotProduct = (dirVector.x * shipUp.x) + (dirVector.y * shipUp.y);
float cosAngle = dotProduct / (shipUp.Magnitude() * dirVector.Magnitude()) ;
float angle = acos(cosAngle) * 180.f / PI;
mPlayerShip->SetDirectionAngle( x > GameConfig::getInstance().ScreenWidth/2.f ? -angle : angle);
}
示例7: acos
/* AngleBetween */
float Vector2::AngleBetween(Vector2& vec) {
return acos(DotProduct(vec)/(Magnitude() * vec.Magnitude()));
}
示例8: Normalize
public: static Vector2 Normalize (Vector2 &A) {
return A *= float
(float (1) /
A.Magnitude());
}
示例9:
float Vector2::CompProj(const Vector2& argVec1, const Vector2& argVec2)
{
return Vector2::Dot(argVec1, argVec2) / argVec1.Magnitude();
};
示例10: Magnitude
double Magnitude( Vector2 const& i_vector )
{
return i_vector.Magnitude();
}