コード例 #1
0
	void graphics::move(float x, float y, float z)
	{
		//glTranslatef(x, y, z);
		v3 vec = {x, y, z};
		
		switch (matrixMode)
		{
			case SINNCA_MODELVIEW_MATRIX:
			{
				snTranslateM4(getModelMatrix(), getModelMatrix(), &vec);
				break;
				
			}
			case SINNCA_PROJECTION_MATRIX:
			{
				snTranslateM4(getProjectionMatrix(), getProjectionMatrix(), &vec);
				break;
			}
			case SINNCA_TEXTURE_MATRIX:
			{
				snTranslateM4(getTextureMatrix(), getTextureMatrix(), &vec);
				break;
			}
		}
	}
コード例 #2
0
	void graphics::scale(point p)
	{
		//glScalef(p.x, p.y, p.z);
		v3 vec = {p.x, p.y, p.z};
		
		switch (matrixMode)
		{
			case SINNCA_MODELVIEW_MATRIX:
			{
				snScaleM4(getModelMatrix(), getModelMatrix(), &vec);
				break;
				
			}
			case SINNCA_PROJECTION_MATRIX:
			{
				snScaleM4(getProjectionMatrix(), getProjectionMatrix(), &vec);
				break;
			}
			case SINNCA_TEXTURE_MATRIX:
			{
				snScaleM4(getTextureMatrix(), getTextureMatrix(), &vec);
				break;
			}
		}
	}
コード例 #3
0
ファイル: sceneView.cpp プロジェクト: MichaelVlad/Equalizer
void SceneView::cull()
{
    _dynamicObjectCount = 0;

    if (_camera->getNodeMask()==0) return;

    _renderInfo.setView(_camera->getView());

    // update the active uniforms
    updateUniforms();

    if (!_renderInfo.getState())
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_state attached, creating a default state automatically."<< std::endl;

        // note the constructor for osg::State will set ContextID to 0 which will be fine to single context graphics
        // applications which is ok for most apps, but not multiple context/pipe applications.
        _renderInfo.setState(new osg::State);
    }
    
    osg::State* state = _renderInfo.getState();

    if (!_localStateSet)
    {
        _localStateSet = new osg::StateSet;
    }
    
    // we in theory should be able to be able to bypass reset, but we'll call it just incase.
    //_state->reset();
   
    state->setFrameStamp(_frameStamp.get());
    state->setDisplaySettings(_displaySettings.get());


    if (!_cullVisitor)
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView:: attached, creating a default CullVisitor automatically."<< std::endl;
        _cullVisitor = CullVisitor::create();
    }
    if (!_stateGraph)
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView:: attached, creating a global default StateGraph automatically."<< std::endl;
        _stateGraph = new StateGraph;
    }
    if (!_renderStage)
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_renderStage attached, creating a default RenderStage automatically."<< std::endl;
        _renderStage = new RenderStage;
    }

    _cullVisitor->setTraversalMask(_cullMask);
    bool computeNearFar = cullStage(getProjectionMatrix(),getViewMatrix(),_cullVisitor.get(),_stateGraph.get(),_renderStage.get(),getViewport());

    if (computeNearFar)
    {
        CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane();
        CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane();
        _cullVisitor->clampProjectionMatrix(getProjectionMatrix(),zNear,zFar);
    }
}
コード例 #4
0
/** Triangulate 3D points.
 * @param std::vector<Match> vector with matches
 * @param Eigen::Matrix3f rotation matrix
 * @param Eigen::Vector3f translation vector
 * @param Eigen::Matrix<float, 4, Eigen::Dynamic> output matrix with computed 3D points
 * @return int number of inliers, i.e., points that satisfy the Chirality constraint */
int MonoOdometer5::triangulate(std::vector<Match> matches, Eigen::Matrix3f R, Eigen::Vector3f t, Eigen::Matrix<float, 4, Eigen::Dynamic> &points3D)
{
    points3D.resize(4, matches.size());
    
	// get projection matrices 
	//    previous camera has identity rotation and translation
	//    current camera has rotation R and translation t
    Eigen::Matrix<float, 3, 4> projMatrixPrev = getProjectionMatrix(K_, Eigen::Matrix3f::Identity(), Eigen::Vector3f::Zero());        
    Eigen::Matrix<float, 3, 4> projMatrixCurr = getProjectionMatrix(K_, R, t);
    
	// triangulation by orthogonal regression
    Eigen::Matrix4f J;
    for(int i=0; i<matches.size(); i++)
    {
        cv::Point2f pPrev = matches[i].pPrev_;
        cv::Point2f pCurr = matches[i].pCurr_;
        
        for(int j=0; j<4; j++)
        {
            J(0, j) = projMatrixPrev(2, j) * pPrev.x - projMatrixPrev(0, j);
            J(1, j) = projMatrixPrev(2, j) * pPrev.y - projMatrixPrev(1, j);
            J(2, j) = projMatrixCurr(2, j) * pCurr.x - projMatrixCurr(0, j);
            J(3, j) = projMatrixCurr(2, j) * pCurr.y - projMatrixCurr(1, j);
        }

        Eigen::JacobiSVD<Eigen::Matrix4f> svdJ(J, Eigen::ComputeFullU | Eigen::ComputeFullV);
        
        points3D(0, i) = svdJ.matrixV()(0, 3);
        points3D(1, i) = svdJ.matrixV()(1, 3);
        points3D(2, i) = svdJ.matrixV()(2, 3);
        points3D(3, i) = svdJ.matrixV()(3, 3);
    }
    
	// get reprojection points
    Eigen::Matrix<float, 3, Eigen::Dynamic> p2DPrev, p2DCurr;
    p2DPrev.resize(3, matches.size());
    p2DCurr.resize(3, matches.size());
    p2DPrev = projMatrixPrev * points3D;
    p2DCurr = projMatrixCurr * points3D;

	// test Chirality constraint and count number of inliers
    int inlierCounter = 0;
    for(int i=0; i<matches.size(); i++)
    {
        if(p2DPrev(2, i) * points3D(3, i) > 0 && p2DCurr(2, i) * points3D(3, i) > 0)
        {
            inlierCounter++;
        }
    }
    
    return inlierCounter;
}
コード例 #5
0
ファイル: Camera.cpp プロジェクト: AKS2346/Cinder
Vec2f Camera::worldToScreen( const Vec3f &worldCoord, float screenWidth, float screenHeight ) const
{
	Vec3f eyeCoord = getModelViewMatrix().transformPointAffine( worldCoord );
	Vec3f ndc = getProjectionMatrix().transformPoint( eyeCoord );
	
	return Vec2f( ( ndc.x + 1.0f ) / 2.0f * screenWidth, ( 1.0f - ( ndc.y + 1.0f ) / 2.0f ) * screenHeight );
}
コード例 #6
0
ファイル: Camera.cpp プロジェクト: TommyStarK/Bomberman
void		Camera::lockShader(gdl::AShader& shader, bool setColor, glm::vec4 const& color) const
{
  if (setColor)
    shader.setUniform(SHADER_CURRENT_COLOR, color);
  shader.setUniform(SHADER_TRANSFORMATION_MATRIX, getTransformationMatrix());
  shader.setUniform(SHADER_PROJECTION_MATRIX, getProjectionMatrix());
}
コード例 #7
0
ファイル: ElCamera.cpp プロジェクト: chenbk85/3dlearn
ElRay ElCamera::getCameraToViewportRay(float screenx, float screeny)
{
	D3DXMATRIX proj = getProjectionMatrix();
	D3DXMATRIX view = getViewMatrix();

	// Compute the vector of the Pick ray in screen space
	D3DXVECTOR3 v;
	v.x = ((2.0f * screenx) - 1.0f) / proj._11;
	v.y = (1.0f - (2.0f * screeny)) / proj._22;
	v.z = 1.0f;

	// Transform the screen space Pick ray into 3D space
	D3DXMATRIX m;
	D3DXMatrixInverse(&m, NULL, &view);
	
	D3DXVECTOR3 origin, direction;
	direction.x = v.x * m._11 + v.y * m._21 + v.z * m._31;
	direction.y = v.x * m._12 + v.y * m._22 + v.z * m._32;
	direction.z = v.x * m._13 + v.y * m._23 + v.z * m._33;
	origin.x = m._41;
	origin.y = m._42;
	origin.z = m._43;

	return ElRay(origin, direction);
}
コード例 #8
0
	void SimulatorViewport::draw(Application* application)
	{
		resetOpenGL();

		User* user = Kernel::getInstance()->users.front();
		glm::mat4 projectionMatrix = getProjectionMatrix();
		glEnable(GL_DEPTH_TEST);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glLoadMatrixf(glm::value_ptr(projectionMatrix));
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		application->draw(projectionMatrix, glm::mat4(), user->matrix);

		resetOpenGL();

		shader->use();
		shader->setUniform(Uniforms::projectionMatrix, projectionMatrix);
		shader->setUniform(Uniforms::viewMatrix, user->matrix);
		faceModel->draw([this](const glm::mat4& modelMatrix)
		{

		});

/*
		glDisable(GL_LIGHTING);
		glLoadIdentity();
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(1, 1, 1, 0.25f);
		glBegin(GL_QUADS);
		for (std::list<ViewPortCorners>::iterator it = viewports.begin(); it != viewports.end(); it++)
		{
			glVertex3fv(glm::value_ptr(it->tl));
			glVertex3fv(glm::value_ptr(it->tr));
			glVertex3fv(glm::value_ptr(it->br));
			glVertex3fv(glm::value_ptr(it->bl));
		}
		glEnd();

		glDisable(GL_DEPTH_TEST);
		glColor4f(1, 1, 1, 0.75f);
		for (std::list<ViewPortCorners>::iterator it = viewports.begin(); it != viewports.end(); it++)
		{
			glBegin(GL_LINE_LOOP);
			glVertex3fv(glm::value_ptr(it->tl));
			glVertex3fv(glm::value_ptr(it->tr));
			glVertex3fv(glm::value_ptr(it->br));
			glVertex3fv(glm::value_ptr(it->bl));
			glEnd();
		}


		glColor4f(1, 1, 1, 1);
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_DEPTH_TEST);
		*/

	}
コード例 #9
0
ファイル: camera.cpp プロジェクト: alvin-me/MIVT
  vec3 Camera::project(ivec2 vp, vec3 point) const {
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];

    mat4 projection_glm = getProjectionMatrix(vp);
    mat4 modelview_glm = getViewMatrix();
    for (int i = 0; i < 4; ++i) {
      modelview[i + 0] = modelview_glm[i].x;
      modelview[i + 4] = modelview_glm[i].y;
      modelview[i + 8] = modelview_glm[i].z;
      modelview[i + 12] = modelview_glm[i].w;
      projection[i + 0] = projection_glm[i].x;
      projection[i + 4] = projection_glm[i].y;
      projection[i + 8] = projection_glm[i].z;
      projection[i + 12] = projection_glm[i].w;
    }
    viewport[0] = 0;
    viewport[1] = 0;
    viewport[2] = vp.x;
    viewport[3] = vp.y;

    GLdouble pointProjectedGL[3];
    gluProject(point.x, point.y, point.z, modelview, projection, viewport,
      &pointProjectedGL[0], &pointProjectedGL[1], &pointProjectedGL[2]);

    return vec3(static_cast<float>(pointProjectedGL[0]),
      static_cast<float>(pointProjectedGL[1]),
      static_cast<float>(pointProjectedGL[2]));
  }
コード例 #10
0
ファイル: ofxCubeMap.cpp プロジェクト: Potzer/radome
//--------------------------------------------------------------
void ofxCubeMap::debugDrawCubemapCameras()
{
	for( int i = 0; i < 6; i++ )
	{
		GLuint face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
		ofMatrix4x4 modelViewProjectionMatrix = getLookAtMatrixForFace( face ) * getProjectionMatrix();

		ofMatrix4x4 inverseCameraMatrix;
		inverseCameraMatrix.makeInvertOf( modelViewProjectionMatrix );

		ofPushMatrix();

			glMultMatrixf( inverseCameraMatrix.getPtr() );

			ofNoFill();

				// Draw box in camera space, i.e. frustum in world space, box -1, -1, -1 to +1, +1, +1
				ofBox(0, 0, 0, 2.0f);

			ofFill();

		ofPopMatrix();

	}
}
コード例 #11
0
ファイル: OgreCamera.cpp プロジェクト: carriercomm/gamekit
	//---------------------------------------------------------------------
    void Camera::getCameraToViewportRay(Real screenX, Real screenY, Ray* outRay) const
    {
		Matrix4 inverseVP = (getProjectionMatrix() * getViewMatrix(true)).inverse();

#if OGRE_NO_VIEWPORT_ORIENTATIONMODE == 0
        // We need to convert screen point to our oriented viewport (temp solution)
        Real tX = screenX; Real a = getOrientationMode() * Math::HALF_PI;
        screenX = Math::Cos(a) * (tX-0.5f) + Math::Sin(a) * (screenY-0.5f) + 0.5f;
        screenY = Math::Sin(a) * (tX-0.5f) + Math::Cos(a) * (screenY-0.5f) + 0.5f;
        if ((int)getOrientationMode()&1) screenY = 1.f - screenY;
#endif

		Real nx = (2.0f * screenX) - 1.0f;
		Real ny = 1.0f - (2.0f * screenY);
		Vector3 nearPoint(nx, ny, -1.f);
		// Use midPoint rather than far point to avoid issues with infinite projection
		Vector3 midPoint (nx, ny,  0.0f);

		// Get ray origin and ray target on near plane in world space
		Vector3 rayOrigin, rayTarget;
		
		rayOrigin = inverseVP * nearPoint;
		rayTarget = inverseVP * midPoint;

		Vector3 rayDirection = rayTarget - rayOrigin;
		rayDirection.normalise();

		outRay->setOrigin(rayOrigin);
		outRay->setDirection(rayDirection);
    } 
コード例 #12
0
ファイル: Light.cpp プロジェクト: GuidoSchmidt/EZRWS1314
    void Light::generateShadowMap(std::vector<Geometry*>* renderQueue)
    {

        m_shaderProgram->use();
        m_fbo->use();

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//glEnable(GL_CULL_FACE);
        //glCullFace(GL_FRONT);

        glViewport(0, 0, m_shadowMap_size.x, m_shadowMap_size.y);

        m_shaderProgram->setUniform(m_uniform_loc_view, getViewMatrix());
        m_shaderProgram->setUniform(m_uniform_loc_projection, getProjectionMatrix());

        for(unsigned int i = 0; i < renderQueue->size(); i++)
        {
            m_shaderProgram->setUniform(m_uniform_loc_model, renderQueue->at(i)->getTransform()->getModelMatrix() );
			m_shaderProgram->setUniformSampler(m_uniform_loc_diffuse_tex, renderQueue->at(i)->getMaterial()->getDiffuseTexture(), 0);
            renderQueue->at(i)->drawTriangles();
        }

		//glDisable(GL_CULL_FACE);
        m_shaderProgram->unuse();
        m_fbo->unuse();

    }
コード例 #13
0
ファイル: Camera.hpp プロジェクト: AeroGlass/g3m
 // multiplication of model * projection
 MutableMatrix44D getModelViewMatrix() const {
   if (_dirtyFlags._modelViewMatrixDirty) {
     _dirtyFlags._modelViewMatrixDirty = false;
     _modelViewMatrix = getProjectionMatrix().multiply(getModelMatrix());
   }
   return _modelViewMatrix;
 }
コード例 #14
0
ファイル: MainComponent.cpp プロジェクト: 410pfeliciano/JUCE
    void render() override
    {

        jassert (OpenGLHelpers::isContextActive());

        const float desktopScale = (float) openGLContext.getRenderingScale();
        OpenGLHelpers::clear (Colour::greyLevel (0.1f));

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

        glViewport (0, 0, roundToInt (desktopScale * getWidth()), roundToInt (desktopScale * getHeight()));

        shader->use();

        if (uniforms->projectionMatrix != nullptr)
            uniforms->projectionMatrix->setMatrix4 (getProjectionMatrix().mat, 1, false);

        if (uniforms->viewMatrix != nullptr)
            uniforms->viewMatrix->setMatrix4 (getViewMatrix().mat, 1, false);

        shape->draw (openGLContext, *attributes);

        // Reset the element buffers so child Components draw correctly
        openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, 0);
        openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);

    }
コード例 #15
0
ファイル: Light.hpp プロジェクト: MarkRunWu/DynamO
    /*! \brief Load the specified OpenGL texture matrix with the
      projection required for shadow mapping.
      
      \note The current OpenGL model view matrix must be the matrix
      used for rendering.
      
      \param textureUnit The texture unit whose matrix is to be
      setup for shadowmapping.
    */
    inline magnet::GL::GLMatrix getShadowTextureMatrix()
    {
      return magnet::GL::GLMatrix::translate(magnet::math::Vector(0.5, 0.5, 0.5))
	* magnet::GL::GLMatrix::scale(magnet::math::Vector(0.5, 0.5, 0.5))
	* getProjectionMatrix()
	* getViewMatrix();
    }
コード例 #16
0
ファイル: renderer.cpp プロジェクト: Jaween/ar-trophy
void Renderer::draw(GLFWwindow* window, unsigned char* frame_data, int width, int height)
{	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	// Simple shader
	shader_program->useProgram();
	
	// Background
	updateTexture(environment->getTextureID(), width, height, frame_data);
	glm::mat4 ortho_projection_matrix = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f);
	glm::mat4 env_model_matrix = position_object_in_scene(environment->getPosition());
	glm::mat4 model_projection_matrix = ortho_projection_matrix * env_model_matrix;
	shader_program->setUniforms(model_projection_matrix, environment->getTextureID());
	environment->draw();
	
	// Camera 
	computeMatricesFromInputs(window);
	glm::mat4 projection_matrix = getProjectionMatrix();
	glm::mat4 view_matrix = getViewMatrix();
	
	// Updates data and draws
	glm::mat4 model_matrix = position_object_in_scene(trophy->getPosition());
	glm::mat4 model_view_projection_matrix = projection_matrix * view_matrix * model_matrix; 
	shader_program->setUniforms(model_view_projection_matrix, trophy->getTextureID());
	trophy->draw();
	
	// Swaps drawing canvas
	glfwSwapBuffers(window);
	glfwPollEvents();
}
コード例 #17
0
	void graphics::ortho(float near, float far)
	{
		float left = (float)resW * 0.5f;
		float right = -(float)resW * 0.5f;
		float up = (float)resH * 0.5f;
		float down = -(float)resH * 0.5f;
		
		switch (matrixMode)
		{
			case SINNCA_MODELVIEW_MATRIX:
			{
				snOrthoMatrix(getModelMatrix(), left, right, up, down, near, far);
				break;
				
			}
			case SINNCA_PROJECTION_MATRIX:
			{
				snOrthoMatrix(getProjectionMatrix(), left, right, up, down, near, far);
				break;
			}
			case SINNCA_TEXTURE_MATRIX:
			{
				snOrthoMatrix(getTextureMatrix(), left, right, up, down, near, far);
				break;
			}
		}
	}
コード例 #18
0
ファイル: GLTFNode.cpp プロジェクト: u-engine/Cinder-glTF
		void Node::draw(bool child, int numInstances, std::vector<mat4> rotMats, std::vector<ci::mat4> positions, std::vector<ci::mat4> scales){

				{
					
					if (numInstances == 0){
						gl::pushModelView();
						matrix = rotmat * glm::scale(scale);
						matrix[3] = vec4(trans,1);
						gl::multModelMatrix(matrix);

					}
					else {
						matrix = rotmat;
						rotMats.push_back(matrix);
						positions.push_back(glm::translate(trans));
						scales.push_back(glm::scale(scale));
					}
					
					//matrix[3] = vec4(trans,1);
					//gl::multModelMatrix(matrix);
					//double t1 = ci::app::getElapsedSeconds();
					//ci::app::console() << (t1 - t0) * 1000 << " : " << name << " : matrix node time " << std::endl;
					
					for (MeshRef pMesh : pMeshes)
					{
						//double t0 = ci::app::getElapsedSeconds();
						if (visible)
							pMesh->draw(numInstances, rotMats, positions, scales);
						//double t1 = ci::app::getElapsedSeconds();
						//ci::app::console() << (t1 - t0) * 1000 << " : "<< name << " : node draw time " << std::endl;

					}
					vec4 xform = getModelMatrix() * vec4(0, 0, 0, 1);
					worldPos = xform;
					std::vector<float> distances;
					for (NodeRef pChild : pChildren)
					{
						vec4 start = vec4(1);
						vec4 xform = getProjectionMatrix() * getViewMatrix() * getModelMatrix() * pChild->matrix * vec4(pChild->bounds.getCenter(), 1);
						distances.push_back(xform.z);
					}
					vector<pair<size_t, myiter> > order(distances.size());
					size_t n = 0;
					for (myiter it = distances.begin(); it != distances.end(); ++it, ++n)
						order[n] = make_pair(n, it);

					sort(order.begin(), order.end(), ordering());

					//ci::app::console() << ":::::::::::" << endl;
					for (auto pDrawOrder : order)
					{
						pChildren[pDrawOrder.first]->draw(true, numInstances, rotMats, positions, scales);
					}
					
					if (numInstances == 0){
						gl::popModelView();
					}
				}
		};
コード例 #19
0
ファイル: sceneView.cpp プロジェクト: MichaelVlad/Equalizer
bool SceneView::getProjectionMatrixAsFrustum(double& left, double& right,
                                             double& bottom, double& top,
                                             double& zNear, double& zFar) const
{
    return getProjectionMatrix().getFrustum(left, right,
                                         bottom, top,
                                         zNear, zFar);
}                                  
コード例 #20
0
ファイル: RenderTargetD3D9.cpp プロジェクト: weimingtom/xgame
void RenderTargetD3D9::setProjectionMatrix(const Matrix4& mtx)
{
    //if( m_RenderState.m_mtxProjection == mtx) return;//不会经常出现这种情况
    m_RenderState.m_mtxProjection = mtx;
    D3DXMATRIX mtxD3D;
    getProjectionMatrix(mtxD3D);
    m_pRenderSystem->getD3D9Device()->getDevice()->SetTransform(D3DTS_PROJECTION, &mtxD3D );
}
コード例 #21
0
glm::vec3 Z3DCamera::project(glm::vec3 wpt, glm::ivec4 viewport)
{
  glm::mat4 projection = getProjectionMatrix(CenterEye);
  glm::mat4 modelview = getViewMatrix(CenterEye);


  return glm::project(wpt, modelview, projection, viewport);
}
コード例 #22
0
ファイル: Camera.cpp プロジェクト: MeridianPoint/OpenGlEngine
inline void Camera::BindMatrix(){
	//glB
	//apply id 
	GLint ProgramID;

	GLuint MatrixID = glGetUniformLocation(ProgramID, "ProjectionView");
	glUniformMatrix4fv(MatrixID, 1, GL_FALSE, getProjectionMatrix().ToArray());
}
コード例 #23
0
ファイル: MainComponent.cpp プロジェクト: drmadder/JUCE
    void render() override
    {
        // Make sure an OpenGL graphics context has been defined
        jassert (OpenGLHelpers::isContextActive());

        // This allows to calculate correct pixel number by using
        // physical vs logical pixel number
        const float desktopScale = (float) openGLContext.getRenderingScale();
        
        // You need to clear the display upon every new frame unless you're dead sure
        // that nothing has changed, which you are not...
        OpenGLHelpers::clear (Colour::greyLevel (0.1f));

#if DEFAULT_TEXTURE == 2
        // Having used the juce 2D renderer, it will have messed-up a whole load of GL state, so
        // we need to initialise some important settings before doing our normal GL 3D drawing..
        glEnable (GL_DEPTH_TEST);
        glDepthFunc (GL_LESS);
        // Using a texture to paint main OpenGL object (teapot)
        openGLContext.extensions.glActiveTexture (GL_TEXTURE0); // Using texture #0
        glEnable (GL_TEXTURE_2D);
        // Tell the GPU to use that texture
        texture.bind();
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#endif
        // OpenGL method to blend the computed fragment color values with the values in the color buffers
        glEnable (GL_BLEND);
        // OpenGL method to specify how the red, green, blue, and alpha blending factors are computed.
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        // OpenGL method to specify viewport's x, y, width and height
        glViewport (0, 0, roundToInt (desktopScale * getWidth()), roundToInt (desktopScale * getHeight()));
        // This will call an OpenGL method to tell the GPU to use this program
        usedShaderProgram->use();
        
        if (uniforms->demoTexture != nullptr)
            uniforms->demoTexture->set ((GLint) 0);
            
        // Modify the uniform (global) variable projectionMatrix that will be used by the GPU when executing the shaders
        if (uniforms->projectionMatrix != nullptr)
            // Update the projection matrix with the values given, 1 matrix, do not transpose
            uniforms->projectionMatrix->setMatrix4 (getProjectionMatrix().mat, 1, false);

        // Modify the uniform (global) variable viewMatrix that will be used by the GPU when executing the shaders
        if (uniforms->viewMatrix != nullptr)
            // Update the view matrix with the values given, 1 matrix, do not transpose
            uniforms->viewMatrix->setMatrix4 (getViewMatrix().mat, 1, false);

        // This will fill a vertex buffer that is sent to the GPU to be used along with the attributes
        // by the GPU in the shaders. See Shape struct below. This buffer is called a Vertex Buffer Object
        // (VBO) and allows to send a bunch of variables at once to the GPU for better efficiency
        shape->draw (openGLContext, *attributes);

        // Reset the element buffers so child Components draw correctly
        openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, 0);
        openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
    }
コード例 #24
0
 //-----------------------------------------------------------------------------
 const Matrix4& AutoParamDataSource::getWorldViewProjMatrix(void) const
 {
     if (mWorldViewProjMatrixDirty)
     {
         mWorldViewProjMatrix = getProjectionMatrix() * getWorldViewMatrix();
         mWorldViewProjMatrixDirty = false;
     }
     return mWorldViewProjMatrix;
 }
コード例 #25
0
ファイル: CTransformer.cpp プロジェクト: redagito/RTR2014
const glm::mat4& CTransformer::getViewProjectionMatrix() const
{
	if (m_viewProjection.m_matrixDirty)
	{
		m_viewProjection.m_matrix = getProjectionMatrix() * getViewMatrix();
		m_viewProjection.m_matrixDirty = false;
	}
	return m_viewProjection.m_matrix;
}
コード例 #26
0
ファイル: main_backup.cpp プロジェクト: JNeiger/3D_Scanner
void modelMatrix(GLuint MatrixID)
{
	// Model matrix : an identity matrix (model will be at the origin)
	computeMatricesFromInputs();
	glm::mat4 ProjectionMatrix = getProjectionMatrix();
	glm::mat4 ViewMatrix = getViewMatrix();
	glm::mat4 ModelMatrix = glm::mat4(1.0);
	glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
	glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
}
コード例 #27
0
glm::vec3 Z3DCamera::worldToScreen(glm::vec3 wpt, glm::ivec4 viewport, Z3DEye eye)
{
  glm::vec4 clipSpacePos =
      getProjectionMatrix(eye) * getViewMatrix(eye) * glm::vec4(wpt, 1.f);
  if (clipSpacePos.w == 0.f)
    return glm::vec3(-1.f, -1.f, -1.f);
  glm::vec3 ndcSpacePos = glm::vec3(clipSpacePos.xyz()) / clipSpacePos.w;
  return ((ndcSpacePos + 1.f) / 2.f) * glm::vec3((float)viewport.z, (float)viewport.w, 1.f)
      + glm::vec3((float)viewport.x, (float)viewport.y, 0.f);
}
コード例 #28
0
ファイル: GLMatrices.cpp プロジェクト: chasem74/Engine
	void GLMatrices::scale(float sx, float sy, float sz)
	{
		Core::Mat44 scaleMatrix = Core::Mat44::makeScaleMatrix(sx, sy, sz);

		if(currentMatrixMode == MatrixMode::ModelMatrix) modelMatrices[modelMatrices.size() - 1] = getModelMatrix() * scaleMatrix;
		else if(currentMatrixMode == MatrixMode::ViewMatrix) viewMatrices[viewMatrices.size() - 1] = getViewMatrix() * scaleMatrix;
		else projectionMatrices[projectionMatrices.size() - 1] = getProjectionMatrix() * scaleMatrix;

		matricesReady = false;
	}
コード例 #29
0
ファイル: RenderSystem.cpp プロジェクト: Pinkof/rpgskyengine
void CRenderSystem::GetPickRay(Vec3D& vRayPos, Vec3D& vRayDir,int x, int y)
{
	Matrix mProj;
	getProjectionMatrix(mProj);
	CRect<int> rc;
	getViewport(rc);
	Matrix mView;
	getViewMatrix(mView);
	::GetPickRay(vRayPos,vRayDir,x,y,mView,mProj,rc.getRECT());
}
コード例 #30
0
ファイル: Camera.cpp プロジェクト: ChristophPacher/Cinder
vec2 Camera::worldToScreen( const vec3 &worldCoord, float screenWidth, float screenHeight ) const
{
	vec3 eyeCoord = vec3( getViewMatrix() * vec4( worldCoord, 1 ) );
	vec4 ndc = getProjectionMatrix() * vec4( eyeCoord, 1 );
	ndc.x /= ndc.w;
	ndc.y /= ndc.w;
	ndc.z /= ndc.w;

	return vec2( ( ndc.x + 1.0f ) / 2.0f * screenWidth, ( 1.0f - ( ndc.y + 1.0f ) / 2.0f ) * screenHeight );
}