Esempio n. 1
0
QMatrix4x4 CAD_arch_support::rotationOfFlange(quint8 num)
{
    if (num == 1)
        return matrix_rotation;
    else if(num == 2)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(90.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
    else if(num == 3)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(180.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
    else
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(270.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
}
QMatrix4x4 CAD_electrical_busbarwithtapoffpoints2row::rotationOfFlange(quint8 num)
{
    if(num == 1)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(180.0, 0.0, 1.0, 0.0);
        return matrix_rotation * m;
    }
    else if(num == 2)
        return matrix_rotation;
    else
    {
        QMatrix4x4 m;
        m.setToIdentity();
        if(num % 2 == 0)
        {
            m.rotate(-90.0, 0.0, 0.0, 1.0);
            m.rotate(180.0, 1.0, 0.0, 0.0);
        }
        else
            m.rotate(90.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
}
QMatrix4x4 CAD_Cleanroom_CeilingCornerPiece::rotationOfFlange(quint8 num)
{
    if(num == 1)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(180.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
    else if(num == 2)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(-90.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
    else if(num == 3)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(180.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
    else
        return matrix_rotation;
}
Esempio n. 4
0
void Scene::directionLightPass(RenderTarget *target)
{
    ShaderProgram * shader =ShaderPool::getInstance ()->get("dir_light_pass");
    shader->use ();
    int texture_offset = 5;

    for(int i = 0 ;i<4;i++)
    {
        directionLight.getCSM_FBO (i)->BindForReading(GL_TEXTURE0+i+texture_offset);
        char GLSL_shadowMap_name [30];
        sprintf(GLSL_shadowMap_name,"g_shadow_map[%d]",i);
        directionLight.getCSM_FBO (i)->applyShadowMapTexture (shader,i+texture_offset,GLSL_shadowMap_name);
    }

    QMatrix4x4 m;
    m.setToIdentity ();
    m_quad->setShaderProgram (shader);
    shader->setUniformMat4v ("g_MVP_matrix",m.data ());
    shader->setUniform2Float ("g_screen_size",1024,768);
    shader->setUniformInteger ("g_color_map",0);
    shader->setUniformInteger ("g_position_map",1);
    shader->setUniformInteger ("g_normal_map",2);

    shader->setUniformInteger ("g_depth_map",4);//for depth

    auto camera = target->camera ();
    if(camera)
    {
        shader->setUniform3Float ("g_eye_position",
                                  camera->pos ().x(),
                                  camera->pos ().y(),
                                  camera->pos ().z());
    }

    QMatrix4x4 lightView;
    lightView.setToIdentity();


    QVector3D lightDir = directionLight.getDirection ();
    QVector3D pos = QVector3D(0,0,0);
    lightView.lookAt(pos,lightDir,QVector3D(0,1,0));

    for(int i =0 ;i <4 ;i++)
    {
        if(!camera) break;
        auto split_frustum_aabb = camera->getSplitFrustumAABB (i);
        split_frustum_aabb.transForm (target->camera()->getModelTrans ());
        split_frustum_aabb.transForm (lightView);
        auto matrix = getCropMatrix (split_frustum_aabb);
        QMatrix4x4 light_vp;
        light_vp = matrix * lightView ;
        char GLSL_light_VP_name [30];
        sprintf(GLSL_light_VP_name,"g_light_vp_matrix[%d]",i);
        shader->setUniformMat4v (GLSL_light_VP_name,light_vp.data ());
    }
    this->directionLight.apply(shader);
    this->ambientLight.apply(shader);
    m_quad->draw (true);
}
Esempio n. 5
0
void Dragon2Widget::paintGL()
{
    qglClearColor(Qt::white);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // use the OpenGL shader program for painting
    glUseProgram(_program);

    // set model matrix
    glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, _modelMatrix.data());

    // set view matrix
    QMatrix4x4 viewMatrix;
    viewMatrix.setToIdentity();
    viewMatrix.lookAt(QVector3D(0, 0, -1000), QVector3D(0, 0, 0), QVector3D(0, -1, 0));
    glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, viewMatrix.data());

    // set projection matrix
    QMatrix4x4 projectionMatrix;
    projectionMatrix.setToIdentity();
    projectionMatrix.perspective(30, (float)width()/height(), 0.01f, 1e5f);
    glUniformMatrix4fv(_projectionMatrixLocation, 1, GL_FALSE, projectionMatrix.data());

    // bind ArrayBuffer to _vertBuffer
    glBindBuffer(GL_ARRAY_BUFFER, _vertBuffer);
    // enable vertex attribute "position" (bound to 0 already)
    glEnableVertexAttribArray(0); 
    // set the data of vertex attribute "position" using current ArrayBuffer
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(_vertices.first()), 0);
    // enable vertex attribute "normal" (bound to 1 already)
    glEnableVertexAttribArray(1);
    // set the data of vertex attribute "normal" using current ArrayBuffer
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(_vertices.first()), (void*)(3 * sizeof(float)));

    // bind ElementArrayBuffer to _triangleIndicesBuffer
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _triangleIndicesBuffer);
    // draw mesh using the indices stored in ElementArrayBuffer
    glDrawElements(GL_TRIANGLES, _triangleIndices.size(), GL_UNSIGNED_INT, 0);

    // disable vertex attributes
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

    // unbind buffers
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    // restore states
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_BLEND);
}
Esempio n. 6
0
void AwesomeCamera::rotateView(float z_angle,float x_angle){

//    rotM.setToIdentity();


    double cosPhi = cos(mouse_sens*(-z_angle)/180*M_PI);
    double sinPhi = sin(mouse_sens*(-z_angle)/180*M_PI);


    direction      = QVector3D(cosPhi*direction.x()+sinPhi*direction.z(),direction.y(),
                               cosPhi*direction.z()-sinPhi*direction.x());

    QMatrix4x4 rotMat;
    rotMat.setToIdentity();
    rotMat.rotate(mouse_sens*(-x_angle),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
    QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
    tmpVec.normalize();
    double angleTheta = QVector3D::dotProduct(tmpVec,QVector3D(0,1,0));
    if(qAbs(angleTheta) < 0.9){
        rotMat.setToIdentity();
        rotMat.rotate(mouse_sens*(-x_angle)*(1-qAbs(angleTheta)),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
        QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
        tmpVec.normalize();
        direction = tmpVec;
    }

    side_direction = QVector3D(cosPhi*side_direction.x()+sinPhi*side_direction.z(),0,
                               cosPhi*side_direction.z()-sinPhi*side_direction.x());

    updown_direction = QVector3D::crossProduct(direction,side_direction);



/*
    rot_angles[0] += mouse_sens*(z_angle);//przesuniecie X
    rot_angles[1] -= mouse_sens*(x_angle);//przesuniecie Y
    if(rot_angles[1] > 90) rot_angles[1] = 90;
    if(rot_angles[1] <-90) rot_angles[1] = -90;
//    przesuniecie do przodu
    direction = QVector3D(-sin(rot_angles[0]/180*M_PI),sin(rot_angles[1]/180*M_PI),cos(rot_angles[0]/180*M_PI));
//    przesuniece na boki
    side_direction = QVector3D(sin((rot_angles[0]+90)/180*M_PI),0,-cos((rot_angles[0]+90)/180*M_PI));
//    przesuwanie gora dol
    updown_direction = QVector3D::crossProduct(direction,side_direction);
*/

    direction.normalize();
    side_direction.normalize();
    updown_direction.normalize();

}
Esempio n. 7
0
void View3D::createCoordSystem(Qt3DCore::QEntity* parent)
{
    m_pCoordSysEntity = QSharedPointer<Qt3DCore::QEntity>::create(parent);

    //create geometry
    QSharedPointer<Qt3DExtras::QCylinderGeometry> pAxis =  QSharedPointer<Qt3DExtras::QCylinderGeometry>::create();
    pAxis->setRadius(0.001f);
    pAxis->setLength(30);
    pAxis->setRings(100);
    pAxis->setSlices(20);

    //create mesh
    GeometryMultiplier *pCoordSysMesh = new GeometryMultiplier(pAxis);
    QVector<QColor> vColors;
    vColors.reserve(3);
    QVector<QMatrix4x4> vTransforms;
    vTransforms.reserve(3);
    QMatrix4x4 transformMat;

    // Y - red
    transformMat.setToIdentity();
    vTransforms.push_back(transformMat);
    vColors.push_back(QColor(255, 0, 0));

    // X - blue
    transformMat.setToIdentity();
    transformMat.rotate(90.0f, QVector3D(0,0,1));
    vTransforms.push_back(transformMat);
    vColors.push_back(QColor(0, 0, 255));

    // Z - green
    transformMat.setToIdentity();
    transformMat.rotate(90.0f, QVector3D(1,0,0));
    vTransforms.push_back(transformMat);
    vColors.push_back(QColor(0, 255, 0));

    //Set transforms and colors
    pCoordSysMesh->setTransforms(vTransforms);
    pCoordSysMesh->setColors(vColors);

    //Add material
    GeometryMultiplierMaterial* pCoordSysMaterial = new GeometryMultiplierMaterial;
    pCoordSysMaterial->setAmbient(QColor(0,0,0));
    pCoordSysMaterial->setAlpha(1.0f);

    m_pCoordSysEntity->addComponent(pCoordSysMesh);
    m_pCoordSysEntity->addComponent(pCoordSysMaterial);
}
Esempio n. 8
0
void Renderer::resetModel()
{
    m_theta_x=0;
    m_theta_y=0;

    rotation.setToIdentity();
}
Esempio n. 9
0
void MyGLWidget::paintGL()
{

    // Clear buffer to set color and alpha
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);







    shaderProgram.setUniformValue(unifMatrixPerspective,projectionMatrix);






    // VIEW TRANSFORMATION
    QMatrix4x4 viewMatrix ;
    viewMatrix.lookAt(cameraPos,cameraPos+cameraFront,cameraUp);
    shaderProgram.setUniformValue(unifMatrixView,viewMatrix);

    // MODEL TRANSFORMATION (Neues OpenGL)
    QMatrix4x4 modelMatrix ;
    // Initialisierung des Modells
    modelMatrix.setToIdentity();
    modelMatrixStack.push(modelMatrix);


    // Zeit zwischen den Render Bildern
    elapsedTime = tmrRender.elapsed();
    //qDebug() << elapsedTime ;
    tmrRender.start();


    // glBindTexture(GL_TEXTURE_2D,tList[sun]);
    //qTex->bind();
    textures[1]->bind();
    textures[1]->bind();


    // Übergebe die Textur an die Uniform Variable
    // Die 0 steht dabei für die verwendete Unit (0=Standard)
    //shaderProgram.setUniformValue("texture",0);



    // Triggern des Renderns
    sonne.render();

    // Stack wieder säubern.
    modelMatrixStack.pop();

    //qTex->release();



}
void HgTransformedQuad::transformQuad(int index, const QMatrix4x4& projView, HgQuad* quad,
                                      qreal mirroringPlaneY, const QVector2D& translate, const QPointF& center,
                                      const QSizeF& windowSize)
{
    mIndex = index;
    mQuad = quad;

    QMatrix4x4 tm;
    tm.setToIdentity();
    tm.rotate(quad->outerRotation());

    if (mQuad->mirrorImageEnabled())
    {
        computeMirroredPoints(tm, projView, mirroringPlaneY, translate, center, windowSize);
    }

    tm.translate(quad->position());
    tm.rotate(quad->rotation());
    tm.scale(quad->scale().x(), quad->scale().y());

    tm = projView * tm;

    perspectiveTransformPoints(mTransformedPoints, tm, center, windowSize);

    for (int i = 0; i < 4; i++)
        mTransformedPoints[i] += translate;

}
Esempio n. 11
0
void Scene::pointLightPass(RenderTarget *target)
{
    if(!this->pointLights.empty ())
    {
        for(int i =0;i<pointLights.size ();i++)
        {
            ShaderProgram * shader = ShaderPool::getInstance ()->get("point_light_pass");
            shader->use ();
            PointLight * light = this->pointLights[i];
            light->apply (shader,0);

            m_quad->setShaderProgram (shader);
            QMatrix4x4 m;
            m.setToIdentity ();
            auto camera = target->camera ();
            shader->setUniformMat4v ("g_MVP_matrix",m.data ());
            shader->setUniform2Float ("g_screen_size",1024,768);
            shader->setUniformInteger ("g_color_map",0);
            shader->setUniformInteger ("g_position_map",1);
            shader->setUniformInteger ("g_normal_map",2);
            shader->setUniform3Float ("g_eye_position",
                                      camera->pos ().x(),
                                      camera->pos ().y(),
                                      camera->pos ().z());
            m_quad->draw (true);
        }
    }
}
Esempio n. 12
0
QMatrix4x4 Exercise12::rotateClockwise(int frame)
{
    /////////////////////////////////////////////////////////////////////////////////////////////////
    // TODO: Aufgabe 12
    // Apply correct transformations (rotate, translate, scale) with respect to the current frame
    /////////////////////////////////////////////////////////////////////////////////////////////////

    QMatrix4x4 transform;
    int degree = frame % 360;
    transform.setToIdentity();
    if(degree < 90) {
      transform.translate(0.5, 0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(-0.5, 0.5, 0.0);
    } else if(degree < 180) {
      transform.translate(0.5, -0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(-0.5, -0.5, 0.0);
    } else if(degree < 270) {
      transform.translate(-0.5, -0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(0.5, -0.5, 0.0);
    } else if(degree < 360) {
      transform.translate(-0.5, 0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(0.5, 0.5, 0.0);
    }
    return transform;
}
Esempio n. 13
0
/**
  * Sets mvMatrix to a lookAt transformation.
  * Call setPMatrix or setPerspective first.
  */
void GLESRenderer::setLookAt(const QVector3D & eye,const QVector3D & center,const QVector3D & up )
{
    QMatrix4x4 m;
    m.setToIdentity();
    m.lookAt(eye, center, up);
    setMvMatrix(m);
}
void CombinedNavRenderer::adjustRatios()
{
    m_ratio = static_cast< float >( m_width ) / static_cast< float >( m_height );
    glViewport( 0, 0, m_width, m_height );

    // Reset projection
    QMatrix4x4 pMatrix;
    pMatrix.setToIdentity();

    float xb = m_nx * m_dx;
    float yb = m_ny * m_dy;
    float zb = m_nz * m_dz;

    if ( m_ratio > 1.5 )
    {
        float textureRatio =  ( xb + xb + yb ) / yb;
        float mult = textureRatio / m_ratio;
        if ( m_ratio > textureRatio )
        {
            pMatrix.ortho( 0, ( xb + xb + yb ) / mult, 0, yb, -3000, 3000 );
        }
        else
        {
            pMatrix.ortho( 0, xb + xb + yb, 0, yb * mult , -3000, 3000 );
        }
    }
    else if ( m_ratio < 0.66 )
    {
        float textureRatio = yb / ( yb + zb + zb );
        float mult = textureRatio / m_ratio;
        //qDebug() << "ratio: " << m_ratio << " trat: " << textureRatio << " mult: " << mult;
        if ( m_ratio > textureRatio )
        {
            pMatrix.ortho( 0, yb / mult, 0, ( yb + zb + zb ), -3000, 3000 );
        }
        else
        {
            pMatrix.ortho( 0, yb, 0, ( yb + zb + zb ) * mult, -3000, 3000 );
        }


    }
    else
    {
        float mult = 1.0 / m_ratio;
        //qDebug() << "ratio: " << m_ratio << " trat: " << textureRatio << " mult: " << mult;
        if ( m_ratio > 1.0 )
        {
            pMatrix.ortho( 0, ( xb + yb ) / mult, 0, xb + yb, -3000, 3000 );
        }
        else
        {
            pMatrix.ortho( 0, xb + yb, 0, ( xb + yb ) * mult, -3000, 3000 );
        }
    }

     m_mvpMatrix = pMatrix;
}
Esempio n. 15
0
const QMatrix4x4 &RaycastCube::matrix()
{
    static QMatrix4x4 mat;
    mat.setToIdentity();
//    mat.translate(0.5f, 0.5f, 0.5f);
//    mat.scale(width - 1, height - 1, depth - 1);
    mat.scale(width, height, depth);
    return mat;
}
Esempio n. 16
0
/**
* Get polygon oriented bounding box
**/
void Polygon3D::getLoopOBB(Loop3D &pin, QVector3D &size, QMatrix4x4 &xformMat){
	float alpha = 0.0f;			
	float deltaAlpha = 0.05*3.14159265359f;
	float bestAlpha;

	Loop3D rotLoop;
	QMatrix4x4 rotMat;
	QVector3D minPt, maxPt;
	QVector3D origMidPt;
	QVector3D boxSz;
	QVector3D bestBoxSz;
	float curArea;
	float minArea = FLT_MAX;

	rotLoop = pin;
	Polygon3D::getLoopAABB(rotLoop, minPt, maxPt);
	origMidPt = 0.5f*(minPt + maxPt);

	//while(alpha < 0.5f*_PI){
	int cSz = pin.size();
	QVector3D difVec;
	for(int i=0; i<pin.size(); ++i){
		difVec = (pin.at((i+1)%cSz) - pin.at(i)).normalized();
		alpha = atan2(difVec.x(), difVec.y());
		rotMat.setToIdentity();				
		rotMat.rotate(57.2957795f*(alpha), 0.0f, 0.0f, 1.0f);//57.2957795 rad2degree				

		transformLoop(pin, rotLoop, rotMat);
		boxSz = Polygon3D::getLoopAABB(rotLoop, minPt, maxPt);
		curArea = boxSz.x() * boxSz.y();
		if(curArea < minArea){
			minArea = curArea;
			bestAlpha = alpha;
			bestBoxSz = boxSz;
		}
		//alpha += deltaAlpha;
	}

	xformMat.setToIdentity();											
	xformMat.rotate(57.2957795f*(bestAlpha), 0.0f, 0.0f, 1.0f);//57.2957795 rad2degree
	xformMat.setRow(3, QVector4D(origMidPt.x(), origMidPt.y(), origMidPt.z(), 1.0f));			
	size = bestBoxSz;
}//
Esempio n. 17
0
void MainWidget::paintGL()
{
    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//! [6]

    QMatrix4x4 view;
    view.setToIdentity();
    QMatrix4x4 model;
    model.setToIdentity();

    // Calculate model view transformation
    //model.rotate(rotation);


    eye.setX(-distance*sin(angleYtmp)*cos(angleXtmp)+center.x() );
    eye.setY( distance*cos(angleYtmp)+center.y() );
    eye.setZ( distance*sin(angleYtmp)*sin(angleXtmp)+center.z() );

    view.lookAt(eye, center, up);

    //matrix.translate(0.0, -5.0, -15.0);
    //matrix.translate(0.0, -5.0, 0.0);

    // Set modelview-projection matrix
    program->setUniformValue("mvp_matrix", projection * view * model);
//! [6]

    // Using texture unit 0 which contains cube.png
    program->setUniformValue("texture", 0);

    // Draw cube geometry
    //geometries->drawCubeGeometry(program);


    if(drawState == 0){//POINT_CLOUD
        FSController::getInstance()->geometries->drawPointCloud(program);
    }else if(drawState == 1){//SURFACE_MESH
        FSController::getInstance()->geometries->drawSurfaceMesh(program);
    }
    FSController::getInstance()->geometries->drawGroundPlane(program);
}
Esempio n. 18
0
void ctMatrix4::Scale(QVector3D t_scl)
{
    QMatrix4x4 tmp;
    tmp.setToIdentity();

    tmp(0, 0) = t_scl.x();
    tmp(1, 1) = t_scl.y();
    tmp(2, 2) = t_scl.z();
    m_matrix *= tmp;
}
Esempio n. 19
0
void GeometryEngine::drawNodeGeometry(Node* n)
{
    int m44size = 4 * sizeof(QVector4D);
    QMatrix4x4 m;

    m.setToIdentity();
    m.translate( n->m_position.x(), n->m_position.y(), 0 );
    m_modelsBuffer.write(((char*)m.constData()), m44size);
    m_numNodesToRender++;

}
Esempio n. 20
0
void ctMatrix4::RotateX(float t_xangle)
{
    QMatrix4x4 tmp;
    tmp.setToIdentity();

    tmp(1,1) = cos(t_xangle);
    tmp(1,2) = sin(t_xangle);
    tmp(2,1) = -sin(t_xangle);
    tmp(2,2) = cos(t_xangle);

    m_matrix *= tmp;
}
QMatrix4x4 CAD_HeatCool_ValveLever::rotationOfFlange(quint8 num)
{
    if(num == 1)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(-90.0, 0.0, 1.0, 0.0);
        return matrix_rotation * m;
    }
    else
        return matrix_rotation;
}
Esempio n. 22
0
void CameraShader::apply() {
    QMatrix4x4 mv;
    mv.setToIdentity();
    // ModelView.rotate(eye, at, up);

    mv.rotate(-_pitch, 1.0, 0.0, 0.0);
    mv.rotate(  -_yaw, 0.0, 1.0, 0.0);
    mv.rotate( -_roll, 0.0, 0.0, 1.0);
    mv.translate(-_position.x, -_position.y, -_position.z);

    _shaderProgram->setUniformValue("ModelView", mv);
}
Esempio n. 23
0
void Tutorial03::initializeGL(void)
{
  // initialize OpenGL
  initializeOpenGLFunctions();

  bool success;
  // load and compile vertex shader
  success = shaderProgram.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/SimpleTransform.vert");

  // load and compile fragment shader
  success = shaderProgram.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/SingleColor.frag");

  // link the shader program
  shaderProgram.link();

  GLuint programID = shaderProgram.programId();

  // Get a handle for our buffers
  vertexPosition_modelspaceID = glGetAttribLocation(programID, "vertexPosition_modelspace");

  // Get a handle to the colors
  color_location = glGetAttribLocation(programID, "v_color");

  // Get a handle for our "MVP" uniform
  MatrixID = glGetUniformLocation(programID, "MVP");

  // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
  QMatrix4x4 projection;
  projection.perspective(45.0, 4.0/3.0, 0.1, 100.0);

  // Camera matrix
  QMatrix4x4 view;
  view.lookAt( QVector3D(4,3,3), // Camera is at (4,3,3), in World Space
               QVector3D(0,0,0), // and looks at the origin
               QVector3D(0,1,0)  // Head is up (set to 0,-1,0 to look upside-down)
             );
  // Model matrix : an identity matrix (model will be at the origin)
  QMatrix4x4 model;
  model.setToIdentity();

  // Our ModelViewProjection : multiplication of our 3 matrices
  MVP =  projection * view * model; // Remember, matrix multiplication is the other way around

  glGenBuffers(1, &vertexbuffer);
  glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
  glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

  glGenBuffers(1, &colorbuffer);
  glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
  glBufferData(GL_ARRAY_BUFFER, sizeof(triangle_colors), triangle_colors, GL_STATIC_DRAW);

  glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
}
Esempio n. 24
0
QMatrix4x4 CAD_Steel_BeamI::rotationOfFlange(quint8 num)
{
    if(num <= 2)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(180.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
    else
        return matrix_rotation;
}
Esempio n. 25
0
void Camera::updateRotation( float pitch, float yaw, float roll)
{
    QMatrix4x4 cameraTransformation;
    cameraTransformation.setToIdentity();
    cameraTransformation.rotate(-roll, m_cameraForwardVector.toVector3D());
    cameraTransformation.rotate(-pitch, m_cameraRightVector.toVector3D());
    cameraTransformation.rotate(yaw, m_cameraUpVector.toVector3D());

    m_cameraForwardVector = m_cameraForwardVector * cameraTransformation;
    m_cameraRightVector = m_cameraRightVector * cameraTransformation;
    m_cameraUpVector = m_cameraUpVector * cameraTransformation;
}
Esempio n. 26
0
void ctMatrix4::RotateY(float t_yangle)
{
    QMatrix4x4 tmp;
    tmp.setToIdentity();

    tmp(0,0) = cos(t_yangle);
    tmp(0,2) = -sin(t_yangle);
    tmp(2,0) = sin(t_yangle);
    tmp(2,2) = cos(t_yangle);

    m_matrix *= tmp;
}
Esempio n. 27
0
void ctMatrix4::Translate(QVector3D t_pos)
{
    QMatrix4x4 tmp;
    tmp.setToIdentity();

    tmp(0, 3) = t_pos.x();
    tmp(1, 3) = t_pos.y();
    tmp(2, 3) = t_pos.z();
    m_matrix.translate(t_pos.x(),t_pos.y(),t_pos.z());
    //m_matrix = tmp * m_matrix;
    qDebug() << m_matrix(0, 3);
}
QMatrix4x4 CAD_Cleanroom_CeilingGridFeedThrough::rotationOfFlange(quint8 num)
{
    if(num == 2)
    {
        QMatrix4x4 m;
        m.setToIdentity();
        m.rotate(180.0, 0.0, 0.0, 1.0);
        return matrix_rotation * m;
    }
    else
        return matrix_rotation;
}
Esempio n. 29
0
void ctMatrix4::RotateZ(float t_zangle)
{
    QMatrix4x4 tmp;
    tmp.setToIdentity();

    tmp(0,0) = cos(t_zangle);
    tmp(0,1) = sin(t_zangle);
    tmp(1,0) = -sin(t_zangle);
    tmp(1,1) = cos(t_zangle);

    m_matrix *= tmp;
}
Esempio n. 30
0
void myCam::camMove(int x, int y)
{
    if(this->freeCameramode == true)
    {
        QMatrix4x4 move;
        move.setToIdentity();
        move.translate(x,0,y);
        this->viewMatrix = move * this->viewMatrix;

    }


}