void Matrix4x4::Scale(float kx, float ky, float kz) { Matrix4x4 scaleMat(kx, 0.0f, 0.0f, 0.0f, ky, 0.0f, 0.0f, 0.0f, kz); Transformation(scaleMat); }
void Scale(const glm::vec3 &scaleVec) { glm::mat4 scaleMat(1.0f); scaleMat[0].x = scaleVec.x; scaleMat[1].y = scaleVec.y; scaleMat[2].z = scaleVec.z; m_currMat = m_currMat * scaleMat; }
void renderSprites() { glUseProgram(spriteShaderProgramId); entityManagerRef->visitEntitiesWithTypeMask(componentMask, [&](Entity<EntityManagerTypes...> &entity){ auto &aabbComponent = entity.template getComponent<AABBComponent>(); auto &transformComponent = entity.template getComponent<TransformComponent>(); Eigen::Translation<GLfloat, 3> translationMat((transformComponent.x - HALF_SCREEN_WIDTH) / HALF_SCREEN_WIDTH, (transformComponent.y - HALF_SCREEN_HEIGHT) / HALF_SCREEN_HEIGHT, 0); Eigen::DiagonalMatrix<GLfloat, 3> scaleMat(aabbComponent.width / SCREEN_WIDTH, aabbComponent.height / SCREEN_HEIGHT, 1); Eigen::Transform<GLfloat, 3, Eigen::Affine> transformMatrix = translationMat * scaleMat; boundsSprite.render(transformMatrix.matrix()); }); }
void UBMS360::scaleBooleanMap(cv::UMat& map) { scaleMutex.lock(); if (scaleMatrix.cols != map.cols && scaleMatrix.rows != map.rows) { cv::Mat scaleMat(map.size(), CV_32FC1); for (int i = 0; i < map.rows; ++i) { float c = std::cos(3.1415926535898f * static_cast<float>(map.rows / 2 - i) / map.rows); for (int j = 0; j < map.cols; ++j) { scaleMat.at<float>(i, j) = c; } } scaleMat.copyTo(scaleMatrix); } scaleMutex.unlock(); cv::multiply(map, scaleMatrix, map); }
void BatchRenderer::DrawSolidAABB( const rxAABB& box, const FColor& color ) { SetBatchState( this, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); Unimplemented; #if 0 enum { NUM_CORNERS = 8 }; enum { NUM_INDICES = 6*2*3 }; static const XMVECTOR verts[NUM_CORNERS] = { { -1, -1, -1, 0 }, { 1, -1, -1, 0 }, { 1, -1, 1, 0 }, { -1, -1, 1, 0 }, { -1, 1, -1, 0 }, { 1, 1, -1, 0 }, { 1, 1, 1, 0 }, { -1, 1, 1, 0 } }; static const Index indices[NUM_INDICES]= { // }; enum { NUM_VERTICES = 24 }; enum { NUM_INDICES = 36 }; // Create vertex buffer. mxVertex vertices[ NUM_VERTICES ]; // Fill in the front face vertex data. vertices[0] = mxVertex( Vec3D( -0.5f, -0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[1] = mxVertex( Vec3D( -0.5f, 0.5f, -0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[2] = mxVertex( Vec3D( 0.5f, 0.5f, -0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[3] = mxVertex( Vec3D( 0.5f, -0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); // Fill in the back face vertex data. vertices[4] = mxVertex( Vec3D( -0.5f, -0.5f, 0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[5] = mxVertex( Vec3D( 0.5f, -0.5f, 0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[6] = mxVertex( Vec3D( 0.5f, 0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[7] = mxVertex( Vec3D( -0.5f, 0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); // Fill in the top face vertex data. vertices[8] = mxVertex( Vec3D( -0.5f, 0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[9] = mxVertex( Vec3D( -0.5f, 0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[10] = mxVertex( Vec3D( 0.5f, 0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[11] = mxVertex( Vec3D( 0.5f, 0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); // Fill in the bottom face vertex data. vertices[12] = mxVertex( Vec3D( -0.5f, -0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[13] = mxVertex( Vec3D( 0.5f, -0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[14] = mxVertex( Vec3D( 0.5f, -0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[15] = mxVertex( Vec3D( -0.5f, -0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); // Fill in the left face vertex data. vertices[16] = mxVertex( Vec3D( -0.5f, -0.5f, 0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); vertices[17] = mxVertex( Vec3D( -0.5f, 0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); vertices[18] = mxVertex( Vec3D( -0.5f, 0.5f, -0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); vertices[19] = mxVertex( Vec3D( -0.5f, -0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); // Fill in the right face vertex data. vertices[20] = mxVertex( Vec3D( 0.5f, -0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); vertices[21] = mxVertex( Vec3D( 0.5f, 0.5f, -0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); vertices[22] = mxVertex( Vec3D( 0.5f, 0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); vertices[23] = mxVertex( Vec3D( 0.5f, -0.5f, 0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); // Scale the box. { const Vec3D vScale( length, height, depth ); Matrix4 scaleMat( Matrix4::CreateScale( vScale ) ); Matrix4 invTranspose( scaleMat.Inverse().Transpose() ); for(UINT i = 0; i < NUM_VERTICES; ++i) { vertices[i].xyz = scaleMat.TransformVector( vertices[i].xyz ); vertices[i].N = invTranspose.TransformNormal( vertices[i].N ); vertices[i].T = invTranspose.TransformNormal( vertices[i].T ); } } // Create the index buffer. rxIndex indices[ NUM_INDICES ]; // Fill in the front face index data indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 3; // Fill in the back face index data indices[6] = 4; indices[7] = 5; indices[8] = 6; indices[9] = 4; indices[10] = 6; indices[11] = 7; // Fill in the top face index data indices[12] = 8; indices[13] = 9; indices[14] = 10; indices[15] = 8; indices[16] = 10; indices[17] = 11; // Fill in the bottom face index data indices[18] = 12; indices[19] = 13; indices[20] = 14; indices[21] = 12; indices[22] = 14; indices[23] = 15; // Fill in the left face index data indices[24] = 16; indices[25] = 17; indices[26] = 18; indices[27] = 16; indices[28] = 18; indices[29] = 19; // Fill in the right face index data indices[30] = 20; indices[31] = 21; indices[32] = 22; indices[33] = 20; indices[34] = 22; indices[35] = 23; newMesh->vertices.SetNum( NUM_VERTICES ); MemCopy( newMesh->vertices.ToPtr(), vertices, sizeof(vertices) ); newMesh->indices.SetNum( NUM_INDICES ); MemCopy( newMesh->indices.ToPtr(), indices, sizeof(indices) ); #endif }
/** * This function will create the skew matrix and basis for a non-orthogonal * representation. * * @param ol : The oriented lattice containing B matrix and crystal basis *vectors * @param w : The tranform requested when MDworkspace was created * @param aff : The affine matrix taking care of coordinate transformations */ void vtkDataSetToNonOrthogonalDataSet::createSkewInformation( Geometry::OrientedLattice &ol, Kernel::DblMatrix &w, Kernel::Matrix<coord_t> &aff) { // Get the B matrix Kernel::DblMatrix bMat = ol.getB(); // Apply the W tranform matrix bMat *= w; // Create G* Kernel::DblMatrix gStar = bMat.Tprime() * bMat; Geometry::UnitCell uc(ol); uc.recalculateFromGstar(gStar); m_skewMat = uc.getB(); // Calculate the column normalisation std::vector<double> bNorm; for (std::size_t i = 0; i < m_skewMat.numCols(); i++) { double sum = 0.0; for (std::size_t j = 0; j < m_skewMat.numRows(); j++) { sum += m_skewMat[j][i] * m_skewMat[j][i]; } bNorm.push_back(std::sqrt(sum)); } // Apply column normalisation to skew matrix Kernel::DblMatrix scaleMat(3, 3, true); scaleMat[0][0] /= bNorm[0]; scaleMat[1][1] /= bNorm[1]; scaleMat[2][2] /= bNorm[2]; m_skewMat *= scaleMat; // Setup basis normalisation array // Intel and MSBuild can't handle this // m_basisNorm = {ol.astar(), ol.bstar(), ol.cstar()}; m_basisNorm.push_back(ol.astar()); m_basisNorm.push_back(ol.bstar()); m_basisNorm.push_back(ol.cstar()); // Expand matrix to 4 dimensions if necessary if (4 == m_numDims) { m_basisNorm.push_back(1.0); Kernel::DblMatrix temp(4, 4, true); for (std::size_t i = 0; i < 3; i++) { for (std::size_t j = 0; j < 3; j++) { temp[i][j] = m_skewMat[i][j]; } } m_skewMat = temp; } // Convert affine matrix to similar type as others Kernel::DblMatrix affMat(aff.numRows(), aff.numCols()); for (std::size_t i = 0; i < aff.numRows(); i++) { for (std::size_t j = 0; j < aff.numCols(); j++) { affMat[i][j] = aff[i][j]; } } // Strip affine matrix down to correct dimensions this->stripMatrix(affMat); // Perform similarity transform to get coordinate orientation correct m_skewMat = affMat.Tprime() * (m_skewMat * affMat); m_basisNorm = affMat * m_basisNorm; if (4 == m_numDims) { this->stripMatrix(m_skewMat); } this->findSkewBasis(m_basisX, m_basisNorm[0]); this->findSkewBasis(m_basisY, m_basisNorm[1]); this->findSkewBasis(m_basisZ, m_basisNorm[2]); }
mat4 Transform::modelMat() { return rotateMat() * scaleMat() * translateMat(); }