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


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

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


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

示例1: GetLength

float Vector2::AngleBetween(Vector2 rhs)	const
{ 
	Vector2 perp = Vector2(rhs.y, -rhs.x);
	float len1 = GetLength();
	float len2 = rhs.GetLength();

	float angle = acos(Dot(rhs));

	if (rhs.Dot(perp) > 0)
		return angle;
	else return -angle;
}
开发者ID:Breadmouth,项目名称:FirstYearProjects,代码行数:12,代码来源:Vec2.cpp

示例2: Blur

		GLColorBuffer GLDepthOfFieldFilter::Blur(GLColorBuffer buffer,
													
												 GLColorBuffer coc,
												 Vector2 offset,
												 int divide) {
			SPADES_MARK_FUNCTION();
			// do gaussian blur
			GLProgram *program = blurProgram;
			IGLDevice *dev = renderer->GetGLDevice();
			GLQuadRenderer qr(dev);
			int w = buffer.GetWidth();
			int h = buffer.GetHeight();
			int w2 = w / divide;
			int h2 = h / divide;
			
			static GLProgramAttribute blur_positionAttribute("positionAttribute");
			static GLProgramUniform blur_textureUniform("texture");
			static GLProgramUniform blur_cocUniform("cocTexture");
			static GLProgramUniform blur_offset("offset");
			program->Use();
			blur_positionAttribute(program);
			blur_textureUniform(program);
			blur_cocUniform(program);
			blur_offset(program);
			
			blur_cocUniform.SetValue(1);
			dev->ActiveTexture(1);
			dev->BindTexture(IGLDevice::Texture2D, coc.GetTexture());
			
			blur_textureUniform.SetValue(0);
			dev->ActiveTexture(0);
			
			qr.SetCoordAttributeIndex(blur_positionAttribute());
			
			// x-direction
			float len = offset.GetLength();
			float sX = 1.f / (float)w, sY = 1.f / (float)h;
			while(len > .5f){
				GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w2, h2, false);
				dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
				dev->BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
				blur_offset.SetValue(offset.x * sX, offset.y * sY);
				qr.Draw();
				buffer = buf2;
				
				offset *= .125f;
				len *= .125f;
			}
			
			return buffer;
		}
开发者ID:2mac,项目名称:openspades,代码行数:51,代码来源:GLDepthOfFieldFilter.cpp

示例3: UpdateGame


//.........这里部分代码省略.........
	}

	if(HIWORD(GetAsyncKeyState(VK_RIGHT)))
	{
		gameShip.m_rearEngineOrientation -= GetElapsedTime() / 50.0f;
		gameShip.m_frontEngineOrientation -= GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState('B')))
	{
		gameShip.m_mainEngineOrientation += GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState('N')))
	{
		gameShip.m_mainEngineOrientation -= GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState(VK_UP)))
	{
		Matrix2 rotation(gameShip.m_frontEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.002f),gameShip.m_position + orientation * gameShip.m_frontEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_frontEnginePosition);
	}

	if(HIWORD(GetAsyncKeyState(VK_SPACE)))
	{
		Matrix2 rotation(gameShip.m_mainEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.004f),gameShip.m_position + orientation * gameShip.m_mainEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition);
	}

	if(HIWORD(GetAsyncKeyState(VK_UP)))
	{
		Matrix2 rotation(gameShip.m_rearEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.001f),gameShip.m_position + orientation * gameShip.m_rearEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_rearEnginePosition);
	}
	
	gameShip.UpdateBody();
	gameEmitter.UpdateParticles();

	for(unsigned long i = 0; i < gameMissles.GetSize(); ++i)
	{
		Matrix2 orientation(gameMissles[i]->m_orientation);

		gameMissles[i]->AddBodyForce(gravity);

		Vector2 target = Matrix2(-gameMissles[i]->m_orientation) * (gameMissles[i]->m_target - gameMissles[i]->m_position);

		bool left = false,right = false;

		if(gameMissles[i]->m_life > 50.0f)
		{
			if(target.x > -0.1f && target.x < 0.1f && target.y > 0)
				left = right = true;
			else if(target.x < 0)
				right = true;
			else
				left = true;
		}
		
		if(left)
		{
			gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[0]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]);
		}

		if(right)
		{
			gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[1]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[1]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[1]);
		}

		gameMissles[i]->UpdateBody();
		gameMissles[i]->m_life += GetElapsedTime();

		if(gameMissles[i]->m_spring)
		{
			Vector2 force = *gameMissles[i]->m_spring - gameMissles[i]->m_position;
			gameMissles[i]->AddBodyForce(force * k);
		}

		if(gameMissles[i]->m_life > 1500.0f || target.GetLength() < 0.4f)
		{
			for(unsigned long j = 0; j < 256; ++j)
				gameEmitter.AddParticle(Vector2Normalize(Vector2(randf(),randf())) * randf() / 6.0f,gameMissles[i]->m_position);

			delete gameMissles[i];
			gameMissles.Erase(i);

			--i;
		}
	}

	return true;
}
开发者ID:m1h4,项目名称:Xetrix,代码行数:101,代码来源:Game.cpp

示例4: Update

bool AIDeerBehavior::Update( float dt )
{
	if ( Behavior::Update(dt) )
		return true;

	DeerActor* dActor = dynamic_cast<DeerActor*>(this->zActor);

	//static float testInterval = 0; //Just for debugging.
	//testInterval += dt;
	this->zIntervalCounter += dt;
	//this->zIntervalCounter += dt;
	this->zFearIntervalCounter += dt;
	//this->zAlertnessIntervalCounter += deltaTime;
	
	int nrOfPredators = 0;
	bool nearbyPredatorsExist = false;
		
	//Perform checking for entities here.
	float shortestDistance = 99999;

	float finalDistance = 0;

	int maximumNodesTest = 5;

	//Determine closest threat/target
	
	//std::set<Actor*> aSet = this->GetTargets();

	for(auto i = this->zNearDynamicActors.cbegin(); i != this->zNearDynamicActors.cend(); i++)//for(auto i = aSet.cbegin(); i != aSet.cend(); i++)
	{
		finalDistance = (dActor->GetPosition().GetXZ() - (*i)->GetPosition().GetXZ()).GetLength();

		if( finalDistance < this->zMinimumDistance && !dynamic_cast<DeerActor*>((*i)) && dynamic_cast<BioActor*>((*i)) && dynamic_cast<BioActor*>((*i))->IsAlive() ) 
		{
			dynamic_cast<BioActor*>(*i)->zValid = true;
			if(finalDistance < shortestDistance)
			{
				shortestDistance = finalDistance;
				this->zMainActorTarget = (*i); //Decide which is the biggest threat here, i.e. the main target. For the moment, proximity is the deciding factor. Could use some more complexity.
			}
			nrOfPredators++;
		}
		else if( BioActor* bioActor = dynamic_cast<BioActor*>(*i) )
		{
			bioActor->zValid = false;
		}
	}

	
	//for(int i = 0; i < this->GetCurrentTargets(); i++)
	//{
	//	xDistance = dActor->GetPosition().x - this->zTargets[i].position.x; //Math, could use optimization, I think.
	//	//yDistance = this->GetPosition().y - this->zTargets[i].position.y;
	//	zDistance = dActor->GetPosition().z - this->zTargets[i].position.z;
	//	finalDistance = sqrt(xDistance * xDistance + zDistance * zDistance);
	//	if( finalDistance < this->zMinimumDistance && this->zTargets[i].kind != DEER) 
	//	{
	//		this->zTargets[i].valid = true;
	//		if(finalDistance < shortestDistance)
	//		{
	//			shortestDistance = finalDistance;
	//			this->zMainTarget = this->zTargets[i]; //Decide which is the biggest threat here, i.e. the main target. For the moment, proximity is the deciding factor. Could use some more complexity.
	//		}
	//		nrOfPredators++;
	//	}
	//	else
	//	{
	//		this->zTargets[i].valid = false;
	//	}
	//}
	if(nrOfPredators > 0)
	{
		nearbyPredatorsExist = true;
	}
	else
	{
		nearbyPredatorsExist = false;
	}

	//Time to assess threats.

	if( dActor->GetHealth() < this->GetPreviousHealth() ) //In theory, used to check if the animal has been attacked.
	{
		this->SetFearLevel( this->GetFearLevel() + this->zFearAtDamageDone);
	}
	this->SetPreviousHealth( dActor->GetHealth() );
	
	if(this->zFearIntervalCounter > this->zFearInterval) //Basically, each amount of fearinterval seconds the fear increases or decreases.
	{
		this->zFearIntervalCounter = 0;
		
		if(nearbyPredatorsExist)
		{
			//Getting values and such, comparing animal health against that of other entities, types and more.

			//calculate current fear level:
			float fear = 0;
			//- for each dangerous entity detected, add some fear, fear could be based on type. Deers are afraid of humans for example.
			fear += this->zExtraFearWithNumberOfPlayers * nrOfPredators;
			
//.........这里部分代码省略.........
开发者ID:Crant,项目名称:Game_Project,代码行数:101,代码来源:AIDeerBehavior.cpp


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