//----------------------------------------------------------------------------- // Name: SetupMatrices() // Desc: Sets up the world, view, and projection transform matrices. //----------------------------------------------------------------------------- VOID SetupMatrices() { // Set up world matrix D3DXMATRIXA16 matWorld; D3DXMatrixIdentity( &matWorld ); D3DXMatrixRotationX( &matWorld, 0.0f ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); // Set up our view matrix. A view matrix can be defined given an eye point, // a point to lookat, and a direction for which way is up. Here, we set the // eye five units back along the z-axis and up three units, look at the // origin, and define "up" to be in the y-direction. D3DXVECTOR3 vEyePt( 0.0f, 0.0f,-2.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 ); // 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). D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
//----------------------------------------------------------------------------- // Name: SetupMatrices() // Desc: Sets up the world, view, and projection transform matrices. //----------------------------------------------------------------------------- VOID SetupMatrices() { // For our world matrix, we will just rotate the object about the y-axis. D3DXMATRIXA16 matWorld; // Set up the rotation matrix to generate 1 full rotation (2*PI radians) // every 1000 ms. To avoid the loss of precision inherent in very high // floating point numbers, the system time is modulated by the rotation // period before conversion to a radian angle. UINT iTime = timeGetTime() % 1000; FLOAT fAngle = iTime * ( 2.0f * D3DX_PI ) / 1000.0f; D3DXMatrixRotationY( &matWorld, fAngle ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); // Set up our view matrix. A view matrix can be defined given an eye point, // a point to lookat, and a direction for which way is up. Here, we set the // eye five units back along the z-axis and up three units, look at the // origin, and define "up" to be in the y-direction. 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 ); // 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). D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
void C3d::SetupMatrices() { D3DXMATRIXA16 matWorld1; D3DXMATRIXA16 mat; D3DXVECTOR3 vEyePt(0.0f, vRadius*distance*1.025f,vRadius*distance*-3.0f ); D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec( 0.0f, 0.5f, 0.0f ); if(rotation) { D3DXMatrixIdentity(&mat); MatrixRotationY( &mat, timeGetTime()/1500.0f ); } else { m_abArcBall.GetMat(&mat); vEyePt = D3DXVECTOR3(0.0f, 0.0f,vRadius*distance*-4.0f); vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 1.0f ); } MatrixMultiply(&matWorld , &mat, &matWorld1); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld1 ); D3DXMATRIXA16 matView; MatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec ); g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); D3DXMATRIXA16 matProj; MatrixPerspectiveFovLH( &matProj, D3DX_PI/5, Aspect, 1.0f, vRadius*20);// 10.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
/**----------------------------------------------------------------------------- * 카메라 행렬 설정 *------------------------------------------------------------------------------ */ void SetupCamera() { /// 월드행렬 설정 D3DXMATRIXA16 matWorld; D3DXMatrixIdentity( &matWorld ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); /*D3DXVECTOR3 vEyePt(0.0f, 15.0f,-22.0f ); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f);*/ /*D3DXVECTOR3 vEyePt(0.23f, 1.5f, 0.401f); D3DXVECTOR3 vLookatPt(0.23f, 0.0, 0.4f); D3DXVECTOR3 vUpVec(0, 1, 0);*/ D3DXVECTOR3 vEyePt(float((MAPWIDTH)/2), 20.0f, -10.0f); D3DXVECTOR3 vLookatPt(float((MAPWIDTH)/2), 10.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); /*D3DXVECTOR3 vEyePt(float((MAPWIDTH)/2), 7.0f, -1.0f); D3DXVECTOR3 vLookatPt(float((MAPWIDTH)/2), 5.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; FLOAT fWidth = WIDTH; FLOAT fHeight = HEIGHT; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4.0f, fWidth/fHeight, 1.0f, 100.0f); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
void SetMatrices() { const char *keys = GetKeyState(); if (keys != NULL) { if (keys[DIK_UP]&0x80) mz = mz + speed * looptime; if (keys[DIK_DOWN]&0x80) mz = mz - speed * looptime; if (keys[DIK_LEFT]&0x80) mx = mx - speed * looptime; if (keys[DIK_RIGHT]&0x80) mx = mx + speed * looptime; } // ワールド座標 D3DXMATRIXA16 matWorld1, matWorld2; D3DXMatrixTranslation(&matWorld1, mx, 0.0f, mz); D3DXMatrixRotationY(&matWorld2, D3DX_PI); matWorld2 *= matWorld1; g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld2); // ビュー変換 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, g_aspect, 1.0f, 100.0f); g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj); }
VOID Kinect::SetupMatrics() //Ä«¸Þ¶ó ¼³Ä¡ { //¿ùµåÇà·Ä D3DXMATRIXA16 matWorld; //UINT iTime = timeGetTime() % 1000; //FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f; //D3DXMatrixRotationY(&matWorld, fAngle); // YÃàÀ» ȸÀüÃàÀ¸·Î ȸÀüÇà·ÄÀ» »ý¼ºÇÑ´Ù. //g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld); //»ý¼ºÇÑ È¸Àü Çà·ÄÀ» ¿ùµå Çà·Ä·Î µð¹ÙÀ̽º¿¡ ¼³Á¤ÇÑ´Ù. //ºä Çà·ÄÀ» Á¤ÀÇÇϱâ À§Çؼ´Â 3°¡ÁöÀÇ °ªÀÌ ÇÊ¿äÇÔ D3DXVECTOR3 vEyePt(CameraSpot.x, CameraSpot.y, CameraSpot.z); //´«ÀÇ À§Ä¡ D3DXVECTOR3 vLookatPt(IronLook.x, IronLook.y, IronLook.z); //´«ÀÌ ¹Ù¶óº¸´Â À§Ä¡ D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); //õÁ¤¹æÇâÀ» ³ªÅ¸³»´Â »ó¹æº¤ÅÍ(0,1,0) //D3DXVECTOR3 vEyePt(0.0f, 0, 0); //´«ÀÇ À§Ä¡ //D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 1.0f); //´«ÀÌ ¹Ù¶óº¸´Â À§Ä¡ //D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); //õÁ¤¹æÇâÀ» ³ªÅ¸³»´Â »ó¹æº¤ÅÍ(0,1,0) D3DXMATRIXA16 matView; D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); //1,2,3ÀÇ °ªÀ¸·Î ºä Çà·Ä »ý¼º g_pDevice->SetTransform(D3DTS_VIEW, &matView); //»ý¼ºÇÑ ºä Çà·ÄÀ» µð¹ÙÀ̽º¿¡ ¼³Á¤ //ÇÁ·ÎÁ¦¼Ç Çà·ÄÀ» Á¤ÀÇÇϱâ À§Çؼ´Â ½Ã¾ß°¢(FOV=Field of View)°ú Á¾È¾ºñ (aspect ratio),Ŭ¸®ÇÎ Æò¸éÀÇ °ªÀÌ ÇÊ¿äÇÏ´Ù. D3DXMATRIXA16 matProj; //D3DXMatrixOrthoOffCenterLH(&matProj, 0, (float)CLIENT_WIDTH, (float)CLIENT_HEIGHT, 0, -100.f, 100.f); D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(43), (float)CLIENT_WIDTH / CLIENT_HEIGHT, 0.01f, 100.f); //½Ã¾ß°¢ g_pDevice->SetTransform(D3DTS_PROJECTION, &matProj); //»ý¼ºÇÑ ÇÁ·ÎÁ§¼Ç Çà·ÄÀ» µð¹ÙÀ̽º¿¡ ¼³Á¤ }
// 3D 물체등을 그린다. void RenderScene() { // 뷰 행렬을 만든다. D3DXMATRIXA16 matView; D3DXVECTOR3 vEyePt(gWorldCameraPosition.x, gWorldCameraPosition.y, gWorldCameraPosition.z); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); // 투영행렬을 만든다. D3DXMATRIXA16 matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, FOV, ASPECT_RATIO, NEAR_PLANE, FAR_PLANE); // 프레임마다 0.4도씩 회전을 시킨다. gRotationY += 0.4f * PI / 180.0f; if (gRotationY > 2 * PI) { gRotationY -= 2 * PI; } // 월드행렬을 만든다. D3DXMATRIXA16 matWorld; D3DXMatrixRotationY(&matWorld, gRotationY); // 월드/뷰/투영행렬을 미리 곱한다. D3DXMATRIXA16 matWorldView; D3DXMATRIXA16 matWorldViewProjection; D3DXMatrixMultiply(&matWorldView, &matWorld, &matView); D3DXMatrixMultiply(&matWorldViewProjection, &matWorldView, &matProjection); // 쉐이더 전역변수들을 설정 gpEnvironmentMappingShader->SetMatrix("gWorldMatrix", &matWorld); gpEnvironmentMappingShader->SetMatrix("gWorldViewProjectionMatrix", &matWorldViewProjection); gpEnvironmentMappingShader->SetVector("gWorldLightPosition", &gWorldLightPosition); gpEnvironmentMappingShader->SetVector("gWorldCameraPosition", &gWorldCameraPosition); gpEnvironmentMappingShader->SetVector("gLightColor", &gLightColor); gpEnvironmentMappingShader->SetTexture("DiffuseMap_Tex", gpStoneDM); gpEnvironmentMappingShader->SetTexture("SpecularMap_Tex", gpStoneSM); gpEnvironmentMappingShader->SetTexture("NormalMap_Tex", gpStoneNM); gpEnvironmentMappingShader->SetTexture("EnvironmentMap_Tex", gpSnowENV); // 쉐이더를 시작한다. UINT numPasses = 0; gpEnvironmentMappingShader->Begin(&numPasses, NULL); { for (UINT i = 0; i < numPasses; ++i) { gpEnvironmentMappingShader->BeginPass(i); { // 구체를 그린다. gpTeapot->DrawSubset(0); } gpEnvironmentMappingShader->EndPass(); } } gpEnvironmentMappingShader->End(); }
//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- CD3DCamera::CD3DCamera() { // Set attributes for the view matrix D3DXVECTOR3 vEyePt(0.0f,0.0f,0.0f); D3DXVECTOR3 vLookatPt(0.0f,0.0f,1.0f); D3DXVECTOR3 vUpVec(0.0f,1.0f,0.0f); SetViewParams( vEyePt, vLookatPt, vUpVec ); // Set attributes for the projection matrix SetProjParams( D3DX_PI/4, 1.0f, 1.0f, 1000.0f ); }
// 3D 물체등을 그린다. void RenderScene() { // 뷰행렬 초기화. D3DXMATRIXA16 matView; // D3DXVECTOR3 vEyePt(0.0f, 0.0f, -200.0f); D3DXVECTOR3 vEyePt(gWorldCameraPosition.x, gWorldCameraPosition.y, gWorldCameraPosition.z); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); // 투영행렬 초기화. D3DXMATRIXA16 matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, FOV, ASPECT_RATIO, NEAR_PLANE, FAR_PLANE); // 회전. gRotationY += ((0.4f * PI) / 180.0f); if (gRotationY > 2 * PI) gRotationY -= 2 * PI; // 월드행렬 초기화. D3DXMATRIXA16 matWorld; // D3DXMatrixIdentity(&matWorld); D3DXMatrixRotationY(&matWorld, gRotationY); // 쉐이더에 전달. gpTextureMappingShader->SetMatrix("gWorldMatrix", &matWorld); gpTextureMappingShader->SetMatrix("gViewMatrix", &matView); gpTextureMappingShader->SetMatrix("gProjectionMatrix", &matProjection); gpTextureMappingShader->SetVector("gWorldLightPosition", &gWorldLightPosition); gpTextureMappingShader->SetVector("gWorldCameraPosition", &gWorldCameraPosition); // gpTextureMappingShader->SetTexture("DiffuseMap_Tex", gpEarthDM); // 쉐이더 적용. UINT numPasses = 0; gpTextureMappingShader->Begin(&numPasses, NULL); for (UINT i = 0; i < numPasses; ++i) { gpTextureMappingShader->BeginPass(i); gpSphere->DrawSubset(0); gpTextureMappingShader->EndPass(); } gpTextureMappingShader->End(); }
///////////////////////////////////////// // инициализация камер ///////////////////////////////////////// void setupCameras() { // Создание главной камеры (без отдельных render-targets) m_pRenderCameraPrimary = render::CRenderCamera::Create(); m_pRenderCameraPrimary->setProjection(math::Math::PI/4, 1.0f, 1.0f, 10000.0f); // Создание вторичной камеры (с отдельными render-targets) render::SViewPort viewport(0, 0, 320, 240); render::SRenderTargetInfo params; m_pRenderCameraSecondary = render::CRenderCamera::Create(0, viewport); m_pRenderCameraSecondary->setProjection(math::Math::PI/4, 1.0f, 1.0f, 10000.0f); // Создание таргетов для камеры params.format = render::A8R8G8B8; params.size = math::Vec2i(80, 60); m_renderTarget = render::IRenderTexture::Create(params); m_pRenderCameraSecondary->setColorTarget(m_renderTarget, math::Color(0, 0, 0, 255)); params.format = render::D16; m_renderDepth = render::IRenderTexture::Create(params); m_pRenderCameraSecondary->setDepthStencilTarget(m_renderDepth, 1.0f); // Добавление камер к рендеру render::TheCameraManager::Get().addCamera(m_pRenderCameraPrimary); render::TheCameraManager::Get().addCamera(m_pRenderCameraSecondary); // Создание спрайта для отображения вида вторичной камеры render::TheSpriteManager::Get().set_origin(math::Vec2f(0, 0)); math::Rect rect(0, 0, 1, 1); math::Vec2f pos (0, 0); math::Vec2f size(800, 600); render::SSprite sprite(pos, size, 0xffffffff, m_renderTarget, 0, rect); m_vSprites.push_back(sprite); // Установка контроллеров главной камеры m_cFirstPersonCamera.setCamera(m_pRenderCameraPrimary); //m_cTargetCamera.setCamera(m_pRenderCameraSecondary); m_cTargetCamera.setCamera(m_pRenderCameraPrimary); // Настройка видовой матрицы контроллеров math::Vec3f vEyePt(100.0f, 80.0f, 20.0f); math::Vec3f vLookatPt(0.0f, 0.0f, 0.0f); math::Vec3f vUpVec(0.0f, 1.0f, 0.0f); m_cTargetCamera.setPosition (vEyePt,vLookatPt,vUpVec); m_cFirstPersonCamera.setPosition(vEyePt,vLookatPt); // Установка текущего контроллера m_cFirstPersonCamera.activate(); m_nCamera = 0; }
VOID setViewProjMatrix(){ //View matrix D3DXVECTOR3 vEyePt(0.0f, 2.0f, -30.0f); D3DXVECTOR3 vLookatPt(0.0f, 2.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMATRIX matView; D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); g_pDevice->SetTransform(D3DTS_VIEW, &matView); //Projection Matrix D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4, 1.0f, 1.0f, 5000.0f); g_pDevice->SetTransform(D3DTS_PROJECTION, &matProj); }
void MapCamera::SetPos(float x, float y) { MapObject::SetPos(x, y); D3DXVECTOR3 vEyePt(mPosX, mPosY, -20.0f); D3DXVECTOR3 vLookatPt(mPosX, mPosY, 20.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMATRIXA16 matView; D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); Global::GetDevice()->SetTransform(D3DTS_VIEW, &matView); gSceneMgr.GetFader()->SetPosition(mPosX, mPosY); }
//----------------------------------------------------------------------------- // Name: SetupMatrices() // Desc: Sets up the world, view, and projection transform matrices. //----------------------------------------------------------------------------- VOID SetupCameraMatrices() { 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 AmjuGLDX9::LookAt(float eyeX, float eyeY, float eyeZ, float x, float y, float z, float upX, float upY, float upZ) { AMJU_CALL_STACK; D3DXVECTOR3 vEyePt(eyeX, eyeY, eyeZ); D3DXVECTOR3 vLookatPt(x, y, z); D3DXVECTOR3 vUpVec(upX, upY, upZ); D3DXMATRIX matLookAt; D3DXMatrixLookAtRH( &matLookAt, &vEyePt, &vLookatPt, &vUpVec ); g_matrixStack->LoadIdentity(); g_matrixStack->LoadMatrix( &matLookAt ); }
void OnFrameRender(IDirect3DDevice9* pd3dDevice) { pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); if (SUCCEEDED(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)SCREEN_WIDTH) / ((float)SCREEN_HEIGHT); D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, aspectRatio, 1.0f, 100.0f ); pd3dDevice->SetVertexShader(g_pVS); pd3dDevice->SetVertexDeclaration(g_pDecl); pd3dDevice->SetVertexShaderConstantF(8, matWorld * matView * matProj, 4); pd3dDevice->SetPixelShader(g_pPS); FLOAT Offset[] = { -1.0f/SCREEN_WIDTH, 0.0f, 0.0f, 0.0f, 1.0f/SCREEN_WIDTH, 0.0f, 0.0f, 0.0f, -2.0f/SCREEN_WIDTH, 0.0f, 0.0f, 0.0f, 2.0f/SCREEN_WIDTH, 0.0f, 0.0f, 0.0f, -3.0f/SCREEN_WIDTH, 0.0f, 0.0f, 0.0f, 3.0f/SCREEN_WIDTH, 0.0f, 0.0f, 0.0f, }; pd3dDevice->SetPixelShaderConstantF(0, Offset, 6); FLOAT weight[] = { 0.2f, 0.2f, 0.2f, 0.2f, }; pd3dDevice->SetPixelShaderConstantF(6, weight, 1); pd3dDevice->SetTexture(0, g_pTexture); pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX)); pd3dDevice->SetIndices(g_pIB); pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2); pd3dDevice->EndScene(); } pd3dDevice->Present(NULL, NULL, NULL, NULL); }
//----------------------------------------------------------------------------- // Desc: 设置观察矩阵和投影矩阵 //----------------------------------------------------------------------------- VOID SetViewAndProjMatrix() { //创建并设置观察矩阵 D3DXVECTOR3 vEyePt( 0.0f, 10.0f,-20.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, 500.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
VOID SetupMatrices() { D3DXMATRIXA16 matWorld; D3DXMatrixIdentity( &matWorld ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); D3DXVECTOR3 vEyept( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 1.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 / 3, 1.2f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
/**----------------------------------------------------------------------------- <<<<<<< HEAD * ?됰젹 ?ㅼ젙 ======= * 행렬 설정 >>>>>>> cb393cf62d002037487db55658f3a21dde6a512c *------------------------------------------------------------------------------ */ void InitMatrix() { /// 월드행렬 D3DXMatrixIdentity( &g_matWorld ); /// 월드행렬을 단위행렬으로 설정 g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_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 ); D3DXMatrixLookAtLH( &g_matView, &vEyePt, &vLookatPt, &vUpVec ); g_pd3dDevice->SetTransform( D3DTS_VIEW, &g_matView ); /// 프로젝션 행렬 설정 D3DXMatrixPerspectiveFovLH( &g_matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_matProj ); }
void d3d_set_projection_ext(gs_scalar xfrom, gs_scalar yfrom, gs_scalar zfrom,gs_scalar xto, gs_scalar yto, gs_scalar zto,gs_scalar xup, gs_scalar yup, gs_scalar zup,double angle,double aspect,double znear,double zfar) { D3DXVECTOR3 vEyePt( xfrom, yfrom, zfrom ); D3DXVECTOR3 vLookatPt( xto, yto, zto ); D3DXVECTOR3 vUpVec( xup, yup, zup ); // Get D3DX to fill in the matrix values D3DXMATRIX matView; D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec ); // Set our view matrix d3dmgr->SetTransform( D3DTS_VIEW, &matView ); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian(angle), aspect, znear, zfar ); d3dmgr->SetTransform( D3DTS_PROJECTION, &matProj ); }
void d3d_set_projection(gs_scalar xfrom, gs_scalar yfrom, gs_scalar zfrom,gs_scalar xto, gs_scalar yto, gs_scalar zto,gs_scalar xup, gs_scalar yup, gs_scalar zup) { D3DXVECTOR3 vEyePt( xfrom, yfrom, zfrom ); D3DXVECTOR3 vLookatPt( xto, yto, zto ); D3DXVECTOR3 vUpVec( xup, yup, zup ); // Get D3DX to fill in the matrix values D3DXMATRIX matView; D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec ); // Set our view matrix d3dmgr->SetTransform( D3DTS_VIEW, &matView ); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian(45), view_wview[view_current] / (double)view_hview[view_current], 1.0f, 32000.0f ); d3dmgr->SetTransform( D3DTS_PROJECTION, &matProj ); }
//----------------------------------------------------------------------------- // Name: SetupMatrices() // Desc: Sets up the world, view, and projection transform matrices. //----------------------------------------------------------------------------- VOID D3DSample::SetupMatrices( ) { // Set up world matrix D3DXMATRIXA16 matWorld; D3DXMatrixRotationY( &matWorld, timeGetTime() / 1000.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 ); }
//----------------------------------------------------------------------------- // Name: SetupMatrices() // Desc: Sets up the world, view, and projection transform matrices. //----------------------------------------------------------------------------- VOID SetupMatrices() { D3DXMATRIXA16 matWorld; D3DXMatrixIdentity(&matWorld); D3DXVECTOR3 vEyePt(0.0f, 3.0f, -2.0f); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMATRIXA16 matView; sFnPtr_D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); D3DXMATRIXA16 matProj; sFnPtr_D3DXMatrixPerspectiveFovLH(&matProj, (float)D3DX_PI/4.f, 1.0f, 0.01f, 10.0f); g_pmWorld->SetMatrix((float *) &matWorld); g_pmView->SetMatrix((float *) &matView); g_pmProjection->SetMatrix((float *) &matProj); }
ExampleObject() : m_camera(render::CRenderCamera::Create()) //: ::render::IRendererable(10) { m_spFont = render::IFont::Create(20, L"Arial", render::IFont::Heavy); m_mesh.load("teapot.xml"); m_pTexture = ::render::ITexture::Create("tiger.bmp"); math::Vec3f vEyePt( 5.0f, 4, 0 ); math::Vec3f vLookatPt( 0.0f, 0.0f, 0.0f ); math::Vec3f vUpVec( 0.0f, 1.0f, 0.0f ); m_camera->lookAt(vEyePt, vLookatPt, vUpVec); m_camera->setProjection(math::Math::PI/4, 1.0f, 1.0f, 10000.0f); //input m_cEsc.attachToControl(input::Keyboard, input::KeyEscape); m_cEsc.addHandler(this, &ExampleObject::onEsc); }
VOID SetupMatrices() { // For our world matrix, we will just rotate the object about the y-axis. // 物件只围绕y轴旋转 D3DXMATRIXA16 matWorld; // Set up the rotation matrix to generate 1 full rotation (2*PI radians) every 1000 ms. // 配置旋转矩阵为每1000ms一整圈(2*PI 弧度) // To avoid the loss of precision inherent in very high floating point numbers, // 为了避免高浮点数固有的精度损失, // the system time is modulated by the rotation period before conversion to a radian angle. // 系统时间被旋转周期求模,在它被转化成弧度角前 //UINT iTime = timeGetTime() % 1000; //FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f; D3DXMatrixRotationY( &matWorld, g_fYAngle ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); // Set up our view matrix. // 设置视图矩阵 // A view matrix can be defined given an eye point, // a point to lookat, and a direction for which way is up. Here, we set the // eye five units back along the z-axis and up three units, look at the // origin, and define "up" to be in the y-direction. 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 ); // 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). // 投影矩阵,我们配置一个透视转化(把图形从3D视图空间转化到2D视口空间,透视划分使得远的物件小) // 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). // 构建透视转化,四个参数(1)the field of view (2)the aspect ratio (3)the near clipping plane (4)the far clipping plane D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
//============================================================================// void EC_RENDER::sInitMatrixes() { D3DXMATRIXA16 matWorld; D3DXMatrixRotationY( &matWorld, 0 ); m_logic.device->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 ); m_logic.device->SetTransform( D3DTS_VIEW, &matView ); D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100000.0f ); m_logic.device->SetTransform( D3DTS_PROJECTION, &matProj ); }
void OnFrameRender(IDirect3DDevice9* pd3dDevice) { pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); if (SUCCEEDED(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)SCREEN_WIDTH) / ((float)SCREEN_HEIGHT); D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, aspectRatio, 1.0f, 100.0f ); pd3dDevice->SetVertexShader(g_pVS); pd3dDevice->SetPixelShader(g_pPS); pd3dDevice->SetVertexDeclaration(g_pDecl); D3DXMATRIX matWorldViewProj; D3DXMatrixTranspose(&matWorldViewProj, &(matWorld * matView * matProj)); D3DXHANDLE hMatrix = g_pVSConstantTable->GetConstantByName(NULL, "WorldViewProj"); g_pVSConstantTable->SetMatrix(pd3dDevice, hMatrix, &matWorldViewProj); FLOAT fMaterial[] = {0, 1, 0, 0}; pd3dDevice->SetVertexShaderConstantF(8, fMaterial, 1); pd3dDevice->SetTexture(0, g_pTexture); pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX)); pd3dDevice->SetIndices(g_pIB); pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2); pd3dDevice->EndScene(); } pd3dDevice->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 ); }
//----------------------------------------------------------------------------- // 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 ); }
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 ); }