Пример #1
0
void Small::Chase(float weight)
{
	XMMATRIX rotationmatrix;
	XMVECTOR playerlocation = Target->Location;

	XMVECTOR leftvector = {0, 0, 0, 0};
	XMVECTOR rightvector = {0, 0, 0, 0};

	XMMATRIX rotationmatrixleft = XMMatrixRotationZ(float(M_PI)/2.0f);
	XMMATRIX rotationmatrixright = XMMatrixRotationZ(float(M_PI)/-2.0f);

	leftvector = XMVector3Transform(Direction, rotationmatrixleft);
	rightvector = XMVector3Transform(Direction, rotationmatrixright);

	Direction = XMVector2Normalize(Direction);

	XMVECTOR differencevector = playerlocation - Location;

	differencevector = XMVector2Normalize(differencevector);

	float radiandifference = XMVectorGetX(XMVector2AngleBetweenNormals(leftvector, differencevector));
	float epsilon = XMVectorGetX(XMVector2AngleBetweenNormals(Direction, differencevector));

	if (radiandifference <= float(M_PI/2.0f)) 
	{
		rotationmatrix = XMMatrixRotationZ(weight);

		if (epsilon <= (1.25f * weight))
		{
			Direction = differencevector;
			Direction = XMVector2Normalize(Direction);

		}
		else
		{
			Direction = XMVector3Transform(Direction, rotationmatrix);
			Direction = XMVector2Normalize(Direction);
		}
	}
	else if (radiandifference > float(M_PI/2.0f)) 
	{
		rotationmatrix = XMMatrixRotationZ(-weight);

		if (epsilon <= (1.25f * weight))
		{
			Direction = differencevector;
			Direction = XMVector2Normalize(Direction);

		}
		else
		{
			Direction = XMVector3Transform(Direction, rotationmatrix);
			Direction = XMVector2Normalize(Direction);
		}
	}
}
void GCamera::Move(XMFLOAT3 direction)
{
	mPosition = GMathVF(XMVector3Transform(GMathFV(mPosition),
		XMMatrixTranslation(direction.x, direction.y, direction.z)));
	mTarget = GMathVF(XMVector3Transform(GMathFV(mTarget),
		XMMatrixTranslation(direction.x, direction.y, direction.z)));
	mUp = GMathVF(XMVector3Transform(GMathFV(mUp),
		XMMatrixTranslation(direction.x, direction.y, direction.z)));

	this->lookatViewMatrix();
}
Пример #3
0
void Camera::Move(XMFLOAT3 direction)
{
	mPosition = to(XMVector3Transform(to(mPosition),
		XMMatrixTranslation(direction.x, direction.y, direction.z)));
	mTarget = to(XMVector3Transform(to(mTarget),
		XMMatrixTranslation(direction.x, direction.y, direction.z)));
	mUp = to(XMVector3Transform(to(mUp),
		XMMatrixTranslation(direction.x, direction.y, direction.z)));

	this->initViewMatrix();
}
    //--------------------------------------------------------------------------------------
    // Name: Update()
    // Desc: Adds a new frame of positions, updates the coordiante system, and calculates 
    //       left and right hand.
    //--------------------------------------------------------------------------------------
    VOID SpineRelativeCameraSpaceCoordinateSystem::Update( const NUI_SKELETON_FRAME* pRawSkeletonFrame, INT iSkeletonIndex, XMVECTOR vLeft, XMVECTOR vRight )
    {
        if ( pRawSkeletonFrame == NULL ) return;
        if ( iSkeletonIndex < 0 || iSkeletonIndex >= NUI_SKELETON_COUNT ) return;
        CONST XMVECTOR *pSkeletonPosition = &pRawSkeletonFrame->SkeletonData[iSkeletonIndex].SkeletonPositions[0];

        if ( m_dwLastTrackingID != pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID )
        {
            m_vAverageNormalToGravity = pRawSkeletonFrame->vNormalToGravity;
        }
        else
        {
            m_vAverageNormalToGravity = m_fSpineUpdateRate * m_vAverageNormalToGravity +
                 pRawSkeletonFrame->vNormalToGravity * ( 1.0f - m_fSpineUpdateRate );
        }
        
#if 0
        CHAR out[255];
        sprintf_s( out, "x=%f,y=%f,z=%f,w=%f\n", pRawSkeletonFrame->vNormalToGravity.x, pRawSkeletonFrame->vNormalToGravity.y, pRawSkeletonFrame->vNormalToGravity.z, pRawSkeletonFrame->vNormalToGravity.w );
        OutputDebugString( out );
#endif 
        m_matRotateToNormalToGravity = NuiTransformMatrixLevel( m_vAverageNormalToGravity );
        XMVECTOR vSpineTilted = XMVector3Transform( pSkeletonPosition[NUI_SKELETON_POSITION_SPINE], m_matRotateToNormalToGravity );
        XMVECTOR vHeadTilted = XMVector3Transform( pSkeletonPosition[NUI_SKELETON_POSITION_HEAD], m_matRotateToNormalToGravity );
        m_vLeftHandRelative = XMVector3Transform( vLeft, m_matRotateToNormalToGravity );
        m_vRightHandRelative = XMVector3Transform( vRight, m_matRotateToNormalToGravity );


        FLOAT fSpineHeadLength = XMVectorGetY( vHeadTilted ) - XMVectorGetY( vSpineTilted );
        if ( m_dwLastTrackingID != pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID )
        {
            m_dwLastTrackingID = pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID;
            m_vAverageSpine = vSpineTilted;
            m_fAverageSpineHeadLength = fSpineHeadLength;
        }
        else
        {
            m_vAverageSpine = m_vAverageSpine * m_fSpineUpdateRate + 
                vSpineTilted * ( 1.0f - m_fSpineUpdateRate );
            m_fAverageSpineHeadLength = ATG::Lerp( fSpineHeadLength, m_fAverageSpineHeadLength, m_fBodySizeUpdateRate );
        }

        m_vEstiamtedPivotOffsetLeft = XMVectorSet( m_fAverageSpineHeadLength * 0.3f, m_fAverageSpineHeadLength * 0.1f, 0.0f, 0.0f );
        m_vEstiamtedPivotOffsetRight = XMVectorSet( -m_fAverageSpineHeadLength * 0.3f, m_fAverageSpineHeadLength * 0.1f, 0.0f, 0.0f );
        m_vRightHandRelative -= m_vAverageSpine;
        m_vRightHandRelative += m_vEstiamtedPivotOffsetRight;
        m_vLeftHandRelative -= m_vAverageSpine;
        m_vLeftHandRelative += m_vEstiamtedPivotOffsetLeft;
        static XMVECTOR vFlipZ = XMVectorSet( 1.0f, 1.0f, -1.0f, 1.0f );
        m_vRightHandRelative *= vFlipZ;
        m_vLeftHandRelative *= vFlipZ;

    }
Пример #5
0
void TestTriangleStripsDX::Update()
{
	if (processInput)
	{
		float rotAmount = 0.0f;
		XMMATRIX rotMatrix = XMMatrixIdentity();
		if (input.right || input.left)
		{
			if (input.right)
				rotAmount = rotDelta;
			if (input.left)
				rotAmount = -rotDelta;
			rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&up), XMConvertToRadians(rotAmount));
		}
		else if (input.up || input.down)
		{
			if (input.up)
				rotAmount = rotDelta;
			if (input.down)
				rotAmount = -rotDelta;
			rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&right), XMConvertToRadians(rotAmount));
		}

		XMStoreFloat4(&eye, XMVector3Transform(XMLoadFloat4(&eye), rotMatrix));
		XMStoreFloat4(&right, XMVector3Normalize(XMVector3Cross(XMLoadFloat4(&up), (XMLoadFloat4(&center) - XMLoadFloat4(&eye)))));

		XMMATRIX viewMatrix = XMMatrixLookAtRH(XMLoadFloat4(&eye), XMLoadFloat4(&center), XMLoadFloat4(&up));
		mDeviceContext->UpdateSubresource(viewMatrixBuffer, 0, NULL, &viewMatrix, 0, 0);
	}
}
Пример #6
0
void BatchRenderer::DrawCube( const float4x4& worldMatrix, const FColor& color )
{
	static const XMVECTOR verts[8] =
    {
        { -1, -1, -1, 0 },
        { 1, -1, -1, 0 },
        { 1, -1, 1, 0 },
        { -1, -1, 1, 0 },
        { -1, 1, -1, 0 },
        { 1, 1, -1, 0 },
        { 1, 1, 1, 0 },
        { -1, 1, 1, 0 }
    };
	const UINT* edgeIndices = AABB::GetEdges();

    // copy to vertex buffer
    //assert( 8 <= MAX_VERTS );

	XMFLOAT3 transformedVerts[8];
	for( int i=0; i < 8; ++i )
	{
		XMVECTOR v = XMVector3Transform( verts[i], worldMatrix );
		XMStoreFloat3( &transformedVerts[i], v );
	}

	for( int iEdge = 0; iEdge < AABB::NUM_EDGES; iEdge++ )
	{
		XMFLOAT3 & start = transformedVerts[ edgeIndices[iEdge*2] ];
		XMFLOAT3 & end = transformedVerts[ edgeIndices[iEdge*2 + 1] ];
		DrawLine3D( as_vec3(start), as_vec3(end), color, color );
	}
}
void CarModel::MoveBackward(){

	  //Move the airplane in the direction it is facing based on its
	  //direction vector and the speed factor which can be adjusted for smooth motion

	  XMFLOAT3 effectiveDirectionVector;
	  XMFLOAT4X4 fuselageDirectionMatrix = m_Body->GetWorldRotateMatrix();
      XMStoreFloat3( &effectiveDirectionVector,  XMVector3Transform( XMLoadFloat3(&m_directionVector), XMLoadFloat4x4(&fuselageDirectionMatrix) ));

	  float deltaX = -effectiveDirectionVector.x*CAR_FORWARD_SPEED_FACTOR;
	  float deltaY = -effectiveDirectionVector.y*CAR_FORWARD_SPEED_FACTOR;
	  float deltaZ = -effectiveDirectionVector.z*CAR_FORWARD_SPEED_FACTOR;

	  //Move all the  component parts of the airplane relative to the world
	  //co-ordinate system

	  m_Body->worldTranslate(deltaX, deltaY, deltaZ);
	  m_WheelFL->worldTranslate(deltaX, deltaY, deltaZ);
	   m_WheelFR->worldTranslate(deltaX, deltaY, deltaZ);
	    m_WheelBL->worldTranslate(deltaX, deltaY, deltaZ);
		 m_WheelBR->worldTranslate(deltaX, deltaY, deltaZ);
	  //Spin the wheels
	float wheelRadianAngularIncrement = XM_PIDIV4/5; //sign changes direction of the propeller
	m_WheelFL->orientRotateZ(wheelRadianAngularIncrement);
	m_WheelFR->orientRotateZ(wheelRadianAngularIncrement);
	m_WheelBL->orientRotateZ(wheelRadianAngularIncrement);
	m_WheelBR->orientRotateZ(wheelRadianAngularIncrement);
}
Пример #8
0
void CSphere::update(float delta)
{
	// 카메라 좌표계 기준으로 이동시켜야 하므로 좌표계를 변환
	auto camera = CGameManager::GetInstance()->GetRenderer()->GetCamera();
	auto cameraAngle = XMConvertToRadians((*camera->getRotate()).m128_f32[1]);
	translation( XMVector3Transform(mSpeed, XMMatrixRotationY(cameraAngle)) );
	
	// 네 모서리와 부딪혔는지 체크
	auto width = camera->getWidth();
	auto height = camera->getHeight();
	auto pos = ConvertCenterToViewingCoord();

	// 위쪽 벽에 공이 닿음
	if (pos.m128_f32[1] + mScale.m128_f32[0] >= (height / 2))
		mulSpeed({ 1.f, -1.f, 1.f });

	// 아래쪽 벽에 공이 닿음 - 게임 오버
	if (pos.m128_f32[1] - mScale.m128_f32[0] <= -(height / 2))
		CGameManager::GetInstance()->GetEventManager()->triggerEvent("Gameover");

	// 왼쪽 벽에 공이 닿음
	if (pos.m128_f32[0] - mScale.m128_f32[0] < -(width / 2))
		CGameManager::GetInstance()->GetEventManager()->triggerEvent("RotateLeft");

	// 오른쪽 벽에 공이 닿음
	if (pos.m128_f32[0] + mScale.m128_f32[0] > (width / 2))
		CGameManager::GetInstance()->GetEventManager()->triggerEvent("RotateRight");

	CPrimitive::update(delta);
}
Пример #9
0
//
// CalcLightPosition
//
void CalcLightPosition(POINT_LIGHT_SOURCE *pLight)
{
    if (pLight->bMoveable)
    {
        float Angle = (g_ElapsedTime / 100.0f * pLight->Velocity);

        if (pLight->bClockwiseOrbit)
            pLight->OrbitAngle -= Angle;
        else
            pLight->OrbitAngle += Angle; 

        float Rad = XMConvertToRadians(pLight->OrbitAngle);

        // Position on orbit
        //pLight->Position = pLight->Center;
        pLight->Position.x = sinf(Rad) * pLight->OrbitRadius;
        pLight->Position.y = 0.0f;
        pLight->Position.z = cosf(Rad) * pLight->OrbitRadius;

        XMMATRIX Roll = XMMatrixRotationZ(XMConvertToRadians(pLight->OrbitRoll));
        XMVECTOR V = XMLoadFloat3(&pLight->Position);
        
        // Orbit roll angle
        V = XMVector3Transform(V, Roll);
        XMStoreFloat3(&pLight->Position, V);

        pLight->Position.x += pLight->Center.x;
        pLight->Position.y += pLight->Center.y;
        pLight->Position.z += pLight->Center.z;
    }
    else
    {
        pLight->Position = pLight->Center;
    }
}
Пример #10
0
//ALEX OWEN - 30/03/15 
void GameObject::updateVectors()
{
	XMMATRIX rotationMatrix = getRotationMatrix();
	FXMVECTOR _forwardVector = XMVector3Transform(FORWARD,rotationMatrix);
	FXMVECTOR _rightVector = XMVector3Transform(RIGHT,rotationMatrix);
	FXMVECTOR _upVector = XMVector3Transform(UP,rotationMatrix);

	XMFLOAT3* _temp = &forwardVector;
	XMStoreFloat3(_temp,_forwardVector);
	_temp = &rightVector;
	XMStoreFloat3(_temp,_rightVector);
	_temp = &upVector;
	XMStoreFloat3(_temp,_upVector);
	updated = false;

	//forwardVector = XMStoreFloat4(_forwardVector)
	//forwardVector.x = XMVectorGetX(
}
Пример #11
0
float ObjectToCamera(XMFLOAT4X4* _objMatrix, XMFLOAT3 _cameraPos)
{
	XMVECTOR obj = XMVectorZero();
	obj = XMVector3Transform(obj, XMLoadFloat4x4(_objMatrix));
	float ObjtoCameraX = XMVectorGetX(obj) - _cameraPos.x;
	float ObjtoCameraY = XMVectorGetY(obj) - _cameraPos.y;
	float ObjtoCameraZ = XMVectorGetZ(obj) - _cameraPos.z;
	return ObjtoCameraX*ObjtoCameraX + ObjtoCameraY*ObjtoCameraY + ObjtoCameraZ*ObjtoCameraZ;
}
Пример #12
0
void BatchRenderer::DrawFrustum( const XNA::Frustum& frustum, const FColor& color )
{
	// compute corner points
	XMVECTOR Origin = XMVectorSet( frustum.Origin.x, frustum.Origin.y, frustum.Origin.z, 0 );

	FLOAT Near = frustum.Near;
	FLOAT Far = frustum.Far;
	FLOAT RightSlope = frustum.RightSlope;
	FLOAT LeftSlope = frustum.LeftSlope;
	FLOAT TopSlope = frustum.TopSlope;
	FLOAT BottomSlope = frustum.BottomSlope;

	XMFLOAT3 CornerPoints[8];
	CornerPoints[0] = XMFLOAT3( RightSlope * Near, TopSlope * Near, Near );
	CornerPoints[1] = XMFLOAT3( LeftSlope * Near, TopSlope * Near, Near );
	CornerPoints[2] = XMFLOAT3( LeftSlope * Near, BottomSlope * Near, Near );
	CornerPoints[3] = XMFLOAT3( RightSlope * Near, BottomSlope * Near, Near );

	CornerPoints[4] = XMFLOAT3( RightSlope * Far, TopSlope * Far, Far );
	CornerPoints[5] = XMFLOAT3( LeftSlope * Far, TopSlope * Far, Far );
	CornerPoints[6] = XMFLOAT3( LeftSlope * Far, BottomSlope * Far, Far );
	CornerPoints[7] = XMFLOAT3( RightSlope * Far, BottomSlope * Far, Far );

	XMVECTOR Orientation = XMLoadFloat4( &frustum.Orientation );
	XMMATRIX Mat = XMMatrixRotationQuaternion( Orientation );
	for( UINT i = 0; i < 8; i++ )
	{
		XMVECTOR Result = XMVector3Transform( XMLoadFloat3( &CornerPoints[i] ), Mat );
		Result = XMVectorAdd( Result, Origin );
		XMStoreFloat3( &CornerPoints[i], Result );
	}

	// copy to vertex buffer
	//Assert( (12 * 2) <= MAX_VERTS );

#define DBG_DRAW_LINE(pointA,pointB)	\
	DrawLine3D( pointA.x,pointA.y,pointA.z, pointB.x,pointB.y,pointB.z,	\
	color, color );

	DBG_DRAW_LINE(CornerPoints[0],CornerPoints[1]);
	DBG_DRAW_LINE(CornerPoints[1],CornerPoints[2]);
	DBG_DRAW_LINE(CornerPoints[2],CornerPoints[3]);
	DBG_DRAW_LINE(CornerPoints[3],CornerPoints[0]);

	DBG_DRAW_LINE(CornerPoints[0],CornerPoints[4]);
	DBG_DRAW_LINE(CornerPoints[1],CornerPoints[5]);
	DBG_DRAW_LINE(CornerPoints[2],CornerPoints[6]);
	DBG_DRAW_LINE(CornerPoints[3],CornerPoints[7]);

	DBG_DRAW_LINE(CornerPoints[4],CornerPoints[5]);
	DBG_DRAW_LINE(CornerPoints[5],CornerPoints[6]);
	DBG_DRAW_LINE(CornerPoints[6],CornerPoints[7]);
	DBG_DRAW_LINE(CornerPoints[7],CornerPoints[4]);

#undef DBG_DRAW_LINE

}
Пример #13
0
XMVECTOR Camera::PreviewMove(XMVECTOR amount) {

	XMMATRIX rotate = XMMatrixRotationY(m_CameraRotation.y);
	XMVECTOR movement = amount;
	movement = XMVector3Transform(movement, rotate);
	XMVECTOR position = XMLoadFloat3(&m_CameraPosition);
	//XMStoreFloat3(&m_CameraPosition, position);
	return position + movement;

}
Пример #14
0
void Camera::UpdateLookAt() {


	XMMATRIX rotationMatrix = XMMatrixRotationX(m_CameraRotation.x) * XMMatrixRotationY(m_CameraRotation.y);
	XMVECTOR lookAtOffset = XMVector3Transform(XMVECTOR{0.0f, 0.0f, 1.0f}, rotationMatrix);
	XMVECTOR cameraPosition = XMLoadFloat3(&m_CameraPosition);
	XMVECTOR cameraLookAt = cameraPosition + lookAtOffset;
	XMStoreFloat3(&m_CameraLookAt, cameraLookAt);

}
Пример #15
0
void GCamera::Rotate(XMFLOAT3 axis, float degrees)
{
	if (XMVector3Equal(GMathFV(axis), XMVectorZero()) ||
		degrees == 0.0f)
		return;

	// rotate vectors
	XMFLOAT3 look_at_target = GMathVF(GMathFV(mTarget) - GMathFV(mPosition));
	XMFLOAT3 look_at_up = GMathVF(GMathFV(mUp) - GMathFV(mPosition));
	look_at_target = GMathVF(XMVector3Transform(GMathFV(look_at_target),
		XMMatrixRotationAxis(GMathFV(axis), XMConvertToRadians(degrees))));
	look_at_up = GMathVF(XMVector3Transform(GMathFV(look_at_up),
		XMMatrixRotationAxis(GMathFV(axis), XMConvertToRadians(degrees))));

	// restore vectors's end points mTarget and mUp from new rotated vectors
	mTarget = GMathVF(GMathFV(mPosition) + GMathFV(look_at_target));
	mUp = GMathVF(GMathFV(mPosition) + GMathFV(look_at_up));

	this->lookatViewMatrix();
}
Пример #16
0
XMFLOAT3 trans(XMFLOAT4X4 const& w, XMFLOAT3 point)
{
    XMMATRIX world = XMLoadFloat4x4(&w);
    XMVECTOR pt = XMLoadFloat3(&point);

    XMVECTOR result = XMVector3Transform(pt, world);

    XMFLOAT3 res;
    XMStoreFloat3(&res, result);

    return res;
}
Пример #17
0
void Camera::Rotate(XMFLOAT3 axis, float degrees)
{
	if (XMVector3Equal(to(axis), XMVectorZero()) ||
		degrees == 0.0f)
		return;

	// rotate vectors
	XMFLOAT3 look_at_target = to(to(mTarget) - to(mPosition));
	XMFLOAT3 look_at_up = to(to(mUp) - to(mPosition));
	look_at_target = to(XMVector3Transform(to(look_at_target),
		XMMatrixRotationAxis(to(axis), XMConvertToRadians(degrees))));
	look_at_up = to(XMVector3Transform(to(look_at_up),
		XMMatrixRotationAxis(to(axis), XMConvertToRadians(degrees))));

	// restore vectors's end points mTarget and mUp from new rotated vectors
	mTarget = to(to(mPosition) + to(look_at_target));
	mUp = to(to(mPosition) + to(look_at_up));

	this->initViewMatrix();

	XMVECTOR w = XMVectorZero();
}
Пример #18
0
/**
 *	Transforms a three component vector by the current matrix
 *	adding in a fourth, implicit w value of one to support
 *	translation.
 *
 *  @param vVec The vector to transform.
 *  @return The resulting vector.
 */
CFVec4		CFMat4x4::TransformVec4( CFVec3Arg vVec )
{
	CFVec4 v4Return;

	const XMMATRIX& matA = *reinterpret_cast<const XMMATRIX*>( this );
	const XMVECTOR& vArg = *reinterpret_cast<const XMVECTOR*>( &vVec );

	XMVECTOR& vResult = *reinterpret_cast<XMVECTOR*>( &v4Return );

	//Transform vArg by the matrix:
	vResult = XMVector3Transform( vArg, matA );

	return v4Return;
}
Пример #19
0
void EnemyModel::MoveForwardDelta(float delta)
{
	XMFLOAT3 effectiveDirectionVector;
	XMFLOAT4X4 torsoDirectionMatrix = m_Torso->GetWorldRotateMatrix();
    XMStoreFloat3( &effectiveDirectionVector,  XMVector3Transform( XMLoadFloat3(&m_directionVector), XMLoadFloat4x4(&torsoDirectionMatrix) ));

	float deltaX = effectiveDirectionVector.x*delta;
	float deltaY = effectiveDirectionVector.y*delta;
	float deltaZ = effectiveDirectionVector.z*delta;
	
	m_Head->worldTranslate(deltaX, deltaY, deltaZ);
	m_Torso->worldTranslate(deltaX, deltaY, deltaZ);
	m_LeftArm->worldTranslate(deltaX, deltaY, deltaZ);
	m_RightArm->worldTranslate(deltaX, deltaY, deltaZ);
	m_LeftLeg->worldTranslate(deltaX, deltaY, deltaZ);
	m_RightLeg->worldTranslate(deltaX, deltaY, deltaZ);
}
Пример #20
0
void  SceneNode::update_collision_tree(XMMATRIX* world, float scale)
{
	// the m_local_world_matrix matrix will be used to calculate the local transformations for this node
	XMMATRIX m_local_world_matrix = XMMatrixIdentity();

	m_local_world_matrix = XMMatrixRotationX(XMConvertToRadians(m_xangle));
	m_local_world_matrix *= XMMatrixRotationY(XMConvertToRadians(m_yangle));
	m_local_world_matrix *= XMMatrixRotationZ(XMConvertToRadians(m_zangle));

	m_local_world_matrix *= XMMatrixScaling(m_scale, m_scale, m_scale);

	m_local_world_matrix *= XMMatrixTranslation(m_x, m_y, m_z);

	// the local matrix is multiplied by the passed in world matrix that contains the concatenated
	// transformations of all parent nodes so that this nodes transformations are relative to those
	m_local_world_matrix *= *world;

	// calc the world space scale of this object, is needed to calculate the  
	// correct bounding sphere radius of an object in a scaled hierarchy
	m_world_scale = scale * m_scale;

	XMVECTOR v;
	if (m_p_model)
	{
		v = XMVectorSet(m_p_model->GetBoundingSphere_x(),
			m_p_model->GetBoundingSphere_y(),
			m_p_model->GetBoundingSphere_z(), 0.0);
	}
	else v = XMVectorSet(0, 0, 0, 0); // no model, default to 0

	// find and store world space bounding sphere centre
	v = XMVector3Transform(v, m_local_world_matrix);
	m_world_centre_x = XMVectorGetX(v);
	m_world_centre_y = XMVectorGetY(v);
	m_world_centre_z = XMVectorGetZ(v);

	// traverse all child nodes, passing in the concatenated world matrix and scale
	for (int i = 0; i< m_children.size(); i++)
	{
		m_children[i]->update_collision_tree(&m_local_world_matrix, m_world_scale);
	}
}
/*
Fires a cannonball if not cooling down.
*/
void Cannon::Fire(CannonBall* cannonBall,  std::vector<Hittable*> targets, XMVECTOR currentVeloctiy, float damage)
{
	if (active)
	{
		// Set tint and inactive.
		tint.x = redTint;
		coolDown = coolDownTime;
		active = false;

		XMMATRIX matrix = XMMatrixTranspose(XMLoadFloat4x4(&worldMatrix));

		cannonBall->Fire(
			XMVector3Transform(position, matrix),
			(this->forward * (Random::Range(5,7)) + this->up/Random::Range(1.8,2.2)), // For some reason it looks 400x better without using current velocity...
			targets,
			damage);

		cannonBall->velocity += currentVeloctiy;
	}
}
Пример #22
0
	void SetVertexPos(std::array<DefaultVertex,4>& v,XMFLOAT3 pos,XMFLOAT2 base,XMFLOAT2 size,float angle)
	{
		v[0].pos = XMFLOAT3(pos.x, pos.y , pos.z);
		v[1].pos = XMFLOAT3(pos.x + size.x, pos.y, pos.z);
		v[2].pos = XMFLOAT3(pos.x, pos.y + size.y, pos.z);
		v[3].pos = XMFLOAT3(pos.x + size.x, pos.y + size.y, pos.z);
		std::for_each(v.begin(), v.end(), [base](DefaultVertex& p)
		{
			p.pos = p.pos - XMFLOAT3(base.x, base.y, 0.f);
		});
		XMFLOAT3X3 matRotate;
		XMStoreFloat3x3(&matRotate, XMMatrixIdentity());
		float rad = XMConvertToRadians(angle);
		matRotate._11 = matRotate._22 = cosf(rad);
		matRotate._12 = sinf(rad);
		matRotate._21 = -sinf(rad);
		std::for_each(v.begin(), v.end(), [base, matRotate](DefaultVertex& p)
		{
			XMStoreFloat3(&p.pos, XMVector3Transform(XMLoadFloat3(&p.pos), XMLoadFloat3x3(&matRotate)));
			p.pos = XMFLOAT3(p.pos.x + base.x, p.pos.y + base.y, p.pos.z);
		});
	}
Пример #23
0
void EnemyIceBear::DrawLifeBar(const GameContext& gameContext)
{
	int width = OverlordGame::GetGameSettings().Window.Width;
	int height = OverlordGame::GetGameSettings().Window.Height;

	XMFLOAT3 worldPos = m_Position;
	worldPos.y += 8;

	XMVECTOR healthPos = XMLoadFloat3(&worldPos);
	XMMATRIX proj = XMLoadFloat4x4(&gameContext.pCamera->GetViewProjection());

	healthPos = XMVector3Transform(healthPos, proj);
	
	XMFLOAT4 screenPos;
	XMStoreFloat4(&screenPos, healthPos);

	screenPos.x /= screenPos.w;
	screenPos.y /= screenPos.w;

	if (screenPos.z > 0)
	{
		XMFLOAT3 pos = XMFLOAT3(screenPos.x, screenPos.y, 0.9f);

		pos.x = width*(pos.x + 1.0f) / 2.0f;
		pos.y = height * (1.0f - ((pos.y + 1.0f) / 2.0f));
		m_pHealthBarFrame->GetTransform()->Translate(pos);

		XMFLOAT3 posInside = XMFLOAT3(pos.x - 48, pos.y, 0.9f);
		m_pHealthBarInside->GetTransform()->Translate(posInside);
	}
	else
	{
		m_pHealthBarFrame->GetTransform()->Translate(XMFLOAT3(-300, 0, 0));
		m_pHealthBarInside->GetTransform()->Translate(XMFLOAT3(-300, 0, 0));
	}

}
Пример #24
0
void UIModel::SetUIPosition(Camera & camera)
{
	auto cameraPos = camera.GetPosition();
	auto normalviewVec = camera.GetNormalNiewDIr();
	float nearPlaneDist = 1.0f;

	XMFLOAT3 centerPos = {
		cameraPos.x + normalviewVec.x / nearPlaneDist,
		cameraPos.y + normalviewVec.y / nearPlaneDist,
		cameraPos.z + normalviewVec.z / nearPlaneDist, };

	float deltaX = (m_uiPosx * camera.GetViewSizeWidth() - camera.GetViewSizeWidth() / 2.0f);
	float deltaY = (m_uiPosy * camera.GetViewSizeHeight() - camera.GetViewSizeHeight() / 2.0f);

	XMVECTOR v = { centerPos.x, centerPos.y, centerPos.z};

	//xz평면으로 돌리는 행렬
	XMMATRIX mat = XMMatrixRotationZ(-m_zRot);
	mat *= XMMatrixRotationY(-m_yRot);
	mat *= XMMatrixRotationX(-m_xRot);

	//XZ평면에서 움직임
	mat *= XMMatrixTranslation(deltaX, deltaY, 0.0f);

	//다시 원래 각도로 돌리는 행렬
	mat *= XMMatrixRotationX(m_xRot);
	mat *= XMMatrixRotationY(m_yRot);
	mat *= XMMatrixRotationZ(m_zRot);

	//위치이동
	XMFLOAT3 resultPos;
	auto resultVec = XMVector3Transform(v, mat);
	XMStoreFloat3(&resultPos, resultVec);

	SetPosition(resultPos);
}
Пример #25
0
void XM_CALLCONV Camera::UpdateFollow( FXMMATRIX world ) {
	XMVECTOR target = XMVector3Transform( XMLoadFloat4( &XMFLOAT4( 0.f, 0.f, -800.f, 1.f )), world);
	XMVECTOR pos = XMVector3Transform( XMLoadFloat4( &XMFLOAT4( 0.f, 200.f, 500.f, 1.f ) ), world );
	Update( pos, target );
}
Пример #26
0
Vector3 Transform::GetWorldPosition()
{
	return XMVector3Transform(XMVectorZero(), createWorldMatrix());
}
Пример #27
0
		Vector3 transform(const Vector3& v) const
		{
			return Vector3(XMVector3Transform(v, *this));
		}
Пример #28
0
void Game::Update()
{
	m_pCube->Update();
	XMVECTOR cameraPos = XMLoadFloat3(&m_pCamera->GetCameraPos());
	/*cameraPos += XMVectorSet(0.0001f,0.0f,0.0f,0.0f);
	XMFLOAT3 newCameraPos;
	XMStoreFloat3(&newCameraPos,cameraPos);*/
	//cameraPos * XMMatrixRotationY(XM_PIDIV2/9.0f);

	//Camera Rotation code
	/*XMFLOAT3 newCameraPos;
	cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationY(-(XM_PIDIV2/9000.0f))));
	XMStoreFloat3(&newCameraPos,cameraPos);
	m_pCamera->SetCameraPos(newCameraPos);
	m_pCamera->UpdateViewMatrix();*/

	//keyboard input test code
	//bool pressed = ENGINE->GetInputManager()->IsKeyDown(VK_UP);

	//cout << pressed;
	XMFLOAT3 newCameraPos;
	if(ENGINE->GetInputManager()->IsKeyDown(VK_UP))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationX((XM_PIDIV2/9000.0f))));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(VK_DOWN))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationX(-(XM_PIDIV2/9000.0f))));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(VK_LEFT))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationY((XM_PIDIV2/9000.0f))));
	}
	//if(ENGINE->GetInputManager()->IsKeyDown(VK_RIGHT))
	if(ENGINE->GetInputManager()->IsCommandDown(L"RIGHT"))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationY(-(XM_PIDIV2/9000.0f))));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x57))//W
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,0,0.01f));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x53))//S
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,0,-0.01f));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x41))//A
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(-0.01f,0,0));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x44))//D
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0.01f,0,0));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x51))//Q
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,-0.01f,0));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x45))//E
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,0.01f,0));
	}
	
	XMStoreFloat3(&newCameraPos,cameraPos);
	m_pCamera->SetCameraPos(newCameraPos);
	m_pCamera->UpdateViewMatrix();
}
Пример #29
0
void Small::Cohesion(float weight)
{
	XMMATRIX rotationmatrix;
	XMVECTOR flocktotal = {0, 0, 0, 0};

	bool isalone = true;

	for (int i = 0; i < SmallVector->size(); i++)
	{
		if (SmallVector->at(i)->ID != this->ID)
		{
			if (SmallVector->at(i)->Chasing)
			{
				if (Target->ID == SmallVector->at(i)->Target->ID)
				{
					flocktotal += SmallVector->at(i)->Location;
					isalone = false;
				}
			}
		}
	}

	if (!isalone)
	{
		XMVECTOR flockaverage = flocktotal / SmallVector->size();

		XMVECTOR leftvector = {0, 0, 0, 0};
		XMVECTOR rightvector = {0, 0, 0, 0};

		XMMATRIX rotationmatrixleft = XMMatrixRotationZ(float(M_PI)/2.0f);
		XMMATRIX rotationmatrixright = XMMatrixRotationZ(float(M_PI)/-2.0f);

		leftvector = XMVector3Transform(Direction, rotationmatrixleft);
		rightvector = XMVector3Transform(Direction, rotationmatrixright);

		Direction = XMVector2Normalize(Direction);

		XMVECTOR differencevector = flockaverage - Location;

		differencevector = XMVector2Normalize(differencevector);

		float radiandifference = XMVectorGetX(XMVector2AngleBetweenNormals(leftvector, differencevector));
		float epsilon = XMVectorGetX(XMVector2AngleBetweenNormals(Direction, differencevector));

		if (radiandifference <= float(M_PI/2.0f)) 
		{
			rotationmatrix = XMMatrixRotationZ(weight);

			if (epsilon <= (1.25f * weight))
			{
				Direction = differencevector;
				Direction = XMVector2Normalize(Direction);

			}
			else
			{
				Direction = XMVector3Transform(Direction, rotationmatrix);
				Direction = XMVector2Normalize(Direction);
			}
		}
		else if (radiandifference > float(M_PI/2.0f)) 
		{
			rotationmatrix = XMMatrixRotationZ(-weight);

			if (epsilon <= (1.25f * weight))
			{
				Direction = differencevector;
				Direction = XMVector2Normalize(Direction);

			}
			else
			{
				Direction = XMVector3Transform(Direction, rotationmatrix);
				Direction = XMVector2Normalize(Direction);
			}
		}
	}
}
Пример #30
0
void Small::Separation(float weight)
{
	XMMATRIX rotationmatrix;
	XMVECTOR closestflockmatedifference = {-1000.0f, -1000.0f, 0, 0};

	bool isalone = true;

	for (int i = 0; i < SmallVector->size(); i++)
	{
		if (SmallVector->at(i)->ID != this->ID)
		{
			if (SmallVector->at(i)->Chasing)
			{
				if (Target->ID == SmallVector->at(i)->Target->ID)
				{
					XMVECTOR tempvector = {XMVectorGetX(SmallVector->at(i)->Location), XMVectorGetY(SmallVector->at(i)->Location), 0, 0};
					XMVECTOR tempdifference = Location - tempvector;

					if (XMVectorGetX(XMVector2Length(tempdifference)) < XMVectorGetX(XMVector2Length(closestflockmatedifference)))
					{
						closestflockmatedifference = tempdifference;
						isalone = false;
					}
				}
			}
		}
	}

	if (!isalone)
	{
		XMVECTOR leftvector = {0, 0, 0, 0};
		XMVECTOR rightvector = {0, 0, 0, 0};

		XMMATRIX rotationmatrixleft = XMMatrixRotationZ(float(M_PI)/2.0f);
		XMMATRIX rotationmatrixright = XMMatrixRotationZ(float(M_PI)/-2.0f);

		leftvector = XMVector3Transform(Direction, rotationmatrixleft);
		rightvector = XMVector3Transform(Direction, rotationmatrixright);

		Direction = XMVector2Normalize(Direction);

		XMVECTOR differencevector = closestflockmatedifference;

		differencevector = XMVector2Normalize(differencevector);

		float radiandifference = XMVectorGetX(XMVector2AngleBetweenNormals(leftvector, differencevector));
		float epsilon = XMVectorGetX(XMVector2AngleBetweenNormals(Direction, differencevector));

		if (radiandifference <= float(M_PI/2.0f)) 
		{
			rotationmatrix = XMMatrixRotationZ(weight);

			if (epsilon <= (1.25f * weight))
			{
				Direction = differencevector;
				Direction = XMVector2Normalize(Direction);

			}
			else
			{
				Direction = XMVector3Transform(Direction, rotationmatrix);
				Direction = XMVector2Normalize(Direction);
			}
		}
		else if (radiandifference > float(M_PI/2.0f)) 
		{
			rotationmatrix = XMMatrixRotationZ(-weight);

			if (epsilon <= (1.25f * weight))
			{
				Direction = differencevector;
				Direction = XMVector2Normalize(Direction);

			}
			else
			{
				Direction = XMVector3Transform(Direction, rotationmatrix);
				Direction = XMVector2Normalize(Direction);
			}
		}
	}
}