GLC_ContextSharedData::GLC_ContextSharedData()
    : m_pDefaultShader(NULL)
    , m_IsClean(false)
    , m_CurrentMatrixMode()
    , m_MatrixStackHash()
    , m_UniformShaderData()
    , m_ColorMaterialIsEnable()
    , m_LightingIsEnable()
    , m_TwoSidedLighting()
    , m_LightsEnableState()
{
    QStack<GLC_Matrix4x4>* pStack1= new QStack<GLC_Matrix4x4>();
    pStack1->push(GLC_Matrix4x4());
    m_MatrixStackHash.insert(GL_MODELVIEW, pStack1);

    QStack<GLC_Matrix4x4>* pStack2= new QStack<GLC_Matrix4x4>();
    pStack2->push(GLC_Matrix4x4());
    m_MatrixStackHash.insert(GL_PROJECTION, pStack2);

    QStack<GLC_Matrix4x4>* pStack3= new QStack<GLC_Matrix4x4>();
    pStack3->push(GLC_Matrix4x4());
    m_MatrixStackHash.insert(GL_TEXTURE, pStack3);

    m_ColorMaterialIsEnable.push(false);
    m_LightingIsEnable.push(false);
    m_TwoSidedLighting.push(false);

    initLightEnableState();
}
Exemplo n.º 2
0
//////////////////////////////////////////////////////////////////////
// Private services Functions
//////////////////////////////////////////////////////////////////////
void GLC_Context::init()
{
	QStack<GLC_Matrix4x4>* pStack1= new QStack<GLC_Matrix4x4>();
	pStack1->push(GLC_Matrix4x4());
	m_MatrixStackHash.insert(GL_MODELVIEW, pStack1);

	QStack<GLC_Matrix4x4>* pStack2= new QStack<GLC_Matrix4x4>();
	pStack2->push(GLC_Matrix4x4());
	m_MatrixStackHash.insert(GL_PROJECTION, pStack2);

	m_LightingIsEnable.push(false);
}
Exemplo n.º 3
0
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());
}
Exemplo n.º 4
0
void EditPositionDialog::updateMatrix()
{
	double alphaX= glc::toRadian(rx->value());
	double alphaY= glc::toRadian(ry->value());
	double alphaZ= glc::toRadian(rz->value());

	GLC_Matrix4x4 rotationMatrix(GLC_Matrix4x4().fromEuler(alphaX, alphaY, alphaZ));
	m_pOccurence->structInstance()->setMatrix(GLC_Matrix4x4(tx->value(), ty->value(), tz->value()) * rotationMatrix);
	const int occurenceCount= m_pOccurence->structInstance()->numberOfOccurence();
	QList<GLC_StructOccurence*> occurencesList= m_pOccurence->structInstance()->listOfStructOccurences();
	for (int i= 0; i < occurenceCount; ++i)
	{
		occurencesList[i]->updateChildrenAbsoluteMatrix();
	}

	emit positionUpdated();
}
Exemplo n.º 5
0
GLC_3DViewInstance GLC_Factory::createRectangle(const GLC_Point3d& point, const GLC_Vector3d& normal, double l1, double l2)
{
	// Create the rectangle to (0,0) and  z normal
	GLC_3DViewInstance rectangleInstance(createRectangle(l1, l2));

	// Create the plane rotation matrix
	const GLC_Matrix4x4 rotationMatrix(glc::Z_AXIS, normal);
	// Vector from origin to the plane
	rectangleInstance.setMatrix(GLC_Matrix4x4(point) * rotationMatrix);

	return rectangleInstance;
}
QQuaternion GLC_Matrix4x4::quaternion() const
{
	QQuaternion subject;
	GLC_Matrix4x4 rotMat= rotationMatrix();
	if ((this->type() != GLC_Matrix4x4::Identity) && (rotMat != GLC_Matrix4x4()))
	{
		const double matrixTrace= rotMat.trace();
		double s, w, x, y, z;

		if (matrixTrace > 0.0)
		{
			s= 0.5 / sqrt(matrixTrace);
			w= 0.25 / s;
			x= (rotMat.m_Matrix[9] - rotMat.m_Matrix[6]) * s;
			y= (rotMat.m_Matrix[2] - rotMat.m_Matrix[8]) * s;
			z= (rotMat.m_Matrix[4] - rotMat.m_Matrix[1]) * s;
		}
		else
		{
			if ((abs(rotMat.m_Matrix[0]) > abs(rotMat.m_Matrix[5])) &&  (abs(rotMat.m_Matrix[0]) > abs(rotMat.m_Matrix[15])))
			{	// column 0 greater
		        s= sqrt(1.0 + rotMat.m_Matrix[0] - rotMat.m_Matrix[5] - rotMat.m_Matrix[10]) * 2.0;

		        w= (rotMat.m_Matrix[6] + rotMat.m_Matrix[9] ) / s;
		        x= 0.5 / s;
		        y= (rotMat.m_Matrix[1] + rotMat.m_Matrix[4] ) / s;
		        z= (rotMat.m_Matrix[2] + rotMat.m_Matrix[8] ) / s;
			}
			else if ((abs(rotMat.m_Matrix[5]) > abs(rotMat.m_Matrix[0])) &&  (abs(rotMat.m_Matrix[5]) > abs(rotMat.m_Matrix[15])))
			{	// column 1 greater
		        s= sqrt(1.0 + rotMat.m_Matrix[5] - rotMat.m_Matrix[0] - rotMat.m_Matrix[10]) * 2.0;

		        w= (rotMat.m_Matrix[2] + rotMat.m_Matrix[8]) / s;
		        x= (rotMat.m_Matrix[1] + rotMat.m_Matrix[4]) / s;
		        y= 0.5 / s;
		        z= (rotMat.m_Matrix[6] + rotMat.m_Matrix[9]) / s;
			}
			else
			{	// column 3 greater
		        s= sqrt(1.0 + rotMat.m_Matrix[10] - rotMat.m_Matrix[0] - rotMat.m_Matrix[5]) * 2.0;

		        w = (rotMat.m_Matrix[1] + rotMat.m_Matrix[4]) / s;
		        x = (rotMat.m_Matrix[2] + rotMat.m_Matrix[8]) / s;
		        y = (rotMat.m_Matrix[6] + rotMat.m_Matrix[9]) / s;
		        z = 0.5 / s;
			}
		}
		subject= QQuaternion(w, x, y, z);
	}

	return subject;
}
Exemplo n.º 7
0
GLC_3DViewInstance GLC_Factory::createCuttingPlane(const GLC_Point3d& point, const GLC_Vector3d& normal, double l1, double l2, GLC_Material* pMat)
{
	// Create the rectangle to (0,0) and  z normal
	GLC_Rectangle* pRectangle= new GLC_Rectangle(l1, l2);
	pRectangle->replaceMasterMaterial(pMat);

	GLC_3DViewInstance rectangleInstance(pRectangle);

	// Create the plane rotation matrix
	const GLC_Matrix4x4 rotationMatrix(glc::Z_AXIS, normal);
	// Vector from origin to the plane
	rectangleInstance.setMatrix(GLC_Matrix4x4(point) * rotationMatrix);

	return rectangleInstance;

}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
void glc::gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
    GLdouble m[4][4];
    double sine, cotangent, deltaZ;
    double radians = fovy / 2 * __glPi / 180;

    deltaZ = zFar - zNear;
    sine = sin(radians);
    if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
	return;
    }
    cotangent = cos(radians) / sine;

    __gluMakeIdentityd(&m[0][0]);
    m[0][0] = cotangent / aspect;
    m[1][1] = cotangent;
    m[2][2] = -(zFar + zNear) / deltaZ;
    m[2][3] = -1;
    m[3][2] = -2 * zNear * zFar / deltaZ;
    m[3][3] = 0;
    GLC_ContextManager::instance()->currentContext()->glcMultMatrix(GLC_Matrix4x4(&m[0][0]));
}
Exemplo n.º 10
0
QPair<GLC_Vector3d, double> GLC_Matrix4x4::rotationVectorAndAngle() const
{
	QPair<GLC_Vector3d, double> subject(GLC_Vector3d(), 0.0);
	if (GLC_Matrix4x4(*this).optimise().type() != GLC_Matrix4x4::Identity)
	{
		QQuaternion quaternion= this->quaternion();
		quaternion.normalize();

	    const double cos_angle= quaternion.scalar();
	    const double angle= acos(cos_angle);
	    double sin_angle= sqrt(1.0 - cos_angle * cos_angle);


	    if (fabs(sin_angle) < 0.0005) sin_angle= 1.0;

	    subject.first.setX(quaternion.x() / sin_angle);
	    subject.first.setY(quaternion.y() / sin_angle);
	    subject.first.setZ(quaternion.z() / sin_angle);

	    subject.second= angle * 2.0;
	}

	return subject;
}