void CAXModel::UpdateMatrix(void)
{
	D3DXMATRIX matPosition;
	D3DXMATRIX matSize;
	D3DXMATRIX matRotate;
	D3DXMATRIX matAnchorPoint;
	D3DXMATRIX matComplate;
	
	D3DXMATRIX mT;
	{
		AVector3 vLeft(1.0f, 0.0f, 0.0f);
		AVector3 vUp(0.0f, 1.0f, 0.0f);
		AVector3 vLook(0.0f, 0.0f, 1.0f);
		AVector3 vUpNew, vLeftNew, vLookNew;
		D3DXMATRIX mX, mY, mZ;

		D3DXMatrixRotationX(&mX, m_fRotX);
		D3DXMatrixRotationY(&mY, m_fRotY);
		D3DXMatrixRotationZ(&mZ, -m_fRotZ);

		D3DXMatrixTranslation(&mT, vUp.x, vUp.y, vUp.z);
		mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mZ; vUpNew = AVector3(mT._41, mT._42, mT._43);

		D3DXMatrixTranslation(&mT, vLeft.x, vLeft.y, vLeft.z);
		mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mZ; vLeftNew = AVector3(mT._41, mT._42, mT._43);

		D3DXMatrixTranslation(&mT, vLook.x, vLook.y, vLook.z);
		mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mZ; vLookNew = AVector3(mT._41, mT._42, mT._43);

		mT._11 = vLeftNew.x;   mT._12 = vLeftNew.y;   mT._13 = vLeftNew.z;   mT._14 = 0.0f;		// Left Vector
		mT._21 = vUpNew.x;     mT._22 = vUpNew.y;     mT._23 = vUpNew.z;     mT._24 = 0.0f;		// Up Vector
		mT._31 = vLookNew.x;   mT._32 = vLookNew.y;   mT._33 = vLookNew.z;   mT._34 = 0.0f;		// Front Vector
		mT._41 = 0.0f;         mT._42 = 0.0f;         mT._43 = 0.0f;         mT._44 = 1.0f;		// Translation
	}

	D3DXMatrixTranslation(&matAnchorPoint, m_vAnchorPoint.x, m_vAnchorPoint.y, m_vAnchorPoint.z);
	D3DXMatrixScaling(&matSize, m_vSize.x, m_vSize.y, m_vSize.z);
	D3DXMatrixTranslation(&matPosition, m_vPosition.x, m_vPosition.y, m_vPosition.z);

	m_matComplate = matAnchorPoint * matSize * mT * matPosition;
	
	m_bUpdateMatrix = false;
}
Exemple #2
0
	const mtx& mtx::view(const vec3& pos, const vec3& at, const vec3& up)
	{
		vec3 vLook(at - pos);
		vLook.normalize();

		vec3 vRight(up.cross(vLook));
		vRight.normalize();

		vec3 vUp(vLook.cross(vRight));
		vUp.normalize();

		_11 = vRight.x ; _12 = vUp.x ; _13 = vLook.x ; _14 = 0.0f;
		_21 = vRight.y ; _22 = vUp.y ; _23 = vLook.y ; _24 = 0.0f;
		_31 = vRight.z ; _32 = vUp.z ; _33 = vLook.z ; _34 = 0.0f;

		_41 = -vRight.dot(pos);
		_42 = -vUp.dot(pos);
		_43 = -vLook.dot(pos);
		_44 = 1.0f;

		return *this;
	}
Exemple #3
0
void CRouter::MoveOn(D3DXVECTOR3 *vCurPos, float *angle, const float fSpeed, float fTime)
{
	if (m_pCurDest != NULL)
	{
		D3DXMATRIX mat;
		D3DXMATRIX mTrans;
		D3DXMatrixRotationY(&mat, *angle);
		D3DXMatrixTranslation(&mTrans, vCurPos->x, vCurPos->y, vCurPos->z);
		D3DXMatrixMultiply(&mat,&mat,&mTrans);

		if (m_pCurDest->pPrev->mode2Next == linear_mode)
		{
			MoveLinearly(vCurPos, &mat, fSpeed, fTime);
			if (IsPassBeyondPt(m_pCurDest->pPos, &mat))
			{
				m_pCurDest = m_pCurDest->pNext;
				PreparePath(TRUE, &mat, fSpeed);
			}

		}
		else
		{
			MoveCurvely(vCurPos, &mat, fSpeed, fTime);
			if(fabs(m_fAgl2Ajust) < 1e-4)
			{
				m_pCurDest = m_pCurDest->pNext;
				PreparePath(FALSE, &mat, fSpeed);
			}
		}

		D3DXVECTOR3 vLook(0,0,1);
		D3DXVec3TransformNormal(&vLook, &vLook, &mat);
		*angle = CaculateYaw(&vLook);
	}

}
//-----------------------------------------------------------------------------
void CPUTCameraControllerFPS::Update(float deltaSeconds)
{
    if( !mpCamera )
    {
        return;
    }
    float speed = mfMoveSpeed * deltaSeconds;
    if (keyPressed[KEY_SHIFT] == CPUT_KEY_DOWN || keyPressed[KEY_CTRL] == CPUT_KEY_DOWN) {
        speed *= 0.1f;
    }

    float4x4 *pParentMatrix = mpCamera->GetParentMatrix();

    float3 vRight(pParentMatrix->getXAxis());
    float3 vUp(pParentMatrix->getYAxis());
    float3 vLook(pParentMatrix->getZAxis());
    float3 vPositionDelta(0.0f);
    int    rotateX = 0;
    int    rotateY = 0;
    bool   bRotate = false;
    // Added the ability to toggle on/off rotation mode
    if (keyPressed[KEY_SPACE] == CPUT_KEY_DOWN) {
        bRotate = true;
    }
    if(keyPressed[KEY_W] == CPUT_KEY_DOWN) {
        vPositionDelta +=  vLook *  speed;
        rotateY = -1;
    }
    if(keyPressed[KEY_A] == CPUT_KEY_DOWN) {
        vPositionDelta += vRight * -speed;
        rotateX = -1;
    }
    if(keyPressed[KEY_S] == CPUT_KEY_DOWN) {
        vPositionDelta +=  vLook * -speed;
        rotateY = 1;
    }
    if(keyPressed[KEY_D] == CPUT_KEY_DOWN) {
        vPositionDelta += vRight *  speed;
        rotateX = 1;
    }
    if(keyPressed[KEY_E] == CPUT_KEY_DOWN) {
        vPositionDelta +=    vUp *  speed;
    }
    if(keyPressed[KEY_Q] == CPUT_KEY_DOWN) {
        vPositionDelta +=    vUp * -speed;
    }
    if (bRotate && (rotateX || rotateY))
    {
        // this lets you rotate the camera with the keyboard if you don't have a mouse. like if you only have one
        // usb slot available on a mobile.
        float nDeltaX = (float)(rotateX) * speed * 10.0f;
        float nDeltaY = (float)(rotateY) * speed * 10.0f;

        float4x4 rotationX = float4x4RotationX(nDeltaY*mfLookSpeed);
        float4x4 rotationY = float4x4RotationY(nDeltaX*mfLookSpeed);

        float3 position = mpCamera->GetPosition();
        mpCamera->SetPosition(0.0f, 0.0f, 0.0f); // Rotate about camera center
        float4x4 parent      = *mpCamera->GetParentMatrix();
        float4x4 orientation = rotationX  *parent * rotationY;
        orientation.orthonormalize();
        mpCamera->SetParentMatrix( orientation );
        mpCamera->SetPosition( position.x, position.y, position.z ); // Move back to original position
    }
    else
    {
        float x,y,z;
        mpCamera->GetPosition( &x, &y, &z );
        mpCamera->SetPosition( x+vPositionDelta.x, y+vPositionDelta.y, z+vPositionDelta.z );
    }
    mpCamera->Update();

    //Compute animation as an offset from the current position
    mpCamera->mPosition += float3( vPositionDelta.x, vPositionDelta.y, vPositionDelta.z );
    //END
    return;
}
HRESULT DXSourceWindow::Render(BufferQueue* pSyncBuffer,unsigned int uiTransferId)
{

	DXcopyApp::FrameData* pFrame = NULL;
    unsigned int uiBufferIdx = pSyncBuffer->getBufferForWriting((void*&)pFrame);

	//change the fill color
	float clearColorSource[4] = { m_clearColorR, m_clearColorG, m_clearColorB, 1.0f }; //red,green,blue,alpha

	//fill the backbuffer of the Source with 'clearColorR'
	m_pImmediateContext->ClearRenderTargetView( m_pBackBuffer_RTV, clearColorSource );
	m_pImmediateContext->ClearDepthStencilView( m_pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); 


	D3DXMATRIX mWorldViewProjection;
	D3DXMATRIX mWorldView;
    D3DXMATRIX mWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    
    // Set the per object constant data
	D3DXMatrixRotationAxis( &mWorld, &D3DXVECTOR3(1,1,1), m_Cube_angle  );
	
	m_Cube_angle += 0.04f * 0.01745f;
	
	if (m_Cube_angle >= 2.0f*3.1415926f) { m_Cube_angle = 0.0f; }

	D3DXVECTOR3 vEye( 0.0f, 0.0f, 2.0f );
	D3DXVECTOR3 vLook( 0.0f,0.0f,0.0f ); 
	D3DXVECTOR3 vUp( 0.0f,1.0f,0.0f );
	D3DXMatrixLookAtLH( &mView, &vEye, &vLook, &vUp );
	
	D3DXMatrixPerspectiveFovLH(&mProj, 3.1415926f/4.0f,  (float)DXwindow::m_width/(float)DXwindow::m_height,    0.1f, 10.0f);
	
	mWorldViewProjection = mWorld * mView * mProj;
	mWorldView			 = mWorld * mView;

	D3D11_MAPPED_SUBRESOURCE MappedResource;
	m_pImmediateContext->Map( m_Cube_pcb, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource );
	CUBE_CB* pCB = ( CUBE_CB* )MappedResource.pData;
	D3DXMatrixTranspose( &pCB->f4x4WorldViewProjection, &mWorldViewProjection );
	D3DXMatrixTranspose( &pCB->f4x4WorldView, &mWorldView );
	m_pImmediateContext->Unmap( m_Cube_pcb, 0 );

	m_pImmediateContext->VSSetConstantBuffers( 0, 1, &m_Cube_pcb );
	m_pImmediateContext->PSSetConstantBuffers( 0, 1, &m_Cube_pcb );

	m_pImmediateContext->VSSetShader( m_Cube_pVertexShader, NULL, 0 );
	m_pImmediateContext->PSSetShader( m_Cube_pPixelShader, NULL, 0 );

	m_pImmediateContext->IASetInputLayout( m_Cube_pVertexLayout11 );
	m_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	UINT Stride = sizeof( CUBE_Vertex1 );
	UINT Offset = 0;
	m_pImmediateContext->IASetVertexBuffers( 0, 1, &m_Cube_pVertexBuffer, &Stride, &Offset );
	m_pImmediateContext->IASetIndexBuffer( m_Cube_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );
	m_pImmediateContext->PSSetShaderResources( 0, 1, &m_Cube_pTextureRV );
	m_pImmediateContext->PSSetSamplers( 0, 1, &m_Cube_pSamplerLinear );
	m_pImmediateContext->DrawIndexed( 36, 0, 0 );


	// update frame data
	pFrame->uiTransferId = uiTransferId;

	m_pImmediateContext->CopyResource(m_source_SDItexture[uiBufferIdx], m_pBackBuffer );
	AmdDxMarkerInfo   m_pInfo;
	m_pInfo.markerValue = pFrame->uiTransferId;
	m_pInfo.markerOffset = pFrame->ullMarkerBusAddress & 0xfff;
 
	BOOL WriteMarkerSuccess = m_pSDI->WriteMarker11(m_source_SDItexture[uiBufferIdx], &m_pInfo);
	if ( !WriteMarkerSuccess ) { PASS_TEST(E_FAIL) }
 
	// This Flush() call is not necessary but with this one, the performance will be much better.
	m_pImmediateContext->Flush();
	pSyncBuffer->releaseWriteBuffer();
	m_pSwapChain->Present(0,0);


	return S_OK;
}