Example #1
0
Camera::Camera(HWND g_hWnd, GraphicsEngineParams params)
{
	this->forceBoundries = false;
	this->g_hWnd = g_hWnd;
	this->params = params;
	this->pos = D3DXVECTOR3(0, 0, 0);
	this->terrain = NULL;
	this->followTarget = NULL;
	this->moveOnlyInXZ = false;
	this->angleX = 0;
	this->angleY = 0;
	
	this->speed = 1.0f;
	this->sensitivity = 1.0f;

	this->updateCamera = true;
	this->activeWindowDisabling = true;

	D3DXMatrixPerspectiveFovLH(&this->projection, (float)D3DX_PI * this->params.FOV, this->params.windowWidth / (float)this->params.windowHeight, this->params.NearClip, this->params.FarClip);
}
Example #2
0
void DXCamera::Init()
{
	// world
	D3DXMatrixIdentity( &_world );

	// view
	_eyeVec = D3DXVECTOR3( 0.0f, 50, -70 ); // camera position
	_lookVec = D3DXVECTOR3( 0.0f, 30.0f, 0.0f ); // look at point
	_upVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );

	D3DXMatrixLookAtLH( &_view, &_eyeVec, &_lookVec, &_upVec );

	// projection
	D3DXMatrixPerspectiveFovLH( &_proj, FOV, 1.0f, NEAR_PLANE, FAR_PLANE );

	// transform camera
	D3D9_DEVICE->SetTransform( D3DTS_WORLD, &_world );
	D3D9_DEVICE->SetTransform( D3DTS_VIEW, &_view );
	D3D9_DEVICE->SetTransform( D3DTS_PROJECTION, &_proj );
}
VOID SetupMatrix()
{
	// Translate so the center of the box is the coordinate system origin.
	D3DXMATRIXA16 matWorld ;
	D3DXMatrixTranslation( &matWorld, -0.5f, -0.5f, 0.5f) ;
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

	// Set up view matrix
	D3DXVECTOR3 vEyePt( 0.0f, 3.0f, -5.0f );		
	D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );	
	D3DXVECTOR3 vUpVec( 0.0f, 3.0f, 0.0f );	
	D3DXMATRIXA16 matView;
	D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
	g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

	// Set up perspective matrix
	D3DXMATRIXA16 matProj;
	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
	g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
Example #4
0
//-----------------------------------------------------------------------------
// Desc: 设置变换矩阵
//-----------------------------------------------------------------------------
VOID SetMatrices()
{
	//建立并设置世界矩阵
	D3DXMATRIX matWorld;
	D3DXMatrixIdentity( &matWorld );
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

	//建立并设置观察矩阵
	D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
	D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
	D3DXMATRIX matView;
	D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
	g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

	//建立并设置投影矩阵
	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
	g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
Example #5
0
BOOL jcd3d::jcd3d_setProjectionPerspectiveTransform(LPDIRECT3DDEVICE9 lpd3dd, INT windowWidth, INT windowHeight)
{
	if(lpd3dd == NULL)
	{
		return NULL;
	}
	else
	{
		D3DXMATRIX out;
		D3DXMatrixPerspectiveFovLH(&out, D3DX_PI * 0.5f, (FLOAT)windowWidth / (FLOAT)windowHeight, 1.0f, 1000.0f);
		if(FAILED(lpd3dd->SetTransform(D3DTS_PROJECTION, &out)))
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
}
Example #6
0
//------------------------------------------------------------------
// Storm3D_Camera::ApplyMirrored
//------------------------------------------------------------------
void Storm3D_Camera::ApplyMirrored()
{
	// Create View matrix
    D3DXMatrixLookAtLH(&mv,(D3DXVECTOR3*)&position,
		(D3DXVECTOR3*)&target,(D3DXVECTOR3*)&upvec);    
	Storm3D2->GetD3DDevice()->SetTransform(D3DTS_VIEW,&mv);

	// Calc aspect!
	Storm3D_SurfaceInfo ss=Storm3D2->GetScreenSize();
	float aspect=(float)ss.width/(float)ss.height;

	// Create Projection matrix
    D3DXMATRIX matProj;
    //D3DXMatrixPerspectiveFovLH(&matProj,fov,-aspect,1.0f,vis_range);
    D3DXMatrixPerspectiveFovLH(&matProj,fov,-aspect,znear,vis_range);
	Storm3D2->GetD3DDevice()->SetTransform(D3DTS_PROJECTION,&matProj);

	// Multiply matrices to get VP (view-projection) matrix
	vp=mv*matProj;
}
/**-----------------------------------------------------------------------------
 * 행렬 설정
 *------------------------------------------------------------------------------
 */
void InitMatrix()
{
	/// 월드 행렬 설정
	D3DXMatrixIdentity( &g_matWorld );
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld );

    /// 뷰 행렬을 설정
    D3DXVECTOR3 vEyePt( 100.0f, 100.0f, -130.0f );
    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
    D3DXMatrixLookAtLH( &g_matView, &vEyePt, &vLookatPt, &vUpVec );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &g_matView );

    /// 프로젝션 행렬 설정
    D3DXMatrixPerspectiveFovLH( &g_matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_matProj );

	/// 카메라 초기화
	g_pCamera->SetView( &vEyePt, &vLookatPt, &vUpVec );
}
Example #8
0
void SetupProjectiveTransform(D3DXVECTOR3 &From, D3DXVECTOR3 &To, float HotSpotA)
{
 D3DXMATRIX V, InvV;
 D3DXMATRIX matTexScale;
 D3DXMATRIX m_matTex2;
 D3DXMATRIX m_matLightProj, m_matLightView;

 D3DXVECTOR3 vUp;
 vUp.x = 0;
 vUp.y = 1;
 vUp.z = 0;

 // Set the light projection matrix.

 D3DXMatrixPerspectiveFovLH( &m_matLightProj, R3D_DEG2RAD(HotSpotA), 1.33f, r3dRenderer->NearClip, r3dRenderer->FarClip ); //1.0f, 20000.0f);

    
 // Set the light view matrix.
 D3DXMatrixLookAtLH( &m_matLightView, &From, &To, &vUp);

 // This will scale and offset -1 to 1 range of x, y
 // coords output by projection matrix to 0-1 texture
 // coord range.
    ZeroMemory( &matTexScale, sizeof( D3DMATRIX ) );
    matTexScale._11 = 0.5f;
    matTexScale._22 = 0.5f;
    matTexScale._33 = 0.0f; 
    matTexScale._41 = 0.5f; 
    matTexScale._42 = 0.5f;
    matTexScale._43 = 0.5f; 
    matTexScale._44 = 1.0f;


    D3DXMATRIX mat, mat2;
    D3DXMatrixMultiply( &mat, &m_matLightProj, &matTexScale );
    D3DXMatrixMultiply( &mat2, &m_matLightView, &mat ); 

  D3DXMatrixTranspose( &mat2, &mat2 );

  r3dRenderer->pd3ddev->SetVertexShaderConstantF(  20, (float *)&mat2,  4 );
}
Example #9
0
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RestoreDeviceObjects()
{
    m_pFont->RestoreDeviceObjects();

    // Setup render state
    m_pd3dDevice->SetRenderState( D3DRS_LIGHTING,     TRUE );
    m_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
    m_pd3dDevice->SetRenderState( D3DRS_ZENABLE,      TRUE );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );

    // Setup the light
    D3DLIGHT8 light;
    light.Type         = D3DLIGHT_DIRECTIONAL;
    light.Diffuse.r    = light.Diffuse.g  = light.Diffuse.b  = 1.0f;
    light.Specular.r   = light.Specular.g = light.Specular.b = 0.0f;
    light.Ambient.r    = light.Ambient.g  = light.Ambient.b  = 0.3f;
    light.Position     = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
    D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &D3DXVECTOR3( 0.3f, -1.0f, 1.0f ) );
    light.Attenuation0 = light.Attenuation1 = light.Attenuation2 = 0.0f;
    light.Range        = sqrtf(FLT_MAX);
    m_pd3dDevice->SetLight(0, &light );
    m_pd3dDevice->LightEnable(0, TRUE );

    m_ArcBall.SetWindow( m_d3dsdBackBuffer.Width, m_d3dsdBackBuffer.Height, 0.85f );
    m_ArcBall.SetRadius( m_fObjectRadius );

    FLOAT fAspect = m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height;

    D3DXMATRIX matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, m_fObjectRadius/64.0f,
                                m_fObjectRadius*200.0f);
    m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

    // update the local copies of the meshes
    UpdateLocalMeshes(&m_MeshAttrSorted);
    UpdateLocalMeshes(&m_MeshStripReordered);
    UpdateLocalMeshes(&m_MeshVertexCacheOptimized);

    return S_OK;
}
Example #10
0
void DX9Renderer::Draw()
{
	m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);
	
	m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
	
	if (SUCCEEDED(m_pD3DDevice->BeginScene()))
	{
		D3DXMATRIX matWorld, matView, matProj;
		
		D3DXMatrixIdentity(&matWorld);
		
		D3DXVECTOR3 vEyePt( 0.0f, 0.0f, -5.0f );
		D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
		D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
		D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );

		float aspectRatio = ((float)800) / ((float)600);
		D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, aspectRatio, 1.0f, 100.0f );

		m_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
		m_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);
		m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);

		RenderableObjectListPtr list = this->GetRenderableObjectList();
		for (unsigned int i = 0; i < list->RenderableObjectNum(); i++)
		{
			DX9RenderableObject* obj = reinterpret_cast<DX9RenderableObject*>(list->GetRenderableObject(i).get());
			m_pD3DDevice->SetFVF(obj->GetFVF());

			m_pD3DDevice->SetStreamSource(0, (DX9::VertexBuffer)obj->GetVertexBuffer(), 0, obj->GetVertexSize());
			m_pD3DDevice->SetIndices((DX9::IndexBuffer)obj->GetIndexBuffer());
			m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, obj->GetVertexNum(), 0, obj->GetIndexNum());
		}

		m_pD3DDevice->EndScene();
	}

	m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
VOID SetupMatrix()
{
	// Translate so the center of the box is the coordinate system origin.
	D3DXMATRIXA16 matTrans ;
	D3DXMatrixTranslation( &matTrans, -0.5f, -0.5f, 0.5f) ;

	// rotation by time elapsed
	D3DXMATRIXA16 matRol ;
	UINT  iTime  = timeGetTime() % 1000;
	FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;


	if( g_rotAxis == 4 )	// rotate by x-axis.
		D3DXMatrixRotationX( &matRol, fAngle );

	else if( g_rotAxis == 2 ) // rotate by y-axis.
		D3DXMatrixRotationY( &matRol, fAngle );

	else if( g_rotAxis == 1 ) // rotate by z-axis.
		D3DXMatrixRotationZ( &matRol, fAngle );

	else
		D3DXMatrixIdentity( &matRol ) ; // hold on

	D3DXMATRIXA16 matWorld = matTrans * matRol ;
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

	// Set up view matrix
	D3DXVECTOR3 vEyePt( 0.0f, 3.0f, -5.0f );		
	D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );	
	D3DXVECTOR3 vUpVec( 0.0f, 3.0f, 0.0f );	
	D3DXMATRIXA16 matView;
	D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
	g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

	// Set up perspective matrix
	D3DXMATRIXA16 matProj;
	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
	g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

}
Example #12
0
void SetViewAndProjMatrix()
{
	D3DXVECTOR3 vEyePt(0.0f,10.0f,-10.0f);
	D3DXVECTOR3 vLookatPt(0.0f,0.0f,0.0f);
	D3DXVECTOR3 vUpVec(0.0f,1.0f,0.0f);
	D3DXMATRIXA16 matView;
	D3DXMatrixLookAtLH(&matView,&vEyePt,&vLookatPt,&vUpVec);
	d3d.GetD3DDevice()->SetTransform(D3DTS_VIEW,&matView);

	D3DXMATRIXA16 matProj;
	D3DXMatrixPerspectiveFovLH(&matProj,D3DX_PI/4,1.0f,1.0f,100.0f);
	d3d.GetD3DDevice()->SetTransform(D3DTS_PROJECTION,&matProj);

	//设置纹理过虑
	//d3d.GetD3DDevice()->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);
	//d3d.GetD3DDevice()->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
	//各项异性
	//d3d.GetD3DDevice()->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_ANISOTROPIC);
	//d3d.GetD3DDevice()->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_ANISOTROPIC);
	//d3d.GetD3DDevice()->SetSamplerState(0,D3DSAMP_MAXANISOTROPY,8);
}
Example #13
0
void DrawScence::SetViewProjectionMatrix()
{
	D3DXMATRIX matView;
	D3DXMatrixLookAtLH(&matView,
					   &m_Camera.g_vPos,
					   &m_Camera.g_vViewAt,
					   &m_Camera.g_vUp);
	m_pD3DDevice->SetTransform(D3DTS_VIEW,&matView);

	CRect rect;
	GetWindowRect(m_hWnd,&rect);

	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH(&matProj,
							   D3DX_PI * 0.5,
							   1.0f * rect.Width() / rect.Height(),
							   1.0f,
							   10000.0f);
	m_pD3DDevice->SetTransform(D3DTS_PROJECTION,&matProj);

}
Example #14
0
void SetupMatrix()
{
	// translate model to origin
	D3DXMATRIX world ;
	D3DXMatrixTranslation(&world, 0.0f, 0.0f, 0.0f) ;
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &world) ;

	// set view
	D3DXVECTOR3 upVec(0.0f, 1.0f, 0.0f) ;
	D3DXVECTOR3 lookCenter(0.0f, 0.0f, 0.0f) ;
	D3DXVECTOR3 eyePt(0.0f, 0.0f, -20.0f) ;

	D3DXMATRIX view ;
	D3DXMatrixLookAtLH(&view, &eyePt, &lookCenter, &upVec) ;
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &view) ;

	// set projection
	D3DXMATRIX proj ;
	D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4, 1.0f, 1.0f, 1000.0f) ;
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &proj) ;
}
//-----------------------------------------------------------------------------
// Desc: 设置变换矩阵
//-----------------------------------------------------------------------------
VOID SetupMatrices()
{
	//创建并设置世界矩阵
	D3DXMATRIXA16 matWorld;
	D3DXMatrixIdentity(&matWorld);
	D3DXMatrixRotationY(&matWorld, timeGetTime() / 2000.0f);
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);

	//创建并设置观察矩阵
	D3DXVECTOR3 vEyePt(0.0f, 0.0f, -20);
	D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f);
	D3DXMATRIXA16 matView;
	D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);

	//创建并设置投影矩阵
	D3DXMATRIXA16 matProj;
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 2, 1.0f, 0.0f, 100.0f);
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
}
Example #16
0
//
// Framework Functions
//
bool Setup()
{
	//
	// Create the teapot geometry.
	//

	D3DXCreateTeapot(g_device, &Teapot, 0);

	//
	// Position and aim the camera.
	//

	D3DXVECTOR3 position(0.0f, 0.0f, -3.0f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
    D3DXMATRIX V;
	D3DXMatrixLookAtLH(&V, &position, &target, &up);
	g_device->SetTransform(D3DTS_VIEW, &V);

	//
	// Set projection matrix.
	//

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
			&proj,
			D3DX_PI * 0.5f, // 90 - degree
			(float)Width / (float)Height,
			1.0f,
			1000.0f);
	g_device->SetTransform(D3DTS_PROJECTION, &proj);

	//
	// Switch to wireframe mode.
	//

	g_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

	return true;
}
Example #17
0
// Setup the renderer for really close drawing
void d3d_SetReallyClose(CReallyCloseData* pData)
{
	assert(pData);

	D3DMATRIX mIdentity = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};

	//preserve our old viewport
	PD3DDEVICE->GetViewport(&pData->m_OldViewport);

	// view port min-max Z change for pv model.
	D3DVIEWPORT9 ViewportData;
	ViewportData.X		= pData->m_OldViewport.X;
	ViewportData.Y		= pData->m_OldViewport.Y;
	ViewportData.Width	= pData->m_OldViewport.Width;
	ViewportData.Height = pData->m_OldViewport.Height;
	ViewportData.MinZ	= 0;
	ViewportData.MaxZ	= 0.1f;


	PD3DDEVICE->SetViewport(&ViewportData);

	float aspect = g_ViewParams.m_fScreenWidth / g_ViewParams.m_fScreenHeight;

	// Setup the projection transform by using the power of D3D.
	D3DXMATRIX NewProj;

	D3DXMatrixPerspectiveFovLH(&NewProj,
							   g_CV_PVModelFOV.m_Val * 0.01745329251994f, // convert degrees to rad on the fly.
							   aspect,
							   g_CV_ModelNear.m_Val,
							   g_CV_ModelFar.m_Val);

	//save the old transforms
	PD3DDEVICE->GetTransform(D3DTS_PROJECTION, &pData->m_OldProj);
	PD3DDEVICE->GetTransform(D3DTS_VIEW, &pData->m_OldView);

	//setup the new matrices
	PD3DDEVICE->SetTransform(D3DTS_PROJECTION, &NewProj);
	PD3DDEVICE->SetTransform(D3DTS_VIEW, &mIdentity);
}
Example #18
0
// Sets the projection matrix which dictates how our 3D scene is projected onto our 2D monitor
void CD3DObj::setProjMatrix(float fov, float nearClip, float farClip)
{
	assert(mEffect != NULL);
	
	// Create the projection matrix
	D3DXMATRIXA16 matrix;
	
	mFOV = fov;
	mNearClip = nearClip;
	mFarClip = farClip;
	
	// Create projection matrix
	D3DXMatrixPerspectiveFovLH(&matrix, mFOV, mAspectRatio, mNearClip, mFarClip);
	
	// Set the projection matrix
	mResult = mDevice->SetTransform(D3DTS_PROJECTION, &matrix);
	assert(mResult == D3D_OK);
	
	// Set the projection matrix in the shader
	mResult = mEffect->SetMatrix("gProjMat", &matrix);
	assert(mResult == D3D_OK);
}
Example #19
0
void render()
{
   if(ball.state==GAME)
   {
      matrix proj,view,world;
      D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI/2.5, (float)width/height, 0.1f, 50.0f );
      SET_M(D3DTS_PROJECTION,proj);
      D3DXMatrixLookAtLH(&view,&vector(0,0,-10),&vector(0,0,0),&vector(0,1,0));
      SET_M(D3DTS_VIEW,view);
      trans(world,-clamp(ball.pers.x,top.x,bottom.x)/32,clamp(ball.pers.y,top.y,bottom.y)/32,0);
      SET_M(D3DTS_WORLD,world);
      ball.draw();
      gx->calc_fps();
   }
   else if(ball.state==MENU)
   {
      ball.render_menu();
   }
   //char buf[32];
   //sprintf(buf,"%i",ball.nomer);
   //SetWindowText(gx->handle,buf);
}
Example #20
0
	void Renderer::Initialise()
	{
		D3DXVECTOR3 viewVectors[3] =
		{
			D3DXVECTOR3(0.0f, 0.0f, -5.0f),	//eye
			D3DXVECTOR3(0.0f, 0.0f, 1.0f),	//look at
			D3DXVECTOR3(0.0f, 1.0f, 0.0f)	//up
		};

		D3DXMATRIXA16 viewMatrix;
		D3DXMatrixLookAtLH(&viewMatrix, &viewVectors[0], &viewVectors[1], &viewVectors[2]);
		mDevice->SetTransform(D3DTS_VIEW, &viewMatrix);

		// Setting to perspective...
		D3DXMATRIXA16 projectionMatrix;
		D3DXMatrixPerspectiveFovLH(&projectionMatrix, D3DX_PI / 4.0f, (float)mPresentParameters.BackBufferHeight / (float)mPresentParameters.BackBufferHeight, 0.5f, 100.0f);
		
		mDevice->SetRenderState(D3DRS_LIGHTING, false);
		mDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
	}
//
// Framework Functions
//
bool Setup()
{
    //
    // Create the terrain.
    //

    D3DXVECTOR3 lightDirection(0.0f, 1.0f, 0.0f);
    TheTerrain = new Terrain(Device, "castlehm257.raw", 257, 257, 1, 0.2f);
    TheTerrain->genTexture(&lightDirection);

    //
    // Create the font.
    //

    FPS = new FPSCounter(Device);

    //
    // Set texture filters.
    //

    Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
    Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
    Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

    //
    // Set projection matrix.
    //

    D3DXMATRIX proj;
    D3DXMatrixPerspectiveFovLH(
        &proj,
        D3DX_PI * 0.25f, // 45 - degree
        (float)Width / (float)Height,
        1.0f,
        1000.0f);
    Device->SetTransform(D3DTS_PROJECTION, &proj);

    return true;
}
Example #22
0
Renderer::Renderer(HINSTANCE hInstance,
  HWND hWnd) :
    m_pDevice(NULL),
    m_pVB(NULL),
    m_pIB(NULL),
    m_pVBInstanceData(NULL),
    m_pVertexDeclHardware(NULL),
    m_pSphere(NULL)
{
  D3DXMatrixIdentity(&m_View);
  D3DXMatrixIdentity(&m_Projection);
  m_hInstance = hInstance;
  m_hWnd = hWnd;

  m_VecEye = D3DXVECTOR3(2.0f, 2.0f, 10.0f);

  D3DXVECTOR3 vecAt (0.0f, 0.0f, 0.0f);
  D3DXVECTOR3 vecUp (0.0f, 1.0f, 0.0f);

  D3DXMatrixPerspectiveFovLH(&m_Projection, (40.0f/180.0f)*D3DX_PI, 1.0f, 0.1f, 25.0f);
  D3DXMatrixLookAtLH( &m_View, &m_VecEye, &vecAt, &vecUp );
}
Example #23
0
int		CObjectRightView::SetupMatrices()
{
    // For our world matrix, we will just leave it as the identity
    D3DXMATRIX	matWorld;
    D3DXMatrixIdentity( &matWorld );
	
	matWorld._22 = -1.0f;

	D3DXVec3TransformCoord((D3DXVECTOR3 *) &matWorld._41, &m_vecOrigin, &matWorld);

	if( FAILED( g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ) ) ) {
		DirectXStatus = -1;
		return	1;
	}


    // For the projection matrix, we set up a perspective transform (which
    // transforms geometry from 3D view space to 2D viewport space, with
    // a perspective divide making objects smaller in the distance). To build
    // a perpsective transform, we need the field of view (1/4 pi is common),
    // the aspect ratio, and the near and far clipping planes (which define at
    // what distances geometry should be no longer be rendered).
    D3DXMATRIX matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4,  (float) m_iWidth/(float) m_iHeight, 0.03f, 10.0f );
	if( FAILED( g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ) ) ) {
		DirectXStatus = -1;
		return	1;
	}

	D3DXMATRIXA16 matrix;
	//Calculate the new view matrix for the camera
	g_Camera->calculateViewMatrix(&matrix);
	
	if( FAILED( g_pd3dDevice->SetTransform( D3DTS_VIEW, &matrix ) ) ) {
		DirectXStatus = -1;
	}

	return	0;
}
void SetupMatrix()
{
	// Set object position
	D3DXMatrixTranslation(&matWorld[0], -2.0f, 0.0f, 0.0f) ;
	D3DXMatrixTranslation(&matWorld[1], 2.0f, 0.0f, 0.0f) ;
	D3DXMatrixTranslation(&matWorld[2], 0.0f, 2.0f, 0.0f) ;
	D3DXMatrixTranslation(&matWorld[3], 0.0f, -2.0f, 0.0f) ;

	// set view
	D3DXVECTOR3 eyePt(0.0f, 0.0f, -10.0f) ;
	D3DXVECTOR3 upVec(0.0f, 1.0f, 0.0f) ;
	D3DXVECTOR3 lookCenter(0.0f, 0.0f, 0.0f) ;

	D3DXMATRIX view ;
	D3DXMatrixLookAtLH(&view, &eyePt, &lookCenter, &upVec) ;
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &view) ;

	// set projection
	D3DXMATRIX proj ;
	D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4, 1.0f, 1.0f, 1000.0f) ;
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &proj) ;
}
Example #25
0
void D3DBase::resetViewport(float width, float height)
{
	if (m_swapChain)
	{
		m_deviceContext->OMSetRenderTargets(0, 0, 0);        
        m_renderTargetView.ReleaseAndGetAddressOf();
		
		HRESULT hr = m_swapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);

		// Add error handling

		// Get buffer and create a render target view
		ID3D11Texture2D* pBuffer;
		hr = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**) &pBuffer);

		hr = m_device->CreateRenderTargetView(pBuffer, NULL, m_renderTargetView.ReleaseAndGetAddressOf());

		pBuffer->Release();

        m_deviceContext->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), NULL);
        // setBackBufferRenderTarget();
		
		// Setup projection matrix
		float fov = (float) D3DX_PI / 4.0f;
		float aspectRatio = width / height;
		D3DXMatrixPerspectiveFovLH(&m_projectionMatrix, fov, aspectRatio, 1.0f, 1000.0f);
		
		// Setup the viewport
		D3D11_VIEWPORT viewport;
		viewport.Width = width;
		viewport.Height = height;
		viewport.MinDepth = 0.0f;
		viewport.MaxDepth = 1.0f;
		viewport.TopLeftX = 0;
		viewport.TopLeftY = 0;

		m_deviceContext->RSSetViewports(1, &viewport);
	}	
}
Example #26
0
VOID SetupMatrices()
{
	// 旋转
	D3DXMATRIXA16 matWorld;
	D3DXMatrixIdentity( &matWorld );
	//根据x轴和y轴移动距离旋转
	setupRotate(&matWorld,D3DXToRadian(g_fSpinX),D3DXToRadian(g_fSpinY),0.0f);
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

	// 摄像机的位置
	D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
	D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
	D3DXMATRIXA16 matView;
	D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
	g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

	// 设置视锥体大小
	D3DXMATRIXA16 matProj;
	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
	g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
void TransformationClass::Initialize(HWND hwnd)
{
	m_screenDepth = 100.0f;
	m_screenNear = 1.0f;

	//Obtain window dimensions from the haddle
	RECT dimensions;
	GetClientRect(hwnd, &dimensions);
	m_screenWidth = dimensions.right - dimensions.left;
	m_screenHeight = dimensions.bottom - dimensions.top;

	// Setup the projection matrix.
	float fieldOfView, screenAspect;
	fieldOfView = D3DX_PI / 4.0f;
	screenAspect = (float)m_screenWidth / (float)m_screenHeight;

	// Create the projection matrix for 3D rendering.
	D3DXMatrixPerspectiveFovLH(&m_projectionMatrix, fieldOfView, screenAspect, m_screenNear, m_screenDepth);

	// Create an orthographic projection matrix for 2D rendering.
	//m_orthoMatrix = XMMatrixOrthographicLH((float)m_screenWidth, (float)m_screenHeight, m_screenNear, m_screenDepth);
}
Example #28
0
void dxCamera::setTransforms(const enMatrix& mat)
{
	dxDeviceInfo info(Device);

// World:

	D3DXMATRIX world;

	D3DXMatrixTranslation(&world, 0, 0, 0);

	Device->SetTransform(D3DTS_WORLD, &world);

// View:

	D3DXMATRIX	view;
	D3DXVECTOR3	eye(mat.P.X, mat.P.Y, mat.P.Z);
	D3DXVECTOR3	at(mat.P.X + mat.Z.X, mat.P.Y + mat.Z.Y, mat.P.Z + mat.Z.Z);
	D3DXVECTOR3	up(mat.Y.X, mat.Y.Y, mat.Y.Z);

	D3DXMatrixLookAtLH(&view, &eye, &at, &up);

	Device->SetTransform(D3DTS_VIEW, &view);

// Get aspect:

	int rw, rh;

	info.getRenderTargetSize(rw, rh);

	float aspect = (float) rw / (float) rh;

// Proj:

	D3DXMATRIX proj;

	D3DXMatrixPerspectiveFovLH(&proj, 3.14159265f / 4, aspect, 0.01f, 4000);

	Device->SetTransform(D3DTS_PROJECTION, &proj);
}
Example #29
0
void CD3DDevice::MatrixSet()
{
	D3DXMATRIX matView;
	D3DXVECTOR3 vEye(0.0f, 0.0f, -50.0f);
	D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp);
	m_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);

	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 6.0f, 1.0f, 1.0f, 1000.0f);
	m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);
	
	D3DVIEWPORT9 viewPort;
	viewPort.X = 0;
	viewPort.Y = 0;
	viewPort.Width = WINDOW_WIDTH;
	viewPort.Height = WINDOW_HEIGHT;
	viewPort.MinZ = 0.0f;
	viewPort.MaxZ = 1.0f;
	m_pD3DDevice->SetViewport(&viewPort);
}
Example #30
0
/*
 * constructor
 */
Camera::Camera(int screenWidth, int screenHeight) {
	// initialise the camera positions
	position	= D3DXVECTOR3(0.0f, 0.0f, 0.0f);

	// initialise the aim positions
	aim.x		= 0.0f;
	aim.y		= 0.0f;

	// set the view point away from the camera
	aim.z		= 20.0f;

	// set the up direction
	upDirection	= D3DXVECTOR3(0.0f, 1.0f, 0.0f);

	// set the projection
	D3DXMatrixPerspectiveFovLH(
		&matProjection,						// projection transform matrix
		D3DXToRadian(45),					// horizontal field of view
		(float) screenWidth / screenHeight,	// aspect ratio
		1.0f,								// near view-plane
		100.0f								// far view-plane
	);
}