Beispiel #1
0
void
fix_colors(int row1, int col1, int row2, int col2, int delta1, int delta2)
{
    int r1, c1, r2, c2;
    struct crange *cr;
    struct frange *fr;

    fr = find_frange(currow, curcol);

    if (color_base)
	for (cr = color_base; cr; cr = cr->r_next) {
	    r1 = cr->r_left->row;
	    c1 = cr->r_left->col;
	    r2 = cr->r_right->row;
	    c2 = cr->r_right->col;

	    if (!(fr && (c1 < fr->or_left->col || c1 > fr->or_right->col))) {
		if (r1 != r2 && r1 >= row1 && r1 <= row2) r1 = row2 - delta1;
		if (c1 != c2 && c1 >= col1 && c1 <= col2) c1 = col2 - delta1;
	    }

	    if (!(fr && (c2 < fr->or_left->col || c2 > fr->or_right->col))) {
		if (r1 != r2 && r2 >= row1 && r2 <= row2) r2 = row1 + delta2;
		if (c1 != c2 && c2 >= col1 && c2 <= col2) c2 = col1 + delta2;
	    }

	    if (r1 > r2 || c1 > c2)	/* the 0 means delete color range */
		add_crange(cr->r_left, cr->r_right, 0);
	    else {
		cr->r_left = lookat(r1, c1);
		cr->r_right = lookat(r2, c2);
	    }
	}
}
Beispiel #2
0
void
del_range(struct ent *left, struct ent *right)
{
    struct range *r;
    int minr, minc, maxr, maxc;

    minr = left->row < right->row ? left->row : right->row;
    minc = left->col < right->col ? left->col : right->col;
    maxr = left->row > right->row ? left->row : right->row;
    maxc = left->col > right->col ? left->col : right->col;

    left = lookat(minr, minc);
    right = lookat(maxr, maxc);

    if (find_range((char *)0, 0, left, right, &r)) 
	return;

    if (r->r_next)
        r->r_next->r_prev = r->r_prev;
    if (r->r_prev)
        r->r_prev->r_next = r->r_next;
    else
	rng_base = r->r_next;
    scxfree((char *)(r->r_name));
    scxfree((char *)r);
    modflg++;
}
Beispiel #3
0
void
sync_cranges()
{
    struct crange *cr;

    cr = color_base;
    while (cr) {
	cr->r_left = lookat(cr->r_left->row, cr->r_left->col);
	cr->r_right = lookat(cr->r_right->row, cr->r_right->col);
	cr = cr->r_next;
    }
}
Beispiel #4
0
void
sync_enode(struct enode *e)
{
    if (e) {
	if ((e->op & REDUCE)) {
	    e->e.r.left.vp = lookat(e->e.r.left.vp->row, e->e.r.left.vp->col);
	    e->e.r.right.vp = lookat(e->e.r.right.vp->row, e->e.r.right.vp->col);
	} else if (e->op != O_VAR && e->op !=O_CONST && e->op != O_SCONST) {
	    sync_enode(e->e.o.left);
	    sync_enode(e->e.o.right);
	}
    }
}
Beispiel #5
0
void
sync_franges()
{
    struct frange *fr;

    fr = frame_base;
    while (fr) {
	fr->or_left  = lookat(fr->or_left->row,  fr->or_left->col);
	fr->or_right = lookat(fr->or_right->row, fr->or_right->col);
	fr->ir_left  = lookat(fr->ir_left->row,  fr->ir_left->col);
	fr->ir_right = lookat(fr->ir_right->row, fr->ir_right->col);
	fr = fr->r_next;
    }
}
Beispiel #6
0
void PerspectiveCamera::mouseDragged(CameraScratch &scratch, QMouseEvent *event)
{
    int xDiff = scratch.pickX - event->pos().x();
    int yDiff = scratch.pickY - event->pos().y();

    if (scratch.moveType == MoveType::ROTATING) {
        Vector3 origLook = eye() + lookDir();
        setYRot(yRot() + xDiff * 0.5f);
        setUpRot(upRot() + yDiff * -0.5f);

        // move eye to look at original focal point (Maya style)
        Vector3 lookAway = lookDir() * -1;
        setCenter(origLook + lookAway);
    }
    else if (scratch.moveType == MoveType::PANNING) {
        float panScale = 0.05f;

        Vector3 mUp = scratch.origUp * -1.0f * yDiff * panScale;
        Vector3 mLeft = scratch.origLeft * -1.0f * xDiff * panScale;

        setCenter(eye() + mUp + mLeft);
    } else if (scratch.moveType == MoveType::TRUCKING) {
        Point3 at = lookat();
        Vector3 l = lookDir() * -0.01f * yDiff;

        setCenter(l + center());
    }

    scratch.pickX = event->pos().x();
    scratch.pickY = event->pos().y();
}
Beispiel #7
0
//render screen
void render(Level &level, Player &plr) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    plr.cameraTarget = lookat(GLCoord(plr.pos.x, plr.pos.y, plr.pos.z),
            plr.cameraDirection);
    gluLookAt(plr.pos.x, plr.pos.y, plr.pos.z,
            plr.cameraTarget.x, plr.cameraTarget.y, plr.cameraTarget.z,
            0,  0, 1);
    draw_floor(plr.pos);
    draw_ceiling(plr.pos);
    Coord colorpos = color(level, plr.pos, plr.cameraTarget - plr.pos);
    for(int y = -VIEWDISTANCE; y < VIEWDISTANCE; y++) {
        for(int x = -VIEWDISTANCE; x < VIEWDISTANCE; x++) {
            Coord curpos = Coord((int)plr.pos.x, (int)plr.pos.y) + Coord(x, y);
            if(!level.data.contains(curpos))
                generate(level.data, curpos, GENDISTANCE);
            char data = '.';
            data = level.data.get(curpos, '.');
            if(data == '#')
                Cube(GLCoord(curpos.x, curpos.y, 0), wallTexture).draw();
            else if(data == '%')
                Cube(GLCoord(curpos.x, curpos.y, 0), highlightTexture).draw();
        }
    }
    level.srch.render();
    if(level.data.get(colorpos, '.') == '%')
        level.data.add('#', colorpos);
    SDL_GL_SwapWindow(screen);
}
Beispiel #8
0
// Shift cells left
void shift_cells_left(int deltarows, int deltacols) {
    int r, j, c;
    register struct ent *p;
    register struct ent *n;
    struct ent **pp;
    for (j = 0; j < deltacols; j++)
        for (r = currow; r < currow + deltarows; r++)
            for (c = curcol; c < maxcol; c++) {

                // libero memoria de ent donde estoy parado
                pp = ATBL(tbl, r, c);
                clearent(*pp);

                p = *ATBL(tbl, r, c + 1);
                if (p && ( (p->flags & is_valid) || (p->expr && (p->flags & is_strexpr)) || p->label )  ) {
                    n = lookat(r, c);
                    (void) copyent(n, p, 1, 0, 0, 0, r, c, 0); // copio p a n
                    n->col--;
                    pp = ATBL(tbl, r, c + 1);
                } else { // Si desplazo celda de ultima columna
                    pp = ATBL(tbl, r, c);
                }
                clearent(*pp);
            }
    return;
}
Beispiel #9
0
// Shift cells down
void shift_cells_down(int deltarows, int deltacols) {
    int r, c;
    struct ent **pp;
    register struct ent * p;
    register struct ent *n;
    int lim = maxrow - currow + 1;

    // Move cell content
    if (currow > maxrow) maxrow = currow;
    maxrow += deltarows;

    lim = maxrow - lim;
    if ((maxrow >= maxrows) && !growtbl(GROWROW, maxrow, 0))
        return;

    for (r = maxrow; r > lim; r--) {
        for (c = curcol; c < curcol + deltacols; c++) {
            p = *ATBL(tbl, r - deltarows, c);
            if (p) {
                n = lookat(r, c);
                copyent(n, p, 1, 0, 0, 0, r - deltarows, c, 0);
                n->row += deltarows;
                p = (struct ent *)0;

                pp = ATBL(tbl, r - deltarows, c);
                clearent(*pp);
            }
        }
    }
    return;
}
Beispiel #10
0
// Shift cells up
void shift_cells_up(int deltarows, int deltacols) {
    register struct ent ** pp;
    register struct ent * n;
    register struct ent * p;
    int r, c, i;

    //if (currow + deltarows - 1 > maxrow) return;

    // Delete cell content
    for (i = 0; i < deltarows; i++)
        for (r = currow; r < maxrow; r++)
            for (c = curcol; c < curcol + deltacols; c++) {

                // libero memoria de ent donde estoy parado
                pp = ATBL(tbl, r, c);
                clearent(*pp);

                p = *ATBL(tbl, r+1, c);
                if (p && ( (p->flags & is_valid) || (p->expr && (p->flags & is_strexpr)) || p->label )  ) {
                    // Copio celda inferior hacia arriba
                    n = lookat(r, c);
                    (void) copyent(n, p, 1, 0, 0, 0, r, c, 0);
                    n->row--;
                    pp = ATBL(tbl, r+1, c);
                } else {
                    pp = ATBL(tbl, r, c);
                }
                clearent(*pp);
            }
    return;
}
Beispiel #11
0
int main(int argc, char** argv) {
    if (2>argc) {
        std::cerr << "Usage: " << argv[0] << "obj/model.obj" << std::endl;
        return 1;
    }

    float *zbuffer = new float[width*height];
    for (int i=width*height; i--; zbuffer[i] = -std::numeric_limits<float>::max());

    TGAImage frame(width, height, TGAImage::RGB);
    lookat(eye, center, up);
    viewport(width/8, height/8, width*3/4, height*3/4);
    projection(-1.f/(eye-center).norm());
    light_dir = proj<3>((Projection*ModelView*embed<4>(light_dir, 0.f))).normalize();

    for (int m=1; m<argc; m++) {
        model = new Model(argv[m]);
        Shader shader;
        for (int i=0; i<model->nfaces(); i++) {
            for (int j=0; j<3; j++) {
                shader.vertex(i, j);
            }
            triangle(shader.varying_tri, shader, frame, zbuffer);
        }
        delete model;
    }
    frame.flip_vertically(); // to place the origin in the bottom left corner of the image
    frame.write_tga_file("framebuffer.tga");

    delete [] zbuffer;
    return 0;
}
Beispiel #12
0
duprow()
{
    if (currow >= MAXROWS - 1 || maxrow >= MAXROWS - 1) {
	error ("The table can't be any bigger");
	return;
    }
    modflg++;
    currow++;
    openrow (currow);
    for (curcol = 0; curcol <= maxcol; curcol++) {
	register struct ent *p = tbl[currow - 1][curcol];
	if (p) {
	    register struct ent *n;
	    n = lookat (currow, curcol);
	    copyent ( n, p, 1, 0);
	}
    }
    for (curcol = 0; curcol <= maxcol; curcol++) {
	register struct ent *p = tbl[currow][curcol];
	if (p && (p -> flags & is_valid) && !p -> expr)
	    break;
    }
    if (curcol > maxcol)
	curcol = 0;
}
Beispiel #13
0
dupcol() 
{
    if (curcol >= MAXCOLS - 1 || maxcol >= MAXCOLS - 1) {
	error ("The table can't be any wider");
	return;
    }
    modflg++;
    curcol++;
    opencol (curcol);
    for (currow = 0; currow <= maxrow; currow++) {
	register struct ent *p = tbl[currow][curcol - 1];
	if (p) {
	    register struct ent *n;
	    n = lookat (currow, curcol);
	    copyent ( n, p, 0, 1);
	}
    }
    for (currow = 0; currow <= maxrow; currow++) {
	register struct ent *p = tbl[currow][curcol];
	if (p && (p -> flags & is_valid) && !p -> expr)
	    break;
    }
    if (currow > maxrow)
	currow = 0;
}
Beispiel #14
0
Val view_parse(int pass, Pval *pl)
{
  Val v = {V_NULL, 0};
  if (pass == T_EXEC) {
    View *view = initview();

    Vector3 ref = pvl_get_v3(pl, "from", v3_make(0,-5,0));
    Vector3 at = pvl_get_v3(pl, "at", v3_make(0,0,0));
    Vector3 up = pvl_get_v3(pl, "up", v3_make(0,0,1));
    double fov = pvl_get_num(pl, "fov", 90);
    double w = pvl_get_num(pl, "imgw", 320);
    double h = pvl_get_num(pl, "imgh", 240);

    lookat(view, ref.x, ref.y, ref.z, at.x, at.y, at.z, up.x, up.y, up.z);
    setviewpoint(ref.x, ref.y, ref.z);
    setviewnormal(at.x - ref.x ,at.y - ref.y, at.z - ref.z);
    makeviewV();

    perspective(view, fov * DTOR, w/h, 1.0, 100000.0);
    viewport(view, 0.,0., w, h);

    v.type = V_CAMERA;
    v.u.v = view;
  }
  return v;
}
Beispiel #15
0
void
add_crange(struct ent *r_left, struct ent *r_right, int pair)
{
    struct crange *r;
    int minr, minc, maxr, maxc;

    minr = r_left->row < r_right->row ? r_left->row : r_right->row;
    minc = r_left->col < r_right->col ? r_left->col : r_right->col;
    maxr = r_left->row > r_right->row ? r_left->row : r_right->row;
    maxc = r_left->col > r_right->col ? r_left->col : r_right->col;

    if (!pair) {
	if (color_base)
	    for (r = color_base; r; r = r->r_next)
		if (    (r->r_left->row == r_left->row) &&
			(r->r_left->col == r_left->col) &&
			(r->r_right->row == r_right->row) &&
			(r->r_right->col == r_right->col)) {
		    if (r->r_next)
			r->r_next->r_prev = r->r_prev;
		    if (r->r_prev)
			r->r_prev->r_next = r->r_next;
		    else
			color_base = r->r_next;
		    scxfree((char *)r);
		    modflg++;
		    FullUpdate++;
		    return;
		}
	error("Color range not defined");
	return;
    }

    r = (struct crange *)scxmalloc((unsigned)sizeof(struct crange));
    r->r_left = lookat(minr, minc);
    r->r_right = lookat(maxr, maxc);
    r->r_color = pair;

    r->r_next = color_base;
    r->r_prev = (struct crange *)0;
    if (color_base)
	color_base->r_prev = r;
    color_base = r;

    modflg++;
    FullUpdate++;
}
Beispiel #16
0
void
fix_frames(int row1, int col1, int row2, int col2, int delta1, int delta2)
{
    int r1, r2, c1, c2;
    struct frange *fr, *cfr;

    cfr = find_frange(currow, curcol);
    if (frame_base)
	for (fr = frame_base; fr; fr = fr->r_next) {
	    r1 = fr->or_left->row;
	    c1 = fr->or_left->col;
	    r2 = fr->or_right->row;
	    c2 = fr->or_right->col;

	    if (!(cfr && (c1 < cfr->or_left->col || c1 > cfr->or_right->col))) {
		if (r1 >= row1 && r1 <= row2) r1 = row2 - delta1;
		if (c1 >= col1 && c1 <= col2) c1 = col2 - delta1;
	    }

	    if (!(cfr && (c2 < cfr->or_left->col || c2 > cfr->or_right->col))) {
		if (r2 >= row1 && r2 <= row2) r2 = row1 + delta2;
		if (c2 >= col1 && c2 <= col2) c2 = col1 + delta2;
	    }

	    fr->or_left = lookat(r1, c1);
	    fr->or_right = lookat(r2, c2);

	    r1 = fr->ir_left->row;
	    c1 = fr->ir_left->col;
	    r2 = fr->ir_right->row;
	    c2 = fr->ir_right->col;

	    if (!(cfr && (c1 < cfr->or_left->col || c1 > cfr->or_right->col))) {
		if (r1 >= row1 && r1 <= row2) r1 = row2 - delta1;
		if (c1 >= col1 && c1 <= col2) c1 = col2 - delta1;
	    }

	    if (!(cfr && (c2 < cfr->or_left->col || c2 > cfr->or_right->col))) {
		if (r2 >= row1 && r2 <= row2) r2 = row1 + delta2;
		if (c2 >= col1 && c2 <= col2) c2 = col1 + delta2;
	    }

	    fr->ir_left = lookat(r1, c1);
	    fr->ir_right = lookat(r2, c2);
	}
}
Beispiel #17
0
char *
r_name(int r1, int c1, int r2, int c2)
{
    struct ent *v1, *v2;
    struct range *r;
    static char buf[100];

    v1 = lookat(r1, c1);
    v2 = lookat(r2, c2);
    if (!find_range((char *)0, 0, v1, v2, &r)) {
	return (r->r_name);
    } else {
        (void) sprintf(buf, "%s", v_name(r1, c1));
	(void) sprintf(buf+strlen(buf), ":%s", v_name(r2, c2));
	return (buf);
    }
}
Beispiel #18
0
void TinyRenderer::renderObject(TinyRenderObjectData& renderData)
{
    int width = renderData.m_rgbColorBuffer.get_width();
    int height = renderData.m_rgbColorBuffer.get_height();
    
    Vec3f light_dir_local = Vec3f(renderData.m_lightDirWorld[0],renderData.m_lightDirWorld[1],renderData.m_lightDirWorld[2]);
    Vec3f light_color = Vec3f(renderData.m_lightColor[0],renderData.m_lightColor[1],renderData.m_lightColor[2]);
    float light_distance = renderData.m_lightDistance;
    Model* model = renderData.m_model;
    if (0==model)
        return;
    
    renderData.m_viewportMatrix = viewport(0,0,width, height);
    
    b3AlignedObjectArray<float>& zbuffer = renderData.m_depthBuffer;
    b3AlignedObjectArray<float>* shadowBufferPtr = renderData.m_shadowBuffer;
    int* segmentationMaskBufferPtr = (renderData.m_segmentationMaskBufferPtr && renderData.m_segmentationMaskBufferPtr->size())?&renderData.m_segmentationMaskBufferPtr->at(0):0;
    
    TGAImage& frame = renderData.m_rgbColorBuffer;
    
    {
        // light target is set to be the origin, and the up direction is set to be vertical up.
        Matrix lightViewMatrix = lookat(light_dir_local*light_distance, Vec3f(0.0,0.0,0.0), Vec3f(0.0,0.0,1.0));
        Matrix lightModelViewMatrix = lightViewMatrix*renderData.m_modelMatrix;
        Matrix modelViewMatrix = renderData.m_viewMatrix*renderData.m_modelMatrix;
        Vec3f localScaling(renderData.m_localScaling[0],renderData.m_localScaling[1],renderData.m_localScaling[2]);
        
        Shader shader(model, light_dir_local, light_color, modelViewMatrix, lightModelViewMatrix, renderData.m_projectionMatrix,renderData.m_modelMatrix, renderData.m_viewportMatrix, localScaling, model->getColorRGBA(), width, height, shadowBufferPtr, renderData.m_lightAmbientCoeff, renderData.m_lightDiffuseCoeff, renderData.m_lightSpecularCoeff);
        
        for (int i=0; i<model->nfaces(); i++)
        {
            for (int j=0; j<3; j++) {
                shader.vertex(i, j);
            }

			mat<4,3,float> stackTris[3];

			b3AlignedObjectArray< mat<4,3,float> > clippedTriangles;
			clippedTriangles.initializeFromBuffer(stackTris,0,3);

			bool hasClipped = clipTriangleAgainstNearplane(shader.varying_tri,clippedTriangles);

			if (hasClipped)
			{
				for (int t=0;t<clippedTriangles.size();t++)
				{
					triangleClipped(clippedTriangles[t], shader.varying_tri, shader, frame, &zbuffer[0], segmentationMaskBufferPtr, renderData.m_viewportMatrix, renderData.m_objectIndex);
				}
			}
			else
			{
				triangle(shader.varying_tri, shader, frame, &zbuffer[0], segmentationMaskBufferPtr, renderData.m_viewportMatrix, renderData.m_objectIndex);
			}
        }
    }
    
}
// 생성자
ZCamera::ZCamera()
{
    D3DXVECTOR3	eye(0.0f,0.0f,0.0f);
    D3DXVECTOR3	lookat(0.0f,0.0f,-1.0f);
    D3DXVECTOR3	up(0.0f,1.0f,0.0f);
    D3DXMatrixIdentity( &m_matView );
    D3DXMatrixIdentity( &m_matBill );
    SetView( &eye, &lookat, &up );
}
Beispiel #20
0
void
sync_ranges()
{
    int i, j;
    struct range *r;
    struct ent *p;

    for (r = rng_base; r; r = r->r_next) {
	r->r_left.vp = lookat(r->r_left.vp->row, r->r_left.vp->col);
	r->r_right.vp = lookat(r->r_right.vp->row, r->r_right.vp->col);
    }
    for (i=0; i<=maxrow; i++)
	for (j=0; j<=maxcol; j++)
	    if ((p = *ATBL(tbl,i,j)) && p->expr)
		sync_enode(p->expr);
    sync_franges();
    sync_cranges();
}
Beispiel #21
0
void Mtx44::lookat(
    float ex, float ey, float ez,
    float tx, float ty, float tz,
    float ux, float uy, float uz)
{
    Vec3 eye(ex, ey, ez);
    Vec3 target(tx, ty, tz);
    Vec3 up(ux, uy, uz);
    lookat(eye, target, up);
}
Beispiel #22
0
// there are so many parameters omg
// param pos: position
// param lookat: lookat point
// param up: camera upvector
// param fovy: camera field of view
// param aperture: camera aperture width for depth of field
// param focallength: camera focal length for depth of field
// param dof: whether or not to render with depth of field
Camera::Camera(float posx, float posy, float posz, float lookatx, float lookaty, float lookatz, float upx, float upy, float upz, float fovy, float aperture, float focallength, bool dof, unsigned int ndepthrays):pos(posx, posy, posz), fovy(fovy), aperture(aperture), focallength(focallength), dof(dof), ndepthrays(ndepthrays)
{
	Vec3 lookat(lookatx, lookaty, lookatz);
	w = (lookat - pos).normal();
	
	Vec3 up(upx, upy, upz);
	u = cross(w, up).normal();

	v = cross(w, u).normal();	
}
Beispiel #23
0
	void camera::update( float lag )
	{
		tnode::update( lag );
		const math::matrix44 mat = m_local_transform.get_matrix();
		math::vector3 eye(0,0,0), lookat(0,0,1);
		math::vec_transform( &eye, &mat );
		math::vec_transform( &lookat, &mat );
		math::matrix44 viewtransform;
		math::build_matrix_lookat_lh( &viewtransform, &eye, &lookat, &vector3(0,1,0) );
		get_core()->get_scene_renderer()->set_viewtransform(viewtransform);
	}
Beispiel #24
0
		void saveImage(std::string filename){
			std::ofstream file;
			file.open(filename);

			file << "P3" << std::endl;
			file << width_ << " " << height_ << std::endl;
			file << "255" << std::endl;

			Hitable *list[4];
			//float R = cos(M_PI / 4);
			list[0] = new Sphere(Vec3<float>(-1.5,0.0,-1.0), 0.5, new Lambertian(Vec3<float>(0.1,0.2,0.5)));
			list[1] = new Sphere(Vec3<float>(1, -100.5, -1.0), 100, new Lambertian(Vec3<float>(0.1, 0.4, 0.3)));
			list[2] = new Sphere(Vec3<float>(1.5, 0.0, -1.0), 0.5, new Metal(Vec3<float>(0.8, 0.6, 0.2),1.0));
			//list[3] = new Sphere(Vec3<float>(0.0, 0.0, -1.0), 0.5, new Dieletric(1.5));
			list[3] = new Box(Vec3<float>(0.0, -0.5, -1.5), Vec3<float>(0.5, 0.0, -1.0), new Dieletric(1.5));
			//list[4] = new Sphere(Vec3<float>(0.0, 0.0, -1.0), -0.495, new Dieletric(1.5));
			//list[4] = new Plane(Vec3<float>(-4.0, 5.0, -2.0), Vec3<float>(4.0, -1.0, -2.0), new Dieletric(1.5));
			//list[4] = new Plane(Vec3<float>(0.0, 0.0, -4.0), Vec3<float>(0.0, 1.0, 1.0), new Dieletric(1.5));
			//list[4] = new Sphere(Vec3<float>(-1.0, 0.0, -5.0), 3.5, new Lambertian(Vec3<float>(0.6, 0.4, 0.5)));
			//list[5] = new Sphere(Vec3<float>(-1.0, 0.0, -1.0), 0.5, new Dieletric(10.5));

			Hitable * world = new Hitable_list(list, 4);
			//Hitable *world = random_scene();

			Vec3<float> lookfrom(2.0, 0.0, 1.0), lookat(0.0, 0.0, -1.0);
			float dist_to_focus = (lookfrom - lookat).length();
			float aperture = 2.0;

			Camera cam(lookfrom, lookat,Vec3<float>(0,1,0), 60, float(width_/height_));
			int ns = 100;
			for (int i = height_-1; i >= 0; i--){
				for (int j = 0; j < width_; j++){

					Vec3<float> col(0.0, 0.0, 0.0);
					for (int s = 0; s < ns; s++)
					{
						float u = float(i + Rand()) / float(height_);
						float v = float(j + Rand()) / float(width_);

						Ray<float> r = cam.getRay(u, v);
						Vec3<float> p = r.point_at_parameter(2.0);
						col += color(r, world, 0);
					}

					float n = float(ns);
					col /= n;
					col = Vec3<float>(sqrt(col.x()), sqrt(col.y()), sqrt(col.z()));
					int ir = int(255.99*col.x()), ig = int(255.99*col.y()), ib = int(255.99*col.z());

					file << ir << " " << ig << " " << ib << endl;
				}
			}
			file.close();
		}
Beispiel #25
0
void
fix_ranges(int row1, int col1, int row2, int col2, int delta1, int delta2)
{
    int r1, r2, c1, c2, i, j;
    struct range *r;
    struct frange *fr;
    struct ent *p;

    fr = find_frange(currow, curcol);

    /* First we fix all of the named ranges. */
    if (rng_base)
	for (r = rng_base; r; r = r->r_next) {
	    r1 = r->r_left.vp->row;
	    c1 = r->r_left.vp->col;
	    r2 = r->r_right.vp->row;
	    c2 = r->r_right.vp->col;

	    if (!(fr && (c1 < fr->or_left->col || c1 > fr->or_right->col))) {
		if (r1 >= row1 && r1 <= row2) r1 = row2 - delta1;
		if (c1 >= col1 && c1 <= col2) c1 = col2 - delta1;
	    }

	    if (!(fr && (c2 < fr->or_left->col || c2 > fr->or_right->col))) {
		if (r2 >= row1 && r2 <= row2) r2 = row1 + delta2;
		if (c2 >= col1 && c2 <= col2) c2 = col1 + delta2;
	    }
	    r->r_left.vp = lookat(r1, c1);
	    r->r_right.vp = lookat(r2, c2);
	}

    /* Next, we go through all valid cells with expressions and fix any ranges
     * that need fixing.
     */
    for (i=0; i<=maxrow; i++)
	for (j=0; j<=maxcol; j++)
	    if ((p = *ATBL(tbl,i,j)) && p->expr)
		fix_enode(p->expr, row1, col2, row2, col2, delta1, delta2);
    fix_frames(row1, col1, row2, col2, delta1, delta2);
    fix_colors(row1, col1, row2, col2, delta1, delta2);
}
Beispiel #26
0
void Renderer::orbit(Vec2f delta)
{
//    printf("delta = %f, %f\n", delta.x, delta.y);

    Vec3f u, v, w;
    w = _up;
    w.normalize();
    Vec3f up = _nonParallelVector(w);
    u = up.cross(w);
    u.normalize();
    v = w.cross(u);

    Matrix4f basis;
    basis.identity();
    basis.c[0][0] = u.x;
    basis.c[0][1] = u.y;
    basis.c[0][2] = u.z;
    basis.c[1][0] = v.x;
    basis.c[1][1] = v.y;
    basis.c[1][2] = v.z;
    basis.c[2][0] = w.x;
    basis.c[2][1] = w.y;
    basis.c[2][2] = w.z;

    Matrix4f basisInv = basis.inverted();

    Vec3f newEye = basisInv * _eye;
    float r = newEye.length();
    float phi = atan2f(newEye.y, newEye.x);
    float theta = asinf(newEye.z / r);

    // increment phi and theta by mouse motion
    //printf("delta phi = %f\n", M_PI_2 * delta.x);
    //printf("delta theta = %f\n", M_PI_2 * delta.y);

    phi = phi - M_PI_2 * delta.x;
    theta = theta - M_PI_2 * delta.y;
    float thetaLimit = (float) (89 * M_PI / 180);
    if (theta > thetaLimit)
        theta = thetaLimit;
    if (theta < -thetaLimit)
        theta = -thetaLimit;

    newEye.x = r * cosf(theta) * cosf(phi);
    newEye.y = r * cosf(theta) * sinf(phi);
    newEye.z = r * sinf(theta);
    newEye = basis * newEye;
    printf("old eye = %f, %f, %f\n", _eye.x, _eye.y, _eye.z);
    printf("new eye = %f, %f, %f\n", newEye.x, newEye.y, newEye.z);
    lookat(newEye, _target, _up);
}
Beispiel #27
0
char *
v_name(int row, int col)
{
    struct ent *v;
    struct range *r;
    static char buf[20];

    v = lookat(row, col);
    if (!find_range((char *)0, 0, v, v, &r)) {
	return (r->r_name);
    } else {
        (void) sprintf(buf, "%s%d", coltoa(col), row);
	return (buf);
    }
}
Beispiel #28
0
void SceneManagerTriangle::Update()
{
	float aspect = (float)m_width / (float)m_height;
	mat4 proj_matrix = perspective(60.0f, aspect, 0.1f, 1000.0f);
	mat4 view_matrix = lookat(vec3(0.0f, 0.0f, 3.0f),
		vec3(0.0f, 0.0f, 0.0f),
		vec3(0.0f, 1.0f, 0.0f));
	float factor = 0;// GetTickCount() / 50 % 360;
	mat4 mv_matrix = view_matrix * translate(m_x_offset, m_y_offset, m_z_offset) * scale(1.0f) * rotate(factor, vec3(0.0f, 1.0f, 0.0f));

	SetUniform(0, mv_matrix);
	SetUniform(1, proj_matrix);

	Soft3dPipeline::Instance()->Clear(0xffffff);
}
Beispiel #29
0
void
fix_enode(struct enode *e, int row1, int col1, int row2, int col2,
	int delta1, int delta2)
{
    if (e) {
	if ((e->op & REDUCE)) {
	    int r, c;
	    int r1, c1, r2, c2;
	    struct frange *fr;

	    fr = find_frange(currow, curcol);
	    r1 = e->e.r.left.vp->row;
	    c1 = e->e.r.left.vp->col;
	    r2 = e->e.r.right.vp->row;
	    c2 = e->e.r.right.vp->col;
	    if (r1>r2) r = r2, r2 = r1, r1 = r;
	    if (c1>c2) c = c2, c2 = c1, c1 = c;

	    if (!(fr && (c1 < fr->or_left->col || c1 > fr->or_right->col))) {
		if (r1 != r2 && r1 >= row1 && r1 <= row2) r1 = row2 - delta1;
		if (c1 != c2 && c1 >= col1 && c1 <= col2) c1 = col2 - delta1;
	    }

	    if (!(fr && (c2 < fr->or_left->col || c2 > fr->or_right->col))) {
		if (r1 != r2 && r2 >= row1 && r2 <= row2) r2 = row1 + delta2;
		if (c1 != c2 && c2 >= col1 && c2 <= col2) c2 = col1 + delta2;
	    }
	    e->e.r.left.vp = lookat(r1, c1);
	    e->e.r.right.vp = lookat(r2, c2);

	} else if (e->op != O_VAR && e->op !=O_CONST && e->op != O_SCONST) {
	    fix_enode(e->e.o.left, row1, col1, row2, col2, delta1, delta2);
	    fix_enode(e->e.o.right, row1, col1, row2, col2, delta1, delta2);
	}
    }
}
Beispiel #30
0
void RootScene::create(){
	root = new node ;
	
	//camera
	Vector3 eye(CAMERA_POS),lookat(LOOKAT_POS),up(UP_DIR);
	camera.create( eye, lookat, up );

	//background
	ground_plan.create( GROUND, 1.0f );

	//main_role
	root->push_child( main_role.create() );
	//enemy
	root->push_child( enemy.create() );
}