示例#1
0
Box::Box(float x, float y, float z, XMVECTOR position, float mass, bool fixed, XMVECTOR orientation)
{
	this->position = position;	// its the center position of the box
	this->velocity = XMVectorSet(0.f, 0.f, 0.f, 0.f);
	length = XMVectorSet(x, y, z, 0.f);
	
	centerOfMass = Point(position, false);

	this->transform = XMMatrixTranslationFromVector(this->position);
	this->centerOfMass.fixed = fixed;
	this->orientation = XMQuaternionRotationRollPitchYawFromVector(orientation);

	if (fixed) 
	{
		centerOfMass.mass = 1.0f;
		massInverse = 0.0f;
		intertiaTensorInverse = XMMATRIX();
	}
	else 
	{
		centerOfMass.mass = mass;
		massInverse = 1.0f / mass;
		float prefix = (1.0f / 12.0f) * centerOfMass.mass;

		XMMATRIX matrix = XMMATRIX(XMVectorSet(prefix*(y*y + z*z), 0.f, 0.f, 0.f),
			XMVectorSet(0.f, prefix * (x*x + z*z), 0.f, 0.f),
			XMVectorSet(0.f, 0.f, prefix*(x*x + y*y),0.f),
			XMVectorSet(0.f, 0.f, 0.f, 1.f));
		intertiaTensorInverse = XMMatrixInverse(&XMMatrixDeterminant(matrix), matrix);
	}

	XMVECTOR xLength = XMVectorSet(x, 0.f, 0.f, 0.f) / 2;
	XMVECTOR yLength = XMVectorSet(0.f, y, 0.f, 0.f) / 2;
	XMVECTOR zLength = XMVectorSet(0.f, 0.f, z, 0.f) / 2;

	for (int i = 0; i < 8; i++) 
	{
		corners[0] = XMVECTOR();
	}

	this->angularMomentum = XMVECTOR();
	this->angularVelocity = XMVECTOR();
	this->torqueAccumulator = XMVECTOR();



	corners[0] = -xLength - yLength - zLength;
	corners[1] = xLength - yLength - zLength;
	corners[2] = -xLength + yLength - zLength;
	corners[3] = xLength + yLength - zLength;
	corners[4] = -xLength - yLength + zLength;
	corners[5] = xLength - yLength + zLength;
	corners[6] = -xLength + yLength + zLength;
	corners[7] = xLength + yLength + zLength;

}
// Updates the cameras matrices
void CCamera::UpdateViewMatrix()
{
	if ((mSetting == ECameraSetting::FirstPerson || mSetting == ECameraSetting::ThirdPerson) && mParent == NULL)
	{
		mSetting = ECameraSetting::FreeRoam;
	}

	switch (mSetting)
	{
	case ECameraSetting::ThirdPerson:
		{
			// Add first and third person camera angles
			mWorldMat = mParent->GetMatrix( false );
			
			mPos.x = mWorldMat._41;
			mPos.y = mWorldMat._42;
			mPos.z = mWorldMat._43;

			MoveLocalX( mOffset.x );
			MoveY( mOffset.y );
			MoveLocalZ( mOffset.z );

			RotateLocalX( D3DXToRadian( 15 ) );
			
			break;
		}
	case ECameraSetting::FirstPerson:
		{
			// Add first and third person camera angles
			mWorldMat = mParent->GetMatrix( false );

			mPos.x = mWorldMat._41;
			mPos.y = mWorldMat._42;
			mPos.z = mWorldMat._43;

			MoveLocalX( mOffset.x );
			MoveY( mOffset.y );
			MoveLocalZ( mOffset.z );
			
			break;
		}
	}

	if (mSetting != ECameraSetting::BirdsEye)
	{
		mWorldMat._41 = mPos.x;
		mWorldMat._42 = mPos.y;
		mWorldMat._43 = mPos.z;
	}
	
	// The rendering pipeline actually needs the inverse of the
	// camera world matrix - called the view matrix.
	XMVECTOR vector = XMVECTOR();
	CXMMATRIX world = XMMATRIX( mWorldMat );
	mView = XMMatrixInverse( &vector, world );
}
示例#3
0
XMVECTOR CSkeletonGroup::CalculateAlignment()
{

	// Calculate the avarage velocity
	XMVECTOR avgVelocity = XMVECTOR();
	for (size_t i = 0; i < m_vSkeletons.size(); i++)
	{
		CSkeleton* other = reinterpret_cast<CSkeleton*>(m_vSkeletons[i]);
		XMFLOAT3 vec = other->GetWorldVelocity();
		XMVECTOR otherVelocity = XMLoadFloat3(&vec);
		avgVelocity += otherVelocity;
	}
	avgVelocity /= (float)m_vSkeletons.size();
	avgVelocity.m128_f32[1] = 0.0f;

	if (XMVector3Length(avgVelocity).m128_f32[0] > 1.0f)
		avgVelocity = XMVector3Normalize(avgVelocity);

	return avgVelocity * ALIGNMENT_STRENGTH;

}
示例#4
0
XMVECTOR CSkeletonGroup::CalculateSeparation(CSkeleton* _current)
{
	XMVECTOR mathOutput = XMVECTOR();

	// For all skeletons
	for (size_t i = 0; i < m_vSkeletons.size(); i++)
	{
		// Cast the skeleton for future use
		CSkeleton* other = reinterpret_cast<CSkeleton*>(m_vSkeletons[i]);

		// Convert the positions for math
		XMVECTOR mathOtherPos = XMLoadFloat3(other->GetPosition());
		XMVECTOR mathCurrentPos = XMLoadFloat3(_current->GetPosition());

		// Find the distance between them
		XMVECTOR mathFromVector = mathCurrentPos - mathOtherPos;
		float fDistance = XMVector3Length(mathFromVector).m128_f32[0];

		// If within safe distance
		if (fDistance < SEPARATION_DISTANCE)
		{
			mathFromVector = XMVector3Normalize(mathFromVector);

			mathFromVector *= (SEPARATION_DISTANCE - fDistance) / SEPARATION_DISTANCE;

			mathOutput += mathFromVector;
		}
	}

	// Rescale the velocity
	if (XMVector3Length(mathOutput).m128_f32[0] > 1.0f)
		mathOutput = XMVector3Normalize(mathOutput);

	// Scale by modifier
	return mathOutput * SEPARATION_STRENGTH;



}