void Camera::Update()
{
	D3DXMATRIXA16 matRotationX, matRotationY;
	D3DXMATRIXA16 matRotation;
	D3DXMatrixRotationX(&matRotationX, camRotX);
	D3DXMatrixRotationY(&matRotationY, camRotY);
	matRotation = matRotationX * matRotationY;

	eyePosition = D3DXVECTOR3(0, 0, -camDistance);
	D3DXVec3TransformCoord(&eyePosition, &eyePosition, &matRotation);
	if ( lookTarget )
	{
		lookAt = (*lookTarget);
		eyePosition = (*lookTarget) + eyePosition;
	}
	
	D3DXMatrixLookAtLH(&matView, &eyePosition, &lookAt, &upVector);
	GameManager::GetDevice()->SetTransform(D3DTS_VIEW, &matView);

}
/**-----------------------------------------------------------------------------
 * 행렬 설정
 *------------------------------------------------------------------------------
 */
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 );
}
Esempio n. 3
0
// Sets up the view of the scene based on passed in eye and target
void CD3DObj::setViewMatrix(const CPos &eye, const CPos &lookAt)
{
	assert(mEffect != NULL);

	D3DXMATRIXA16 matrix;
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); // World's up vector

	// Create the view matrix
	// **NOTE** We can cast to (D3DXVECTOR3*) because our CPos has it's data members (x,y,z)
	// declared the same way a D3DXVECTOR3 does
	D3DXMatrixLookAtLH(&matrix, (D3DXVECTOR3*)(&eye), (D3DXVECTOR3*)(&lookAt), &up);
	
	// Set the view matrix for fixed function pipeline
	mResult = mDevice->SetTransform(D3DTS_VIEW, &matrix);
	assert(mResult == D3D_OK);
	
	// Set the view matrix for shader
	mResult = mEffect->SetMatrix("gViewMat", &matrix);
	assert(mResult == D3D_OK);
}
Esempio n. 4
0
void Render()
{
	float angle = timeGetTime() % 10000 * 1.f / 10000 * 2 * D3DX_PI ;
	int r = 3;
	D3DXVECTOR3 pos(cos(angle) * r, 0.f, sin(angle) * r);
	D3DXVECTOR3 target(0.f, 0.f, 0.f);
	D3DXVECTOR3 up(0.f, 1.f, 0.f);
	D3DXMATRIX matrixView;
	D3DXMatrixLookAtLH(&matrixView, &pos, &target, &up);
	pDevice->SetTransform(D3DTS_VIEW, &matrixView);

	pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 220, 0, 255), 1.0f, 0);
	pDevice->SetStreamSource(0, VB, 0, sizeof(Vertex));	//4 将顶点缓存与数据流进行链接,
	pDevice->SetFVF(Vertex::FVF);						//5 设置顶点格式
			
	pDevice->BeginScene();
	pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);	//6 绘制
	pDevice->EndScene();
	pDevice->Present(NULL, NULL, NULL, NULL);
}
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 );
}
Esempio n. 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;
}
Esempio n. 7
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 );
}
Esempio n. 8
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 );
}
Esempio n. 9
0
void setCameraMatrix(IDirect3DDevice9 * device)
{
	D3DXMATRIX cameraMatrix;
	D3DXMatrixRotationYawPitchRoll(&cameraMatrix, cameraYaw, 0, 0);
	D3DXVECTOR3 transTemp;
	D3DXVec3TransformCoord(&transTemp, &move, &cameraMatrix);
	cameraPos += transTemp;

	D3DXMatrixRotationYawPitchRoll(&cameraMatrix, cameraYaw, cameraPitch, cameraRoll);

	D3DXVec3TransformCoord(&cameraTarget, &D3DXVECTOR3(0, 0, -1), &cameraMatrix);
	D3DXVec3TransformCoord(&cameraUpVector, &D3DXVECTOR3(0, 1, 0), &cameraMatrix);

	D3DXVECTOR3 targetTemp = cameraTarget + cameraPos;

	D3DXMatrixLookAtLH(&cameraMatrix, &cameraPos, &targetTemp, &cameraUpVector);
	device->SetTransform(D3DTS_VIEW, &cameraMatrix);

	move = D3DXVECTOR3(0, 0, 0);
}
Esempio n. 10
0
    void Camera::lookAt(const D3DXVECTOR3& eye, const D3DXVECTOR3& at, const D3DXVECTOR3& up)
    {
        D3DXVECTOR3 axisUp = up;
        D3DXVECTOR3 axisTo = (at-eye);
        //check if up and  at - eye is perpendicular. If not, make them.
        if( D3DXVec3Dot(&axisUp,&axisTo) != 0)
        {
            D3DXVECTOR3 temp;
            D3DXVec3Cross(&temp, &axisUp, &axisTo);
            D3DXVec3Cross(&axisUp, &axisTo, &temp);
        }
        D3DXVec3Normalize(&axisUp, &axisUp);
        D3DXVec3Normalize(&axisTo, &axisTo);

        D3DXMatrixIdentity(&m_viewMatrix);
        D3DXMatrixLookAtLH(&m_viewMatrix,&eye,&at,&axisUp);

        //calculate transforms
        m_translation = -eye;
        D3DXVECTOR3 ref = D3DXVECTOR3(0,0,1);
        D3DXVECTOR3 rotAxis;
        D3DXVec3Cross(&rotAxis,&axisTo,&ref);
        D3DXVec3Normalize(&rotAxis, &rotAxis);
        float angle;
        

        angle = acos(D3DXVec3Dot( &ref, &axisTo ))*0.5f;

        m_orientation = D3DXQUATERNION(sin(angle)*rotAxis.x, sin(angle)*rotAxis.y, sin(angle)*rotAxis.z, cos(angle));

        //check if up vector is still "up"
        
        D3DXVECTOR3 rotatedUp = MathUtil::rotateVec3ByQuat(&axisUp, &m_orientation);
        if(D3DXVec3Dot(&rotatedUp,&up)<0)
        {
            m_orientation = D3DXQUATERNION(axisTo.x*sin(MathUtil::PI*0.5f),axisTo.y*sin(MathUtil::PI*0.5f), axisTo.z*sin(MathUtil::PI*0.5f), cos(MathUtil::PI*0.5f)) * m_orientation;
        }


        m_viewCacheValid = true;
    }
Esempio n. 11
0
//////////////////////////////////////////////////////////////////////////////////////////
//			Mise a jour																	//
//////////////////////////////////////////////////////////////////////////////////////////
void CCamera::Update()
{
	D3DXVECTOR3 up, position, lookAt;
	float yaw, pitch, roll;
	D3DXMATRIX rotationMatrix;

	// Defini l'axe qui symbolise la verticalite, Y
	up.x = 0.0f;
	up.y = 1.0f;
	up.z = 0.0f;

	// Position de la cam
	position.x = m_positionX;
	position.y = m_positionY;
	position.z = m_positionZ;

	// Endroit ou la cam regarde
	lookAt.x = 0.0f;
	lookAt.y = 0.0f;
	lookAt.z = 1.0f;

	// Yaw (Y axis), pitch (X axis), et roll (Z axis) en radians
	pitch = m_rotationX * 0.0174532925f;
	yaw   = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;

	// Cree la matrice de rotation pour les yaw/pitch/roll
	D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);

	// Transferme les vecteurs lookAt et Up via la matrice de rotation pour que l'angle de vue soit correcte
	D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
	D3DXVec3TransformCoord(&up, &up, &rotationMatrix);

	// Relativise la direction de vue par rapport a la position de la cam
	lookAt = position + lookAt;

	// Cree la matrice a partir des trois vecteurs
	D3DXMatrixLookAtLH(&m_viewMatrix, &position, &lookAt, &up);

	return;
}
Esempio n. 12
0
void CameraClass::Render()
{
	D3DXVECTOR3 up, position, lookAt;
	float yaw, pitch, roll;
	D3DXMATRIX rotationMatrix;

	// Setup the vector that points upwards.
	up.x = 0.0f;
	up.y = 1.0f;
	up.z = 0.0f;

	// Setup the position of the camera in the world.
	position.x = m_positionX;
	position.y = m_positionY;
	position.z = m_positionZ;

	// Setup where the camera is looking by default.
	lookAt.x = 0.0f;
	lookAt.y = 0.0f;
	lookAt.z = 1.0f;

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotationX * 0.0174532925f;
	yaw   = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;

	// Create the rotation matrix from the yaw, pitch, and roll values.
	D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
	D3DXVec3TransformCoord(&up, &up, &rotationMatrix);

	// Translate the rotated camera position to the location of the viewer.
	lookAt = position + lookAt;

	// Finally create the view matrix from the three updated vectors.
	D3DXMatrixLookAtLH(&m_viewMatrix, &position, &lookAt, &up);

	return;
}
void c_Camera::UpdateCameraNormal(void)
{
	//位置情報マトリックス生成
	D3DXMATRIX matrix;
	D3DM_INIT(matrix);
	D3DXMatrixTranslation(&matrix,m_vRecPos.x,m_vRecPos.y,m_vRecPos.z);
	
	//現在マトリックスからのズレを計算
	D3DXVec3TransformCoord(&m_vCameraIdentity,&m_vRangeFromRecPos,&matrix);
	
	//目標までのVec3生成
	D3DXVECTOR3 vLook;
	if(m_pmTargetMatrix)
	D3DXVec3TransformCoord(&vLook,&m_vRangeFromTarget,m_pmTargetMatrix);
	else
	D3DXVec3TransformCoord(&vLook,&m_vRangeFromTarget,&matrix);
	//vUp生成
	D3DXVECTOR3 vUP;
	D3DXVec3TransformCoord(&vUP,&D3DXVECTOR3(0.0f,1.0f,0.0f),&matrix);

	//最終合算
	D3DXMatrixLookAtLH(&m_matView,&m_vCameraIdentity,&vLook,&vUP);
	//D3DXVec3TransformCoord(&m_vRecPos,
	//	&D3DXVECTOR3(0.0f,150.0f,-300.0f),
	//	&GetModelMatrix());

	//D3DXVECTOR3 vLook;
	//D3DXVec3TransformCoord(&vLook,
	//	&D3DXVECTOR3(0.0f,100.0f,0.0f),
	//	&GetModelMatrix());

	//D3DXVECTOR3 vUP;
	//D3DXVec3TransformNormal(&vUP,
	//	&D3DXVECTOR3(0.0f,1.0f,0.0f),
	//	&GetModelMatrix());

	//D3DXMatrixLookAtLH(&m_matView,
	//	&m_vRecPos,&vLook,&vUP);
	//D3DM_INIT(m_matView);
	//D3DXMatrixTranslation(&m_matView,m_vRecPos.x,m_vRecPos.y,m_vRecPos.z);
}
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 );

}
Esempio n. 15
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);
}
Esempio n. 16
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 );
}
Esempio n. 17
0
//-----------------------------------------------------------------------------
// 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);
}
Esempio n. 18
0
void TTscene::Update(const tt::GameContext& context)
{
	if(MyServiceLocator::GetInstance()->GetService<IInputService>()->IsActionTriggered(InputActionId::ToggleVSync)){
		tcout << _T("Toggle") << endl;
		MyServiceLocator::GetInstance()->GetService<IGraphicsService>()->GetGraphicsDevice()->ToggleVSync();
	}

	D3DXMATRIX tempView, tempProj;	
	D3DXMatrixLookAtLH(&tempView, &D3DXVECTOR3(100,200,100), &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,0,1));
	D3DXMatrixOrthoLH(&tempProj, 500, 500, 10, 1000);
	auto lightView = tt::Matrix4x4(tempView);
	auto lightProj = tt::Matrix4x4(tempProj);

	Material::SetDominantDirectionalLightViewProjection(lightView * lightProj);
	
	delete g_pScript;
	g_pScript = new ScriptComponent(_T("Resources/Scripts/TestScript.lua"));
	g_pScript->Load(InitializeLuaScript);
	g_pScript->Initialize();
	g_pScript->Update(context);
}
Esempio n. 19
0
QUAT Storm3D_Spotlight::getOrientation() const
{
	D3DXVECTOR3 lightPosition(data->properties.position.x, data->properties.position.y, data->properties.position.z);
	D3DXVECTOR3 up(0, 1.f, 0);
	D3DXVECTOR3 lookAt = lightPosition;
	lookAt += D3DXVECTOR3(data->properties.direction.x, data->properties.direction.y, data->properties.direction.z);

	D3DXMATRIX tm;
	D3DXMatrixLookAtLH(&tm, &lightPosition, &lookAt, &up);

	float det = D3DXMatrixDeterminant(&tm);
	D3DXMatrixInverse(&tm, &det, &tm);

	MAT m;

	for(int j = 0; j < 4; ++j)
	for(int i = 0; i < 4; ++i)
		m.Set(j*4 + i, tm[j*4 + i]);

	return m.GetRotation();
}
Esempio n. 20
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);
}
Esempio n. 21
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);

}
Esempio n. 22
0
void ColoredCubeApp::updateScene(float dt)
{
	D3DApp::updateScene(dt);
	xLine.update(dt);
	yLine.update(dt);
	zLine.update(dt);
	quad1.update(dt);
	quad2.update(dt);
	quad3.update(dt);
	quad4.update(dt);
	quad5.update(dt);

	for(int i = 0; i < WALL_SIZE; ++i) {
		wall[i].update(dt);
	}

	D3DXVECTOR3 pos(0.0f,0.0f,15.0f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
}
Esempio n. 23
0
void CCamera::YRotate ( int iID, float fY )
{
	// rotate the camera on it's y axis

	// update internal pointer
	if ( !this->UpdatePtr ( iID ) )
		return;

	D3DXMatrixLookAtLH 
						( 
							&m_ptr->matView,
							&D3DXVECTOR3 ( m_ptr->fX,   m_ptr->fY,    m_ptr->fZ ),
							&D3DXVECTOR3 ( 0.0f, 0.0f,  0.0f ),
							&D3DXVECTOR3 ( 0.0f, 1.0f,  0.0f )
						);

	D3DXMatrixRotationY ( &m_ptr->matRotateY, fY );
	D3DXMatrixMultiply  ( &m_ptr->matView, &m_ptr->matView, &m_ptr->matRotateY );

	m_pD3D->SetTransform ( D3DTS_VIEW, &m_ptr->matView );
}
Esempio n. 24
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) ;
}
Esempio n. 25
0
/*******************************************************************
* update view from Camera heading and pitch
********************************************************************/
void Camera::updateView()
{	
	//create rotation matrix
	D3DXMatrixRotationYawPitchRoll( &rotationMatrix, heading, pitch, 0 );

	//create new view and up vectors
	D3DXVec3TransformCoord( &view, &dV, &rotationMatrix );
	D3DXVec3TransformCoord( &up, &dU, &rotationMatrix );

	//create new forward and strafe vectors
	D3DXVec3Normalize( &forward, &view );	
	D3DXVec3Cross( &strafeRight, &up, &view );
	D3DXVec3Normalize( &strafeRight, &strafeRight );

	//take into account eye position
	view = eye + view;
	
	//update view matrix
	D3DXMatrixLookAtLH( &viewMatrix, &eye, &view, &up );

}
Esempio n. 26
0
// Update the scene for every frame
void Camera::OnFrameMove()
{
	// No need to handle if no drag since last frame move
	if(!m_bDragSinceLastUpdate)
		return ;

	m_bDragSinceLastUpdate = false ;

	if(m_nMouseWheelDelta)
	{
		m_fRadius -= m_nMouseWheelDelta * m_fRadius * 0.1f / 120.0f;

		// Make the radius in range of [m_fMinRadius, m_fMaxRadius]
		// This can Prevent the cube became too big or too small
		m_fRadius = max(m_fRadius, m_fMinRadius) ;
		m_fRadius = min(m_fRadius, m_fMaxRadius) ;
	}

	// The mouse delta is retrieved IN every WM_MOUSE message and do not accumulate, so clear it after one frame
	m_nMouseWheelDelta = 0 ;

	// Get the inverse of the view Arcball's rotation matrix
	D3DXMATRIX mCameraRot ;
	D3DXMatrixInverse( &mCameraRot, NULL, m_ViewArcBall.GetRotationMatrix() );

	// Transform vectors based on camera's rotation matrix
	D3DXVECTOR3 vWorldUp;
	D3DXVECTOR3 vLocalUp = D3DXVECTOR3( 0, 1, 0 );
	D3DXVec3TransformCoord( &vWorldUp, &vLocalUp, &mCameraRot );

	D3DXVECTOR3 vWorldAhead;
	D3DXVECTOR3 vLocalAhead = D3DXVECTOR3( 0, 0, 1 );
	D3DXVec3TransformCoord( &vWorldAhead, &vLocalAhead, &mCameraRot );

	// Update the eye point based on a radius away from the lookAt position
	m_vEyePt = m_vLookatPt - vWorldAhead * m_fRadius;

	// Update the view matrix
	D3DXMatrixLookAtLH( &m_matView, &m_vEyePt, &m_vLookatPt, &vWorldUp );
}
Esempio n. 27
0
//-------------------------------------------------------------
// Name: FrameMove()
// Desc: �� �����Ӹ��� ȣ���. �ִϸ��̼� ó���� ���
//-------------------------------------------------------------
HRESULT CMyD3DApplication::FrameMove()
{
    UpdateInput( &m_UserInput );// ���̓f�[�^�̍X�V

	//---------------------------------------------------------
	// �Է¿� ���� ��ǥ�踦 �����Ѵ�
	//---------------------------------------------------------
	// ȸ��
    D3DXMATRIX m;
    D3DXMATRIX matRotY;
    D3DXMATRIX matRotX;

    if( m_UserInput.bRotateLeft && !m_UserInput.bRotateRight )
        m_fWorldRotY += m_fElapsedTime;
    else if( m_UserInput.bRotateRight && !m_UserInput.bRotateLeft )
        m_fWorldRotY -= m_fElapsedTime;

    if( m_UserInput.bRotateUp && !m_UserInput.bRotateDown )
        m_fWorldRotX += m_fElapsedTime;
    else if( m_UserInput.bRotateDown && !m_UserInput.bRotateUp )
        m_fWorldRotX -= m_fElapsedTime;

	//---------------------------------------------------------
	// ��� ����
	//---------------------------------------------------------
	// ���� ȸ��
    D3DXMatrixRotationX( &matRotX, m_fWorldRotX );
    D3DXMatrixRotationY( &matRotY, m_fWorldRotY );
    D3DXMatrixMultiply( &m, &matRotX, &matRotY );

    // �����
    D3DXVECTOR3 vFromPt   = D3DXVECTOR3( 0.0f, 2.73f, -8.0f );
    D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 2.73f, 0.0f );
    D3DXVECTOR3 vUpVec    = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
    D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec );
	m_mView = m * m_mView;
    m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView );

	return S_OK;
}
Esempio n. 28
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;
}
Esempio n. 29
0
BoundingCone::BoundingCone(const BoundingBox& box, const D3DXMATRIX& projection, const D3DXVECTOR3& apex, const D3DXVECTOR3& direction )
{
	m_direction = direction;

	const D3DXVECTOR3 yAxis(0.f, 1.f, 0.f);
    const D3DXVECTOR3 zAxis(0.f, 0.f, 1.f);
    D3DXVec3Normalize(&m_direction, &m_direction);
    
    D3DXVECTOR3 axis = yAxis;

    if ( fabsf(D3DXVec3Dot(&yAxis, &m_direction))>0.99f )
	{
        axis = zAxis;
	}
    
    D3DXMatrixLookAtLH( &m_lookAt, &apex, &(apex+m_direction), &axis );
    
    float maxx = 0.f, maxy = 0.f;
    m_near = 1e32f;
    m_far =  0.f;

    D3DXMATRIX concatMatrix;
    D3DXMatrixMultiply( &concatMatrix, &projection, &m_lookAt );

	D3DXVECTOR3 ppPts[ box.CornerCount ];
	box.GetCorners( ppPts );

	for(int index=0; index<box.CornerCount; index++)
    {
		D3DXVECTOR3 vec = ppPts[index];
        D3DXVec3TransformCoord(&vec, &vec, &concatMatrix);
        maxx = max(maxx, fabsf(vec.x / vec.z));
        maxy = max(maxy, fabsf(vec.y / vec.z));
        m_near = min(m_near, vec.z);
        m_far  = max(m_far, vec.z);
    }

    m_fovx = atanf(maxx);
    m_fovy = atanf(maxy);
}
Esempio n. 30
0
//-----------------------------------------------------------------------------
// Name: D3DUtil_GetCubeMapViewMatrix()
// Desc: Returns a view matrix for rendering to a face of a cubemap.
//-----------------------------------------------------------------------------
D3DXMATRIX D3DUtil_GetCubeMapViewMatrix( DWORD dwFace )
{
    D3DXVECTOR3 vEyePt   = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vLookDir;
    D3DXVECTOR3 vUpDir;

    switch( dwFace )
    {
        case D3DCUBEMAP_FACE_POSITIVE_X:
            vLookDir = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );
            vUpDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
            break;
        case D3DCUBEMAP_FACE_NEGATIVE_X:
            vLookDir = D3DXVECTOR3(-1.0f, 0.0f, 0.0f );
            vUpDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
            break;
        case D3DCUBEMAP_FACE_POSITIVE_Y:
            vLookDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
            vUpDir   = D3DXVECTOR3( 0.0f, 0.0f,-1.0f );
            break;
        case D3DCUBEMAP_FACE_NEGATIVE_Y:
            vLookDir = D3DXVECTOR3( 0.0f,-1.0f, 0.0f );
            vUpDir   = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
            break;
        case D3DCUBEMAP_FACE_POSITIVE_Z:
            vLookDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
            vUpDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
            break;
        case D3DCUBEMAP_FACE_NEGATIVE_Z:
            vLookDir = D3DXVECTOR3( 0.0f, 0.0f,-1.0f );
            vUpDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
            break;
    }

    // Set the view transform for this cubemap surface
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookDir, &vUpDir );
    return matView;
}