Example #1
0
void R3Affine::
Pop(void) const
{
    // Pop matrix off stack
    Matrix().Pop();

    // Restore mirror flag
    if (IsMirrored()) {
        R3draw_mirrored = !R3draw_mirrored;
#if (RN_3D_GRFX == RN_IRISGL)
        frontface(R3draw_mirrored);
        backface(!R3draw_mirrored);
#elif (RN_3D_GRFX == RN_OPENGL)
        glFrontFace((R3draw_mirrored) ? GL_CW : GL_CCW);
#elif (RN_3D_GRFX == RN_3DR)
	G3dSetState(R3dr_gc, G3DL_FRONT_CCW, (R3draw_mirrored) ? 0 : 1);
#else
	RNAbort("Not Implemented");
#endif
    }
}
Example #2
0
void R3Affine::
Draw(void) const
{
    // Multiply top of stack by matrix
    Matrix().Draw();

    // Set mirror flag - this screws up Push/Pop ???
    if (IsMirrored()) {
        R3draw_mirrored = !R3draw_mirrored;
#if (RN_3D_GRFX == RN_IRISGL)
        frontface(R3draw_mirrored);
        backface(!R3draw_mirrored);
#elif (RN_3D_GRFX == RN_OPENGL)
        glFrontFace((R3draw_mirrored) ? GL_CW : GL_CCW);
#elif (RN_3D_GRFX == RN_3DR)
	G3dSetState(R3dr_gc, G3DL_FRONT_CCW, (R3draw_mirrored) ? 0 : 1);
#else
	RNAbort("Not Implemented");
#endif
    }
}
Example #3
0
main()
{
        char    device[10], *p;
	float	x, y, tdir = TRANS;
	int	but, nplanes;
	int	i, n;
	char	buf[10][128];

	fprintf(stderr,"Enter output device: ");
	gets(device);

	prefposition(50, 50);

	vinit(device);

	window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
	lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0.0);


	makeobj(1);
		makepoly();
			rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
		closepoly();
	closeobj();

	if ((nplanes = getdepth()) == 1)
		makecubes(0);

	makecubes(1);

	backface(1);
		
	if (backbuffer() < 0) {
		vexit();
		fprintf(stderr, "lcube: device doesn't support double buffering.\n"); 
		exit(0); 
	}        

	while((but = slocator(&x, &y)) != 44) {
		pushmatrix();
			rotate(100.0 * x, 'y');
			rotate(100.0 * y, 'x');
			color(BLACK);
			clear();
			callobj(3);
			if (nplanes == 1)
				callobj(2);
		popmatrix();
		swapbuffers();

		switch (but = checkkey()) {
		case 'x':
			translate(tdir, 0.0, 0.0);
			break;
		case 'y':
			translate(0.0, tdir, 0.0);
			break;
		case 'z':
			translate(0.0, 0.0, tdir);
			break;
		case '-':
			tdir = -tdir;
			break;
		case '+':
			tdir = TRANS;
			break;
		case 27: /* ESC */
		case 'q':
			vexit();
			exit(0);
		default:
			;
		}
	}

	vexit();
}
Example #4
0
main()
{
        char    *p;
	float	tdir = TRANS;
	float	scal = 1.0 + SCAL;
	int	but, nplanes;
	int	x, y, i, n;
	short	val;
	int	bf = 1;
	int	fill = 1;

	prefsize(500L, 500L);

	vinit("mswin");
	winopen("lcube");

	unqdevice(INPUTCHANGE);
	qdevice(SKEY);
	qdevice(XKEY);
	qdevice(YKEY);
	qdevice(ZKEY);
	qdevice(EQUALKEY);
	qdevice(MINUSKEY);
	qdevice(ESCKEY);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;
	

	window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
	lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0);

	if ((nplanes = getplanes()) == 1)
		makecubes(0);

	makecubes(1);

	backface(1);
		
	doublebuffer();
	gconfig();

	/*
	 * Doublebuffer does a backbuffer(TRUE)....
	 */

	while(1) {
		x = 500 - (int)getvaluator(MOUSEX);
		y = 500 - (int)getvaluator(MOUSEY);
		x *= 3;
		y *= 3;
		pushmatrix();
			rotate(x, 'y');
			rotate(y, 'x');
			color(BLACK);
			clear();
			callobj((Object)3);
			if (nplanes == 1)
				callobj((Object)2);
		popmatrix();
		swapbuffers();

		if (qtest()) {
			but = qread(&val);
			but = qread(&val);	/* swallow up event */

			switch (but) {

			case SKEY:
				scale(scal, scal, scal);
				break;
			case XKEY:
				translate(tdir, 0.0, 0.0);
				break;
			case YKEY:
				translate(0.0, tdir, 0.0);
				break;
			case ZKEY:
				translate(0.0, 0.0, tdir);
				break;
			case MINUSKEY:
				tdir = -tdir;

				if (scal < 1.0)
					scal = 1.0 + SCAL;
				else
					scal = 1.0 - SCAL;

				break;
			case EQUALKEY:
				tdir = TRANS;
				break;
			case BKEY:
				bf = !bf;
				backface(bf);
				break;
			case FKEY:
				fill = !fill;
				if (fill)
					polymode(PYM_FILL);
				else
					polymode(PYM_LINE);
				break;
			case ESCKEY:
			case QKEY:
				gexit();
				exit(0);
			default:
				;
			}
		}
	}
}
Example #5
0
/**
*    render
*    Base render method that performs the calculations necessary before the
*    render equation is called.
*    Preconditions:
*        A pointer to the Pixel object that draws the pixels.
*        A pointer to the windows transform Matrix (WNAC).
*        A pointer to the Instance Matrix (TRS (I)).
*        A pointer to the zbuffer Matrix.
*        A pointer to the Light object.
*        A pointer to the eye point (Vertex).
*        A pointer to the Color of the object's material.
*        A pointer to the ambient light Color.
*        The attenuation value (double).
*        The shininess value (double).
*      
*    Postconditions:
*        Performs necessary preconditions before calling another render method
*        to perform the actual rendering equation.
*/
void Face::render( Pixel* pix, Matrix* wnd, Matrix* trs, Matrix* zbuffer,
    Light* light, Vertex* eye, Color* material, Color* amb, double attenuation,
    double shininess )
{
    // Obtain the average normal.
    Vector* tmp_np = avgNormal( vertices->get(1) );
    Vector* tmp_nq = avgNormal( vertices->get(2) );
    Vector* tmp_nr = avgNormal( vertices->get(3) );

    Vector* np = tmp_np->multiply( trs );
    Vector* nq = tmp_nq->multiply( trs );
    Vector* nr = tmp_nr->multiply( trs );
    
    np->normalize();
    nq->normalize();
    nr->normalize();
    
    delete tmp_np;
    delete tmp_nq;
    delete tmp_nr;
    
    Vertex* p = vertices->get(1)->multiply(trs);
    Vertex* q = vertices->get(2)->multiply(trs);
    Vertex* r = vertices->get(3)->multiply(trs);

    // Lighting Computations
    p->setColor( material );
    q->setColor( material );
    r->setColor( material );
    
    // Shading for vertex 1.
    Color* color = obtainShading(  p, np, light, amb, eye, attenuation,
        shininess );
    p->setRed( color->getRed() );
    p->setGreen( color->getGreen() );
    p->setBlue( color->getBlue() );
    delete color;

    // Shading for vertex 2.
    color = obtainShading( q, nq, light, amb, eye, attenuation,shininess );
    q->setRed( color->getRed() );
    q->setGreen( color->getGreen() );
    q->setBlue( color->getBlue() );
    delete color;

    // Shading for vertex 3.
    color = obtainShading( r, nr, light, amb, eye, attenuation,shininess );
    r->setRed( color->getRed() );
    r->setGreen( color->getGreen() );
    r->setBlue( color->getBlue() );
    delete color;

    Vertex* tmp = p->multiply( wnd );
    delete p;
    p = tmp;
    tmp = q->multiply( wnd );
    delete q;
    q = tmp;
    tmp = r->multiply( wnd );
    delete r;
    r = tmp;

    p->homogenize();
    q->homogenize();
    r->homogenize();

    if ( backface(p, q, r) == 0 ) {
        renderBarycentric( pix, p, q, r, zbuffer );
    }

    delete np;
    delete nq;
    delete nr;

    delete p;
    delete q;
    delete r;
}
Example #6
0
main()
{
	int	i, itest,  dobackface, dofill, dodouble;
	char	buf[100];
	float	H;
	short	idata;
	int	xr, yr;

	vinit("mswin");
	winopen("piston");
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&idata) != REDRAW)
		;

	doublebuffer();

	gconfig();

	unqdevice(INPUTCHANGE);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	qdevice(ESCKEY);
        qdevice(REDRAW);

	makecyl();

	polymode(PYM_FILL);

	backface(1);
/*
 * set up a perspective projection with a field of view of
 * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1,
 * and the far clipping plane at 1000.0.
 */
	perspective(400, 1.5, 0.1, 600.0);
	lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0);

/*
 * here we loop back here adnaseum until someone hits a key
 */
	xr = yr = 0;

 	while(1) {
		for (i = 0; i < 360; i += 5) {
			color(BLACK);
			clear();
			color(RED);
			H = 1.0 + cos(2.0 * 3.14159265*i / 180.0);

			yr = 500 - (int)getvaluator(MOUSEY);
			xr = 500 - (int)getvaluator(MOUSEX);
			yr = 500 - (int)getvaluator(MOUSEY);
			xr *= 3;
			yr *= 3;

			pushmatrix();
				rotate(xr, 'x');
				rotate(yr, 'y');
				piston(H);
			popmatrix();

			if (dodouble)
				swapbuffers();

			if (qtest()) {
				itest = qread(&idata);
				itest = qread(&idata); /* Zap Up event */
				if (itest == BKEY) {
					dobackface = !dobackface;
					backface(dobackface);
				} else if (itest == FKEY) {
					dofill = !dofill;
					if (dofill)
						polymode(PYM_FILL);
					else
						polymode(PYM_LINE);
				} else if(itest == QKEY || itest == ESCKEY) {
					 gexit();
					 exit(0);
				}

			}
		}
	}
}