Assembly *GraspGLObjects::CreateSuccessIndicator( void ) { Assembly *assembly = new Assembly(); Sphere *sphere = new Sphere( prompt_radius ); sphere->SetColor( GREEN ); assembly->AddComponent( sphere ); return assembly; }
Assembly *GraspGLObjects::CreateProjectiles( int fingers ) { Assembly *assembly = new Assembly(); double finger_spacing = finger_ball_radius * 2; for ( int trg = - fingers; trg <= fingers ; trg++ ){ Sphere *sphere = new Sphere( finger_ball_radius*1.0 ); // Create a color that varies as a function of the ball's position. if ( fingers == 0 ) sphere->SetColor( 200.0f/255.0f, 0.0f, 0.0f, 1.0f ); else sphere->SetColor( 200.0f/255.0f, (75.0f + float(trg) * 75.0f / 2.0f ) / 255.0f , 0.0f, 1.0f ); // Space the balls vertically. sphere->SetPosition( 0.0, finger_spacing * trg, 0.0 ); assembly->AddComponent( sphere ); } return assembly; }
MarkerStructureGLObject::MarkerStructureGLObject( char *model_file ) { if ( model_file ) { FILE *fp = fopen( model_file, "r" ); fAbortMessageOnCondition( ( NULL == fp ), "ReadModelMarkerPositions()", "Error opening %s for read.", model_file ); int mrk; for ( mrk = 0; mrk < MAX_MARKERS; mrk++ ) { int id, items; double x, y, z; items = fscanf( fp, "%d %lf\t %lf\t %lf", &id, &x, &y, &z ); if ( items != 4 ) break; fAbortMessageOnCondition( ( id < 0 || id >= MAX_MARKERS ), "ReadModelMarkerPositions()", "Marker %d ID = %d out of range [0 %d].", mrk, id, MAX_MARKERS - 1 ); modelMarker[mrk].id = id; modelMarker[mrk].position[X] = x; modelMarker[mrk].position[Y] = y; modelMarker[mrk].position[Z] = z; } nModelMarkers = mrk; fclose( fp ); } else nModelMarkers = 0; modelMarkerBalls = new Assembly(); for ( int mrk = 0; mrk < nModelMarkers; mrk++ ) { Sphere *sphere = new Sphere( STRUCTURE_BALL_RADIUS ); sphere->SetPosition( modelMarker[mrk].position ); sphere->SetColor( 0.0, 1.0, 0.0, 1.0 ); modelMarkerBalls->AddComponent( sphere ); } AddComponent( modelMarkerBalls ); realMarkerBalls = new Assembly(); for ( int mrk = 0; mrk < nModelMarkers; mrk++ ) { Sphere *sphere = new Sphere( STRUCTURE_BALL_RADIUS ); sphere->SetPosition( modelMarker[mrk].position ); sphere->SetColor( 0.5, 0.0, 0.5, 1.0 ); realMarkerBalls->AddComponent( sphere ); } AddComponent( realMarkerBalls ); HideRealMarkers(); }
Assembly *GraspGLObjects::CreateResponse( void ) { static int fingers = target_balls - 1; static double finger_spacing = target_ball_radius; Assembly *projectiles = new Assembly(); for ( int trg = - fingers; trg <= fingers ; trg++ ){ Sphere *sphere = new Sphere( target_ball_radius * 0.75 ); sphere->SetColor( 200.0f/255.0f, (75.0f + float(trg) * 75.0f/2.0f)/255.0f , 0.0f, 1.0f ); // Space the balls vertically. sphere->SetPosition( 0.0, 0.0 + target_ball_spacing * trg, 0.0 ); projectiles->AddComponent( sphere ); } return projectiles; }
// The following objects are not used during the Grasp protocol and are not seen by the subject. // Rather, these objects are used in the GraspGUI and elswhere to visualize the subject's pose. // Perhaps they would be better placed in another class so that they are not included when not needed. Assembly *GraspGLObjects::CreateHead( void ) { Assembly *head = new Assembly(); // Skull Ellipsoid *skull = new Ellipsoid( head_shape ); skull->SetColor( .4f, 0.0f, .4f ); // Eyes head->AddComponent( skull ); Sphere *sphere = new Sphere( 20.0 ); sphere->SetColor( 0.0f, 0.0f, 1.0f ); sphere->SetPosition( -50.0, 20.0, -100.0 ); head->AddComponent( sphere ); sphere = new Sphere( 20.0 ); sphere->SetColor( 0.0f, 0.0f, 1.0f ); sphere->SetPosition( 50.0, 20.0, -100.0 ); head->AddComponent( sphere ); // Nose Cylinder *cylinder = new Cylinder( 20.0, 5.0, 30.0 ); cylinder->SetPosition( 0.0, -20.0, - head_shape[Z] ); cylinder->SetOrientation( 0.0, 90.0, 0.0 ); cylinder->SetColor( YELLOW ); head->AddComponent( cylinder ); return head; }
/* * RayTracer class */ RayTracer::RayTracer() { const int spheresPerDimension = 3; // create objects for(int x = 0; x < spheresPerDimension; ++x) { for(int y = 0; y < spheresPerDimension; ++y) { for(int z = 0; z < spheresPerDimension; ++z) { if(((x+y+z) % 3) == 0) continue; Sphere *sphere = new Sphere(1.0f); sphere->SetReflectance(0.2f); sphere->SetOrigin(Vector((float)x, (float)y, (float)z) * 2.5f + Vector(-2.5f, -2.5f, 0.0f)); sphere->SetColor((x % 2) ? 1.0f : 0.5f, (y % 2) ? 1.0f : 0.5f, (z % 2) ? 1.0f : 0.5f); objects.insert(objects.end(), sphere); } } } }
Assembly *GraspGLObjects::CreateRoom( void ) { Assembly *structure = new Assembly(); structure->SetColor( BLACK ); // Tunnel tunnel = new Assembly(); Cylinder *cylinder = new Cylinder( room_radius, room_radius, room_length, room_facets ); cylinder->SetColor( WHITE ); cylinder->SetTexture( wall_texture ); cylinder->SetOrientation( 90.0, 0.0, 0.0 ); tunnel->AddComponent( cylinder ); // Reference Bars double bar_length = room_length - 5.0 * reference_bar_radius; for (int i=0; i < reference_bars; i++ ){ Cylinder *referenceBar = new Cylinder( reference_bar_radius, reference_bar_radius, bar_length, reference_bar_facets ); referenceBar->SetOffset( room_radius, 0.0, 0.0 ); referenceBar->SetOrientation( 90.0 + 180 * (float) i / (float) reference_bars, referenceBar->kVector ); referenceBar->SetColor( 1.0 - (double) i / reference_bars, 1.0f - (double) i / reference_bars, 1.0f - (double) i / reference_bars, 1.0 ); // The texturing on the bars may be commented out for the moment because it lengthens the rendering time too much. referenceBar->SetTexture( references_texture ); tunnel->AddComponent( referenceBar ); referenceBar = new Cylinder( reference_bar_radius, reference_bar_radius, bar_length, reference_bar_facets ); referenceBar->SetOffset( room_radius, 0.0, 0.0 ); referenceBar->SetOrientation( - 90.0 + 180 * (float) i / (float) reference_bars, referenceBar->kVector ); referenceBar->SetColor( (double) i / reference_bars, (double) i / reference_bars, (double) i / reference_bars, 1.0 ); // See above. referenceBar->SetTexture( references_texture ); tunnel->AddComponent( referenceBar ); } structure->AddComponent( tunnel ); Sphere *sphere = new Sphere( target_ball_radius ); sphere->SetPosition( 0.0, 0.0, room_length / 2.0 ); sphere->SetColor( RED ); structure->AddComponent( sphere ); return structure; }
Assembly *GraspGLObjects::CreateOrientationTarget( void ) { Assembly *target = new Assembly(); if ( useBars ) { for (int trg = - target_bars ; trg <= target_bars ; trg++ ){ Cylinder *cylinder = new Cylinder( target_bar_radius, target_bar_radius,2.0 * room_radius ); cylinder->SetPosition( 0.0 + target_bar_spacing * trg, 0.0, 0.0 ); cylinder->SetOrientation(0.0, 90.0, 0.0); cylinder->SetColor( Translucid( BLUE ) ); target->AddComponent( cylinder ); } } else { for (int trg = - target_balls ; trg <= target_balls ; trg++ ){ Sphere *sphere = new Sphere( target_ball_radius ); sphere->SetPosition( 0.0, 0.0 + target_ball_spacing * trg, 0.0 ); sphere->SetColor(( 255.0 - abs(trg) * 50.0 ) / 255.0, 0.0, 0.0); target->AddComponent( sphere ); } } return target; }