本文整理汇总了C++中GLC_Matrix4x4类的典型用法代码示例。如果您正苦于以下问题:C++ GLC_Matrix4x4类的具体用法?C++ GLC_Matrix4x4怎么用?C++ GLC_Matrix4x4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GLC_Matrix4x4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rotationMatrix
void GLC_CuttingPlane::moveManipulatorRep(const GLC_Point3d& pos)
{
// Create the widget rotation matrix
const GLC_Matrix4x4 rotationMatrix(m_CompMatrix.rotationMatrix());
const GLC_Matrix4x4 translationMatrix(pos);
const GLC_Matrix4x4 offsetMatrix(m_Normal * m_ManipulatorOffsetFactor);
GLC_Matrix4x4 scaleMatrix;
scaleMatrix.setMatScaling(m_ScaleFactor, m_ScaleFactor, m_ScaleFactor);
GLC_3DWidget::instanceHandle(1)->setMatrix(offsetMatrix * translationMatrix * rotationMatrix *scaleMatrix);
// Rotation manipulator
QVector<GLC_Matrix4x4> rotations(3);
rotations[0].setMatRot(glc::Y_AXIS, glc::PI / 2.0); // X
rotations[0]= GLC_Matrix4x4(glc::X_AXIS, -glc::PI / 2.0) * rotations[0];
rotations[1].setMatRot(glc::X_AXIS, -glc::PI / 2.0); // Y
// Z
for (int i= 0; i < 3; ++i)
{
GLC_3DWidget::instanceHandle(2 + i)->setMatrix(offsetMatrix * translationMatrix * rotationMatrix * rotations.at(i) * scaleMatrix);
}
GLC_Arrow* pArrow= dynamic_cast<GLC_Arrow*>(GLC_3DWidget::instanceHandle(1)->geomAt(0));
Q_ASSERT(NULL != pArrow);
pArrow->setViewDir(rotationMatrix * GLC_3DWidget::widgetManagerHandle()->cameraHandle()->forward().normalize());
}
示例2: project
GLC_Point2d GLC_Viewport::project(const GLC_Point3d &point, bool useCameraMatrix) const
{
GLC_Matrix4x4 modelView;
GLC_Matrix4x4 projectionMatrix;
GLint viewport[4]= {0, 0, m_Width, m_Height};
if (useCameraMatrix)
{
modelView= m_pViewCam->modelViewMatrix();
projectionMatrix= m_ProjectionMatrix;
}
else
{
modelView= GLC_Context::current()->modelViewMatrix();
glGetIntegerv(GL_VIEWPORT, viewport);
projectionMatrix= GLC_Context::current()->projectionMatrix();
}
double x;
double y;
double z;
glc::gluProject(point.x(), point.y(), point.z(), modelView.getData(), projectionMatrix.getData(), viewport, &x, &y, &z);
GLC_Vector2d subject;
subject.setX(x);
subject.setY(y);
return subject;
}
示例3: EVDS_Object_GetStateVector
////////////////////////////////////////////////////////////////////////////////
/// @brief
////////////////////////////////////////////////////////////////////////////////
GLC_Matrix4x4 SchematicsRenderingManager::getTransformationMatrix(Object* element) {
//Calculate scale
double scale = element->getVariable("scale");
if (scale <= 0.0) {
//if (firstRecursive) { //Use default scale for firstmost object
scale = schematics_editor->getCurrentSheet()->getVariable("sheet.scale");
if (scale <= 0.0) scale = 1.0;
//} else { //No scaling change
//scale = 1.0;
//}
}
//Get state vector
EVDS_STATE_VECTOR vector;
EVDS_Object_GetStateVector(element->getEVDSObject(),&vector);
//Calculate transformation
GLC_Matrix4x4 scaling;
GLC_Matrix4x4 transformation;
EVDS_MATRIX rotationMatrix;
EVDS_Quaternion_ToMatrix(&vector.orientation,rotationMatrix);
scaling.setMatScaling(1/scale,1/scale,1/scale);
transformation = transformation*GLC_Matrix4x4(vector.position.x,vector.position.y,vector.position.z);
transformation = transformation*GLC_Matrix4x4(rotationMatrix);
if (element->getParent() && (element->getParent()->getType() != "foxworks.schematics.sheet")) {
transformation = transformation*getTransformationMatrix(element->getParent());
} else {
transformation = transformation*scaling; //First operation is scaling
}
return transformation;
}
示例4: Q_ASSERT
// Set Arcs orientation and position in concordance with mouse position
void GLC_RepTrackBallMover::init()
{
Q_ASSERT(NULL != m_pRepMoverInfo);
Q_ASSERT(!m_pRepMoverInfo->m_VectorInfo.isEmpty());
Q_ASSERT(!m_pRepMoverInfo->m_MatrixInfo.isEmpty());
GLC_Vector3d VectAngle(m_pRepMoverInfo->m_VectorInfo.first());
VectAngle.setZ(0);
VectAngle.setLength(1);
GLC_Matrix4x4 MatRot;
double Angle;
// Compute the 2 arcs orientation
if (VectAngle.y() > 0)
{ // Angle entre 0 et PI
Angle= acos(VectAngle.x());
MatRot.setMatRot(Z_AXIS, Angle);
}
else
{ // Angle between 0 et -PI
Angle= -acos(VectAngle.x());
MatRot.setMatRot(Z_AXIS, Angle);
}
// Composition of orientation matrix and mapping matrix
MatRot= m_pRepMoverInfo->m_MatrixInfo.first() * MatRot;
m_Arc1.setMatrix(MatRot * m_MatArc1);
m_Arc2.setMatrix(MatRot * m_MatArc2);
}
示例5: glGetIntegerv
QList<GLC_Point2d> GLC_Viewport::project(const QList<GLC_Point3d> &points, bool useCameraMatrix) const
{
QList<GLC_Point2d> subject;
GLC_Matrix4x4 modelView;
GLC_Matrix4x4 projectionMatrix;
GLint viewport[4]= {0, 0, m_Width, m_Height};
if (useCameraMatrix)
{
modelView= m_pViewCam->modelViewMatrix();
projectionMatrix= m_ProjectionMatrix;
}
else
{
modelView= GLC_Context::current()->modelViewMatrix();
glGetIntegerv(GL_VIEWPORT, viewport);
projectionMatrix= GLC_Context::current()->projectionMatrix();
}
double x;
double y;
double z;
const int count= points.count();
for (int i= 0; i < count; ++i)
{
const GLC_Point3d point= points.at(i);
glc::gluProject(point.x(), point.y(), point.z(), modelView.getData(), projectionMatrix.getData(), viewport, &x, &y, &z);
subject.append(GLC_Point2d(x, y));
}
return subject;
}
示例6: fontMetrics
void GLC_Viewport::renderText(const GLC_Point3d& point, const QString &text, const QColor &color, const QFont &font)
{
m_TextRenderingCollection.clear();
if (!text.isEmpty())
{
QFontMetrics fontMetrics(font);
const double width= fontMetrics.width(text);
const double height= fontMetrics.height();
// Compute the ratio betwwen screen and world
const GLC_Matrix4x4 invertedViewMatrix(GLC_Context::current()->modelViewMatrix().rotationMatrix().invert());
const GLC_Vector2d projectedPoint1(project(point, false));
const GLC_Vector3d vector(invertedViewMatrix * GLC_Vector3d(0.0, height, 0.0));
const GLC_Vector2d projectedPoint2(project((point + vector), false));
const double ratio= height / (projectedPoint2 - projectedPoint1).length();
QPixmap pixmap(width, height);
pixmap.fill(Qt::transparent);
QPainter painter;
painter.begin(&pixmap);
painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing);
painter.setFont(font);
painter.setPen(color);
painter.drawText(0, fontMetrics.ascent(), text);
painter.end();
QImage image= pixmap.toImage();
GLC_Texture *pTexture= new GLC_Texture(image);
GLC_Material* pMaterial= new GLC_Material(Qt::black);
pMaterial->setTexture(pTexture);
pMaterial->setOpacity(0.99);
GLC_3DViewInstance rectangle= GLC_Factory::instance()->createRectangle(width, height);
GLC_Matrix4x4 scaleMatrix;
scaleMatrix.setMatScaling(ratio, ratio, ratio);
rectangle.setMatrix(scaleMatrix);
rectangle.multMatrix(invertedViewMatrix);
rectangle.multMatrix(GLC_Matrix4x4(point));
rectangle.geomAt(0)->addMaterial(pMaterial);
m_TextRenderingCollection.add(rectangle);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glDisable(GL_DEPTH_TEST);
m_TextRenderingCollection.render(0, glc::TransparentRenderFlag);
glEnable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
m_TextRenderingCollection.clear();
}
}
示例7: gluPickMatrix
void glc::gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay,
GLint viewport[4])
{
if (deltax <= 0 || deltay <= 0) {
return;
}
/* Translate and scale the picked region to the entire window */
GLC_Matrix4x4 translate;
translate.setMatTranslate((viewport[2] - 2 * (x - viewport[0])) / deltax, (viewport[3] - 2 * (y - viewport[1])) / deltay, 0.0);
GLC_Matrix4x4 scaling;
scaling.setMatScaling(viewport[2] / deltax, viewport[3] / deltay, 0.0);
GLC_ContextManager::instance()->currentContext()->glcMultMatrix(translate * scaling);
}
示例8: Q_ASSERT
void GLC_Arrow::createWire()
{
Q_ASSERT(m_WireData.isEmpty());
GLfloatVector floatVector;
floatVector.append(static_cast<float>(m_StartPoint.x()));
floatVector.append(static_cast<float>(m_StartPoint.y()));
floatVector.append(static_cast<float>(m_StartPoint.z()));
floatVector.append(static_cast<float>(m_EndPoint.x()));
floatVector.append(static_cast<float>(m_EndPoint.y()));
floatVector.append(static_cast<float>(m_EndPoint.z()));
GLC_Geometry::addVerticeGroup(floatVector);
// Arrow Head
GLC_Point3d headPoint1(-m_HeadLenght, m_HeadLenght * tan(m_HeadAngle / 2.0), 0.0);
GLC_Point3d headPoint2(headPoint1.x(), -(headPoint1.y()), headPoint1.z());
// Arrow frame
GLC_Vector3d xArrow= (m_EndPoint - m_StartPoint).normalize();
GLC_Vector3d yArrow= ((-m_ViewDir) ^ xArrow).normalize();
GLC_Vector3d zArrow= (xArrow ^ yArrow).normalize();
GLC_Matrix4x4 headMatrix;
headMatrix.setColumn(0, xArrow);
headMatrix.setColumn(1, yArrow);
headMatrix.setColumn(2, zArrow);
GLC_Matrix4x4 translate(m_EndPoint);
headPoint1= translate * headMatrix * headPoint1;
headPoint2= translate * headMatrix * headPoint2;
// add head data
floatVector.clear();
floatVector.append(static_cast<float>(headPoint1.x()));
floatVector.append(static_cast<float>(headPoint1.y()));
floatVector.append(static_cast<float>(headPoint1.z()));
floatVector.append(static_cast<float>(m_EndPoint.x()));
floatVector.append(static_cast<float>(m_EndPoint.y()));
floatVector.append(static_cast<float>(m_EndPoint.z()));
floatVector.append(static_cast<float>(headPoint2.x()));
floatVector.append(static_cast<float>(headPoint2.y()));
floatVector.append(static_cast<float>(headPoint2.z()));
GLC_Geometry::addVerticeGroup(floatVector);
}
示例9: glcOrtho
void GLC_Context::glcOrtho(double left, double right, double bottom, double top, double nearVal, double farVal)
{
GLC_Matrix4x4 orthoMatrix;
double* m= orthoMatrix.setData();
const double tx= - (right + left) / (right - left);
const double ty= - (top + bottom) / (top - bottom);
const double tz= - (farVal + nearVal) / (farVal - nearVal);
m[0]= 2.0 / (right - left);
m[5]= 2.0 / (top - bottom);
m[10]= -2.0 / (farVal - nearVal);
m[12]= tx;
m[13]= ty;
m[14]= tz;
glcMultMatrix(orthoMatrix);
}
示例10: normalize
void glc::gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,
GLdouble upz)
{
float forward[3], side[3], up[3];
GLfloat m[4][4];
forward[0] = centerx - eyex;
forward[1] = centery - eyey;
forward[2] = centerz - eyez;
up[0] = upx;
up[1] = upy;
up[2] = upz;
normalize(forward);
/* Side = forward x up */
cross(forward, up, side);
normalize(side);
/* Recompute up as: up = side x forward */
cross(side, forward, up);
__gluMakeIdentityf(&m[0][0]);
m[0][0] = side[0];
m[1][0] = side[1];
m[2][0] = side[2];
m[0][1] = up[0];
m[1][1] = up[1];
m[2][1] = up[2];
m[0][2] = -forward[0];
m[1][2] = -forward[1];
m[2][2] = -forward[2];
GLC_Matrix4x4 translate;
translate.setMatTranslate(-eyex, -eyey, -eyez);
GLC_Matrix4x4 result= GLC_Matrix4x4(&m[0][0]) * translate;
GLC_ContextManager::instance()->currentContext()->glcMultMatrix(result);
}
示例11: glcFrustum
void GLC_Context::glcFrustum(double left, double right, double bottom, double top, double nearVal, double farVal)
{
GLC_Matrix4x4 perspMatrix;
double* m= perspMatrix.setData();
const double a= (right + left) / (right - left);
const double b= (top + bottom) / (top - bottom);
const double c= - (farVal + nearVal) / (farVal - nearVal);
const double d= - (2.0 * farVal * nearVal) / (farVal - nearVal);
m[0]= (2.0 * nearVal) / (right - left);
m[5]= (2.0 * nearVal) / (top - bottom);
m[8]= a;
m[9]= b;
m[10]= c;
m[11]= -1.0;
m[14]= d;
m[15]= 0.0;
glcMultMatrix(perspMatrix);
}
示例12: setModelViewProjectionMatrix
void GLC_UniformShaderData::setModelViewProjectionMatrix(const GLC_Matrix4x4& modelView, const GLC_Matrix4x4& projection)
{
// Set model view matrix
const double* pMvmatrixData= modelView.getData();
GLfloat mvFloatMatrix[4][4];
GLfloat* pData= &(mvFloatMatrix[0][0]);
for (int i= 0; i < 16; ++i)
{
pData[i]= static_cast<GLfloat>(pMvmatrixData[i]);
}
// Set model view projection matrix
GLC_Matrix4x4 modelViewProjectionMatrix= projection * modelView;
const double* pMvpmatrixData= modelViewProjectionMatrix.getData();
GLfloat mvpFloatMatrix[4][4];
pData= &(mvpFloatMatrix[0][0]);
for (int i= 0; i < 16; ++i)
{
pData[i]= static_cast<GLfloat>(pMvpmatrixData[i]);
}
// Set the transpose of inv model view matrix (For normal computation)
GLC_Matrix4x4 invTransposeModelView= modelView.inverted();
invTransposeModelView.transpose();
GLfloat invTmdv[3][3];
{
const double* data= invTransposeModelView.getData();
invTmdv[0][0]= static_cast<GLfloat>(data[0]); invTmdv[1][0]= static_cast<GLfloat>(data[4]); invTmdv[2][0]= static_cast<GLfloat>(data[8]);
invTmdv[0][1]= static_cast<GLfloat>(data[1]); invTmdv[1][1]= static_cast<GLfloat>(data[5]); invTmdv[2][1]= static_cast<GLfloat>(data[9]);
invTmdv[0][2]= static_cast<GLfloat>(data[2]); invTmdv[1][2]= static_cast<GLfloat>(data[6]); invTmdv[2][2]= static_cast<GLfloat>(data[10]);
}
Q_ASSERT(GLC_Shader::hasActiveShader());
GLC_Shader* pCurrentShader= GLC_Shader::currentShaderHandle();
pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->modelViewLocationId(), mvFloatMatrix);
pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->mvpLocationId(), mvpFloatMatrix);
pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->invModelViewLocationId(), invTmdv);
}
示例13: QVector4D
//////////////////////////////////////////////////////////////////////
// Private slots Functions
//////////////////////////////////////////////////////////////////////
void ModelViewGadgetWidget::updateAttitude()
{
AttitudeActual::DataFields data = attActual->getData(); // get attitude data
GLC_StructOccurence *rootObject = m_World.rootOccurence(); // get the full 3D model
double x = data.q3;
double y = data.q2;
double z = data.q4;
double w = data.q1;
if (w == 0.0) {
w = 1.0;
}
// create and gives the product of 2 4x4 matrices to get the rotation of the 3D model's matrix
QMatrix4x4 m1;
m1.setRow(0, QVector4D(w, z, -y, x));
m1.setRow(1, QVector4D(-z, w, x, y));
m1.setRow(2, QVector4D(y, -x, w, z));
m1.setRow(3, QVector4D(-x, -y, -z, w));
QMatrix4x4 m2;
m2.setRow(0, QVector4D(w, z, -y, -x));
m2.setRow(1, QVector4D(-z, w, x, -y));
m2.setRow(2, QVector4D(y, -x, w, -z));
m2.setRow(3, QVector4D(x, y, z, w));
QMatrix4x4 m0 = m1 * m2;
// convert QMatrix4x4 to GLC_Matrix4x4
GLC_Matrix4x4 rootObjectRotation;
{
double *newMatrixData = rootObjectRotation.setData();
double *oldMatrixData = (double *)m0.data();
for (int i = 0; i < 16; i++) {
newMatrixData[i] = oldMatrixData[i];
}
}
// sets and updates the 3D model's matrix
rootObject->structInstance()->setMatrix(rootObjectRotation);
rootObject->updateChildrenAbsoluteMatrix();
updateGL();
}
示例14: glcMultMatrix
void GLC_ContextSharedData::glcMultMatrix(const GLC_Matrix4x4 &matrix)
{
const GLC_Matrix4x4 current= m_MatrixStackHash.value(m_CurrentMatrixMode)->top();
m_MatrixStackHash.value(m_CurrentMatrixMode)->top()= current * matrix;
#ifdef GLC_OPENGL_ES_2
m_UniformShaderData.setModelViewProjectionMatrix(m_MatrixStackHash.value(GL_MODELVIEW)->top(), m_MatrixStackHash.value(GL_PROJECTION)->top());
#else
if (GLC_Shader::hasActiveShader())
{
m_UniformShaderData.setModelViewProjectionMatrix(m_MatrixStackHash.value(GL_MODELVIEW)->top(), m_MatrixStackHash.value(GL_PROJECTION)->top());
}
::glMultMatrixd(matrix.getData());
#endif
}
示例15: Q_ASSERT
QList<GLC_Point2d> glc::polygonIn2d(QList<GLC_Point3d> polygon3d)
{
const int count= polygon3d.count();
Q_ASSERT(count > 2);
// Compute face normal
const GLC_Point3d point1(polygon3d[0]);
const GLC_Point3d point2(polygon3d[1]);
const GLC_Point3d point3(polygon3d[2]);
const GLC_Vector3d edge1(point2 - point1);
const GLC_Vector3d edge2(point3 - point2);
GLC_Vector3d polygonPlaneNormal(edge1 ^ edge2);
polygonPlaneNormal.normalize();
// Create the transformation matrix
GLC_Matrix4x4 transformation;
GLC_Vector3d rotationAxis(polygonPlaneNormal ^ Z_AXIS);
if (!rotationAxis.isNull())
{
const double angle= acos(polygonPlaneNormal * Z_AXIS);
transformation.setMatRot(rotationAxis, angle);
}
QList<GLC_Point2d> subject;
// Transform polygon vertexs
for (int i=0; i < count; ++i)
{
polygon3d[i]= transformation * polygon3d[i];
// Create 2d vector
subject << polygon3d[i].toVector2d(Z_AXIS);
}
return subject;
}