void Test5::SetupMeshes() { mesh1 = GetGreng().GetMeshManager().CreateMeshCube(); mesh2 = GetGreng().GetMeshManager().CreateMeshQuad(); mesh3 = GetGreng().GetMeshManager().CreateMeshFromObjFile( "assets/mt.obj"); mesh4 = GetGreng().GetMeshManager().CreateMeshFromObjFile( "assets/RB-BumbleBee.obj"); GetGreng().GetMeshManager().ComputeNormals(mesh3); GetGreng().GetMeshManager().ComputeTangentSpace(mesh3); GetGreng().GetMeshManager().ComputeNormals(mesh4); Matrix4f s; MatrixScale(s, Vec3f(0.1)); Matrix4f rx; MatrixRotationX(rx, -M_PI / 2.0); Matrix4f ry; MatrixRotationY(ry, -M_PI / 2.0); Matrix4f rxy; MatrixMultiply(ry, rx, rxy); MatrixMultiply(rxy, s, mesh3ConstMatrix); }
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 CPlayer::PostDraw(void) { if (!m_pMesh) { return; } // 後ろ向きモデルのため、Y軸180度回転 MATRIX world; MatrixRotationY(&world, RAD * 180); MatrixMultiply(&world, &m_world, &world); DrawMeshAlpha(&world, m_pMesh); }
// Camera rotate horizontally void CViewerScene::CameraRotateHor (float _fAngle) { OGVec3 vTarget (0, 0, 0); OGMatrix mR; MatrixRotationY(mR, _fAngle); OGVec3 vDir, vRight; MatrixVec3Multiply(vDir, m_pCamera->GetDirection(), mR); MatrixVec3Multiply(vRight, m_pCamera->GetRight(), mR); vDir.normalize(); OGVec3 vUp = vDir.cross (vRight); m_pCamera->Setup (vTarget - (vDir*m_fCameraDistance), vTarget, vUp); }
void BoxBrowser::SetZoomMatrix() { MATRIX mtxScale = MatrixScale( zScale, zScale, zScale ); MATRIX matrixX = MatrixRotationX( FROM_ANGLE( zRotX ) ); MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zRotZ ) ); // rotate and translate MATRIX mx = MatrixRotationY( FROM_ANGLE( zRotY ) ); //rotate mx = MatrixMultiply( mx, matrixX ); mx = MatrixMultiply( mx, matrixZ ); mx = MatrixMultiply( mx, mtxScale ); //scale this thing up mx = MatrixMultiply( mx, MatrixTranslation( zPosX, zPosY, zPosZ ) ); //translate into place //apply matrix tiny3d_SetMatrixModelView( &mx ); }
void BoxBrowser::CreateMatrix( float xpos, float ypos, float zpos, float xrot, float yrot, float zrot, float scale ) { MATRIX mtxScale = MatrixScale( scale, scale, scale ); MATRIX matrixX = MatrixRotationX( FROM_ANGLE( xrot ) ); MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zrot ) ); // rotate and translate MATRIX mx = MatrixRotationY( FROM_ANGLE( yrot ) ); //rotate mx = MatrixMultiply( mx, matrixX ); mx = MatrixMultiply( mx, matrixZ ); mx = MatrixMultiply( mx, mtxScale ); //scale this thing up mx = MatrixMultiply( mx, MatrixTranslation( xpos, ypos, zpos ) ); //translate into place //put this matrix in the list mtxBox.push_back( mx ); }
void Test5::Render() { Test3::Render(); if (mesh1 != nullptr) { Matrix4f r; MatrixRotationZ(r, angle); Matrix4f s; MatrixScale(s, Vec3f(10)); Matrix4f rot; MatrixMultiply(r, s, rot); Matrix4f transl; MatrixTranslation(transl, Vec3f(-100, 30, 0)); Matrix4f model; MatrixMultiply(transl, rot, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); auto program = shaderProgram ? shaderProgram : shaderProgram2; GetGreng().GetRenderer().RenderMesh( mesh1, 0, &tex6, 1, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, {}, {}, frameBuffer); } if (mesh2 != nullptr) { Matrix4f r; MatrixRotationZ(r, -angle); Matrix4f s; MatrixScale(s, Vec3f(10)); Matrix4f rot; MatrixMultiply(r, s, rot); Matrix4f transl; MatrixTranslation(transl, Vec3f(100, 30, 0)); Matrix4f model; MatrixMultiply(transl, rot, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); auto program = shaderProgram ? shaderProgram : shaderProgram2; GetGreng().GetRenderer().RenderMesh( mesh2, 0, &tex2, 1, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, {}, {}, frameBuffer); } if (mesh3 != nullptr) { Matrix4f rangle; MatrixRotationY(rangle, 0); Matrix4f model; MatrixMultiply(rangle, mesh3ConstMatrix, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); greng::Texture* texts[6] = { tex4, tex4normal, tex3, tex3normal, tex5, tex5normal }; auto program = shaderProgram ? shaderProgram : shaderProgram4; for (unsigned int i = 0; i < 3; i++) { GetGreng().GetRenderer().RenderMesh( mesh3, i, &texts[i * 2], 2, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, nullptr, &GetCamera().GetPos().Get(), frameBuffer); } } if (mesh4 != nullptr) { Matrix4f rangle; MatrixRotationY(rangle, 0); Matrix4f model_1; MatrixMultiply(rangle, mesh3ConstMatrix, model_1); Matrix4f trans; MatrixTranslation(trans, Vec3f(-150, 0, 0)); Matrix4f model; MatrixMultiply(trans, model_1, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); greng::Texture* texts[6] = { tex7, tex7normal, tex7, tex7normal, tex7, tex7normal, }; auto program = shaderProgram ? shaderProgram : shaderProgram4; for (unsigned int i = 0; i < 3; i++) { GetGreng().GetRenderer().RenderMesh( mesh4, i, &texts[i * 2], 2, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, nullptr, &GetCamera().GetPos().Get(), frameBuffer); } } GetGreng().GetRenderer().DrawPoint(GetCamera(), light1.position, 10, Color4f(1, 1, 1, 1), false); }