Пример #1
0
void getRotationAndEyePositionFromModelView( const Matrix4f& modelViewMatrix,
                                                   Matrix3f& rotationMatrix,
                                                   Vector3f& eye )
{
    Matrix4f iMv;
    modelViewMatrix.inverse( iMv );
    iMv.get_sub_matrix( rotationMatrix, 0, 0 );
    iMv.get_translation( eye );
}
Пример #2
0
Matrix4f Camera::GetView() const
{
	Matrix4f cameraRotation = m_transform.GetTransformedRot().Conjugate().ToRotationMatrix();
	Matrix4f cameraTranslation;

	cameraTranslation.InitTranslation(m_transform.GetTransformedPos() * -1);

	return cameraRotation * cameraTranslation;
}
Пример #3
0
Matrix4f CameraSettings::getModelViewMatrix() const
{
    Matrix4f modelView;
    modelView = modelRotation_;
    modelView.set_translation( cameraPosition_ );
    modelView = cameraRotation_ * modelView;

    return modelView;
}
Пример #4
0
 // Generic camera (from REST) in meters
 void onCamera( const ::zeq::Event& event )
 {
     const auto& matrix = ::zeq::hbp::deserializeCamera( event );
     Matrix4f modelViewMatrix;
     modelViewMatrix.set( matrix.begin(), matrix.end(), false );
     auto cameraSettings = _config.getFrameData().getCameraSettings();
     cameraSettings->setModelViewMatrix( modelViewMatrix );
     _config.postRedraw();
 }
	void DSDirectionalLightPass()    
    {		
        m_DSDirLightPassTech.Enable();
        m_DSDirLightPassTech.SetEyeWorldPos(m_pGameCamera->GetPos());
        Matrix4f WVP;
        WVP.InitIdentity();        
        m_DSDirLightPassTech.SetWVP(WVP);
        m_quad.Render();  
	}
Пример #6
0
const Matrix4f Camera::GetMatrix()
{
	Matrix4f p = Matrix4f::Translation(pos);
	Matrix4f r = Matrix4f::RotationXYZ(angles);

	if(order == ORDER_TRANS_ROT)
		return r.Mul(p);

	return p.Mul(r);
}
Пример #7
0
Matrix4f Matrix4f::Translate(Vector3f vector)
{
	Matrix4f translatedMatrix = Matrix4f().InitializeIdentity(); 

	translatedMatrix.Set(3,0,vector.GetX());
	translatedMatrix.Set(3,1,vector.GetY());
	translatedMatrix.Set(3,2,vector.GetZ());

	return ((*this) * translatedMatrix);
}
Пример #8
0
static Matrix4f zero(void)
{
	Matrix4f zeroMatrix;
	
	for(int x = 0; x < 4; x++)
		for(int y = 0; y < 4; y++)
			zeroMatrix.setValue(x, y, 0.0f);
	
	return zeroMatrix;
}
Пример #9
0
Matrix4f Matrix4f::Scale(Vector3f vector)
{
	Matrix4f scaledMatrix = Matrix4f().InitializeIdentity();

	scaledMatrix.Set(0,0,vector.GetX());
	scaledMatrix.Set(1,1,vector.GetY());
	scaledMatrix.Set(2,2,vector.GetZ());

	return ((*this) * scaledMatrix);
}
Пример #10
0
Matrix4f computeModelViewMatrix( const Matrix3f& rotationMatrix, const Vector3f& eye )
{
    Matrix4f rotationTranspose = Matrix4f::IDENTITY;
    rotationTranspose.set_sub_matrix( rotationMatrix, 0, 0 );
    rotationTranspose = transpose( rotationTranspose );

    Matrix4f modelViewMatrix = Matrix4f::IDENTITY;
    modelViewMatrix.set_translation( -eye );
    return rotationTranspose * modelViewMatrix;
}
Пример #11
0
const Matrix4f& Pipeline::GetWPTrans()
{
	Matrix4f PersProjTrans;

	GetWorldTrans();
	PersProjTrans.InitPersProjTransform(m_persProjInfo);

	m_WPtransformation = PersProjTrans * m_Wtransformation;
	return m_WPtransformation;
}
Пример #12
0
		void LightNode::render()
		{
			//printf("%s%s\n" , "Rendering " , getName() );
			//TO DO---> View matrix and World Matrix can be stored, and send to the Renderer directly
			Matrix4f& viewMat = sceneManager->getActiveCamera()->getViewMatrix();
			Matrix4f temp;
			temp.multiply(globalTransform);
			sceneManager->getRenderer()->setTransform(temp , WORLD);
            sceneManager->getRenderer()->addLight(lightData);
		}
Пример #13
0
bool Render::on_motion_notify_event(GdkEventMotion* event)
{
  bool redraw=true;
  Vector2f dragp(event->x, event->y);
  Vector2f delta = m_downPoint - dragp;
  double factor = 0.3;
  Vector3d delta3f(-delta.x*factor, delta.y*factor, 0);
  get_model()->setMeasuresPoint(Vector2d((10.+event->x)/(get_width()-20),
					 (10.+get_height()-event->y)/(get_height()-20)));
  if (event->state & GDK_BUTTON1_MASK) { // move or rotate
    if (event->state & GDK_SHIFT_MASK) { // move object
      if (false);//delta3f.x<1 && delta3f.y<1) redraw=false;
      else {
	Shape *shape;
	TreeObject *object;
	if (!m_view->get_selected_stl(object, shape))
	  return true;
	if (!object && !shape)
	  return true;
	Transform3D *transf;
	if (!shape)
	  transf = &object->transform3D;
	else
	  transf = &shape->transform3D;
	transf->move(delta3f);
	m_downPoint = dragp;
	//m_view->get_model()->CalcBoundingBoxAndCenter();
      }
    }
    else { // rotate
      m_arcBall->dragAccumulate(event->x, event->y, &m_transform);
    }
    if (redraw) queue_draw();
    return true;
  }
  else {
    if (event->state & GDK_BUTTON2_MASK) { // zoom
      double factor = 1.0 + 0.01 * (delta.x - delta.y);
      m_zoom *= factor;
    }
    else if (event->state & GDK_BUTTON3_MASK) { // pan
      Matrix4f matrix;
      memcpy(&matrix.m00, &m_transform.M[0], sizeof(Matrix4f));
      Vector3f m_transl = matrix.getTranslation();
      m_transl += delta3f;
      matrix.setTranslation(m_transl);
      memcpy(&m_transform.M[0], &matrix.m00, sizeof(Matrix4f));      
    }
    m_downPoint = dragp;
    if (redraw) queue_draw();
    return true;
  }
  return Gtk::DrawingArea::on_motion_notify_event (event);
}
Пример #14
0
	Matrix4f Transform::getProjectedTransformation() {
		Matrix4f transMat = getTransformation();
		Matrix4f proMat = Matrix4f();
		proMat.initProjection(Transform::fov,
				      Transform::width,
				      Transform::height,
				      Transform::zNear,
				      Transform::zFar );

		return proMat*transMat;
	}
Пример #15
0
void TestMatrixInverse()
{
   Vector3f rot( .6f, 1.2f, 1.8f );
   Matrix4f m;
   m.SetRotation( rot );
   Matrix4f n = m.OrthonormalInverse();

   std::cout << "Original matrix" << std::endl << m;
   std::cout << "Inverse" << std::endl << n;
   std::cout << "Product" << std::endl << n * m;
}
Пример #16
0
const Matrix4f& Pipeline::GetWVOrthoPTrans()
{
    GetWorldTrans();
    GetViewTrans();

    Matrix4f P;
    P.InitOrthoProjTransform(m_orthoProjInfo);
    
    m_WVPtransformation = P * m_Vtransformation * m_Wtransformation;
    return m_WVPtransformation;
}
Пример #17
0
void BaseRendererSystem::bind_program( Program& program, 
	Mesh& mesh, Matrix4f& camera ) {

	if( program.vertex_shader == -1 ) {
		program.vertex_shader = glCreateShaderObjectARB( GL_VERTEX_SHADER );
		const char* src = program.vertex_source.c_str();
		glShaderSourceARB( program.vertex_shader, 1, &src, NULL );
		glCompileShaderARB( program.vertex_shader );

		program.fragment_shader = 
			glCreateShaderObjectARB( GL_FRAGMENT_SHADER );
		src = program.fragment_source.c_str();
		glShaderSourceARB( program.fragment_shader, 1, &src, NULL );
		glCompileShaderARB( program.fragment_shader );

		program.program = glCreateProgramObjectARB();
		glAttachObjectARB( program.program, program.vertex_shader );
		glAttachObjectARB( program.program, program.fragment_shader );

		for( GLuint i = 0; i < Program::MAX_FRAMEBUFFERS; ++i )
			if( program.frag_location[i].length() ) {
				glBindFragDataLocationEXT( program.program, i, 
					program.frag_location[i].c_str() );
			}

		glLinkProgramARB( program.program );

		if( true || glGetError() != 0 ) {
			char error_message[2048];
			int nwritten = 0;
			glGetInfoLogARB( program.program, 2048, &nwritten, error_message );

			std::cerr << "Program failed to compile: " << std::endl;
			std::cerr << error_message << std::endl;
		}
	}

	glUseProgramObjectARB( program.program );

	if( program.camera_transform.length() ) {
		if( program.variables.count( program.camera_transform ) ) {
			std::copy( camera.ptr(), camera.ptr()+16,
				(float*)program.variables[ program.camera_transform ]
					->data );
		} else {
			program.variables[ program.camera_transform ] =
				ProgramVariable::mat4( camera );
		}
	}
	
	Program::variable_map::iterator i;
	for( i = program.variables.begin(); i != program.variables.end(); ++i )
		bind_variable( program, mesh, i->first, *i->second );
}
void InterpolationHelper::interpolateActor(){


    Matrix4f transformOne, transformTwo;

	Matrix3f rotationOne, rotationTwo;
	Matrix3f resultingRotation;

    Matrix4f resultingTransform;


    currentTime=renderer->currentTime-startTime;

    float relativeTime=currentTime/moveTime;

    transformOne=baseTransform;
    transformTwo=targetActor->transformMatrix;

    if (currentTime>moveTime){
        resultingTransform=transformOne.lerp(1.0,transformTwo); //calculate resulting position
        moveActor->transformMatrix=resultingTransform;
        bFinished=true;
        return;
    }

        float x=relativeTime*2.0f;
        float y=0.0f;

        if (x< 1)
            y=x*x;
        else
            y=2-( (x-2) * (x-2) );

        y=y*0.5;

        if (bLinear)
            y=relativeTime;


	rotationOne=getRotationMatrix(transformOne);
	rotationTwo=getRotationMatrix(transformTwo);
	resultingRotation=rotationOne.lerp(y,rotationTwo);


    //interpolate between them
    resultingTransform=transformOne.lerp(y,transformTwo); //calculate resulting position


	//normalize rotations!
	resultingRotation=normalizeRotations(resultingRotation);
	resultingTransform.setRotation(resultingRotation);

    moveActor->transformMatrix=resultingTransform;
}
Пример #19
0
void UiRenderer::renderImage(radix::Vector3f position, radix::Vector3f scale, std::string path) {
  Matrix4f matrix;
  matrix.translate(position);
  matrix.scale(scale);

  const Mesh &mesh = MeshLoader::getMesh("GUIElement.obj");
  const Material &material = MaterialLoader::fromTexture(path);

  Shader &sh = ShaderLoader::getShader("unshaded.frag");
  renderer.renderMesh(*renderContext.get(), sh, matrix, mesh, material);
  sh.release();
}
Пример #20
0
Matrix4f Transform::GetTransformation() const
{
	Matrix4f translationMatrix;
	Matrix4f scaleMatrix;

	translationMatrix.InitTranslation(Vector3f(m_pos.GetX(), m_pos.GetY(), m_pos.GetZ()));
	scaleMatrix.InitScale(Vector3f(m_scale, m_scale, m_scale));

	Matrix4f result = translationMatrix * m_rot.ToRotationMatrix() * scaleMatrix;

	return GetParentMatrix() * result;
}
Пример #21
0
Matrix4f Quaternion::calcStateTransMatrix(Vector3f w, float t){
	Matrix4f A;
	A << 0, -w[0], -w[1], -w[2],
		w[0], 0, w[2], -w[1],
		w[1], -w[2], 0, w[0],
		w[2], w[1], -w[0], 0;
	A *= 0.5f;
	Matrix4f T;
	T.setIdentity();
	T += A * t;
	return T;
}
Пример #22
0
Matrix4f ProcessController::GetSTLTransformationMatrix(int object, int file) const 
{
	Matrix4f result = rfo.transform3D.transform;
	Vector3f translation = result.getTranslation();
//	result.setTranslation(translation+PrintMargin);

	if(object >= 0)
		result *= rfo.Objects[object].transform3D.transform;
	if(file >= 0)
		result *= rfo.Objects[object].files[file].transform3D.transform;
	return result;
}
Пример #23
0
void drawRect(SDL_Surface *surface, int x, int y, int w, int h, const Uint32 color) {
	Matrix4f edgeMatrix;
	edgeMatrix.addCol(Vec4f(x,   y,   0, 1));
	edgeMatrix.addCol(Vec4f(x+w, y,   0, 1));
	edgeMatrix.addCol(Vec4f(x,   y,   0, 1));
	edgeMatrix.addCol(Vec4f(x,   y+h, 0, 1));
	edgeMatrix.addCol(Vec4f(x+w, y,   0, 1));
	edgeMatrix.addCol(Vec4f(x+w, y+h, 0, 1));
	edgeMatrix.addCol(Vec4f(x,   y+h, 0, 1));
	edgeMatrix.addCol(Vec4f(x+w, y+h, 0, 1));
	drawEdges(surface, &edgeMatrix, color);
}
Пример #24
0
// static
SimilarityTransform SimilarityTransform::fromMatrix( const Matrix4f& m )
{
    Matrix3f r = m.getSubmatrix3x3();
    float s = r.getRow( 0 ).norm();

    return
    {
        s,
        r / s,
        m.getCol( 3 ).xyz
    };
}
void CData4Viewer::drawRGBView()
{
	_pKinect->_pRGBCamera->setGLProjectionMatrix( 0.1f,100.f);

	glMatrixMode ( GL_MODELVIEW );
	Eigen::Affine3f tmp; tmp.setIdentity();
	Matrix4f mv = btl::utility::setModelViewGLfromPrj(tmp); //mv transform X_m to X_w i.e. model coordinate to world coordinate
	glLoadMatrixf( mv.data() );
	_pKinect->_pRGBCamera->renderCameraInLocal(*_pKinect->_pCurrFrame->_acvgmShrPtrPyrRGBs[_pGL->_usLevel],  _pGL.get(),false, NULL, 0.2f, true ); //render in model coordinate
	//PRINTSTR("drawRGBView");
    return;
}
Пример #26
0
Matrix4f Matrix4f::OrthographicProjection(int width, int height, float zFar, float zNear)
{
	
	float	zRange = zFar -zNear;
	
	Matrix4f orthographicMatrix = Matrix4f().InitializeIdentity();
	
	orthographicMatrix.Set(0,0,1/width);	orthographicMatrix.Set(1,1,1/height);
	orthographicMatrix.Set(2,2,-2/zRange);	orthographicMatrix.Set(3,2,-1 * ((zFar+zNear)/zRange));

	return (*this) * orthographicMatrix;
}
Пример #27
0
Matrix4f Matrix4f::WorldSpaceToScreenSpace(float halfWidth,float halfHeight)
{

	Matrix4f screenMatrix = Matrix4f().InitializeIdentity();

	screenMatrix.Set(0,0,halfWidth);
	screenMatrix.Set(1,1,-halfHeight);
	screenMatrix.Set(3,0,halfWidth - 0.5);
	screenMatrix.Set(3,1,halfHeight - 0.5);

	return (*this) * screenMatrix;
}
Пример #28
0
//---------------------------------------------------------------------------------------------------------------------
void Gui::drawCamera(const Eigen::Matrix3f & _orientation, const Eigen::Vector4f & _position, unsigned _r , unsigned _g , unsigned _b, std::string _tag) {
	// Create a pointcloud vertically oriented in the origin
	pcl::PointCloud<pcl::PointXYZ> camera;
	camera.push_back(PointXYZ(0.07, 0.05, 0));
	camera.push_back(PointXYZ(-0.07, 0.05, 0));
	camera.push_back(PointXYZ(-0.07, -0.05, 0));
	camera.push_back(PointXYZ(0.07, -0.05, 0));
	camera.push_back(PointXYZ(0.12, 0.1, 0.2));
	camera.push_back(PointXYZ(-0.12, 0.1, 0.2));
	camera.push_back(PointXYZ(-0.12, -0.1, 0.2));
	camera.push_back(PointXYZ(0.12, -0.1, 0.2));

	// Rotate and move camera to the desired position and orientation.
	Matrix4f transformation = Matrix4f::Zero();
	transformation << _orientation;
	transformation.col(3) << _position(0), _position(1), _position(2), 1;

	//std::cout << transformation << std::endl;

	pcl::PointCloud<pcl::PointXYZ> cameraRotated;
	transformPointCloud(camera, cameraRotated, transformation);

	// Draw camera
	PointXYZ p1 = cameraRotated[3];
	for (unsigned i = 0; i < 4; i++) {
		PointXYZ p2 = cameraRotated[i];
		drawLine(p1,p2, _r, _g, _b);
		p1 = p2;
	}

	p1 = cameraRotated[4];
	for (unsigned i = 4; i < 8; i++) {
		PointXYZ p2 = cameraRotated[i];
		drawLine(p1, p2, _r, _g, _b);
		p1 = p2;
	}

	for (unsigned i = 0; i < 4; i++) {
		PointXYZ p1 = cameraRotated[i];
		PointXYZ p2 = cameraRotated[i+4];
		drawLine(p1, p2, _r, _g, _b);
	}

	// Marker on top
	ModelCoefficients coef;
	coef.values.push_back((cameraRotated[0].x + cameraRotated[1].x)/2);
	coef.values.push_back((cameraRotated[0].y + cameraRotated[1].y)/2);
	coef.values.push_back((cameraRotated[0].z + cameraRotated[1].z)/2);
	coef.values.push_back(0.01);
	m3dViewer->addSphere(coef,"cameraTop"+to_string(mPcCounter++), mViewPortMapViewer);

}
Пример #29
0
void drawCurve( const Curve& curve, float framesize )
{
    // Save current state of OpenGL
    glPushAttrib( GL_ALL_ATTRIB_BITS );

    // Setup for line drawing
    glDisable( GL_LIGHTING ); 
    glColor4f( 1, 1, 1, 1 );
    glLineWidth( 1 );
    
    // Draw curve
    glBegin( GL_LINE_STRIP );
    for( unsigned i = 0; i < curve.size(); ++i )
    {
        glVertex( curve[ i ].V );
    }
    glEnd();

    glLineWidth( 1 );

    // Draw coordinate frames if framesize nonzero
    if( framesize != 0.0f )
    {
        Matrix4f M;

	//cout << curve.size() <<endl; 
        for( unsigned i = 0; i < curve.size(); ++i )
        {
            M.setCol( 0, Vector4f( curve[i].N, 0 ) );
            M.setCol( 1, Vector4f( curve[i].B, 0 ) );
            M.setCol( 2, Vector4f( curve[i].T, 0 ) );
            M.setCol( 3, Vector4f( curve[i].V, 1 ) );

	//display vectors for debugging 
	    //cout << i << " " << curve[i].T[0] << " " << curve[i].T[1] << " " << curve[i].T[2] << endl; 


            glPushMatrix();
            glMultMatrixf( M );
            glScaled( framesize, framesize, framesize );
            glBegin( GL_LINES );
            glColor3f( 1, 0, 0 ); glVertex3d( 0, 0, 0 ); glVertex3d( 1, 0, 0 );
            glColor3f( 0, 1, 0 ); glVertex3d( 0, 0, 0 ); glVertex3d( 0, 1, 0 );
            glColor3f( 0, 0, 1 ); glVertex3d( 0, 0, 0 ); glVertex3d( 0, 0, 1 );
            glEnd();
            glPopMatrix();
        }
    }
    
    // Pop state
    glPopAttrib();
}
Пример #30
0
//-----------------------------------------------------------------------------
// 説明: シャドウのレンダリング(ポリゴンなどの描画関数を呼び出す前に呼ぶ)
// 引数: 
//       lightName [in] 光源の名前
//       lightDif [in] 光源のディフューズ
//       lightSpc [in] 光源のスペキュラ
//       lookAtMat [in] カメラ姿勢への変換行列
// 返り値:
// その他: 
//-----------------------------------------------------------------------------
void GLUTShadow_GLSL_VBO::renderShadowBegin(GLenum lightName, const Vector4f* lightAmb, const Vector4f* lightDif, const Vector4f* lightSpc, const Matrix4f* lookAtMat)
{
	/* フレームバッファとデプスバッファをクリアする */
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* モデルビュー変換行列の設定 */
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glLoadMatrixf((*lookAtMat).data());
	//m_glutWidget->getGLUTView()->ApplyViewPoint();
	//GLfloat model[16];
	Matrix4f mat = Matrix4f::Identity();
	Matrix4f inv_mat = mat;
	glGetFloatv(GL_MODELVIEW_MATRIX, mat.data());
	//inv_mat.data() = model;
	inv_mat = mat.inverse();
	//inv_mat = !inv_mat;

	/* テクスチャ変換行列を設定する */
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();

	/* テクスチャ座標の [-1,1] の範囲を [0,1] の範囲に収める */
	glTranslatef(0.5f, 0.5f, 0.5f);
	glScalef(0.5f, 0.5f, 0.5f);

	/* テクスチャのモデルビュー変換行列と透視変換行列の積をかける */
	glMultMatrixf(m_modelview);

	/* 現在のモデルビュー変換の逆変換をかけておく */
	glMultMatrixf( inv_mat.data() );

	/* モデルビュー変換行列に戻す */
	glMatrixMode(GL_MODELVIEW);

    /* テクスチャオブジェクトを結合する */
    glBindTexture(GL_TEXTURE_2D, m_tex);

	/* テクスチャマッピングとテクスチャ座標の自動生成を有効にする */
	glEnable(GL_TEXTURE_2D);
	//glEnable(GL_TEXTURE_GEN_S);
	//glEnable(GL_TEXTURE_GEN_T);
	//glEnable(GL_TEXTURE_GEN_R);
	//glEnable(GL_TEXTURE_GEN_Q);

	/* 光源の明るさを日向の部分での明るさに設定 */
    glLightfv(lightName, GL_AMBIENT, (*lightAmb).data() );
	glLightfv(lightName, GL_DIFFUSE, (*lightDif).data() );
    glLightfv(lightName, GL_SPECULAR, (*lightSpc).data() );
	//m_glutWidget->getGLUTView()->ApplyLightFv(false);

}