示例#1
0
void CamerasExporter::operator()(Object *ob, Scene *sce)
{
    // TODO: shiftx, shifty, YF_dofdist
    Camera *cam = (Camera*)ob->data;
    std::string cam_id(get_camera_id(ob));
    std::string cam_name(id_name(cam));

    switch (cam->type) {
    case CAM_PANO:
    case CAM_PERSP: {
        COLLADASW::PerspectiveOptic persp(mSW);
        persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
        persp.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch), false, "aspect_ratio");
        persp.setZFar(cam->clipend, false, "zfar");
        persp.setZNear(cam->clipsta, false, "znear");
        COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
        addCamera(ccam);
        break;
    }
    case CAM_ORTHO:
    default:
    {
        COLLADASW::OrthographicOptic ortho(mSW);
        ortho.setXMag(cam->ortho_scale, "xmag");
        ortho.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch), false, "aspect_ratio");
        ortho.setZFar(cam->clipend, false, "zfar");
        ortho.setZNear(cam->clipsta, false, "znear");
        COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
        addCamera(ccam);
        break;
    }
    }
}
示例#2
0
void TraceGLWindow::draw()
{
	if(!valid())
	{
		glClearColor(0.7f, 0.7f, 0.7f, 1.0);

		// We're only using 2-D, so turn off depth 
		glDisable( GL_DEPTH_TEST );

		ortho();

		m_nWindowWidth=w();
		m_nWindowHeight=h();
	}

	glClear( GL_COLOR_BUFFER_BIT );

	unsigned char* buf;
	raytracer->getBuffer(buf, m_nDrawWidth, m_nDrawHeight);

	if ( buf ) {
		// just copy image to GLwindow conceptually
		glRasterPos2i( 0, 0 );
		glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
		glPixelStorei( GL_UNPACK_ROW_LENGTH, m_nDrawWidth );
		glDrawBuffer( GL_BACK );
		glDrawPixels( m_nDrawWidth, m_nDrawHeight, GL_RGB, GL_UNSIGNED_BYTE, buf );
	}
		
	glFlush();
}
示例#3
0
    void Camera::ortho2D (Real left, Real right, Real bottom, Real top, Real n, Real f)
    {

        MvGl2DemoMatrixIdentity(mProjectionMatrix);
        ortho (mProjectionMatrix, left, right, bottom, top, n, f);
        return;
    }
示例#4
0
void SharedProgramState::setOrthoProjectionMatrix(const AABB& volume)
{
  float minX, minY, minZ, maxX, maxY, maxZ;
  volume.bounds(minX, minY, minZ, maxX, maxY, maxZ);

  setProjectionMatrix(ortho(minX, maxX, minY, maxY, minZ, maxZ));
}
void OriginalView::draw()
{
	if(!valid())
	{
		glClearColor(0.7f, 0.7f, 0.7f, 1.0);

		// We're only using 2-D, so turn off depth 
		glDisable( GL_DEPTH_TEST );

		// Tell openGL to read from the front buffer when capturing
		// out paint strokes 
		glReadBuffer( GL_FRONT );
		ortho();

	}

	glClear( GL_COLOR_BUFFER_BIT );

	if ( m_pDoc->m_ucBitmap ) 
	{
		// note that both OpenGL pixel storage and the Windows BMP format
		// store pixels left-to-right, BOTTOM-to-TOP!!  thus all the fiddling
		// around with startrow.

		m_nWindowWidth=w();
		m_nWindowHeight=h();

		int drawWidth, drawHeight;
		GLvoid* bitstart;

		// we are not using a scrollable window, so ignore it
		Point scrollpos;	// = GetScrollPosition();
		scrollpos.x=scrollpos.y=0;

		drawWidth	= min( m_nWindowWidth, m_pDoc->m_nWidth );
		drawHeight	= min( m_nWindowHeight, m_pDoc->m_nHeight );

		int	startrow	= m_pDoc->m_nHeight - (scrollpos.y + drawHeight);
		if ( startrow < 0 ) 
			startrow = 0;


		if(this->bToggleEdge){
			bitstart = m_pDoc->m_ucEdgeImage + 3 * ((m_pDoc->m_nWidth * startrow) + scrollpos.x);
		} else {
			bitstart = m_pDoc->m_ucBitmap + 3 * ((m_pDoc->m_nWidth * startrow) + scrollpos.x);}

		// just copy image to GLwindow conceptually
		glRasterPos2i( 0, m_nWindowHeight - drawHeight );
		glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
		glPixelStorei( GL_UNPACK_ROW_LENGTH, m_pDoc->m_nWidth );
		glDrawBuffer( GL_BACK );
		glDrawPixels( drawWidth, drawHeight, GL_RGB, GL_UNSIGNED_BYTE, bitstart );}

		if(bMarker)
			drawMarker();
			
	glFlush();
}
示例#6
0
/**
 * P(r) calculated from the expansion.
 */
double pr(double *pars, double d_max, int n_c, double r) {
    double sum = 0.0;
	int i;
    for (i=0; i<n_c; i++) {
        sum += pars[i] * ortho(d_max, i+1, r);
    }
    return sum;
}
示例#7
0
PGL_USING_NAMESPACE
TOOLS_USING_NAMESPACE

/* ----------------------------------------------------------------------- */
ViewCameraMenu::ViewCameraMenu(ViewCameraGL * camera,QWidget * parent, const char * name):
  QMenu(parent)
{
  if(name)setObjectName(name);

  QPixmap home(ViewerIcon::getPixmap(ViewerIcon::home));
  QPixmap read(ViewerIcon::getPixmap(ViewerIcon::fileopen));
  QPixmap save(ViewerIcon::getPixmap(ViewerIcon::filefloppy));
  QPixmap persp(ViewerIcon::getPixmap(ViewerIcon::perspective));
  QPixmap ortho(ViewerIcon::getPixmap(ViewerIcon::orthographic));
  QPixmap linked(ViewerIcon::getPixmap(ViewerIcon::linked));
  QPixmap eyef(ViewerIcon::getPixmap(ViewerIcon::eyef));

  QAction * action = addAction(home,tr("Home"),      camera,SLOT(home()), Qt::CTRL+Qt::Key_I);

  addAction(tr("&Front View (YZ)"),camera,SLOT(YZView()));
  addAction(tr("&Right View (XZ)"),camera,SLOT(XZView()));
  addAction(tr("&Top View (XY)"),  camera,SLOT(XYView()));
  addSeparator();
  QMenu * __coordMenu = new QMenu(this);
  idGEOMcoord = __coordMenu->addAction(tr("GEOM System"),   camera,SLOT(setGEOMCoordSys()));
  idGLcoord   = __coordMenu->addAction(tr("GL System"),     camera,SLOT(setGLCoordSys()));
  __coordMenu->addSeparator();
  __coordMenu->addAction(tr("&Change"),       camera,SLOT(changeCoordSys()));
  idGEOMcoord->setCheckable(true);
  idGLcoord->setCheckable(true);
  setCoordSys(camera->getCoordSys());
  __coordMenu->setTitle(tr("Coordinates System"));
  addMenu(__coordMenu);
  addSeparator();
  QMenu * __projectionMenu = new QMenu(this);
  idPerspective = __projectionMenu->addAction(persp,tr("&Perspective"),  camera,SLOT(setPerspectiveMode()));
  idOrtho       = __projectionMenu->addAction(ortho,tr("Ort&hographic"), camera,SLOT(setOrthographicMode()));
  __projectionMenu->addSeparator();
  __projectionMenu->addAction(tr("&Change"),       camera,SLOT(changeCameraMode()),Qt::CTRL+Qt::Key_D);
  idPerspective->setCheckable(true);
  idOrtho->setCheckable(true);
  __projectionMenu->setTitle(tr("Projection"));
  addMenu(__projectionMenu);

  setProjectionMode(camera->getProjectionMode());
  QObject::connect(camera,SIGNAL(projectionChanged(bool)),this,SLOT(setProjectionMode(bool)));
  QObject::connect(camera,SIGNAL(coordSysChanged(int)),this,SLOT(setCoordSys(int)));
  addSeparator();
  addAction(save,tr("&Save"),       camera,SLOT(save()));
  addAction(read,tr("&Read"),       camera,SLOT(read()));
  addSeparator();
  QAction * idLock = addAction(linked,tr("&Auto Fit to Window"),       camera,SLOT(lockDim()));
  if(camera)idLock->setChecked(camera->isDimLock());
  QObject::connect(camera,SIGNAL(lockDimChanged(bool)),idLock,SLOT(setChecked(bool)));
  addAction(eyef,tr("&Fit to Window"),       camera,SLOT(reDim()));

}
示例#8
0
 inline Matrix4f getProjection() const {
   if (isPerspective) {
     return perspective(FOV, true, aspect, zNear, zFar);
   } else {
     float distance = (zFar - zNear) / 2.0f;
     return ortho(-orthoScale * aspect, orthoScale * aspect, -orthoScale,
                  orthoScale, -distance, distance);
   }
 }
示例#9
0
	/**
	 * Method used to define a orthogonal projetction as the camera projection
	 * matrix
	 * @param _left  Left screen side coordinate
	 * @param _right Right screen side coordinate
	 * @param _up    Up screen side coordinate
	 * @param _down  Down screen side coordinate
	 * @param _zNear Near plane distance
	 * @param _zFar  Far plane distance
	 */
	void BaseCamera::setOrthogonalProjection(
		float _left,
		float _right,
		float _up,
		float _down,
		float _zNear,
		float _zFar
	)
	{
		this->projectionMatrix = ortho( _left, _right, _up, _down, _zNear, _zFar );
	}
示例#10
0
void LifeCounter::Draw(mat4 view, mat4 projection) {
	projection = ortho(0.0f, 20.0f * (scene->width / (float)scene->height), 0.0f, 20.0f, -20.0f, 20.0f);
	for(int i=0; i<lives; i++) {
		Content::shader(basic).Begin();
			mat4 model = translation(position + vec3(i * icon.size.x, 0, 0))  * mat4_cast(orientation) * scale(size);
			model = model;
			glUniformMatrix4fv(Content::shader(basic)("inv_view"), 1, GL_FALSE, &(model[0][0]));
			icon.Draw(model, projection);
		Content::shader(basic).End();
	}
}
        bool FloatRect::intersects(const Line &line){
            float scalar;

            glm::vec2 ray(line.x2 - line.x1, line.y2 - line.y1);
            float rayLength = length(ray.x, ray.y);
            scalar = skalar(this->x - line.x1, this->y - line.y1, ray.x, ray.y);
            float rayPoint1 = scalar /rayLength;
            scalar = skalar((this->x + this->w) - line.x1, this->y - line.y1, ray.x, ray.y);
            float rayPoint2 = scalar /rayLength;
            scalar = skalar(this->x - line.x1, (this->y + this->h) - line.y1, ray.x, ray.y);
            float rayPoint3 = scalar /rayLength;
            scalar = skalar((this->x + this->w) - line.x1, (this->y + this->h) - line.y1, ray.x, ray.y);
            float rayPoint4 = scalar /rayLength;

            float maxRay = std::fmax(std::fmax(rayPoint1, rayPoint2), std::fmax(rayPoint3, rayPoint4));
            float minRay = std::fmin(std::fmin(rayPoint1, rayPoint2), std::fmin(rayPoint3, rayPoint4));
            if(maxRay < 0.f || minRay > rayLength) return false;

            glm::vec2 ortho(ray.y, -ray.x);
            float orthoLength = length(ortho.x, ortho.y);
            scalar = skalar(this->x - line.x1, this->y - line.y1, ortho.x, ortho.y);
            float orthoPoint1 = scalar / orthoLength;
            scalar = skalar((this->x + this->w) - line.x1, this->y - line.y1, ortho.x, ortho.y);
            float orthoPoint2 = scalar / orthoLength;
            scalar = skalar(this->x - line.x1, (this->y + this->h) - line.y1, ortho.x, ortho.y);
            float orthoPoint3 = scalar / orthoLength;
            scalar = skalar((this->x + this->w) - line.x1, (this->y + this->h) - line.y1, ortho.x, ortho.y);
            float orthoPoint4 = scalar / orthoLength;

            float maxOrtho = std::fmax(std::fmax(orthoPoint1, orthoPoint2), std::fmax(orthoPoint3, orthoPoint4));
            float minOrtho = std::fmin(std::fmin(orthoPoint1, orthoPoint2), std::fmin(orthoPoint3, orthoPoint4));
            if(maxOrtho < 0.f || minOrtho > 0.f) return false;

            glm::vec2 rectX(this->w, 0);
            float rectXLength = rectX.x;
            scalar = skalar(line.x1 - this->x, line.y1 - this->y, rectX.x, rectX.y);
            float rectXPoint1 = scalar / rectXLength;
            scalar = skalar(line.x2 - this->x, line.y2 - this->y, rectX.x, rectX.y);
            float rectXPoint2 = scalar / rectXLength;
            float maxRectX = std::fmax(rectXPoint1, rectXPoint2);
            float minRectX = std::fmin(rectXPoint1, rectXPoint2);
            if(maxRectX < 0.f || minRectX > rectXLength) return false;

            glm::vec2 rectY(0, this->h);
            float rectYLength = rectY.y;
            scalar = skalar(line.x1 - this->x, line.y1 - this->y, rectY.x, rectY.y);
            float rectYPoint1 = scalar / rectYLength;
            scalar = skalar(line.x2 - this->x, line.y2 - this->y, rectY.x, rectY.y);
            float rectYPoint2 = scalar / rectYLength;
            float maxRectY = std::fmax(rectYPoint1, rectYPoint2);
            float minRectY = std::fmin(rectYPoint1, rectYPoint2);
            if(maxRectY < 0.f || minRectY > rectYLength) return false;
            return true;
        }
示例#12
0
GLuint
pick(int x, int y)
{
  int hits;

  (void) glRenderMode(GL_SELECT);
  glInitNames();
  glPushName(~0);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  gluPickMatrix(x, winHeight - y, 8.0, 8.0, viewport);
  ortho();
  glMatrixMode(GL_MODELVIEW);
  selectControlPoints();
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  hits = glRenderMode(GL_RENDER);
  if (hits) {
#ifdef DEBUG
    {
      unsigned int i;
      GLint names;
      GLuint *ptr;

      printf("hits = %d\n", hits);
      ptr = (GLuint *) selectBuffer;
      for (i = 0; i < hits; i++) {  /* for each hit  */
        int j;

        names = *ptr;
        printf("number of names for hit = %d\n", *ptr);
        ptr++;
        printf("  z1 is %g;", (float) *ptr / 0xffffffff);
        ptr++;
        printf("  z2 is %g\n", (float) *ptr / 0xffffffff);
        ptr++;
        printf(" the name is ");
        for (j = 0; j < names; j++) {  /* For each name. */
          printf("%d ", *ptr);
          ptr++;
        }
        printf("\n");
      }
    }
#endif
    return selectBuffer[3];
  } else {
    return ~0;
  }
}
示例#13
0
GameView::GameView(RenderTarget &target)
: ground(ResourceManager::Instance().getResource<ShaderProgram>("renderground"), Model::TesselatedSquare(128), target)
, water(ResourceManager::Instance().getResource<ShaderProgram>("renderwater"), Model::TesselatedSquare(128), target)
, gameObjects(ResourceManager::Instance().getResource<ShaderProgram>("renderGameObjs"), Model::Square(), target)
, hud(ResourceManager::Instance().getResource<ShaderProgram>("renderHud"), hudscene, target)
, loading(ResourceManager::Instance().getResource<ShaderProgram>("renderLoading"), loadingscene, target)
, state(0)
, target(target)
{
	loadingscene.add(new MenuObject(ResourceManager::Instance().getResource<Model>("loadingbar")));
	loading.Register("model_mvp", ortho( -500.0f, 500.0f, 500.0f * target.height / target.width, -500.0f * target.height / target.width, -5.0f, 5.0f));
	loading.AddTexture("tex", ResourceManager::Instance().getResource<Texture>("progressbar"));
}
示例#14
0
void Renderer::guiBegin() {
	glViewport(0,0,contextW,contextH);
	//glBindVertexArray(guiVao);
	glBindBuffer(GL_ARRAY_BUFFER,guiVerticesId);
	//FIXME vao
	const size_t textotal{sizeof(GLfloat)*4};
	guiprogram->use();
	setAttribute(glGetAttribLocation(guiprogram->getId(),"vertex"),2,GL_FLOAT,textotal,0);
	setAttribute(glGetAttribLocation(guiprogram->getId(),"texcoord"),2,GL_FLOAT,textotal,textotal/2);
	mat4 projection=mat4{ortho(0.0f,1.0f,1.0f,0.0f,0.0f,1.0f)};

	guiprogram->projectionMatrix(projection);
}
示例#15
0
bool CanvasWidget::updateCanvasSize()
{
	if (m_frameBuffer == nullptr || m_frameBuffer->getSize() != m_computedSize)
	{
		m_frameBuffer.reset(new video::FrameBuffer());
		m_frameBuffer->setSize(m_computedSize);
		m_backgroundTexture = m_frameBuffer->addTexture("Background");
		setBackground(m_backgroundTexture);
		m_viewMatrix = ortho(0.f, m_computedSize.x, m_computedSize.y, 0.f);
		return true;
	}
	return false;
}
示例#16
0
/**
 * @brief OrthographicProjection: Calculate orthographic projection matrix
 * @param left: left boundary
 * @param right: right boundary
 * @param bottom: bottom boundary
 * @param top: top boundary
 * @param n: n boundary
 * @param f: f boundary
 * @return 4X4 orthographic projection matrix
 */
mat4 OrthographicProjection(float l, float r, float b, float t, float n, float f)
{
    mat4 ortho = mat4::Zero();
    ortho(0, 0) =  2.0f / (r - l);
    ortho(1, 1) =  2.0f / (t - b);
    ortho(2, 2) = -2.0f / (f - n);
    ortho(3, 3) =  1.0f;
    ortho(1, 3) = -(r + l) / (r - l);
    ortho(2, 3) = -(t + b) / (t - b);
    ortho(2, 3) = -(f + n) / (f - n);
    return ortho;
}
示例#17
0
//! renvoie la transformation associee a une camera orthographique (Projection)
Transform Orthographic( const float left, const float right, 
    const float bottom, const float top, 
    const float znear, const float zfar )
{
    // opengl version
    Matrix4x4 ortho(
        2.f / (right - left)     , 0.f                 , 0.f                  , -(right + left) / (right - left),
        0.f                      , 2.f / (top - bottom), 0.f                  , -(top + bottom) / (top - bottom),
        0.f                      , 0.f                 , -2.f / (zfar - znear), -(zfar + znear) / (zfar - znear),
        0.f, 0.f, 0.f, 1.f
    );
    
    return Transform(ortho);
}
示例#18
0
void GraphicsManager::setOrthogonal(float clipNear, float clipFar) {
	// Force calling it from the main thread
	if (!Common::isMainThread()) {
		Events::MainThreadFunctor<void> functor(boost::bind(&GraphicsManager::setOrthogonal, this, clipNear, clipFar));

		return RequestMan.callInMainThread(functor);
	}

	ortho(0.0f, _width, 0.0f, _height, clipNear, clipFar);

	_projectType = kProjectTypeOrthogonal;

	_clipNear  = clipNear;
	_clipFar   = clipFar;
}
示例#19
0
void TileRender::setMatrices( const cinder::Camera &camera )
{
	float left, top, right, bottom, nearPlane, farPlane;
	camera.getFrustum( &left, &top, &right, &bottom, &nearPlane, &farPlane );

	if( camera.isPersp() ) {
		frustum( left, right, bottom, top, nearPlane, farPlane );
	}
	else {
		ortho( left, right, bottom, top, nearPlane, farPlane );
	}

	glMatrixMode( GL_MODELVIEW );
	glLoadMatrixf( camera.getModelViewMatrix().m );
}
示例#20
0
void GFX::set_orthographic(const float screen_ratio, float s, const float aspect_ratio, const float clip_start, const float clip_end, const float screen_orientation)
{
    s = ( s * 0.5f ) * aspect_ratio;

    ortho(-1.0f,
           1.0f,
          -screen_ratio,
           screen_ratio,
          clip_start,
          clip_end );

    scale( 1.0f / s, 1.0f / s, 1.0f );

    if (screen_orientation ) rotate( screen_orientation, 0.0f, 0.0f, 1.0f );
}
示例#21
0
//use CropMatrix to adjust the projection matrix which Cascaded Shadow Maps need;
QMatrix4x4 Scene::getCropMatrix(AABB frustumAABB)
{
    float scaleX = 2.0f/(frustumAABB.max ().x() - frustumAABB.min ().x());
    float scaleY = 2.0f/(frustumAABB.max ().y() - frustumAABB.min ().y());
    float offsetX = -0.5f*(frustumAABB.max ().x() + frustumAABB.min ().x()) * scaleX;
    float offsetY = -0.5f*(frustumAABB.max ().y() + frustumAABB.min ().y()) * scaleY;

    auto CropMatrix = QMatrix4x4(scaleX,0.0f,  0.0f, offsetX,
                                 0.0f,  scaleY,  0.0f, offsetY,
                                 0.0f,    0.0f,  1.0f,  0.0f,
                                 0.0f, 0.0f,  0.0f,  1.0f );
    auto orthoMatrix = QMatrix4x4();

    orthoMatrix.ortho(-1.0, 1.0, -1.0, 1.0, -frustumAABB.max ().z(), -frustumAABB.min ().z() );
    orthoMatrix = CropMatrix * orthoMatrix;
    return orthoMatrix;
}
void OverlayRenderer::render(RenderContext& context, const float viewWidth, const float viewHeight) {
    if (m_vbo == NULL)
        m_vbo = new Vbo(GL_ARRAY_BUFFER, 0xFFFF);
    if (m_compass == NULL)
        m_compass = new CompassRenderer();

    glClear(GL_DEPTH_BUFFER_BIT);

    const Mat4f projection = orthoMatrix(0.0f, 1000.0f, -viewWidth / 2.0f, viewHeight / 2.0f, viewWidth / 2.0f, -viewHeight / 2.0f);
    const Mat4f view = viewMatrix(Vec3f::PosY, Vec3f::PosZ) * translationMatrix(500.0f * Vec3f::PosY);
    Renderer::ApplyTransformation ortho(context.transformation(), projection, view);

    const Mat4f compassTransformation = translationMatrix(Vec3f(-viewWidth / 2.0f + 50.0f, 0.0f, -viewHeight / 2.0f + 50.0f)) * scalingMatrix(2.0f);
    Renderer::ApplyModelMatrix applyCompassTranslate(context.transformation(), compassTransformation);

    m_compass->render(*m_vbo, context);
}
示例#23
0
文件: maths.cpp 项目: MrGurken/Boblin
int Mat4::lua_Orthographic( lua_State* lua )
{
    int result = 0;
    
    int nargs = lua_gettop( lua );
    if( nargs >= 6 )
    {
        float left = static_cast<float>( lua_tonumber( lua, 1 ) );
        float right = static_cast<float>( lua_tonumber( lua, 2 ));
        float top = static_cast<float>( lua_tonumber( lua, 3 ));
        float bottom = static_cast<float>( lua_tonumber( lua, 4 ) );
        float nearplane = static_cast<float>( lua_tonumber( lua, 5 ));
        float farplane = static_cast<float>( lua_tonumber( lua, 6 ) );
        result = lua_Write( lua, ortho( left, right, bottom, top, nearplane, farplane ) );
    }
    
    return result;
}
示例#24
0
void
reshape(int w, int h)
{
  glViewport(0, 0, w, h);
  winWidth = w;
  winHeight = h;

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  ortho();
  glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
  viewport[0] = 0;
  viewport[1] = 0;
  viewport[2] = winWidth;
  viewport[3] = winHeight;
}
示例#25
0
/**
 * P(r) calculated from the expansion, with errors
 */
void pr_err(double *pars, double *err, double d_max, int n_c,
		double r, double *pr_value, double *pr_value_err) {
    double sum = 0.0;
    double sum_err = 0.0;
    double func_value;
	int i;
    for (i=0; i<n_c; i++) {
    	func_value = ortho(d_max, i+1, r);
        sum += pars[i] * func_value;
        //sum_err += err[i]*err[i]*func_value*func_value;
        sum_err += err[i*n_c+i]*func_value*func_value;
    }
    *pr_value = sum;
    if (sum_err>0) {
    	*pr_value_err = sqrt(sum_err);
    } else {
    	*pr_value_err = sum;
    }
}
示例#26
0
void GraphicsManager::setupScene() {
	if (!_screen)
		throw Common::Exception("No screen initialized");

	glClearColor(0, 0, 0, 0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glViewport(0, 0, _width, _height);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

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

	glAlphaFunc(GL_GREATER, 0.1f);
	glEnable(GL_ALPHA_TEST);

	setCullFace(_cullFaceEnabled, _cullFaceMode);

	switch (_projectType) {
		case kProjectTypePerspective:
			perspective(_viewAngle, ((float) _width) / ((float) _height), _clipNear, _clipFar);
			break;

		case kProjectTypeOrthogonal:
			ortho(0.0f, _width, 0.0f, _height, _clipNear, _clipFar);
			break;

		default:
			assert(false);
			break;
	}
}
示例#27
0
void SceneView::updateMatrices()
{
	makeCurrent();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	auto aspect = float(width()) / float(height());
	if (m_ortho) ortho(aspect, m_z);
	else perspective(30.0f, aspect, 0.3f, 50.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// World transform:
	gluLookAt(m_x, m_y, m_z, m_x, m_y, m_z - 1, 0, 1, 0);
	glRotatef(m_beta, 1, 0, 0);
	glRotatef(m_alpha, 0, 1, 0);

	// Object transform:
	m_scene->transform();
}
static void drawTriangle(GLuint verticesVBO, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
    glUseProgram(shaderProgram);
    GLuint posLoc = glGetAttribLocation(shaderProgram, "a_position");
    GLuint mvpLoc = glGetUniformLocation(shaderProgram, "u_mvpMatrix");
    GLuint colorLoc = glGetUniformLocation(shaderProgram, "u_color");

    GLfloat mvpMat[16];
    ortho(-WINDOWS_SIZE/2, WINDOWS_SIZE/2, -WINDOWS_SIZE/2, WINDOWS_SIZE/2, -100, 100, mvpMat);

    glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, mvpMat);
    glUniform4f(colorLoc, r/255.f, g/255.f, b/255.f, a/255.f);

    glBindBuffer(GL_ARRAY_BUFFER, verticesVBO);
    glEnableVertexAttribArray(posLoc);
    glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), BUFFER_OFFSET(0));

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glUseProgram(0);
}
示例#29
0
		void View::PreRender( real64_t dt ) {
			// set up 2d/3d perspective
			if ( is2D ) {
				matrix4 o = ortho(
					0.0f,
					static_cast<real32_t>( width ),
					0.0f,
					static_cast<real32_t>( height ),
					0.0f, // zNear
					1.0f // zFar
				);
				projectionMatrix = glm::make_mat4( o.data );
			}

			if ( callbackPreRender ) {
				callbackPreRender( dt );
			}

			BufferMemory bufferMem;
			perFrameData->MapDiscard( &bufferMem, sizeof( matrix4 ) );
			matrix4 *m = static_cast<matrix4 *>( bufferMem.devicePtr );

			memcpy( m->data, glm::value_ptr( projectionMatrix ), sizeof(m->data) );

			perFrameData->Unmap();
			perFrameData->BindRange( 6, bufferMem.offset, bufferMem.size );

			// sort surfaces etc?

			while ( !renderObjects.empty() ) {
				const auto &object = renderObjects.front();

				if ( object.handle != Renderable::invalidHandle ) {
					//FIXME: this design seems ass-backwards WRT RenderInfo.handle -> Renderable::Draw( RenderInfo )
					Renderable::Get( object.handle )->Draw( object );
				}

				renderObjects.pop();
			}
		}
示例#30
0
void TextBox::Draw(ivec2 pos, vec4 color)
{
	glViewport(0, 0, WIDTH, HEIGHT);
	if (VAO == NULL)
	{
		cout << "Failed to open VAO!" << endl;
		exit(-1);
	}
	ivec2 size = ivec2(WIDTH, HEIGHT);
    if(color.a < 1.f)
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    glUseProgram(shader);
	glUniform4f(glGetUniformLocation(shader, "color"), color.r, color.g, color.b, color.a);
	mat4 proj = ortho(0.0f, static_cast<GLfloat>(size.x), 0.0f, static_cast<GLfloat>(size.y));
    glUniformMatrix4fv(glGetUniformLocation(shader, "projection"), 1, GL_FALSE, value_ptr(proj));
    glBindVertexArray(VAO);
    GLfloat vertices[6][4] = {
        { pos.x,     pos.y + size.y,   0.0, 0.0 },            
        { pos.x,     pos.y,       0.0, 1.0 },
        { pos.x + size.x, pos.y,       1.0, 1.0 },

        { pos.x,     pos.y + size.y,   0.0, 0.0 },
        { pos.x + size.x, pos.y,       1.0, 1.0 },
        { pos.x + size.x, pos.y + size.y,   1.0, 0.0 }           
    };
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); 
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    glBindVertexArray(NULL);
    if(color.a < 1.f)
    {
        glDisable(GL_BLEND);
    }
}