/** * Updates the roll matrix, seems to be senseless right now, just calls D3DXMatrixRotationZ(). * @param roll Angle of rotation, in radians. ***/ void ViewAdjustment::UpdateRoll(float roll) { D3DXMatrixIdentity(&rollMatrix); D3DXMatrixRotationZ(&rollMatrix, roll); D3DXMatrixRotationZ(&rollMatrixNegative, -roll); D3DXMatrixRotationZ(&rollMatrixHalf, roll * 0.5f); }
D3DXMATRIX CParticle::GetRotateMatrix() { D3DXMATRIX d3dRotX,d3dRotY,d3dRotZ; D3DXMatrixRotationZ(&d3dRotX,D3DXToRadian(m_d3dCurRotation[0])); D3DXMatrixRotationZ(&d3dRotY,D3DXToRadian(m_d3dCurRotation[1])); D3DXMatrixRotationZ(&d3dRotZ,D3DXToRadian(m_d3dCurRotation[2])); return d3dRotX*d3dRotY*d3dRotZ; }
void Tree::LineRender(D3DXVECTOR3 start, D3DXVECTOR3 dir, int deep) { Line line; line.Draw(start, start + dir); float d = 0.8; float angle = 30; //変更 D3DXMATRIX right, left; D3DXVECTOR3 vec; D3DXVECTOR3 vR, vL; //start = start + dir; vec = dir; D3DXMatrixRotationZ(&right, D3DXToRadian(-angle)); D3DXVec3TransformCoord(&vec, &dir, &right); vec *= d; line.Draw(start + dir, start + dir + vec); vR = vec; vec = dir; D3DXMatrixRotationZ(&left, D3DXToRadian(angle)); D3DXVec3TransformCoord(&vec, &dir, &left); vec *= d; line.Draw(start + dir, start + dir + vec); vL = vec; if (deep >= 1) { vec = vR; D3DXMatrixRotationZ(&right, D3DXToRadian(-angle)); D3DXVec3TransformCoord(&vec, &vec, &right); vec *= d; LineRender(start + dir + vR, vec, deep - 1); vec = vL; D3DXMatrixRotationZ(&left, D3DXToRadian(angle)); D3DXVec3TransformCoord(&vec, &vec, &left); vec *= d; LineRender(start + dir + vL, vec, deep - 1); } //start = start + vec; //Hello //メッセージ }
void GegnerColumn::DoDraw(void) { D3DXMATRIX matWorld, matRot, matTrans, matTrans2; // Rotations und Translations Matrizen int Winkel; // Rotationswinkel Winkel = int(AnimCount); // Winkel angleichen, damit er immer zwischen 0° und 360° bleibt // if (Winkel > 360) Winkel -= 360; if (Winkel < 0) Winkel += 360; D3DXMatrixRotationZ (&matRot, DegreetoRad[Winkel]); D3DXMatrixTranslation(&matTrans, float (-(xPos-pTileEngine->XOffset+40)),float (-(yPos-pTileEngine->YOffset+100)), 0.0f); // Transformation zum Ursprung D3DXMatrixTranslation(&matTrans2,float (xPos-pTileEngine->XOffset+40), float ( yPos-pTileEngine->YOffset+100), 0.0f); // Transformation wieder zurück D3DXMatrixIdentity (&matWorld); D3DXMatrixMultiply (&matWorld, &matWorld, &matTrans); // Verschieben D3DXMatrixMultiply (&matWorld, &matWorld, &matRot); // rotieren D3DXMatrixMultiply (&matWorld, &matWorld, &matTrans2); // und wieder zurück verschieben // rotierte Matrix setzen #if defined(PLATFORM_DIRECTX) lpD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); #elif defined(PLATFORM_SDL) g_matModelView = matWorld * g_matView; #if defined(USE_GL1) load_matrix( GL_MODELVIEW, g_matModelView.data() ); #endif #endif pGegnerGrafix[GegnerArt]->RenderSprite ((float)(xPos-pTileEngine->XOffset), (float)(yPos-pTileEngine->YOffset), 0, 0xFFFFFFFF); // Normale Projektions-Matrix wieder herstellen D3DXMatrixRotationZ (&matWorld, 0.0f); #if defined(PLATFORM_DIRECTX) lpD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); #elif defined(PLATFORM_SDL) g_matModelView = matWorld * g_matView; #if defined(USE_GL1) load_matrix( GL_MODELVIEW, g_matModelView.data() ); #endif #endif SetScreenShake(); }
void GameObject::Update( float fDT ) { if( m_pMeshObject ) { if( !m_bUseMatrix ) { D3DXMATRIX MatrixTrans; D3DXMatrixTranslation( &MatrixTrans, m_vPosition.x, m_vPosition.y, m_vPosition.z ); D3DXMATRIX MatrixRotateX, MatrixRotateY, MatrixRotateZ; D3DXMatrixRotationX( &MatrixRotateX, m_AngleXYZ.x ); D3DXMatrixRotationY( &MatrixRotateY, m_AngleXYZ.y ); D3DXMatrixRotationZ( &MatrixRotateZ, m_AngleXYZ.z ); D3DXMATRIX MatrixRotate = MatrixRotateX * MatrixRotateY * MatrixRotateZ; m_MatrixRelease = MatrixRotate * MatrixTrans; // если есть предок, то сначала берём его матрицу if( m_pObjectParent ) m_MatrixRelease = m_MatrixRelease * m_pObjectParent->GetReleaseMatrix(); } } for( std::list< GameObject* >::iterator iter = m_ObjectChild.begin(); iter != m_ObjectChild.end(); ++iter ) { (*iter)->Update( fDT ); } }
//--------------------------------------- //NAME : SetTransform() //DESC : 坐标转换 //--------------------------------------- void SetTransform() { //设置世界变换矩阵 D3DXMATRIX matWorld,Rx,Ry,Rz; D3DXMatrixIdentity(&matWorld);//单位矩阵 D3DXMatrixRotationX(&Rx,::timeGetTime()/1000.f);//绕x轴旋转 D3DXMatrixRotationY(&Ry,::timeGetTime()/1000.f);//绕y轴旋转 D3DXMatrixRotationZ(&Rz,::timeGetTime()/1000.f);//绕z轴旋转 matWorld=Rx*Ry*Rz*matWorld; g_pd3dDevice->SetTransform(D3DTS_WORLD,&matWorld); //设置取景变换矩阵 D3DXMATRIX matView; D3DXVECTOR3 vEye(0.0f,0.0f,-30.0f); D3DXVECTOR3 vAt(0.0f,0.0f,0.0f); D3DXVECTOR3 vUp(0.0f,1.0f,0.0f); D3DXMatrixLookAtLH(&matView,&vEye,&vAt,&vUp); g_pd3dDevice->SetTransform(D3DTS_VIEW,&matView); //设置投影变换矩阵 D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj,D3DX_PI/4.0f,1.0f,1.0f,1000.0f); g_pd3dDevice->SetTransform(D3DTS_PROJECTION,&matProj); }
void MenuObjects::Update() { if(mScale.x > 1.0f) { mScale.x -= gDeltaTime * 0.5f; mScale.y -= gDeltaTime * 0.5f; mScale.z -= gDeltaTime * 0.5f; } if(miniSelector == mId - 1) { mRotated = false; } if(miniSelector != mId - 1) { if(((int)(mRotation.y * (180 / PI)) % 90) == 0) { mRotated = true; } } D3DXMatrixScaling(&S, mScale.x, mScale.y, mScale.z); D3DXMatrixRotationX(&Rx, mRotation.x); D3DXMatrixRotationY(&Ry, mRotation.y); D3DXMatrixRotationZ(&Rz, mRotation.z); D3DXMatrixTranslation(&T, mPosition.x, mPosition.y, mPosition.z); W = S * Rx * Ry * Rz * T; }
void MyMesh::RotateZ(FLOAT q) { D3DXMATRIX rot; D3DXMatrixIdentity(&rot); D3DXMatrixRotationZ(&rot, q); rotationMatrix = rotationMatrix * rot; }
void SetMatrix(void) { //世界变换矩阵的设置 D3DXMATRIX matWorld, rx, ry, rz; D3DXMatrixIdentity(&matWorld); D3DXMatrixRotationX(&rx, PI * (timeGetTime() / 1000.0f)); D3DXMatrixRotationY(&ry, PI * (timeGetTime() / 1000.0f) / 2.0f); D3DXMatrixRotationZ(&rz, PI * (timeGetTime() / 1000.0f) / 3.0f); matWorld = rx * ry * rz * matWorld; g_pDevice->SetTransform(D3DTS_WORLD, &matWorld); //取景变换矩阵的设置 D3DXMATRIX matView; D3DXVECTOR3 eye(0.0f, 0.0f, -50.0f); D3DXVECTOR3 at(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &eye, &at, &up); g_pDevice->SetTransform(D3DTS_VIEW, &matView); //投影变换矩阵的设置 D3DXMATRIX matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, PI / 4.0f, 800.0f / 600.0f, 1.0f, 1000.0f); g_pDevice->SetTransform(D3DTS_PROJECTION, &matProjection); //视口变换的设置 D3DVIEWPORT9 vp; vp.X = 0; vp.Y = 0; vp.Width = SCREEN_WIDTH; vp.Height = SCREEN_HEIGHT; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; g_pDevice->SetViewport(&vp); }
void RenderModel::render() { // negative id are for invisible/container objects if(modelId >= 0) { Point_t pos = ref->getPos(); Rot_t rot = ref->getRot(); //Get translation/rotation matrix D3DXMATRIX trans, rotX, rotY, rotZ, scaleMat; D3DXMatrixIdentity(&trans); D3DXMatrixIdentity(&rotX); D3DXMatrixIdentity(&rotY); D3DXMatrixIdentity(&rotZ); D3DXMatrixTranslation(&trans, pos.x, pos.y, pos.z); D3DXMatrixRotationX(&rotX, rot.x); D3DXMatrixRotationY(&rotY, rot.y); D3DXMatrixRotationZ(&rotZ, rot.z); D3DXMatrixScaling(&scaleMat,scale.x,scale.y,scale.z); //DC::get()->print("(%f,%f,%f), (%f,%f,%f)\n", pos.x, pos.y, pos.z, rot.x, rot.y, rot.z); //Render RE::get()->animate(modelId, scaleMat * rotX * rotY * rotZ * trans); } }
/* * constructor */ Transformable::Transformable(void) { D3DXMatrixRotationX(&rotateX, D3DXToRadian(0.0f)); D3DXMatrixRotationY(&rotateY, D3DXToRadian(0.0f)); D3DXMatrixRotationZ(&rotateZ, D3DXToRadian(0.0f)); D3DXMatrixScaling(&scale, 1.0f, 1.0f, 1.0f); D3DXMatrixTranslation(&translate, 0.0f, 0.0f, 0.0f); }
static void renderchain_set_mvp(void *data, unsigned vp_width, unsigned vp_height, unsigned rotation) { #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_HLSL) video_shader_ctx_mvp_t mvp; #endif d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; #if defined(_XBOX360) && defined(HAVE_HLSL) hlsl_set_proj_matrix(XMMatrixRotationZ(rotation * (M_PI / 2.0))); mvp.data = d3d; mvp.matrix = NULL; video_shader_driver_set_mvp(mvp); #elif defined(HAVE_D3D8) D3DXMATRIX p_out, p_rotate, mat; D3DXMatrixOrthoOffCenterLH(&mat, 0, vp_width, vp_height, 0, 0.0f, 1.0f); D3DXMatrixIdentity(&p_out); D3DXMatrixRotationZ(&p_rotate, rotation * (M_PI / 2.0)); d3d_set_transform(d3dr, D3DTS_WORLD, &p_rotate); d3d_set_transform(d3dr, D3DTS_VIEW, &p_out); d3d_set_transform(d3dr, D3DTS_PROJECTION, &p_out); #endif }
VOID CameraWorkBase::SetMatrix( LPD3DXVECTOR3 _pvecScale, LPD3DXVECTOR3 _pvecRotate, LPD3DXVECTOR3 _pvecTranslate ) { // Set World Matrix D3DXMATRIX matScale; D3DXMatrixIdentity( &matScale ); D3DXMatrixScaling( &matScale, _pvecScale->x, _pvecScale->y, _pvecScale->z ); D3DXMATRIX matRotateX; D3DXMatrixIdentity( &matRotateX ); D3DXMatrixRotationX( &matRotateX, _pvecRotate->x ); D3DXMATRIX matRotateY; D3DXMatrixIdentity( &matRotateY ); D3DXMatrixRotationY( &matRotateY, _pvecRotate->y ); D3DXMATRIX matRotateZ; D3DXMatrixIdentity( &matRotateZ ); D3DXMatrixRotationZ( &matRotateZ, _pvecRotate->z ); D3DXMATRIX matTranslate; D3DXMatrixIdentity( &matTranslate ); D3DXMatrixTranslation( &matTranslate, _pvecTranslate->x, _pvecTranslate->y, _pvecTranslate->z ); D3DXMATRIX matWorld; D3DXMatrixIdentity( &matWorld ); matWorld = matScale * matRotateX * matRotateY * matRotateZ * matTranslate; m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); }
void RollingBall::drawObject(IDirect3DDevice9 *d3dDev) { D3DXMATRIX worldMat, viewMat, matTransform, matProjection, matScale, matTranslate, matRotation; if(actor == NULL) { return; } //scaling D3DXMatrixScaling(&matScale,1.0f, 1.0f, 1.0f); worldMat = matScale; //rotation if(xRot) D3DXMatrixRotationX(&matRotation, getRotX()); else D3DXMatrixRotationZ(&matRotation, getRotZ()); worldMat *= matRotation; //translation D3DXMatrixTranslation(&matTranslate, getX(), getY(), getZ()); worldMat *= matTranslate; //final matrix = ISROT, identity * scale * rotation * orbit * translation d3dDev->SetTransform(D3DTS_WORLD, &worldMat); //set texture d3dDev->SetTexture(0, texture); //draw object mesh->DrawSubset(0); }
void SetBlockPosition ( BRUSH* pBrush, float fX, float fY, float fZ, float fScale ) { D3DXMATRIX matTranslation; // translation ( position ) D3DXMATRIX matRotation, matRotateX, matRotateY, matRotateZ; // rotation D3DXMATRIX matScale; // scale D3DXMATRIX matViewInverse; D3DXMATRIX matView; // use this for the inverse function float fDet; // apply scaling to the object D3DXMatrixScaling ( &matScale, fScale, fScale, fScale ); // apply translation to the object D3DXMatrixTranslation ( &matTranslation, fX, fY, fZ ); // setup rotation matrices D3DXMatrixRotationX ( &matRotateX, D3DXToRadian ( 0.0f ) ); // x rotation D3DXMatrixRotationY ( &matRotateY, D3DXToRadian ( 0.0f ) ); // y rotation D3DXMatrixRotationZ ( &matRotateZ, D3DXToRadian ( 0.0f ) ); // z rotation // build final rotation matrix matRotation = matRotateX * matRotateY * matRotateZ; pBrush->Matrix = matRotation * matScale * matTranslation; }
void Graphics::Update(float deltaTime, HWND hWndMain) { float speed = deltaTime / 3; D3DXMATRIX rot; D3DXMatrixRotationZ(&rot, speed); speed *= 3; //m_Camera->Position = m_Light->getDirectionalLights()[0].position; //m_Camera->Forward = m_Light->getDirectionalLights()[0].direction; D3DXMatrixRotationY(&rot, speed); LPRECT Rect = new RECT(); GetWindowRect(hWndMain, Rect); LPPOINT mousePos = new POINT(); GetCursorPos(mousePos); int centerX = (Rect->left + Rect->right) * 0.5f; int centerY = (Rect->top + Rect->bottom) * 0.5f; D3DXVECTOR2 mouseMovement = D3DXVECTOR2(mousePos->x - centerX, centerY - mousePos->y); SetCursorPos(centerX, centerY); m_Camera->Update(deltaTime, mouseMovement); //m_object->SetRotation(m_object->getRotation().x + (deltaTime * 1.2f), 0, 0); m_object->Frame(deltaTime); m_objectT->Frame(deltaTime); }
void Node::update() { if (!needUpdate) { updateChild(); return; } D3DXMATRIX matrix; float tmp_ap_x = m_v2AnchontPoint.x * m_siContentSize.width; float tmp_ap_y = m_v2AnchontPoint.y * m_siContentSize.height; D3DXMatrixTranslation(&matrix, tmp_ap_x, tmp_ap_y, 0); mMatrix = mMatrix * matrix; D3DXMatrixScaling(&matrix, m_v2Scale.x, m_v2Scale.y, 1); mMatrix = mMatrix * matrix; D3DXMatrixRotationX(&matrix, m_v3Rotate.x); mMatrix = mMatrix * matrix; D3DXMatrixRotationY(&matrix, m_v3Rotate.y); mMatrix = mMatrix * matrix; D3DXMatrixRotationZ(&matrix, m_v3Rotate.z); mMatrix = mMatrix * matrix; D3DXMatrixTranslation(&matrix, m_v2Position.x, m_v2Position.y, 0); mMatrix = mMatrix * matrix; if (m_parent) mMatrix = mMatrix * (*m_parent->mMatrix); auto itor = m_childList.begin(); for (; itor != m_childList.end(); ++itor) (*itor)->setUpdate(true); updateChild(); }
void RobotArmDemo::buildBoneWorldTransforms() { // First, construct the transformation matrix that transforms // the ith bone into the coordinate system of its parent. D3DXMATRIX R, T; D3DXVECTOR3 p; for(int i = 0; i < NUM_BONES; ++i) { p = mBones[i].pos; D3DXMatrixRotationZ(&R, mBones[i].zAngle); D3DXMatrixTranslation(&T, p.x, p.y, p.z); mBones[i].toParentXForm = R * T; } // Now, the ith object's world transform is given by its // to-parent transform, followed by its parent's to-parent transform, // followed by its grandparent's to-parent transform, and // so on, up to the root's to-parent transform. // For each bone... for(int i = 0; i < NUM_BONES; ++i) { // Initialize to identity matrix. D3DXMatrixIdentity(&mBones[i].toWorldXForm); // Combine W[i] = W[i]*W[i-1]*...*W[0]. for(int j = i; j >= 0; --j) { mBones[i].toWorldXForm *= mBones[j].toParentXForm; } } }
static void xdk_d3d_set_rotation(void *data, unsigned orientation) { (void)data; xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data; FLOAT angle = 0; switch(orientation) { case ORIENTATION_NORMAL: angle = M_PI * 0 / 180; break; case ORIENTATION_FLIPPED_ROTATED: angle = M_PI * 90 / 180; break; case ORIENTATION_FLIPPED: angle = M_PI * 180 / 180; break; case ORIENTATION_VERTICAL: angle = M_PI * 270 / 180; break; } #if defined(HAVE_HLSL) /* TODO: Move to D3DXMATRIX here */ hlsl_set_proj_matrix(XMMatrixRotationZ(angle)); #elif defined(_XBOX1) D3DXMATRIX p_out, p_rotate; D3DXMatrixIdentity(&p_out); D3DXMatrixRotationZ(&p_rotate, angle); RD3DDevice_SetTransform(d3d->d3d_render_device, D3DTS_WORLD, &p_rotate); RD3DDevice_SetTransform(d3d->d3d_render_device, D3DTS_VIEW, &p_out); RD3DDevice_SetTransform(d3d->d3d_render_device, D3DTS_PROJECTION, &p_out); #endif }
void ScreenElement::UpdateTransform(void) { D3DXMATRIX TempScale, TempRot; D3DXMatrixScaling(&TempScale, scale.x, scale.y, 1); D3DXMatrixRotationZ(&TempRot, rot); transform=TempScale*TempRot; }
myApp::myApp(int nW, int nH, void* hInst, int nCmdShow) : cglApp(nW, nH, hInst, nCmdShow) , m_nPrevMouseX(-100) , m_nPrevMouseY(-100) , camera(m_pD3D->getDevice()) , light(m_pD3D->getDevice()) , mesh(m_pD3D->getDevice(), "Dwarf.x") , effect("shader.fx",m_pD3D->getDevice()) { for (int i = 0; i < MAX_KEYS; i++) m_keysPressed[i] = false; D3DXMATRIX M1,M2; D3DXMatrixRotationX(&M1, PI_F / 2); D3DXMatrixRotationZ(&M2, -PI_F / 4); D3DXMatrixMultiply(&M1,&M1,&M2); mesh.setWorldMatrix(M1); light.setLight(); //mesh.LoadTexture("straw512.jpg", NULL, 0); camera.setCameraPosition(D3DXVECTOR3(1.5f, 1.5f, 2.0f)); camera.setCameraVectors(D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f)); camera.setProjection(2 * atan(16.0f / 9.0f), PI_F / 3, 0.1f, 1000.0f); effect.setLightType(true); mesh.setEffectHadlers(&effect); // Set Parameters }
/** @param texture The texture to draw. @param x The X coordinate. @param y The Y coordinate. @param width The width. @param height The height. @param rotation Rotation of the texture. @param sourceRect The part of the texture to draw. @param flipped Draw the texture flipped or not. @note The rotation is measured in radians. @note The source rect is in image coordinates. Not in 0-1 range. */ void Graphics::drawTexture(IDirect3DTexture9 *texture, float x, float y, int width, int height, float rotation, Rect* sourceRect, bool flipped) { // Set stream source and vertex declaration HR(gd3dDevice->SetStreamSource(0, mVB_fast, 0, sizeof(TextureVertex))); HR(gd3dDevice->SetVertexDeclaration(TextureVertex::Decl)); // Set the translation matrix D3DXMatrixTranslation(&T, x, y, 0); // Set the scaling matrix D3DXMatrixScaling(&S, (float)width/100.0f, (float)height/100.0f, 0); // Set the rotation matrix D3DXMatrixRotationZ(&R, rotation); // Combine them and set the transform matrix (the order is important, it must be scaling * rotation * translation) HR(gd3dDevice->SetTransform(D3DTS_WORLD, &(S*R*T))); // Set the texture HR(gd3dDevice->SetTexture(0, texture)); // Draw the primitive HR(gd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2)); // Restore the transform matrix to the identity matrix // :NOTE: Having a member identity matrix would improve the renderering with some fps D3DXMatrixIdentity(&T); HR(gd3dDevice->SetTransform(D3DTS_WORLD, &T)); gd3dDevice->SetTexture(0, NULL); }
Matrix LampPost::transform(Vector3 scale, Vector3 rotate, Vector3 translate) { Matrix transformation = Matrix(); Identity(&transformation); Matrix scaley; Matrix rotx; Matrix roty; Matrix rotz; Matrix rot; Matrix transy; Identity(&scaley); Identity(&rotx); Identity(&roty); Identity(&rotz); Identity(&rot); Identity(&transy); //scale rotate translate D3DXMatrixScaling(&scaley, scale.x, scale.y, scale.z); D3DXMatrixRotationX(&rotx, rotate.x); D3DXMatrixRotationY(&roty, rotate.y); D3DXMatrixRotationZ(&rotz, rotate.z); D3DXMatrixTranslation(&transy, translate.x, translate.y, translate.z); rot = rotx*roty*rotz; transformation *= scaley; transformation *= rot; transformation *= transy; return transformation; }
void CSprite::SetupMatrices() { const LPDIRECT3DDEVICE9 pd3dDevice = g_D3dDevice->GetDevice() ; D3DXMATRIXA16 matWorld, matX, matY, matZ, matT, matT2, matS ; D3DXMatrixIdentity( &matWorld ) ; D3DXMatrixRotationZ(&matX, m_fAngle[0]) ; D3DXMatrixRotationZ(&matY, m_fAngle[1]) ; D3DXMatrixRotationZ(&matZ, m_fAngle[2]) ; D3DXMatrixTranslation( &matT, m_Position.x, m_Position.y, m_Position.z ) ; D3DXMatrixTranslation( &matT2, m_CenterPosition.x, m_CenterPosition.y, 0.0f) ; D3DXMatrixScaling( &matS, m_fScaleX, m_fScaleY, 0.0f ) ; matWorld = matWorld * matT2 * matX * matY * matZ * matS * matT ; pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ) ; }
void CTerrain::CalcWorldMatrix(IRenderer* _pRenderManager) { //Matrices to make up the World Matrix, mostly unused and set to identity D3DXMATRIX matRotateAroundX; D3DXMatrixIdentity(&matRotateAroundX); D3DXMATRIX matRotateAroundY; D3DXMatrixIdentity(&matRotateAroundY); D3DXMATRIX matRotateAroundZ; D3DXMatrixIdentity(&matRotateAroundZ); D3DXMATRIX matTranslation; D3DXMatrixIdentity(&matTranslation); //Reset World matrix D3DXMatrixIdentity(&m_matWorld); //Create Rotational Matrices for the terrain based the Yaw/Pitch/Roll values D3DXMatrixRotationX(&matRotateAroundX, m_fRotPitch); D3DXMatrixRotationY(&matRotateAroundY, m_fRotYaw); D3DXMatrixRotationZ(&matRotateAroundZ, m_fRotRoll); //Create the Translation Matrix from the terrain Position coordinates, which should never change D3DXMatrixTranslation(&matTranslation, m_f3Center.x, m_f3Center.y, m_f3Center.z); m_matWorld = (matRotateAroundX * matRotateAroundY * matRotateAroundZ * matTranslation); //Set The World Matrix for this Terrain on the Device _pRenderManager->SetWorldMatrix(m_matWorld); }
void CModel::UpdateMatrices() { // Rotation D3DXMATRIX translation; D3DXMATRIX scale; D3DXMATRIX matrixRotationX; D3DXMATRIX matrixRotationY; D3DXMATRIX matrixRotationZ; // Calculate the rotation of the model. float rotX = (GetRotationX() * PrioEngine::kPi) / 180.0f; float rotY = (GetRotationY() * PrioEngine::kPi) / 180.0f; float rotZ = (GetRotationZ() * PrioEngine::kPi) / 180.0f; D3DXMatrixRotationX(&matrixRotationX, rotX); D3DXMatrixRotationY(&matrixRotationY, rotY); D3DXMatrixRotationZ(&matrixRotationZ, rotZ); // Calculate scaling. D3DXMatrixScaling(&scale, GetScaleX(), GetScaleY(), GetScaleZ()); // Calculate the translation of the model. D3DXMatrixTranslation(&translation, GetPosX(), GetPosY(), GetPosZ()); // Calculate the world matrix mWorldMatrix = scale * matrixRotationX * matrixRotationY * matrixRotationZ * translation; }
void CElementManager::CreateCircle(const D3DXVECTOR3& pos, FLOAT intensity, const SMap *map, FLOAT lastTime, FLOAT length, INT max, DWORD color, BOOL isPlayer) { D3DXVECTOR3 dir; D3DXMATRIX trans; if (intensity > 1.f) intensity = 1.f; INT cnt = static_cast<INT>(max*intensity+0.5f); D3DXMatrixRotationZ(&trans, 2*D3DX_PI/cnt); UINT t; do { rand_s(&t); dir.x = t%10-5.f; rand_s(&t); dir.y = t%10-5.f; } while (dir.x == 0.f && dir.y == 0.f); dir.z = 0.f; D3DXVec3Normalize(&dir, &dir); if (isPlayer) for (INT i(0); i < cnt; ++i) { D3DXVec3TransformNormal(&dir, &dir, &trans); m_pEcho.push_back(new CLine(pos, dir, intensity, map, intensity <= 2.f/9, lastTime, length, color)); } else for (INT i(0); i < cnt; ++i) { D3DXVec3TransformNormal(&dir, &dir, &trans); m_pAmbience.push_back(new CLine(pos, dir, intensity, map, intensity <= 2.f/9, lastTime, length, color)); } }
void CHasu::Update() { CPlayer* player = STAGEMANEGER->GetStage()->GetPlayer(); D3DXVECTOR3 pos = player->GetPosition(); if (m_timerFlag == true){ m_time++; } else{ } if (m_time >= DOWN){ m_data.position.y -= 0.05f; if (m_time % 15 == 0){ } if (m_timerFlag == true){ g_bulletPhysics.RemoveRigidBody(m_rigidBody); } m_timerFlag = false; } else if (m_time >= QUAKE){ D3DXMatrixRotationZ(&matWorld2, m_quake); if (m_time % 5 == 0){ m_quake *= -1; } } }
void d3d_set_projection_perspective(gs_scalar x, gs_scalar y, gs_scalar width, gs_scalar height, double angle) { D3DXMATRIX matRotZ, matTrans, matScale; // Calculate rotation matrix D3DXMatrixRotationZ( &matRotZ, angle ); // Roll // Calculate a translation matrix D3DXMatrixTranslation(&matTrans, -x, -y, 0); D3DXMatrixScaling(&matScale, 1, 1, 1); // Calculate our world matrix by multiplying the above (in the correct order) D3DXMATRIX matWorld=matRotZ*matTrans*matScale; D3DXMATRIX matProjection; // the projection transform matrix D3DXMatrixOrthoOffCenterLH(&matProjection, 0, (FLOAT)width, 0, (FLOAT)height, -32000.0f, // the near view-plane 32000.0f); // the far view-plane // Set the matrix to be applied to anything we render from now on d3dmgr->SetTransform( D3DTS_VIEW, &matProjection); D3DXMATRIX matProj; // the projection transform matrix D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(60), width/height, 0.1, 32000); // the far view-plane d3dmgr->SetTransform(D3DTS_PROJECTION, &matProj); // set the projection transform }
void RenderSprite::Rotate(float radians) { D3DXMATRIX mat; // This is untested, old version was a local rotate, this might be backwards D3DXMatrixMultiply(renderModelPtr->GetWorldMatrixPtr(), renderModelPtr->GetWorldMatrixPtr(), D3DXMatrixRotationZ(&mat, radians)); }