Example #1
0
File: main.cpp Project: wy32/CS130
void ddaLine(int x1, int y1, int x2, int y2)
{
	float x,y,xInc,yInc,dx,dy;
	int next;
	
	dx = x2 - x1;
	dy = y2 - y1;
	
	if(abs(dx)>abs(dy))
		next=abs(dx);
	else
		next=abs(dy);

	xInc = dx / next;
	yInc = dy / next;
	
	x = x1;
	y = y1;
	
	renderPixel(x,y);

	for(int i=1;i<=next;i++)
	{
		x = x + xInc;
		y = y + yInc;
		renderPixel(x,y);
	}
}
Example #2
0
File: main.cpp Project: wy32/CS130
void ddaCircle(int x0, int y0, int r)
{
	int x = r, y = 0;
	int radiusError = 1-x;

	while(x >= y)
	{
		renderPixel(x + x0, y + y0); 		//1st octant
		renderPixel(y + x0, x + y0);		//2nd octant
		renderPixel(-x + x0, y + y0);		//4th octant
		renderPixel(-y + x0, x + y0);		//3rd octant
		renderPixel(-x + x0, -y + y0);		//5th octant
		renderPixel(-y + x0, -x + y0);		//6th octant
		renderPixel(x + x0, -y + y0);		//8th octant
		renderPixel(y + x0, -x + y0); 		//7th octant           
		y++;

		if(radiusError<0)
			radiusError+=2*y+1;
		else
		{
			x--;
			radiusError+=2*(y-x+1);
		}
	}

}
Example #3
0
void Rasterizer::RenderPixelsOMP()
{
    int size = pow(m_renderingParams->size(),2);
    float delta = 1.0/(float)size;
    m_percentDone = 0;
    int boxSize = min(m_renderingParams->size()/60, 4);
    if (m_isPreview)
        boxSize = 1;

//    boxSize = 1;

#pragma omp parallel for
    for (int k=0;k<size;k++) {
        if (m_abort)
            continue;
        int idx = m_renderList[ k ];

        QVector3D dir = setupCamera(idx);
        RasterPixel rp = renderPixel(dir, m_galaxies);
        m_percentDone+=delta;

        int i = idx%(int)m_renderingParams->size();
        int j = (idx-i)/(int)m_renderingParams->size();

        m_renderBuffer->DrawBox(m_backBuffer, i,j, boxSize, rp.I());

    }

    m_abort = false;

}
Example #4
0
File: main.cpp Project: wy32/CS130
void GL_render()
{
	glClear(GL_COLOR_BUFFER_BIT);
	renderPixel(400,400);
	ddaLine(200,300,235,400);
	ddaLine(400,500,500,600);
	ddaLine(300,100,600,110);
	ddaCircle(400,400,300);
	glutSwapBuffers();
}
Example #5
0
QImage* Scene::render()
{
    QImage*     image = new QImage( m_Xresolution,
                                    m_Yresolution,
                                    QImage::Format_RGB888 );

    for ( qreal y = 0; y < m_Yresolution; ++y )
    {
        for ( qreal x = 0; x < m_Xresolution; ++x )
        {
            renderPixel( image, x, y );
        }
    }
    return image;
}
Example #6
0
void Raytracer::renderTile(int x0, int x1, int y0, int y1, const osg::Vec3f& eye, const osg::Matrix& projToWorld)
{
    for (int y = y0; y < y1;++y)
    {
        for (int x = x0; x < x1;++x)
        {
            osg::Vec3f p(2.0f * x /(float)_width - 1.0f, 2 * y  / (float)_height - 1.0f, 1);
            osg::Vec3f dir = (p*projToWorld) - eye;
            dir.normalize();

            osg::Vec4f color = renderPixel(x,y, eye, dir);
            common::setColor(_framebuffer,osg::Vec2f(x,y),color);
        }
    }
}