void PRTHierarchy::UpdateTransformationMatrices() { D3DXMATRIX rotX, rotY, rotYInverse; D3DXMatrixRotationY(&rotY, mRotationY); D3DXMatrixRotationX(&rotX, mRotationX); D3DXMatrixIdentity(&mWorldTransform); D3DXMATRIX rot = rotX * rotY; mWorldTransform = mScaleMatrix * rot; mRenderMesh->SetWorldTransformation(mWorldTransform); mApproxMesh->SetWorldTransformation(mWorldTransform); mRenderMesh->SetRotationMatrix(rot); mApproxMesh->SetRotationMatrix(rot); }
void CMesh::SetPosition(float x,float y,float z) { m_vPos.x=x; m_vPos.y=y; m_vPos.z=z; m_fScale=1.0f; m_fAngle=0; D3DXMatrixRotationY((D3DXMATRIX*)&m_matTrans,m_fAngle); m_matTrans._41=m_vPos.x; m_matTrans._42=m_vPos.y; m_matTrans._43=m_vPos.z; }
void cCamera::yaw(float angle) { D3DXMATRIX transform_matrix; // rotate around world y-axis (0, 1, 0) always for land object if(m_camera_type == LAND_OBJECT) D3DXMatrixRotationY(&transform_matrix, angle); else // rotate around own up vector for aircraft D3DXMatrixRotationAxis(&transform_matrix, &m_up, angle); // rotate m_right and m_look around m_up or y-axis D3DXVec3TransformCoord(&m_right, &m_right, &transform_matrix); D3DXVec3TransformCoord(&m_look, &m_look, &transform_matrix); }
void AnimPlayer::Relativize(D3DXVECTOR3* stick_rel,const D3DXVECTOR3* stick_abs,float* rot_rel,const float* rot_abs){ //カメラの回転を求める D3DXVECTOR3 camVec = cam->lookatPt - cam->eyePt; float camRot = atan2f(camVec.x,camVec.z); //カメラ分回転させて相対化 D3DXMATRIX around; D3DXMatrixRotationY(&around,camRot); D3DXVec3TransformCoord(stick_rel,stick_abs,&around); //回転を相対化 *rot_rel = camRot + *rot_abs; }
void CAnimationView::Update(void) { _matrix matScale, matRotX, matRotY, matRotZ, matTrans; D3DXMatrixScaling(&matScale, m_vScale.x, m_vScale.y, m_vScale.z); D3DXMatrixRotationX(&matRotX, m_fAngle[ANGLE_X]); D3DXMatrixRotationY(&matRotY, m_fAngle[ANGLE_Y]); D3DXMatrixRotationZ(&matRotZ, m_fAngle[ANGLE_Z]); D3DXMatrixTranslation(&matTrans, m_vPosition.x, m_vPosition.y, m_vPosition.z); m_matWorld = matScale * matRotX * matRotY * matRotZ * matTrans; Engine::GetGraphicDev() ->SetTransform(D3DTS_WORLD , &m_matWorld); }
PUBLIC void OBJRotY(hOBJ obj, float radian) { obj->wrldRot[eY] += radian; D3DXMATRIX mtxR; //set the rotation matrix D3DXMatrixRotationY(&mtxR, radian); D3DXMatrixMultiply(&obj->wrldMtx.mtxRot,&obj->wrldMtx.mtxRot,&mtxR); //set the world matrix D3DXMatrixMultiply(&obj->wrldMtx.mtxWrld,&obj->wrldMtx.mtxScale,&obj->wrldMtx.mtxRot); D3DXMatrixMultiply(&obj->wrldMtx.mtxWrld,&obj->wrldMtx.mtxWrld,&obj->wrldMtx.mtxTrans); }
/** * Draw() */ void Tank::Draw() { LPDIRECT3DDEVICE9 pDev = GameMain::GetD3DDevice(); D3DXMATRIX m, mPos, mRot; D3DXMatrixTranslation(&mPos, vPos.x, vPos.y, vPos.z); D3DXMatrixRotationY(&mRot, rotBody); // マテリアル設定 pDev->SetMaterial(&material); // 本体描画 D3DXMatrixIdentity(&m); m *= mRot * mPos; pDev->SetTransform(D3DTS_WORLD, &m); pMeshBody->DrawSubset(0); // 頭描画 D3DXMATRIX mPosHead; D3DXMATRIX mRotHead; D3DXMatrixIdentity(&m); D3DXMatrixTranslation(&mPosHead, 0, TANK_BODY_H, 0); D3DXMatrixRotationY(&mRotHead, rotHead); m *= mPosHead * mRot * mRotHead * mPos; pDev->SetTransform(D3DTS_WORLD, &m); pMeshHead->DrawSubset(0); // 砲塔描画 D3DXMATRIX mPosGun; D3DXMatrixIdentity(&m); D3DXMatrixTranslation(&mPosGun, 0, TANK_BODY_H+(TANK_HEAD_H-TANK_GUN_H)*0.5f, (TANK_HEAD_D+TANK_GUN_D)*0.5f); m *= mPosGun * mRot * mRotHead * mPos; pDev->SetTransform(D3DTS_WORLD, &m); pMeshGun->DrawSubset(0); }
void Cube_Textured::Update() { float tick = (float)GameManager::GetTick(); jumpTime += tick; if ((GetAsyncKeyState('A') & 0x8000) != 0) { rotationAxisY -= (rotationSpeed * tick); } else if ((GetAsyncKeyState('D') & 0x8000) != 0) { rotationAxisY += (rotationSpeed * tick); } if ((GetAsyncKeyState('W') & 0x8000) != 0) { position += (direction * moveSpeed * tick); } else if ((GetAsyncKeyState('S') & 0x8000) != 0) { position -= (direction * moveSpeed * tick); } if ((GetAsyncKeyState(VK_SPACE) & 0x8000) != 0 && isJumping == false ) { isJumping = true; jumpTime = 0.0f; } D3DXMATRIX rotX, rotY, move; D3DXMatrixRotationX(&rotX, rotationAxisX); D3DXMatrixRotationY(&rotY, rotationAxisY); world = rotX * rotY; D3DXVECTOR3 baseDirection(0, 0, 1); D3DXVec3TransformCoord(&direction, &baseDirection, &world); if (isJumping) { position.y = jumpPower * jumpTime - 4.9f/*0.5f * ( 9.8f ) */* jumpTime * jumpTime; if (position.y < 0.0) { isJumping = false; position.y = 0.0f; } } D3DXMatrixTranslation(&move, position.x, position.y, position.z); world *= move; }
void Camera::Update(float dt, float offsetHeight) { mDXInput->Update() ; // Find the net direction the camera is traveling in (since the // camera could be running and strafing). D3DXVECTOR3 dir(0.0f, 0.0f, 0.0f); if( mDXInput->KeyDown(DIK_W) ) dir += m_vForward; if( mDXInput->KeyDown(DIK_S) ) dir -= m_vForward; if( mDXInput->KeyDown(DIK_D) ) dir += m_vRight; if( mDXInput->KeyDown(DIK_A) ) dir -= m_vRight; // Move at mSpeed along net direction. D3DXVec3Normalize(&dir, &dir); D3DXVECTOR3 newPos = m_vEyePoint + dir * mSpeed * dt; m_vEyePoint = newPos ; if (m_vEyePoint.y < 1.0f) { m_vEyePoint.y = 1.0f ; } if (m_vEyePoint.y > 2.0f) { m_vEyePoint.y = 2.0f ; } // We rotate at a fixed speed. float pitch = mDXInput->MouseDY() / 360.0f; float yAngle = mDXInput->MouseDX() / 360.0f; // Rotate camera's look and up vectors around the camera's right vector. D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &m_vRight, pitch); D3DXVec3TransformCoord(&m_vForward, &m_vForward, &R); D3DXVec3TransformCoord(&m_vUp, &m_vUp, &R); // Rotate camera axes about the world's y-axis. D3DXMatrixRotationY(&R, yAngle); D3DXVec3TransformCoord(&m_vRight, &m_vRight, &R); D3DXVec3TransformCoord(&m_vForward, &m_vForward, &R); // Rebuild the view matrix to reflect changes. BuildViewMatrix(); }
bool graphics::RenderSceneToTexTure2() { D3DXMATRIX worldMatrix, lightViewMatrix, lightProjectionMatrix, translateMatrix,tempA,tempB,tempC; float posX, posY, posZ; // Set the render target to be the render to texture. _renderTexture2->SetRenderTarget(_D3D->GetDevice()); // Clear the render to texture. _renderTexture2->ClearRenderTarget(_D3D->GetDevice(), 0.0f, 0.0f, 0.0f, 1.0f); // Generate the light view matrix based on the light's position. _light2->GenerateViewMatrix(); // Get the world matrix from the d3d object. _D3D->GetWorldMatrix(worldMatrix); // Get the view and orthographic matrices from the light object. _light2->GetViewMatrix(lightViewMatrix); _light2->GetProjectionMatrix(lightProjectionMatrix); D3DXMatrixRotationY(&worldMatrix,_rotation1); // Setup the translation matrix for the cube model. _model2->RenderToGraphics(_D3D->GetDevice()); _depthShader->Render(_D3D->GetDevice(), _model2->GetIndexCount(), worldMatrix, lightViewMatrix, lightProjectionMatrix); _D3D->GetWorldMatrix(worldMatrix); D3DXMatrixTranslation(&tempA,0.0f,1.0f,0.5f); D3DXMatrixRotationX(&tempB, 90.0f); D3DXMatrixMultiply(&worldMatrix,&tempA,&tempB); D3DXMatrixScaling(&tempC,2.0f,2.0f,2.0f); D3DXMatrixMultiply(&worldMatrix,&worldMatrix,&tempC); _model->RenderToGraphics(_D3D->GetDevice()); _depthShader->Render(_D3D->GetDevice(), _model->GetIndexCount(), worldMatrix, lightViewMatrix, lightProjectionMatrix); // Render the cube model with the depth shader. // Reset the render target back to the original back buffer and not the render to texture anymore. _D3D->SetBackBufferRenderTarget(); // Reset the viewport back to the original. _D3D->ResetViewport(); return true; }
//------------------------------------------------------------- // Name: FrameMove() // Desc: �� �����Ӹ��� ȣ���. �ִϸ��̼� ó���� ��� //------------------------------------------------------------- HRESULT CMyD3DApplication::FrameMove() { // UFO�� �����δ� m_pos.x = 1.5f*(FLOAT)cos(1.0f*this->m_fTime)+1.0f; m_pos.z = 1.5f*(FLOAT)sin(1.0f*this->m_fTime); m_pos.y = 1.3f; UpdateInput( &m_UserInput ); // �Էµ����� ���� //--------------------------------------------------------- // �Է¿� ���� ��ǥ�踦 �����Ѵ� //--------------------------------------------------------- // ȸ�� 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_mWorld, &matRotY, &matRotX ); //--------------------------------------------------------- // ����� ���� //--------------------------------------------------------- // �� if( m_UserInput.bZoomIn && !m_UserInput.bZoomOut ) m_fViewZoom += m_fElapsedTime; else if( m_UserInput.bZoomOut && !m_UserInput.bZoomIn ) m_fViewZoom -= m_fElapsedTime; D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -m_fViewZoom ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec ); return S_OK; }
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; }
VOID SetupTigerSecondMatrices() { D3DXMATRIXA16 matWorld; D3DXMATRIXA16 matRotateWorld; D3DXMATRIXA16 resultMatrix; D3DXMatrixIdentity( &matWorld ); D3DXMatrixIdentity( &matRotateWorld ); D3DXMatrixRotationY( &matRotateWorld, timeGetTime() / 1000.0f ); D3DXMatrixTranslation( &matWorld, -1.5f, -1.0f, 0.3f ); // 제자리 돌기 D3DXMatrixMultiply( &resultMatrix, &matRotateWorld , &matWorld ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &resultMatrix ); }
/** * SetCamera() * カメラを設定する。 */ void Tank::SetCamera() { D3DXVECTOR3 vEye(0, 10.0f, -30.0f); D3DXVECTOR3 vAt(0, 10.0f, 10.0f); D3DXMATRIX m; D3DXMatrixRotationY(&m, rotBody); D3DXVec3TransformCoord(&vEye, &vEye, &m); D3DXVec3TransformCoord(&vAt, &vAt, &m); vEye += vPos; vAt += vPos; GameMain::GetInstance().SetCamera(vEye, vAt); }
/**----------------------------------------------------------------------------- * 애니메이션 설정 *------------------------------------------------------------------------------ */ VOID Animate() { D3DXMATRIXA16 matX; D3DXMATRIXA16 matY; D3DXMatrixRotationX( &matX, g_xRot ); D3DXMatrixRotationY( &matY, g_yRot ); g_matWorld = matX * matY; g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld ); /// 디바이스에 월드행렬 설정 g_pd3dDevice->SetTransform( D3DTS_VIEW, &g_matView ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_matProj ); SetupLights(); SetupFX(); LogFPS(); // 로깅 }
void CBlock::D(float ang) { D3DXMATRIX mat; D3DXMatrixRotationY(&mat, D3DX_PI*2-ang); int i; for (i=0; i<BLOCK_VERTEX_NUM; ++i) { D3DXVECTOR3 vec3(m_CubeVertex[i]._x, m_CubeVertex[i]._y, m_CubeVertex[i]._z); D3DXVECTOR3 vecOut; D3DXVec3TransformCoord(&vecOut, &vec3, &mat); m_CubeVertex[i]._x = vecOut.x; m_CubeVertex[i]._y = vecOut.y; m_CubeVertex[i]._z = vecOut.z; } }
Vector3 Vector::RotateZ(Vector3 * v, float fAngle) { Vector3 rV = *v; D3DXVec3Normalize(&rV, &rV); Matrix4x4 matRotZ, matRotY; // x축으로 먼저 회전 시킨다음, y축으로 회전 D3DXMatrixRotationZ(&matRotZ, D3DXToRadian(fAngle)); // x가 양수면 z축 방향을 바라봄, x가 음수면 -z축 방향을 바라봄 Vector3 vAxisZ(0, 0, 1); D3DXMatrixRotationY(&matRotY, GetAngleY(&rV)); D3DXVec3TransformNormal(&rV, &vAxisZ, &(matRotZ * matRotY)); return rV; }
void Camera::Yaw(float angle) { D3DXMATRIX T; // rotate around world y (0, 1, 0) always for land object if (m_CameraType == CAMERA_LAND) D3DXMatrixRotationY(&T, angle); // rotate around own up vector for aircraft if (m_CameraType == CAMERA_AIR) D3DXMatrixRotationAxis(&T, &m_Up, angle); // rotate m_Right and m_Look around m_Up or y-axis D3DXVec3TransformCoord(&m_Right,&m_Right, &T); D3DXVec3TransformCoord(&m_Look,&m_Look, &T); }
void CMyObject::Rotate(float x, float y, float z) { D3DXMATRIX mtxRotX; D3DXMATRIX mtxRotY; D3DXMATRIX mtxRotZ; m_rotAngles.x += x; m_rotAngles.y += y; m_rotAngles.z += z; D3DXMatrixRotationX(&mtxRotX,m_rotAngles.x); D3DXMatrixRotationY(&mtxRotY,m_rotAngles.y); D3DXMatrixRotationZ(&mtxRotZ,m_rotAngles.z); m_mtxRot = mtxRotX * mtxRotY * mtxRotZ; }
void Gear::Update() { rotation += 0.01f; if (rotation > 360.0f) rotation -= 360.0f; D3DXMATRIX rot; D3DXMatrixRotationY(&rot, rotation); rot._41 = world._41; rot._42 = world._42; rot._43 = world._43; world = rot; }
void Airplane::setWorldApproach(float fTime, D3DXMATRIXA16* mWorld, D3DXMATRIXA16* mWorld2) { if(!approach) { approach = true; tStart = fTime; } D3DXMatrixRotationY(&mRotationY, Rot); D3DXMatrixRotationZ(&mRotationZ, anim.GetFi(tActual)*A ); D3DXMatrixTranslation(&mTranslation, Xscale*anim.GetX(tActual)+Xtrans, Yscale*anim.GetY(tActual)+Ytrans, Ztrans); *mWorld2 = mRotationY*mRotationZ*mTranslation*(*mWorld); }
void CCamera::yaw(float angle){ D3DXMATRIX T; if (m_cameraType == CameraType::LANDOBJECT) { D3DXMatrixRotationY(&T,angle); } if (m_cameraType == CameraType::AIRCRAFT) { D3DXMatrixRotationAxis(&T,&g_vUp,angle); } D3DXVec3TransformCoord(&g_vLook,&g_vLook,&T); D3DXVec3TransformCoord(&g_vRight,&g_vRight,&T); }
void MANIPULATEPASSIVE::Rotation(float x,float y,float z) { D3DXMATRIX tmp; D3DXMatrixRotationAxis(&tmp,&right,x/180.0f*D3DX_PI); D3DXVec3TransformCoord(&up,&up,&tmp); D3DXVec3TransformCoord(&look,&look,&tmp); D3DXMatrixRotationY(&tmp,y/180.0f*D3DX_PI); D3DXVec3TransformCoord(&right,&right,&tmp); D3DXVec3TransformCoord(&look,&look,&tmp); D3DXMatrixRotationAxis(&tmp,&look,z/180.0f*D3DX_PI); D3DXVec3TransformCoord(&right,&right,&tmp); D3DXVec3TransformCoord(&up,&up,&tmp); }
void CGameObject::setupRotation() { D3DXMATRIX matWorldX, matWorldY, matWorldZ; // Rotate to global orientation D3DXMatrixRotationX(&matWorldX, m_Rotation.x); D3DXMatrixRotationY(&matWorldY, m_Rotation.y); D3DXMatrixRotationZ(&matWorldZ, m_Rotation.z); // Combine the transformations by multiplying them together D3DXMatrixMultiply(&m_MatWorld, &matWorld, &matWorldX); D3DXMatrixMultiply(&m_MatWorld, &m_MatWorld, &matWorldY); D3DXMatrixMultiply(&m_MatWorld, &m_MatWorld, &matWorldZ); }
void OrbitX::draw(int m){ D3DXMATRIX Rotate, Rotate2; D3DXMatrixRotationX(&Rotate, yaw); D3DXMatrixRotationY(&Rotate2, initPos+(Tools::g->CurrentTime - Networks::timediff)*(speeds)); World = Rotate*Rotate2; if(rotateSelf) World = Rotate2*World; Tools::m4_inverse(WorldInverse, World); PaintableX::draw(m); }
//-----------------------------------【Direct3D_Update( )函数】-------------------------------- // 描述:不是即时渲染代码但是需要即时调用的,如按键后的坐标的更改,都放在这里 //-------------------------------------------------------------------------------------------------- void Direct3D_Update( HWND hwnd) { //使用DirectInput类读取数据 g_pDInput->GetInput(); // 按住鼠标左键并拖动,为平移操作 static FLOAT fPosX = 0.0f, fPosY = 0.0f, fPosZ = 0.0f; if (g_pDInput->IsMouseButtonDown(0)) { fPosX += (g_pDInput->MouseDX())* 0.08f; fPosY += (g_pDInput->MouseDY()) * -0.08f; } //鼠标滚轮,为观察点收缩操作 fPosZ += (g_pDInput->MouseDZ())* 0.02f; // 平移物体 if (g_pDInput->IsKeyDown(DIK_A)) fPosX -= 0.005f; if (g_pDInput->IsKeyDown(DIK_D)) fPosX += 0.005f; if (g_pDInput->IsKeyDown(DIK_W)) fPosY += 0.005f; if (g_pDInput->IsKeyDown(DIK_S)) fPosY -= 0.005f; D3DXMatrixTranslation(&g_matWorld, fPosX, fPosY, fPosZ); // 按住鼠标右键并拖动,为旋转操作 static float fAngleX = 0.0f, fAngleY =0.0f; if (g_pDInput->IsMouseButtonDown(1)) { fAngleX += (g_pDInput->MouseDY())* -0.01f; fAngleY += (g_pDInput->MouseDX()) * -0.01f; } // 旋转物体 if (g_pDInput->IsKeyDown(DIK_UP)) fAngleX += 0.005f; if (g_pDInput->IsKeyDown(DIK_DOWN)) fAngleX -= 0.005f; if (g_pDInput->IsKeyDown(DIK_LEFT)) fAngleY -= 0.005f; if (g_pDInput->IsKeyDown(DIK_RIGHT)) fAngleY += 0.005f; D3DXMATRIX Rx, Ry; D3DXMatrixRotationX(&Rx, fAngleX); D3DXMatrixRotationY(&Ry, fAngleY); //得到最终的矩阵并设置 g_matWorld = Rx * Ry * g_matWorld;//得到最终的矩阵 g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld);//设置世界矩阵 }
VOID Render(float timeDelta) { SetupMatrix() ; g_ModelViewCamera->OnFrameMove(); // Save render target g_pd3dDevice->GetRenderTarget(0, &g_pOldRenderTarget) ; g_pd3dDevice->SetRenderTarget(0, g_pRenderSurface) ; g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0 ); // Begin the scene if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { // Without this line, the teapot won't show up, what's the inner stuff of SetTexture? g_pd3dDevice->SetTexture(0, NULL) ; // Disable lighting, since we didn't specify color for vertex g_pd3dDevice->SetRenderState( D3DRS_LIGHTING , FALSE ); g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME) ; D3DXMATRIX word ; D3DXMatrixTranslation(&word, 0.0f, 0.0f, 0.0f) ; static float totalTime = 0.0f ; totalTime += timeDelta * 2 ; D3DXMATRIX rot ; D3DXMatrixRotationY(&rot, totalTime) ; word *= rot ; g_pd3dDevice->SetTransform(D3DTS_WORLD, &word) ; g_pTeapotMesh->DrawSubset(0) ; // End the scene g_pd3dDevice->EndScene(); } // Restore the back buffer g_pd3dDevice->SetRenderTarget(0, g_pOldRenderTarget) ; RenderCube(timeDelta) ; // Present the back-buffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
//------------------------------------------------------------- // Name: FrameMove() // Desc: 매 프레임마다 호출됨. 애니메이션 처리등 담당 //------------------------------------------------------------- HRESULT CMyD3DApplication::FrameMove() { // 입력데이터 갱신 UpdateInput( &m_UserInput ); //--------------------------------------------------------- // 입력에 따라 좌표계를 갱신한다 //--------------------------------------------------------- // 회전 D3DXMATRIX matRotY; D3DXMATRIX matRotX; D3DXMATRIX mCamera; 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( &mCamera, &matRotY, &matRotX ); //--------------------------------------------------------- // 뷰행렬 설정 //--------------------------------------------------------- // 줌(zoom) if( m_UserInput.bZoomIn && !m_UserInput.bZoomOut ) m_fViewZoom += m_fElapsedTime; else if( m_UserInput.bZoomOut && !m_UserInput.bZoomIn ) m_fViewZoom -= m_fElapsedTime; m_vFromPt = D3DXVECTOR4( 0.0f, 0.f, -m_fViewZoom,1 ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, (D3DXVECTOR3*)&m_vFromPt, &vLookatPt, &vUpVec ); m_mView = mCamera * m_mView; return S_OK; }
bool Display(float timeDelta) { if( Device ) { // // Update: Rotate the cube. // D3DXMATRIX xRot; D3DXMatrixRotationX(&xRot, D3DX_PI * 0.2f); static float y = 0.0f; D3DXMATRIX yRot; D3DXMatrixRotationY(&yRot, y); y += timeDelta; if( y >= 6.28f ) y = 0.0f; CubeWorldMatrix = xRot * yRot; // 合并旋转 // // Render // Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0); Device->BeginScene(); // draw back drop D3DXMATRIX I; D3DXMatrixIdentity(&I); Device->SetStreamSource(0, BackDropVB, 0, sizeof(Vertex)); Device->SetFVF(FVF_VERTEX); Device->SetTexture(0, BackDropTex); Device->SetTransform(D3DTS_WORLD, &I); Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); // draw cube Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true); if(Box) Box->draw(&CubeWorldMatrix, 0, CrateTex); Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false); Device->EndScene(); Device->Present(0, 0, 0, 0); } return true; }
Matrix3& Matrix3::RotateY( const Real y ) { #ifdef __USE_D3DX__ D3DXMatrixRotationY( (D3DXMATRIX*)this, y ); #else Real fCos = COS( y ); Real fSin = SIN( y ); Zero(); e[5] = e[15] = 1.0; e[0] = e[10] = fCos; e[2] = -fSin; e[8] = fSin; #endif return *this; }