// Create display list with a torus and initialize state. static void init(void) { theTorus = glGenLists(1); glNewList(theTorus, GL_COMPILE); torus(8, 25); glEndList(); glShadeModel(GL_FLAT); glClearColor(0.0, 0.0, 0.0, 0.0); }
//main function used .Call() SEXP doTorus(SEXP n, SEXP d, SEXP p, SEXP offset, SEXP ismixed, SEXP timedseed) { if (!isNumeric(n) || !isNumeric(d) || !isLogical(timedseed) ) error(_("invalid argument")); if(!isNull(p) && !isNumeric(p)) error(_("invalid argument")); //temporary working variables int nb = asInteger( n ); //number of random vectors int dim = asInteger( d ); //dimension of vector int *prime; //prime numbers used when supplied int seqstart = asInteger( offset ); //sequence starting point int mixed = asLogical( ismixed ); //boolean to use the mixed Torus algo int usetime = asLogical( timedseed ); //boolean to use the machine time if( isNull(p) ) prime = NULL; else prime = INTEGER( p ); //allocate result double *u ; //result in C SEXP resultinR; //result in R PROTECT(resultinR = allocMatrix(REALSXP, nb, dim)); //allocate a n x d matrix u = REAL( resultinR ); //plug the C pointer on the R type R_CheckStack(); //computation step if(prime == NULL) { if (primeNumber[2] == 1) reconstruct_primes(); torus(u, nb, dim, primeNumber, seqstart, mixed, usetime); } else torus(u, nb, dim, prime, seqstart, mixed, usetime); UNPROTECT(1); return resultinR; }
void render() { sphere(); teapot(); cone(); torus(); tetrahedron(); }
void Lesson_7_1::drawGLScene() { if (!m_theTorus) { m_theTorus = glGenLists (1); glNewList(m_theTorus, GL_COMPILE); torus(8, 25); glEndList(); } glShadeModel(GL_FLAT); draw(); glShadeModel(GL_SMOOTH); }
void render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float x=0, y=0, z=0; for (int i = 0; i < NUM_COLS; i++) { for (int j = 0; j < NUM_ROWS; j++) { //Gridlines glColor3f(0.25, 0.25, 0.25); glBegin(GL_LINES); torus(i, j, x, y, z); glVertex3f(x, y, z); torus(i, j+1, x, y, z); glVertex3f(x, y, z); torus(i, j, x, y, z); glVertex3f(x, y, z); torus(i+1, j, x, y, z); glVertex3f(x, y, z); glEnd(); //Cells if (grid[i][j] == true) { glColor3f(0.0, 1.0, 0.0); } else { glColor3f(0.0, 0.0, 0.0); } glBegin(GL_QUADS); torus(i, j, x, y, z); glVertex3f(x, y, z); torus(i+1, j, x, y, z); glVertex3f(x, y, z); torus(i+1, j+1, x, y, z); glVertex3f(x, y, z); torus(i, j+1, x, y, z); glVertex3f(x, y, z); glEnd(); } } glFlush(); }
static gboolean intersection2(t_env *rt, t_vector ray, t_vector origin, int i) { if ((rt->object[i].name == L_SPHERE && limited_sphere(ray, rt->object[i], origin, rt)) || (rt->object[i].name == L_CYLINDER && limited_cylinder(ray, rt->object[i], origin, rt)) || (rt->object[i].name == L_CONE && limited_cone(ray, rt->object[i] , origin, rt)) || (rt->object[i].name == TRIANGLE && triangle(ray, rt->object[i], &rt->t, origin)) || (rt->object[i].name == TORUS && torus(ray, rt->object[i], &rt->t , origin)) || (rt->object[i].name == ELLIPSOIDE && ellipsoide(ray, rt->object[i], &rt->t, origin)) || (rt->object[i].name == PARABOL && parabol(ray, rt->object[i], &rt->t, origin)) || (rt->object[i].name == QUADRILATERAL && quadrilateral(ray, rt->object[i], &rt->t, origin)) || (rt->object[i].name == CUBE && cube(ray, &rt->object[i], &rt->t, origin))) return (1); return (0); }
int main(int argc, char *argv[]) { GLUquadric *quad; GLfloat zero[] = { 0.f, 0.f, 0.f, 0.f }; glutInit(&argc, argv); glutInitWindowSize(winWidth, winHeight); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); (void)glutCreateWindow("hatch"); #ifdef GL_EXT_blend_minmax hasBlendMinmax = glutExtensionSupported("GL_EXT_blend_minmax"); # ifdef _WIN32 /* grab extension function pointer for glBlendEquationEXT */ if (hasBlendMinmax) { glBlendEquationEXT = (PFNGLBLENDEQUATIONEXTPROC) wglGetProcAddress("glBlendEquationEXT"); if (glBlendEquationEXT == NULL) { hasBlendMinmax = 0; } } # endif #endif glutDisplayFunc(redraw); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(motion); glutKeyboardFunc(key); create_menu(); /* draw a perspective scene */ glMatrixMode(GL_PROJECTION); glFrustum(-100., 100., -100., 100., 300., 600.); glMatrixMode(GL_MODELVIEW); /* look at scene from (0, 0, 450) */ gluLookAt(0., 0., 450., 0., 0., 0., 0., 1., 0.); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, zero); glCullFace(GL_BACK); glReadBuffer(GL_BACK); glDisable(GL_DITHER); glNewList(1, GL_COMPILE); glutSolidCube(50.f); glEndList(); glNewList(2, GL_COMPILE); glutSolidTeapot(50.f); glEndList(); quad = gluNewQuadric(); gluQuadricTexture(quad, GL_TRUE); glNewList(3, GL_COMPILE); gluSphere(quad, 70., 20, 20); glEndList(); gluDeleteQuadric(quad); glNewList(4, GL_COMPILE); #if 0 glutSolidTorus(20, 50, 50, 50); #endif torus(20, 50, 50, 100); glEndList(); glNewList(5, GL_COMPILE); glPushMatrix(); glTranslatef(0.f, -80.f, 0.f); cylinder(40, 3, 20, 160); glTranslatef(0.f, 20.f, 0.f); cylinder(40, 3, 60, 20); glTranslatef(0.f, 20.f, 0.f); cylinder(40, 3, 30, 20); glTranslatef(0.f, 60.f, 0.f); cylinder(40, 3, 30, 20); glTranslatef(0.f, 20.f, 0.f); cylinder(40, 3, 60, 20); glPopMatrix(); glEndList(); maxobject = 5; make_stripes(); make_stipple(); glClearColor(0.25f, 0.25f, 0.25f, 1.0f); glClearColor(1.f, 1.f, 1.f, 1.0f); glDepthFunc(GL_LEQUAL); CHECK_ERROR("end of main"); help(); glutMainLoop(); return 0; }
TriMeshf torus(const vec3f ¢er, float majorRadius, float minorRadius, UINT stacks, UINT slices, const vec4f& color) { return torus(center, majorRadius, minorRadius, stacks, slices, [&](unsigned int stackIndex) { return color; }); }
TriMesh<FloatType> Shapes<FloatType>::torus(const vec3<FloatType> ¢er, FloatType majorRadius, FloatType minorRadius, UINT stacks, UINT slices, const vec4<FloatType>& color) { return torus(center, majorRadius, minorRadius, stacks, slices, [&](unsigned int stackIndex) { return color; }); }