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


C++ Vector2::Magnitude方法代码示例

本文整理汇总了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);
    }
}
开发者ID:maxrchung,项目名称:MagicalGirlStoryBoard,代码行数:10,代码来源:Vector2.cpp

示例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;
}
开发者ID:wujohnny80,项目名称:Bullet-Hell,代码行数:31,代码来源:Math.cpp

示例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;
	}
}
开发者ID:maxrchung,项目名称:OsuukiSB,代码行数:34,代码来源:Vector2.cpp

示例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;
}
开发者ID:maxrchung,项目名称:MagicalGirlStoryBoard,代码行数:14,代码来源:Vector2.cpp

示例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;
}
开发者ID:maxrchung,项目名称:OsuukiSB,代码行数:15,代码来源:Vector2.cpp

示例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);
}
开发者ID:MohamedIsmailHafez,项目名称:Space-Shooter,代码行数:20,代码来源:GameManager.cpp

示例7: acos

/* AngleBetween */
float Vector2::AngleBetween(Vector2& vec) {
	return acos(DotProduct(vec)/(Magnitude() * vec.Magnitude()));
}
开发者ID:CaptKH,项目名称:IceBreaker,代码行数:4,代码来源:Vector2.cpp

示例8: Normalize

 public: static Vector2 Normalize (Vector2 &A) {
     return A *= float
     (float (1) /
     A.Magnitude());
 }
开发者ID:elvircrn,项目名称:ccppcodes,代码行数:5,代码来源:vector+(3).cpp

示例9:

		float Vector2::CompProj(const Vector2& argVec1, const Vector2& argVec2)
		{
			return Vector2::Dot(argVec1, argVec2) / argVec1.Magnitude();			
		};
开发者ID:embooglement,项目名称:Protium,代码行数:4,代码来源:Vector.cpp

示例10: Magnitude

 double Magnitude( Vector2 const& i_vector )
 {
     return i_vector.Magnitude();
 }
开发者ID:jpgaribotti,项目名称:libvector,代码行数:4,代码来源:Vector2.cpp


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