• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ LengthSquared函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中LengthSquared函数的典型用法代码示例。如果您正苦于以下问题:C++ LengthSquared函数的具体用法?C++ LengthSquared怎么用?C++ LengthSquared使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: PerpCCW

void EnemyShip::changeVelocity(const float& dt, Engine::ParticleSystem& system)
{
	if (target != nullptr)
	{
		Vector2 toTarget = target->getPosition() - shipPosition;
		
		if (LengthSquared(toTarget) != 0)
		{
			Vector2 normalizedtoTarget = PerpCCW(Normalized(toTarget));

			shipRotation = atan2f(normalizedtoTarget.getY(), normalizedtoTarget.getX());

			if (LengthSquared(toTarget) >= 0)
			{
				velocity = velocity + (Engine::Matrix2::rotation(shipRotation) * Engine::Vector2(0, -(acceleration * dt) * dt));
				system.AddParticle(new THRUSTPARTICLEUP);
			}
			else
			{
				velocity = velocity + (Engine::Matrix2::rotation(shipRotation) * Engine::Vector2(0, (acceleration * dt) * dt));
				system.AddParticle(new THRUSTPARTICLEDOWN);
			}
		}
	}
}
开发者ID:pokelege,项目名称:GeometryWars,代码行数:25,代码来源:EnemyShip.cpp


示例2: Normalize

SVector2 ArriveBehavior::Update(float deltaTime)
{
    if (mActive)
    {
        SVector2 positionToDestination = mpAgent->GetDestination() - mpAgent->GetPosition();
        SVector2 posToDestNorm = Normalize(positionToDestination);

        float maxSpeed = mpAgent->GetMaxSpeed();

        SVector2 desiredVelocity = posToDestNorm * maxSpeed;

        float distSq = LengthSquared(positionToDestination);
        float velocitySq = LengthSquared(mpAgent->GetVelocity());
        float slowingRadiusSq = 160000.0f;
        float stopRadiusSq = 25.0f;

        if (distSq < velocitySq)
        {
            if (distSq < slowingRadiusSq && distSq > stopRadiusSq )
            {
                //desiredVelocity = -velocitySq/(2*sqrt(distSq));
                desiredVelocity = posToDestNorm * maxSpeed * distSq/(slowingRadiusSq*slowingRadiusSq*slowingRadiusSq*slowingRadiusSq);// * maxSpeed/(distSq*distSq);
            }
            else if (distSq <= stopRadiusSq)
            {
                mpAgent->SetPosition(mpAgent->GetDestination());
                desiredVelocity = SVector2(0.0f, 0.0f);
            }
        }
        return desiredVelocity - mpAgent->GetVelocity();
    }

    return SVector2(0.0f, 0.0f);

}
开发者ID:bretthuff22,项目名称:AI,代码行数:35,代码来源:ArriveBehavior.cpp


示例3: Vec3

void ColourNormalFit::Permute3()
{
  const Vec3 scale  = Vec3( 1.0f / 0.5f);
  const Vec3 offset = Vec3(-1.0f * 0.5f);
  const Vec3 scalei = Vec3( 1.0f * 0.5f);
  
  // cache some values
  int const count = m_colours->GetCount();
  Vec3 const* values = m_colours->GetPoints();
  Scr3 const* freq = m_colours->GetWeights();
  
  cQuantizer3<5,6,5> q = cQuantizer3<5,6,5>();
  Scr3 berror = Scr3(DEVIANCE_MAXSUM);
  
  Vec3 c_start = m_start;
  Vec3 c_end   = m_end;
  Scr3 l_start = LengthSquared(Normalize(scale * (offset + m_start)));
  Scr3 l_end   = LengthSquared(Normalize(scale * (offset + m_end)));
  Vec3 q_start = Reciprocal(q.grid + Vec3(1.0f));
  Vec3 q_end   = q_start;

  // adjust offset towards sphere-boundary
  if (!(l_start < Scr3(1.0f)))
    q_start = Vec3(0.0f) - q_start;
  if (!(l_end   < Scr3(1.0f)))
    q_end   = Vec3(0.0f) - q_end;
  
  int trie = 0x3F;
  do {
    // permute end-points +-1 towards sphere-boundary
    Vec3 p_start = q_start & Vec3(!(trie & 0x01), !(trie & 0x02), !(trie & 0x04));
    Vec3 p_end   = q_end   & Vec3(!(trie & 0x08), !(trie & 0x10), !(trie & 0x20));
    
    p_start = q.SnapToLattice(c_start + p_start);
    p_end   = q.SnapToLattice(c_end   + p_end);

    // create a codebook
    // resolve "metric * (value - code)" to "metric * value - metric * code"
    Vec3 codes[3]; Codebook3n(codes, p_start, p_end);

    Scr3 merror = Scr3(DEVIANCE_BASE);
    for (int i = 0; i < count; ++i) {
      // find the closest code
      Vec3 value = Normalize(scale * (offset + values[i]));
      Scr3 dist; MinDeviance3<false>(dist, i, value, codes);
      
      // accumulate the error
      AddDeviance(dist, merror, freq[i]);
    }
    
    if (berror > merror) {
      berror = merror;

      m_start = p_start;
      m_end   = p_end;
    }

  } while(--trie);
}
开发者ID:Ethatron,项目名称:squish-ccr,代码行数:59,代码来源:colournormalfit.cpp


示例4: clamp

bool Collisions::sphereToBox(RigidBody *sphere, RigidBody *box, CollisionInfo &info)
{
    //translation
    vec2 nearest;
    vec2 clamp_box = box->collider.dims/2;
    vec2 sphere_in_box_world = sphere->position-box->position;
    nearest.x = clamp(sphere_in_box_world.x,-clamp_box.x,clamp_box.x);
    nearest.y = clamp(sphere_in_box_world.y,-clamp_box.y,clamp_box.y);

    float dist = LengthSquared(sphere_in_box_world-nearest);
    float radius = sphere->collider.radius*sphere->collider.radius;

    if(dist < radius)
    {
        float realDist = sqrt(dist);
        info.intersection = (box->position + nearest) + (sphere_in_box_world*(realDist-sphere->collider.radius)/realDist)/2;
        info.normal = Normalize(nearest - sphere_in_box_world);
        info.type = SPHERE_TO_BOX;

        // Side of box collision
        if(abs(nearest.x) < abs(nearest.y))
            info.boxSideCol = SIDE_EDGE;
        else
            info.boxSideCol = UPPER_EGDE;

        return true;
    }
    else
        return false;
}
开发者ID:ValtielArchangel,项目名称:hvmc,代码行数:30,代码来源:hvmc_collisions.cpp


示例5: Length

float Vector::Length()
{
	float r = (float)sqrt(LengthSquared());
	if ( r < 0.0f )
		r = -r;
	return r;
}
开发者ID:TimToxopeus,项目名称:grapplon2,代码行数:7,代码来源:Vector.cpp


示例6: LengthSquared

float4 float4::normalize() const
{
	f32 lsqr = LengthSquared();
	if(NearZero(lsqr)) { return ZERO; };
	f32 recip = InvSqrt(lsqr);
	
	return float4(vec[0]*recip, vec[1]*recip, vec[2]*recip, vec[3]*recip);
};
开发者ID:wrdn,项目名称:GameEngine,代码行数:8,代码来源:float4.cpp


示例7: Collides

        bool Collides(const CollisionRadius& other) const
        {
            T radiusSquared = RadiusSquared() + other.RadiusSquared();

            auto rawDistance = _position - other._position;

            return rawDistance.LengthSquared() <= radiusSquared;
        }
开发者ID:TheBuzzSaw,项目名称:Nullocity,代码行数:8,代码来源:CollisionRadius.hpp


示例8: LengthSquared

/*------------------------------------------------------------------------------
normalize this quaternion
------------------------------------------------------------------------------*/
Quaternion& Quaternion::Normalize() {
	float lengthSquared = LengthSquared();
	float invLength = 0;
	if( lengthSquared ) {
		invLength = 1.0f / sqrtf( lengthSquared );
	}
	*this *= invLength;
	return *this;
}
开发者ID:0x0002,项目名称:Project1,代码行数:12,代码来源:Quaternion.cpp


示例9: LengthSquared

Vector2 Vector2::NormalizeFast() const
{
    float len = LengthSquared();

    if (len > 0)
        return Mul(invsqrt(len));

    return Vector2();
}
开发者ID:jmclaine,项目名称:Sentinel_GameEngine,代码行数:9,代码来源:Vector2.cpp


示例10: FastInvSqRt

void Vector4::FastNormalize()
{
	// No error checking, plus fast inverse square root
	float recLen = FastInvSqRt( LengthSquared() );
	x *= recLen;
	y *= recLen;
	z *= recLen;
	w *= recLen;
}
开发者ID:Johnicholas,项目名称:EldritchCopy,代码行数:9,代码来源:vector4.cpp


示例11: ComputeFaceCurvature

//--------------------------------------------------------------------
// Computes the average curvature per unit surface distance in the face
//--------------------------------------------------------------------
float ComputeFaceCurvature(Point3 *n, Point3 *v, Point3 bc)
{
	Point3 nc = (n[0]+n[1]+n[2])/3.0f;
	Point3 dn0 = n[0]-nc;
	Point3 dn1 = n[1]-nc;
	Point3 dn2 = n[2]-nc;
	Point3 c = (v[0] + v[1] + v[2]) /3.0f;
	Point3 v0 = v[0]-c;
	Point3 v1 = v[1]-c;
	Point3 v2 = v[2]-c;
	float d0 = DotProd(dn0,v0)/LengthSquared(v0);
	float d1 = DotProd(dn1,v1)/LengthSquared(v1);
	float d2 = DotProd(dn2,v2)/LengthSquared(v2);
	float ad0 = (float)fabs(d0);
	float ad1 = (float)fabs(d1);
	float ad2 = (float)fabs(d2);
	return (ad0>ad1)? (ad0>ad2?d0:d2): ad1>ad2?d1:d2;
}
开发者ID:artemeliy,项目名称:inf4715,代码行数:21,代码来源:evalcol.cpp


示例12: Vector2

void PlayerTurret::rotateTurret()
{
	Vector2 mousetoposition = Vector2((float)Input::GetMouseX(), (float)Input::GetMouseY()) - parentPosition;

	if (LengthSquared(mousetoposition) != 0)
	{
		rotationNormal = Engine::Normalized(mousetoposition);
	}
}
开发者ID:pokelege,项目名称:GeometryWars,代码行数:9,代码来源:PlayerTurret.cpp


示例13: LengthSquared

  float SSEVector3::Length() const
  {
    float result[ 4 ];
    float lengthSquared = LengthSquared();

    // Store in all floats, do not multiply fourth value: 0111 1111
    const int mask = 0x7F;
    _mm_store_ss( result, _mm_sqrt_ss( _mm_dp_ps( vec, vec, mask ) ) );
    return result[ 0 ];
  }
开发者ID:pampersrocker,项目名称:MathLib,代码行数:10,代码来源:SSEVector3.cpp


示例14: LengthSquared

Vector3 Vector3::Normalize(const Vector3& v)
{
	float lengthSq = LengthSquared(v);
	if (lengthSq == 0.0f)
	{
		return v;
	}

	return v / static_cast<float>(Math::Sqrt(lengthSq));
}
开发者ID:rumiaqua,项目名称:DxGame,代码行数:10,代码来源:Vector3.cpp


示例15: while

	void magnet::update()
	{
		if(!is_activated())
		{
			return;
		}

		auto mag_pos = body_->GetWorldPoint(local_point_);

		auto ce = body_->GetContactList();
		//			std::set< b2Body* > processed;
		while(ce)
		{
			auto contact = ce->contact;
			if(contact->IsTouching())
			{
				auto fixA = contact->GetFixtureA();
				auto fixB = contact->GetFixtureB();

				//					b2Body* obj = nullptr;
				b2Fixture* fix = nullptr;
				if(fixA == sensor_)
				{
					//						obj = fixB->GetBody();
					fix = fixB;
				}
				else if(fixB == sensor_)
				{
					//						obj = fixA->GetBody();
					fix = fixA;
				}

				//					if(obj != nullptr && processed.find(obj) == processed.end())
				if(fix)
				{
					b2MassData md;
					fix->GetMassData(&md);
					auto metallic_mass = md.mass; // TODO: composition
					auto obj_pos = fix->GetBody()->GetWorldPoint(md.center);
					auto vec = mag_pos - obj_pos;
					auto sqr_dist = vec.LengthSquared();
					auto magnitude = strength_ * metallic_mass / sqr_dist;

					vec *= magnitude / std::sqrt(sqr_dist);
					fix->GetBody()->ApplyForce(vec, obj_pos, true);
					body_->ApplyForce(-vec, mag_pos, true);

					//						processed.insert(obj);
				}
			}

			ce = ce->next;
		}
	}
开发者ID:kamrann,项目名称:workbase,代码行数:54,代码来源:magnet.cpp


示例16: TagCells

void
UniformGrid::ClosestPoint(Point3 p, float radius, int &pindex, float &d)
{
	xHitList.ClearAll();
	yHitList.ClearAll();
	zHitList.ClearAll();
	hitList.SetCount(0);

	//find the cell in the XGrid
	TagCells(p,radius, 0);
	//find the cell in the YGrid
	TagCells(p,radius, 1);
	//find the cell in the ZGrid
	TagCells(p,radius, 2);

	BitArray usedList;
	usedList.SetSize(pointBase.Count());
	usedList.ClearAll();

	int closest = -1;
	d = 0.0f;
	Box3 localBounds;
	localBounds.Init();
	localBounds += p;
	localBounds.EnlargeBy(radius);


	for (int i = 0; i < hitList.Count(); i++)
	{
		int index = hitList[i];
		if (!usedList[index])  //check to see if we have processed this one or not
		{
			if (xHitList[index] && yHitList[index] && zHitList[index])
			{
				usedList.Set(index);
				Point3 source = pointBase[index];
				if (localBounds.Contains(source))
				{
					float dist = LengthSquared(source-p);
					if ((dist < d) || (closest == -1))
					{
						d = dist;
						closest = index;
					}
				}
			}
		}
	}
	pindex = closest;
	d = sqrt(d);


}
开发者ID:DimondTheCat,项目名称:xray,代码行数:53,代码来源:UniformGrid.cpp


示例17: FindVertexAngles

static void FindVertexAngles(PatchMesh &pm, float *vang) {
	int i;
	for (i=0; i<pm.numVerts + pm.numVecs; i++) vang[i] = 0.0f;
	for (i=0; i<pm.numPatches; i++) {
		Patch &p = pm.patches[i];
		for (int j=0; j<p.type; j++) {
			Point3 d1 = pm.vecs[p.vec[j*2]].p - pm.verts[p.v[j]].p;
			Point3 d2 = pm.vecs[p.vec[((j+p.type-1)%p.type)*2+1]].p - pm.verts[p.v[j]].p;
			float len = LengthSquared(d1);
			if (len == 0) continue;
			d1 /= Sqrt(len);
			len = LengthSquared (d2);
			if (len==0) continue;
			d2 /= Sqrt(len);
			float cs = DotProd (d1, d2);
			if (cs>=1) continue;	// angle of 0
			if (cs<=-1) vang[p.v[j]] += PI;
			else vang[p.v[j]] += (float) acos (cs);
		}
	}
}
开发者ID:innovatelogic,项目名称:ilogic-vm,代码行数:21,代码来源:relax.cpp


示例18: LengthSquared

void RangeFit::Compress4( void* block )
{
    // cache some values
    int const count = m_colours->GetCount();
    Vec3 const* values = m_colours->GetPoints();

    // create a codebook
    Vec3 codes[4];
    codes[0] = m_start;
    codes[1] = m_end;
    codes[2] = ( 2.0f/3.0f )*m_start + ( 1.0f/3.0f )*m_end;
    codes[3] = ( 1.0f/3.0f )*m_start + ( 2.0f/3.0f )*m_end;

    // match each point to the closest code
    u8 closest[16];
    float error = 0.0f;
    for( int i = 0; i < count; ++i )
    {
        // find the closest code
        float dist = FLT_MAX;
        int idx = 0;
        for( int j = 0; j < 4; ++j )
        {
            float d = LengthSquared( m_metric*( values[i] - codes[j] ) );
            if( d < dist )
            {
                dist = d;
                idx = j;
            }
        }

        // save the index
        closest[i] = ( u8 )idx;

        // accumulate the error
        error += dist;
    }

    // save this scheme if it wins
    if( error < m_besterror )
    {
        // remap the indices
        u8 indices[16];
        m_colours->RemapIndices( closest, indices );

        // save the block
        WriteColourBlock4( m_start, m_end, indices, block );

        // save the error
        m_besterror = error;
    }
}
开发者ID:KonajuGames,项目名称:libsquish,代码行数:52,代码来源:rangefit.cpp


示例19: Normalize

 static void Normalize(const gmVector3& a_vec, gmVector3& a_result)
 {
   float len2 = LengthSquared(a_vec);
   if(len2 != 0.0f)
   {
     float ooLen = 1.0f / (float)sqrt(len2);
     MulScalar(a_vec, ooLen, a_result);
   }
   else
   {
     a_result.m_x = 0.0f;
     a_result.m_y = 0.0f;
     a_result.m_z = 0.0f;
   }
 }
开发者ID:joechenq,项目名称:multi-script,代码行数:15,代码来源:gmVector3Lib.cpp


示例20: sphereToSphere

bool Collisions::sphereToSphere(RigidBody *sphere1, RigidBody *sphere2, CollisionInfo &info)
{
    float dist = sphere1->collider.radius + sphere2->collider.radius;
    if(LengthSquared(sphere1->position - sphere2->position) < dist*dist)
    {
        vec2 pos1 = sphere1->position;
        vec2 pos2 = sphere2->position;

        info.intersection = vec2 {(pos1.x-pos2.x / 2), (pos1.y-pos2.y / 2)};
        info.normal = Normalize(pos1 - pos2);
        info.type = SPHERE_TO_SPHERE;

        return true;
    }
    else
        return false;
}
开发者ID:ValtielArchangel,项目名称:hvmc,代码行数:17,代码来源:hvmc_collisions.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Lerp函数代码示例发布时间:2022-05-30
下一篇:
C++ LengthNoFlush函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap