コード例 #1
0
ファイル: Weapon.cpp プロジェクト: CarlRapp/CodenameGamma
XMFLOAT4 Weapon::GetWeaponOffsetRotation()
{
	XMVECTOR quat = XMQuaternionIdentity();

	XMFLOAT3 direction = GetFloat3Value( Direction );

	XMFLOAT3 aimPos;
	XMFLOAT3 pipePos;

	if (GetJointPosition("PipeAim", aimPos) && GetJointPosition("Pipe", pipePos))
	{
		//handPos.y = pipePos.y;
		XMVECTOR directionV	= XMLoadFloat3(&direction);
		XMVECTOR handPosV	= XMLoadFloat3(&aimPos);
		XMVECTOR pipePosV	= XMLoadFloat3(&pipePos);

		XMVECTOR offsetDirectionV = pipePosV - handPosV;

		XMVECTOR angleV = XMVector3AngleBetweenVectors(directionV, offsetDirectionV);
		float angle;
		XMStoreFloat(&angle, angleV);

		if (angle != 0)
		{
			XMVECTOR axis = XMVector3Cross(directionV, offsetDirectionV);
			quat = XMQuaternionRotationAxis(axis, angle);
		}
	}

	XMFLOAT4 result;
	XMStoreFloat4(&result, quat);

	return result;
}
コード例 #2
0
ファイル: Vector.cpp プロジェクト: panmar/pg3
    F32 Vector3f::Angle(const Vector3f& a, const Vector3f& b) {
        XMFLOAT3 aSrc(a.v);
        XMFLOAT3 bSrc(b.v);
        XMVECTOR aVec = XMLoadFloat3(&aSrc);
        XMVECTOR bVec = XMLoadFloat3(&bSrc);

        XMVECTOR rVec = XMVector3AngleBetweenVectors(aVec, bVec);

        XMFLOAT3 rSrc;
        XMStoreFloat3(&rSrc, rVec);

        return( rSrc.x );
    }
コード例 #3
0
ファイル: Camera.cpp プロジェクト: AlienJim/3DMinesweeper
void Camera::OrbitVertical(float angle)
{

	//orbit back to the starting position
	//this orbit angle is not quite right.
	float orbitAngle = XMVectorGetX(XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(0.0, 0.0, 1.0)), XMVector3Cross(GetRightXM(), XMVectorSet(0.0, 1.0, 0.0, 1.0))));
	//special case for when you pass 180
	if (mPosition.x < 0)
		orbitAngle = 180 + (90 - orbitAngle);

	OrbitHorizontal(orbitAngle);


	//get the angle between the right? of the camera and the right? of the world
	float check = XMVectorGetX(XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(0.0, 0.0, 1.0)), XMLoadFloat3(&mLook)));
	if (check < MathHelper::Pi * 0.45 ||
		((mPosition.y > 0 && angle < 0 ) ||
		((mPosition.y < 0 && angle > 0)))
		)
	{
		pitch += angle;
		//pitch the camaera by that angle
		XMVECTOR offsetAngle = XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(1.0, 0.0, 0.0)), XMLoadFloat3(&mRight));
		RotateY(XMVectorGetX(offsetAngle) + 0.001f);

		XMMATRIX matrixRot = XMMatrixRotationX(angle);
		XMStoreFloat3(&mPosition, XMVector3TransformNormal(XMLoadFloat3(&mPosition), matrixRot));
		XMStoreFloat3(&mRight, XMVector3TransformNormal(XMLoadFloat3(&mRight), matrixRot));
	}
	//move back
	OrbitHorizontal(-orbitAngle);

	//look at the center
	XMFLOAT3 zero(0.01, 0.01, 0.01);
	LookAt(mPosition, zero, XMFLOAT3(0.0, 1.0, 0.0));
	
}
コード例 #4
0
ファイル: Camera.cpp プロジェクト: AlienJim/3DMinesweeper
void Camera::OrbitHorizontal(float angle)//correct
{
	//get the angle between the up of the camera and the up of the world

	//pitch the camaera by that angle
	XMVECTOR offsetAngle = XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(0.0, 1.0, 0.0)),  XMLoadFloat3(&mUp) );
	Pitch(XMVectorGetX(offsetAngle) + 0.001f);

	XMMATRIX matrixRot = XMMatrixRotationY(angle); //add rotation to the matrix

	XMStoreFloat3(&mPosition, XMVector3TransformNormal(XMLoadFloat3(&mPosition), matrixRot));
	//XMVECTOR lookVector = XMLoadFloat3(&mPosition) - XMVectorZero();
	//XMStoreFloat3(&mLook, lookVector);
	XMStoreFloat3(&mLook, XMVector3TransformNormal(XMLoadFloat3(&mLook), matrixRot));
	//XMStoreFloat3(&mUp, XMVector3TransformNormal(XMLoadFloat3(&mUp), matrixRot));


	//look at the center
	XMFLOAT3 zero(0.01, 0.01, 0.01);
	LookAt(mPosition, zero, XMFLOAT3(0.0, 1.0, 0.0));
}
コード例 #5
0
ファイル: LockOnStrike.cpp プロジェクト: dastyk/Radiant
void LockOnStrike::_MoveProjectiles(Entity playerEntity, float deltaTime)
{
	XMFLOAT3 playerPos;
	
	XMStoreFloat3(&playerPos, _builder->Transform()->GetPosition(playerEntity));
	bool del = false;
	for (int i = 0; i < _projectiles.size(); i++)
	{
	
		if (!_foundTarget[i])
		{
			XMFLOAT3 temp;

			temp.x = playerPos.x + cos(_angles[i]);
			temp.y = playerPos.y - 0.25f;
			temp.z = playerPos.z + sin(_angles[i]);

			_angles[i] += (XM_PI * deltaTime*2.0f);
			if (_angles[i] >= XM_2PI)
			{
				_angles[i] = 0.0f;
			}

			_builder->Transform()->SetPosition(_projectiles[i], temp);

			for (int j = 0; j < _enemies->Size(); j++)
			{
				if (XMVectorGetX(XMVector3Length(XMVectorSet(temp.x - _enemies->GetCurrentElement()->_thisEnemy->GetCurrentPos().x, temp.y - _enemies->GetCurrentElement()->_thisEnemy->GetCurrentPos().y, temp.z - _enemies->GetCurrentElement()->_thisEnemy->GetCurrentPos().z, 0))) <= 3.0f)
				{
					j = _enemies->Size();

					XMFLOAT3 projRot, projPos, enemyPos, direction;
					XMStoreFloat3(&projRot, _builder->Transform()->GetRotation(_projectiles[i]));
					XMStoreFloat3(&projPos, _builder->Transform()->GetPosition(_projectiles[i]));
					XMStoreFloat3(&enemyPos, _builder->Transform()->GetPosition(_enemies->GetCurrentElement()->_thisEnemy->GetEntity()));


					XMStoreFloat3(&direction, XMVector3AngleBetweenVectors(XMVectorSet(projRot.x, 0, projRot.z, 1), XMVectorSet(enemyPos.x - projPos.x, 0, enemyPos.z - projPos.z, 1)));
					_builder->Transform()->SetRotation(_projectiles[i], direction);
					_foundTarget[i] = true;

				}
				_enemies->MoveCurrent();
			}
		}
		else
		{
			float minDistance = 10000;
			XMFLOAT3 closestEnemy, currentEnemy;
			float temp = 0.0f;

			XMFLOAT3 projPos;
			XMStoreFloat3(&projPos, _builder->Transform()->GetPosition(_projectiles[i]));

			if (_enemies->Size() == 0)
			{
				_builder->GetEntityController()->ReleaseEntity(_projectiles[i]);
				_projectiles.erase(_projectiles.begin() + i);
				_angles.erase(_angles.begin() + i);
				_foundTarget.erase(_foundTarget.begin() + i);
			}
			del = false;
			for (int j = 0; j < _enemies->Size(); j++)
			{
				if (_builder->Bounding()->CheckCollision(_projectiles[i], _enemies->GetCurrentElement()->_thisEnemy->GetEntity()))
				{
					_builder->GetEntityController()->ReleaseEntity(_projectiles[i]);
					_projectiles.erase(_projectiles.begin() + i);
					_angles.erase(_angles.begin() + i);
					_foundTarget.erase(_foundTarget.begin() + i);
					_enemies->GetCurrentElement()->_thisEnemyStateController->OnHit(_damage);
					if(_enemies->GetCurrentElement()->_thisEnemy->GetHealth() <= 0.0f)
					{
						_enemies->GetCurrentElement()->_thisEnemyStateController->ThisOneDied();
						_enemies->RemoveCurrentElement();
					}
					del = true;
				}
				else
				{

					XMStoreFloat3(&currentEnemy, _builder->Transform()->GetPosition(_enemies->GetCurrentElement()->_thisEnemy->GetEntity()));

					temp = XMVectorGetX(XMVector3Length(XMVectorSet(currentEnemy.x - projPos.x, currentEnemy.y - projPos.y, currentEnemy.z - projPos.z, 0)));

					if (temp < minDistance)
					{
						minDistance = temp;
						XMStoreFloat3(&closestEnemy, _builder->Transform()->GetPosition(_enemies->GetCurrentElement()->_thisEnemy->GetEntity()));
					}

					_enemies->MoveCurrent();

				}
			}

			if (!del)
			{
				XMVECTOR moveVec;

				// Ta ut vector mellan
				moveVec = XMLoadFloat3(&XMFLOAT3(closestEnemy.x - projPos.x, closestEnemy.y - projPos.y, closestEnemy.z - projPos.z));

				XMVector3Normalize(moveVec);

				_builder->Transform()->MoveAlongVector(_projectiles[i], moveVec * 2 * deltaTime);
			}
		}


	}
}
コード例 #6
0
ファイル: Unit.cpp プロジェクト: CarlRapp/CodenameGamma
void Unit::Update(float DeltaTime, Terrain* TerrainInstance)
{
	if ( IsAlive() && gHealth.first <= 0 )
	{
		SetWeaponState( Hold );
		DropWeapon();
		Kill();
		StopAllAnimations();
		PlayAnimation("Death");
		PlayAnimationAfter("Death", "Dead");
		SoundManager::GetInstance()->Play( gDeathSound, SFX, false );

		if (!PlayingAnimation("Death"))
		{
			SetState( Dead );
			return;
		}		
	}

	GameObject::Update(DeltaTime, TerrainInstance);

	if ( GetState() == Dying )
		return;

	XMVECTOR vel = XMLoadFloat3(&GetFloat3Value( Velocity ));
	if (!XMVector3Equal(vel, XMVectorZero()))
	{
		XMVECTOR dir  = XMLoadFloat3(&GetFloat3Value( Direction ));
		XMVECTOR angleV = XMVector3AngleBetweenVectors(dir, vel);

		float angle;
		XMStoreFloat(&angle, angleV);

		XMVECTOR crossV = XMVector3Cross(dir, vel);

		if (XMVectorGetY(crossV) < 0)
			angle *= -1;

		//cout << 180 * angle / PI << endl;

		if (fabs(angle) <= PI * 0.25f)
			gMoveDirection = Forward;

		else if (fabs(angle) > PI * 0.75f)
			gMoveDirection = Back;

		else if (angle < 0)
			gMoveDirection = Left;

		else if (angle > 0)
			gMoveDirection = Right;

		XMVECTOR L = XMVector3Length(vel);
		float speed;
		XMStoreFloat(&speed, L);
		speed /= UnitsPerMeter;

		switch (gMoveDirection)
		{
		case Forward:
			if (speed > 1.05f * gWalkSpeed)
			{
				SetMoveState(Run);	
				SetAnimationSpeed("Run", speed);
				SetAnimationSpeed(GetAnimation("UpperRun"), speed);							
			}
			else
			{
				SetMoveState(Walk);
				SetAnimationSpeed("Walk", speed);
			}
			break;
		case Back:
			SetMoveState(Walk);
			SetAnimationSpeed("Back", speed);
			break;
		case Right:
			SetMoveState(Walk);
			SetAnimationSpeed("SideStepRight", speed);
			break;
		case Left:
			SetMoveState(Walk);
			SetAnimationSpeed("SideStepLeft", speed);
			break;
		}
	}
	else
	{
		gMoveDirection = None;

		if (!Crouching())
			SetMoveState(Stand);
	}

	if ( gCurrentWeapon )
	{
		XMFLOAT3 handPos;
		XMFLOAT4 handRot;
		
		XMVECTOR pos = XMLoadFloat3(&GetFloat3Value( Position ));
		XMVECTOR dir = XMLoadFloat3(&GetFloat3Value( Direction ));
		XMVECTOR lv = XMVector3Length(dir);

		bool gotJointPos = false;
		bool gotJointRot = false;
		if (m_ModelInstance)
		{
			gotJointPos = GetJointPosition("RightHand", handPos);
			gotJointRot = GetJointRotation("RightHand", handRot);
		}

		if (!gotJointPos)
		{
			pos += dir * (GetRadius() - 10);
			XMStoreFloat3(&handPos, pos);
		}
		
		if (gCurrentWeapon->NeedReload())
		{
			ReloadWeapon();
		}
		
		//gWeapon->Update(DeltaTime);
		//gWeapon->MoveTo( position );
		gCurrentWeapon->MoveTo( handPos );

		XMFLOAT3 weaponPos;
		if (gCurrentWeapon->GetJointPosition("RightHand", weaponPos))
		{
			XMStoreFloat3(&handPos, XMLoadFloat3(&handPos) + (XMLoadFloat3(&handPos) - XMLoadFloat3(&weaponPos)));
			gCurrentWeapon->MoveTo( handPos );
		}
		
		if (gotJointRot)
		{
			gCurrentWeapon->SetRotation( handRot );
		}
		else
			gCurrentWeapon->SetRotation( GetQuaternation() );
	}
	/*
	else
	{
		LoopAnimation("PistolUpperWalk");
	}
	*/
}