matrix<float> grid :: getPositionVector( randomWalker &_randomWalker ) { cartesian position = _randomWalker.getPosition( ); matrix<float> positionVector( 1, 9 ); unsigned int immediateObstacles = 0; for (unsigned int i = (position.x - 1); i < 3; i++) { for (unsigned int j = (position.y - 1); j < 3; j++) { if( ( mat[i][j] != 0 ) && ( i != j ) && ( i+j != 2 ) ) immediateObstacles++; } } switch( immediateObstacles ) { case 0: positionVector(0, 4) = 1; break; case 1: if( mat[position.x-1][position.y] != 0 ) positionVector(0, 3) = 1; else if( mat[position.x][position.y-1] != 0 ) positionVector(0, 1) = 1; else if( mat[position.x+1][position.y] != 0 ) positionVector(0, 5) = 1; else if( mat[position.x][position.y+1] != 0 ) positionVector(0, 7) = 1; break; case 2: case 3: if( ( mat[position.x-1][position.y] != 0 ) && ( mat[position.x][position.y-1] != 0 ) ) positionVector(0, 0) = 1; else if( ( mat[position.x+1][position.y] != 0 ) && ( mat[position.x][position.y-1] != 0 ) ) positionVector(0, 2) = 1; else if( ( mat[position.x+1][position.y] != 0 ) && ( mat[position.x][position.y+1] != 0 ) ) positionVector(0, 8) = 1; else if( ( mat[position.x-1][position.y] != 0 ) && ( mat[position.x][position.y+1] != 0 ) ) positionVector(0, 6) = 1; break; } return positionVector; }
// Return the Position Vector GLfloatVector GLC_MeshData::positionVector() const { if (m_VertexBuffer.isCreated()) { // VBO created get data from VBO const int sizeOfVbo= m_PositionSize; const GLsizeiptr dataSize= sizeOfVbo * sizeof(float); GLfloatVector positionVector(sizeOfVbo); if (!const_cast<QGLBuffer&>(m_VertexBuffer).bind()) { GLC_Exception exception("GLC_MeshData::positionVector() Failed to bind vertex buffer"); throw(exception); } GLvoid* pVbo = const_cast<QGLBuffer&>(m_VertexBuffer).map(QGLBuffer::ReadOnly); memcpy(positionVector.data(), pVbo, dataSize); const_cast<QGLBuffer&>(m_VertexBuffer).unmap(); const_cast<QGLBuffer&>(m_VertexBuffer).release(); return positionVector; } else { return m_Positions; } }
XMMATRIX Transform::GetTransformMatrix() { XMVECTOR scaleVector(m_Scale.AsXMVECTOR()); XMVECTOR rotationVector(m_Rotation.AsXMVECTOR()); XMVECTOR positionVector(m_Position.AsXMVECTOR()); return XMMatrixScalingFromVector(scaleVector) * XMMatrixRotationQuaternion(rotationVector) * XMMatrixTranslationFromVector(positionVector); }
void GLC_MeshData::setVboUsage(bool usage) { if (usage && (m_PositionSize != -1) && (!m_Positions.isEmpty()) && (!m_VertexBuffer.isCreated())) { createVBOs(); fillVbo(GLC_MeshData::GLC_Vertex); fillVbo(GLC_MeshData::GLC_Normal); fillVbo(GLC_MeshData::GLC_Texel); fillVbo(GLC_MeshData::GLC_Color); useVBO(false, GLC_MeshData::GLC_Color); const int lodCount= m_LodList.count(); for (int i= 0; i < lodCount; ++i) { m_LodList.at(i)->setIboUsage(usage); } } else if (!usage && m_VertexBuffer.isCreated()) { m_Positions= positionVector(); m_PositionSize= m_Positions.size(); m_VertexBuffer.destroy(); m_Normals= normalVector(); m_NormalBuffer.destroy(); if (m_TexelBuffer.isCreated()) { m_Texels= texelVector(); m_TexelsSize= m_Texels.size(); m_TexelBuffer.destroy(); } if (m_ColorBuffer.isCreated()) { m_Colors= colorVector(); m_ColorSize= m_Colors.size(); m_ColorBuffer.destroy(); } const int lodCount= m_LodList.count(); for (int i= 0; i < lodCount; ++i) { m_LodList.at(i)->setIboUsage(usage); } } m_UseVbo= usage; }
void GLC_MeshData::copyVboToClientSide() { if (m_VertexBuffer.isCreated() && m_Positions.isEmpty()) { Q_ASSERT(m_NormalBuffer.isCreated()); m_Positions= positionVector(); m_Normals= normalVector(); if (m_TexelBuffer.isCreated()) { m_Texels= texelVector(); } if (m_ColorBuffer.isCreated()) { m_Colors= colorVector(); } } }