Пример #1
0
osg::Node* CreateScene()
{
    osg::Group* pGroup = new osg::Group;

    // osg:Light allows us to set default parameter values to be used by osg::LightSource
    // note: we do not use light number 0, because we do not want to override the osg default headlights
    osg::Light* pLight = new osg::Light;
    pLight->setLightNum( 4 );
    pLight->setDiffuse( osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) );
    pLight->setPosition( osg::Vec4(1,0,0,0) );		// last param	w = 0.0 directional light (direction)
    //				w = 1.0 point light (position)
    // light source
    osg::LightSource* pLightSource = new osg::LightSource;
    pLightSource->setLight( pLight );
    pGroup->addChild( pLightSource );

    pGroup->addChild( CreateSpheres( 0 ) );
    pGroup->addChild( CreateSpheres( 2 ) );
    pGroup->addChild( CreateSpheres( 4 ) );
    pGroup->addChild( CreateSpheres( 6 ) );

    pGroup->getOrCreateStateSet()->setMode( GL_LIGHT4, osg::StateAttribute::ON );

    return pGroup;
}
Пример #2
0
int main(void) 
{
   // set up for random num generator
  	//srand ( time(NULL) );
    srand ( 0);

   Image img(WINDOW_WIDTH, WINDOW_HEIGHT);
   Camera* cam = CameraInit();
   PointLight* light = LightInit();
   Ray* r = new Ray();
	double aspectRatio = WINDOW_WIDTH; 
	aspectRatio /= WINDOW_HEIGHT;
  
  	//SCENE SET UP
  	// (floor)
   Plane* floor = new Plane();
   //floor->center = CreatePoint(0, -1 * WINDOW_HEIGHT / 2, -1 * WINDOW_WIDTH / 2);
   //floor->color = CreateColor(200, 200, 200);
   //floor->normal = CreatePoint(0, 0, -1 * WINDOW_WIDTH / 2);
   // (spheres)
   Sphere* spheres = CreateSpheres();

	// RAY TRACING
	//
   
	r->origin = cam->eye;
   r->direction = cam->lookAt;
   r->direction.x = -1 * aspectRatio * tan(FOV / 2);

   for (int i=0; i < WINDOW_WIDTH; i++) {
   	r->direction.y = tan(FOV / 2);
		for (int j=0; j < WINDOW_HEIGHT; j++) {
         //Looping over the Rays
     		img.pixel(i, j, RayTrace(r, spheres, floor, light));
      		
      	//printf("o: (%lf, %lf, %lf)   ", r.origin.x, r.origin.y, r.origin.z);
         //printf("d: (%lf, %lf, %lf)\n", r.direction.x, r.direction.y, r.direction.z);
      		
      	r->direction.y -= 2 * tan(FOV / 2) / WINDOW_HEIGHT;
		}
		r->direction.x += 2 * tan(FOV / 2) / WINDOW_HEIGHT;
  	}
  	
	// IMAGE OUTPUT
	//
  	// write the targa file to disk
  	img.WriteTga((char *)"vanilla.tga", true); 
  	// true to scale to max color, false to clamp to 1.0
}