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


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

本文整理汇总了C++中Vector2::Normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2::Normalize方法的具体用法?C++ Vector2::Normalize怎么用?C++ Vector2::Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2的用法示例。


在下文中一共展示了Vector2::Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: IsCollision

bool HitBox::IsCollision(Vector2 offset, HitBox *pHitBox, Vector2 hitBoxOffset, CollisionParameter *pParam) const
{
    bool isCollision = false;
    Vector2 overlapCompensation = Vector2(0, 0);

    if (pHitBox != NULL)
    {
        for (unsigned int i = 0; i < collidableObjectList.size(); i++)
        {
            CollidableObject *pCollidableObject1 = collidableObjectList[i];

            for (unsigned int j = 0; j < pHitBox->collidableObjectList.size(); j++)
            {
                CollidableObject *pCollidableObject2 = pHitBox->collidableObjectList[j];
                CollisionParameter tempParam;

                if (CollisionExists(pCollidableObject1, offset + overlapCompensation, pCollidableObject2, hitBoxOffset, &tempParam)
                    && fabs(tempParam.OverlapDistance) > 0.0001)
                {
                    for (unsigned int k = 0; k < tempParam.OverlapEntryList.size(); k++)
                    {
                        pParam->OverlapEntryList.push_back(tempParam.OverlapEntryList[k]);
                    }

                    overlapCompensation += tempParam.OverlapAxis * tempParam.OverlapDistance;
                    isCollision = true;
                }
            }
        }
    }

    pParam->OverlapDistance = overlapCompensation.Length();
    pParam->OverlapAxis = overlapCompensation.Normalize();
    return isCollision;
}
开发者ID:mbasaglia,项目名称:my-little-investigations,代码行数:35,代码来源:Collisions.cpp

示例2: getTransformPlaneAngle

Number TransformGizmo::getTransformPlaneAngle() {
	
	Ray gizmoRay;
	gizmoRay.origin = getConcatenatedMatrix().getPosition();
	gizmoRay.direction = localTransformPlane * -1;
				
	Vector3 gizmoIntersect = gizmoRay.planeIntersectPoint(transformPlane, transformPlaneDistance);
    gizmoIntersect = planeMatrix.Inverse() * gizmoIntersect;
	   
    
	Ray ray = targetScene->projectRayFromCameraAndViewportCoordinate(targetCamera, coreInput->getMousePosition());	
	Vector3 mouseIntersect = ray.planeIntersectPoint(transformPlane, transformPlaneDistance);
    mouseIntersect = planeMatrix.Inverse() * mouseIntersect;
    
	Vector2 planePosition;
    
	if(localTransformPlane.x > 0) {
		planePosition.x = mouseIntersect.z - gizmoIntersect.z;
		planePosition.y = mouseIntersect.y - gizmoIntersect.y;
	} else if(localTransformPlane.y > 0.0) {
		planePosition.x = mouseIntersect.x - gizmoIntersect.x;
		planePosition.y = mouseIntersect.z - gizmoIntersect.z;
	} else if(localTransformPlane.z > 0.0) {
		planePosition.x = mouseIntersect.x - gizmoIntersect.x;
		planePosition.y = mouseIntersect.y - gizmoIntersect.y;
	}
    
	planePosition.Normalize();
	
	return atan2(planePosition.x, planePosition.y);
}
开发者ID:HeadClot,项目名称:Polycode,代码行数:31,代码来源:TransformGizmo.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: Move

void Object::Move(int64 diff) {

	if(!target)
	  return;
   Vector2 to(target->getX(), target->getY());
   Vector2 cur(x, y);
   
   Vector2 goingTo (to - cur);
	Vector2 norm (goingTo.Normalize());

	double deltaMovement = (double)(getMoveSpeed()) * 0.000001f*diff;

	float xx = norm.X * deltaMovement;
	float yy = norm.Y * deltaMovement;

      
   x+= xx;
   y+=yy;

	/* If the target was a simple point, stop when it is reached */
	if(target->isSimpleTarget() && distanceWith(target) < deltaMovement*3) {
	   if(++curWaypoint >= waypoints.size()) {
         setTarget(0);
      } else {
         setTarget(waypoints[curWaypoint].toTarget());
      }
	}
}
开发者ID:DiamondLovesYou,项目名称:IntWars,代码行数:28,代码来源:Object.cpp

示例5: Update

void GalaxianReturnToFormationState::Update(Galaxian* a_galaxian, float a_fDeltaTime)
{
	m_deltaTimeMap[a_galaxian] += a_fDeltaTime;
	if(m_referanceMap[a_galaxian]->m_state == EntityState::REMOVED)
	{
		m_referanceMap[a_galaxian] = m_formation->GetFirstGalaxianInFormation();
	}
	Vector2 referancePosition = m_referanceMap[a_galaxian]->GetPosition();
	int xOffset = a_galaxian->GetPositionInFormation().x - m_referanceMap[a_galaxian]->GetPositionInFormation().x;
	int yOffset = a_galaxian->GetPositionInFormation().y - m_referanceMap[a_galaxian]->GetPositionInFormation().y;
	Vector2 targetPosition = referancePosition + Vector2(xOffset * (GalaxianFormation::SPRITE_WIDTH+12), yOffset * (GalaxianFormation::SPRITE_HEIGHT+6));

	if(a_galaxian->GetPosition().Distance(targetPosition) > 5)
	{
		Vector2 direction = targetPosition - a_galaxian->GetPosition();
		direction.Normalize();
		a_galaxian->Move(direction * a_fDeltaTime * 200);
	}
	else
	{
		a_galaxian->SetPosition(targetPosition);
		a_galaxian->SetDirection(Vector2(0,1));
		a_galaxian->ChangeState(GalaxianInFormationState::getInstance());
	}
}
开发者ID:EricPolman,项目名称:Galaxian,代码行数:25,代码来源:GalaxianReturnToFormationState.cpp

示例6: Update

//-----------------------------------------------------------------------------------------------------------------------------------
void Camera::Update(DX::StepTimer const& timer)
{
	// If the camera is fixed we should not do any more updating
	if (m_cameraMode == CameraMode::kFixed)
	{
		return;
	}

	KeyboardInput& keyboard = ScreenManager::GetKeyboardInput();
	Vector2 diff = Vector2::Zero;

	if (keyboard.IsKeyDown(Keyboard::Keys::Left))
	{
		diff.x = -1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Right))
	{
		diff.x = 1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Up))
	{
		diff.y = -1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Down))
	{
		diff.y = 1;
	}

	if (diff != Vector2::Zero)
	{
		diff.Normalize();
		m_position += diff * (float)timer.GetElapsedSeconds() * m_panSpeed;
	}
}
开发者ID:AlanWills,项目名称:UnderSiege_DirectX,代码行数:35,代码来源:Camera.cpp

示例7: Physics_Response

Vector2 Physics_Response(const float dt, const Vector2& src, const Vector2& contact, const Vector2& velocity, const float restitution/* = 2.0f*/)
{
	if (dt == 0.0f)
	{
		return Vector2(0.f, 0.f);
	}

	Vector2 normal = contact - src;
	normal.Normalize();

	Vector2 vel_dt = velocity * dt;
	SGE::Graphics_DebugLine(src, src + vel_dt, 0xAAAAFF);
	SGE::Graphics_DebugLine(contact, src, 0x00FF00);

	float dot = SGE::Math_Dot(vel_dt, normal);
	Vector2 A = (normal * restitution) * dot;

	SGE::Graphics_DebugLine(contact, contact + A, 0xFFFFFF);

	Vector2 X = vel_dt - A;
	SGE::Graphics_DebugLine(src, src + X, 0xFF0000);

	Vector2 response_vel = X * (1.f/dt);
	return response_vel;
}
开发者ID:NGAEVA,项目名称:2Dgame,代码行数:25,代码来源:SGE_Physics.cpp

示例8: Move

void Object::Move(int64 diff) {

   if (!target)
   {
      direction = Vector2();
      return;
   }

   currentUpwardDisplacement = map->getHeightAtLocation(getPosition().X, getPosition().Y);

   Vector2 to(target->getX(), target->getY());
   Vector2 cur(x, y);
   
   Vector2 goingTo (to - cur);
	direction = goingTo.Normalize();

	double deltaMovement = (double)(getMoveSpeed()) * 0.000001f*diff;

   float xx = direction.X * deltaMovement;
   float yy = direction.Y * deltaMovement;

      
   x+= xx;
   y+= yy;

	/* If the target was a simple point, stop when it is reached */
	if(target->isSimpleTarget() && distanceWith(target) < deltaMovement*3) {
	   if(++curWaypoint >= waypoints.size()) {
         setTarget(0);
      } else {
         setTarget(waypoints[curWaypoint].toTarget());
      }
	}
}
开发者ID:JNeiger,项目名称:IntWars,代码行数:34,代码来源:Object.cpp

示例9: MoveInDirection

void Worm::MoveInDirection(Vector2& direction, float distance)
{
   direction.Normalize();
   Vector2 newPoint = Vector2( m_head->GetPosition() + (direction * distance) );	

   m_head->SetPosition(newPoint);
   m_tail->moveTo(newPoint, distance);
}
开发者ID:chrishaukap,项目名称:GameDev,代码行数:8,代码来源:Worm.cpp

示例10: CalcVelocity

	Vector2 Evasion::CalcVelocity()
	{
		Vector2 offset = mActor->GetPosition()  - mTarget->GetPosition();
		float distance = offset.Length();
		float timeInterval = std::min(0.1f, distance / mActor->GetMaxVelocity());
		Vector2 v = mActor->GetPosition() - mTarget->PredictFuturePosition(timeInterval); // Inefficient!!!

		v.Normalize();
		v = mActor->GetMaxVelocity() * v;
		v -= mActor->GetVelocity();

		// Limit
		v.Normalize();
		v = mActor->GetMaxVelocity() * v;

		return v;
	}
开发者ID:doveiya,项目名称:isilme,代码行数:17,代码来源:Evasion.cpp

示例11:

Vector2 Vector2::RandomXY()
{
    Vector2 v;
    v.X = (float)(Random::Instance->NextDouble() - 0.5);
    v.Y = (float)(Random::Instance->NextDouble() - 0.5);
    v.Normalize();
    return v;
}
开发者ID:CWMlolzlz,项目名称:scripthookvdotnet,代码行数:8,代码来源:Vector2.cpp

示例12:

void
BatMan::AliveUpdate()
{
	Vector2 vec = (_playerRef.GetCollider().Center() - _collider.Center());//normalizeで変な値になってる
	vec = vec.Normalize();
	_pos.x += vec.x * 2;
	_collider.pos = _pos + Vector2(_cameraRef.OffsetX(), 0);
	_walkFrame++;
}
开发者ID:sansanshi,项目名称:repo_test,代码行数:9,代码来源:BatMan.cpp

示例13: CalcVelocity

	Vector2 Flee::CalcVelocity()
	{
		Vector2 v = mActor->GetPosition() - mTarget;
		v.Normalize();
		v = mActor->GetMaxVelocity() * v;
		v -= mActor->GetVelocity();

		return v;
	}
开发者ID:doveiya,项目名称:isilme,代码行数:9,代码来源:Flee.cpp

示例14: UpdateDirection

void FieldCharacter::UpdateDirection(Vector2 directionVector)
{
    directionVector = directionVector.Normalize();

    // We'll snap the player's direction vector according to
    // the nearest direction for which we have an animation.
    double angleToHorizontal = acos(directionVector.GetX());

    // acos() only returns values from 0 to pi,
    // so to get the full circle we need to check
    // whether we're in the bottom two quandrants,
    // and change the angle to account for this if so.
    if (directionVector.GetY() > 0)
    {
        angleToHorizontal = 2 * M_PI - angleToHorizontal;
    }

    if (angleToHorizontal <= M_PI / 8 || angleToHorizontal > M_PI * 15 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionSide);
        SetDirection(CharacterDirectionRight);
    }
    else if (angleToHorizontal > M_PI / 8 && angleToHorizontal <= M_PI * 3 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionDiagonalUp);
        SetDirection(CharacterDirectionRight);
    }
    else if (angleToHorizontal > 3 * M_PI / 8 && angleToHorizontal <= M_PI * 5 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionUp);
    }
    else if (angleToHorizontal > 5 * M_PI / 8 && angleToHorizontal <= M_PI * 7 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionDiagonalUp);
        SetDirection(CharacterDirectionLeft);
    }
    else if (angleToHorizontal > 7 * M_PI / 8 && angleToHorizontal <= M_PI * 9 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionSide);
        SetDirection(CharacterDirectionLeft);
    }
    else if (angleToHorizontal > 9 * M_PI / 8 && angleToHorizontal <= M_PI * 11 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionDiagonalDown);
        SetDirection(CharacterDirectionLeft);
    }
    else if (angleToHorizontal > 11 * M_PI / 8 && angleToHorizontal <= M_PI * 13 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionDown);
    }
    else if (angleToHorizontal > 13 * M_PI / 8 && angleToHorizontal <= M_PI * 15 / 8)
    {
        SetSpriteDirection(FieldCharacterDirectionDiagonalDown);
        SetDirection(CharacterDirectionRight);
    }
}
开发者ID:Abion47,项目名称:my-little-investigations,代码行数:56,代码来源:FieldCharacter.cpp

示例15:

    void SegmentShape2D::SetDirection(Vector2 value)
    {
        if (value != Vector2::Zero)
            value.Normalize();

        if (GetDirection() != value)
        {
            direction = value;
            revision = -1;
        }
    }
开发者ID:Darkttd,项目名称:Bibim,代码行数:11,代码来源:SegmentShape2D.cpp


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