예제 #1
0
// This function called by both OpenGL (GLUT) and DirectX
void mouse_drag_func ( int x, int y )
{
	if ( guiMouseDrag ( x, y ) ) return;	// event handling for nv2D GUIs

	int dx = x - last_x;
	int dy = y - last_y;

	float deltx = window_width / cam.getToPos().z;
	float delty = window_height / cam.getToPos().z;
	
	// Camera interaction
	int mode = 0;
	switch ( mode ) {
	case 0:
		if ( dragging == DRAG_LEFT ) {
			glide += Vector3DF( dx / cam.getToPos().z, 0, 0);		
			cam.moveToPos ( 0, dy, 0 );
		} else if ( dragging == DRAG_RIGHT ) {	
			cam.moveToPos ( 0, 0, -dy*0.001 );
			if ( cam.to_pos.z < 0.001 ) cam.to_pos.z = 0.001;
		}
		break;	
	}
	last_x = x;
	last_y = y;
}
예제 #2
0
// Qt Streams
QDebug operator<<(QDebug dbg, const Camera3D &transform)
{
    dbg << "Camera3D\n{\n";
    dbg << "Position: <" << transform.translation().x() << ", " << transform.translation().y() << ", " << transform.translation().z() << ">\n";
    dbg << "Rotation: <" << transform.rotation().x() << ", " << transform.rotation().y() << ", " << transform.rotation().z() << " | " << transform.rotation().scalar() << ">\n}";
    return dbg;
}
예제 #3
0
char* initialize ( char* cmdline )
{
	// Get comnmand line
	std::string str = cmdline;
	std::vector<std::string>	args;
	while ( str.length() > 0) {
		args.push_back ( strSplit ( str, " " ) );		
	}
	fileName = "";
	for (int n=0; n < args.size(); n++ ) {
		if ( args[n].compare ( "-f" ) == 0 ) {
			startFrame = strToI ( args[n+1] );
		}
		if ( args[n].compare ( "-d" ) == 0 ) {		// max_draw
			maxDraw = strToI ( args[n+1] );
		}
		if ( args[n].find_first_of ( "." ) != std::string::npos ) {
			fileName = args[n];
		}
	}
	if ( fileName.length()== 0 || args.size()==0 ) {
		app_printf ( "USAGE:  state_view [-f #] [-d #] filename.raw\n\n" );
		app_printf ( "  -f #   Start at frame \n" );
		app_printf ( "  -d #   Maximum number of draw calls to read \n" );
		_getch();
		exit(-1);
	}

	for (int n=0; n < 10; n++ ) bShow[n] = true;

	// Initialize camera
	cam.setPos ( 0, 0, 1 );
	cam.setToPos ( -window_width*3/8, -window_height*3/8, 1 );
	cam.updateMatricies ();

	// Initialize bin and call names
	setup_bins ();

	// Load trace file	
	char fname[256];
	strcpy ( fname, fileName.c_str() );
	load_trace_raw ( fname );	

	// required init functions
	init2D ( "arial_12" );		// specify font file (.bin/tga)
	setText ( 1.0, -0.5 );		// scale by 0.5, kerning adjust -0.5 pixels
	setview2D ( window_width, window_height );

	// draw visualization layer
	drawMatrix ();
	
	PERF_INIT ( false );						// Enable CPU perf (do not require nv-perfmarker DLL)
	PERF_SET ( false, 2, false, "" );		// Perf CPU?, CPU level, NV Perfmarkers, Log filename

	return "NVIDIA State Viewer, by Rama Hoetzlein";	// Return Window title
}
예제 #4
0
// This function called by both OpenGL (GLUT) and DirectX
void mouse_move_func ( int x, int y )
{
	mSelectID = (((x-window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10;
	if ( mSelectID < 0 ) mSelectID = 0;
	if ( mSelectID > mEvents.size()-1 ) mSelectID = mEvents.size() -1;

	mSelectBin = ((y-window_height/2.0) - cam.getToPos().y) / 25;
	if ( mSelectBin < 0 ) mSelectBin = 0;
	if ( mSelectBin >= NUM_BIN ) mSelectBin = NUM_BIN-1;
}
void renderCamSetupGL ( Scene& scene, int prog )
{
	// Set model, view, projection matrices
	Camera3D* cam = scene.getCamera ();	
	Matrix4F ident;
	ident.Identity();	
	glProgramUniformMatrix4fv( prog, scene.getParam(prog, UMODEL), 1, GL_FALSE, ident.GetDataF() );
	glProgramUniformMatrix4fv( prog, scene.getParam(prog, UVIEW), 1, GL_FALSE, cam->getViewMatrix().GetDataF() ); 
	glProgramUniformMatrix4fv( prog, scene.getParam(prog, UPROJ), 1, GL_FALSE, cam->getProjMatrix().GetDataF() );
}
예제 #6
0
// Main display loop
void display () 
{
	cam.moveToPos ( glide.x, 0, 0  );
	glide.x *= 0.8;	
		
	PERF_PUSH ( "frame" );

	// Clear framebuffers. OpenGL
	glClearColor( 0.1, 0.1, 0.1, 0.0 );
	glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	drawOverlay ();

	drawGui ();

	draw2D ();

	#ifdef USE_DX
		// DirectX - Swap buffers		
		checkHR ( g_pSwapChain->Present ( 0, 0 ) );
	#else
		// OpenGL - Swap buffers
		SwapBuffers ( g_hDC );  		
	#endif

	PERF_POP ();

	frame++;
}
예제 #7
0
// This function called by both OpenGL (GLUT) and DirectX
void mouse_click_func ( int button, int state, int x, int y )
{
  cangs = cam.getAng();
  ctp = cam.getToPos();
  cdist = cam.getOrbitDist();

  if ( state==GLUT_DOWN && guiMouseDown ( x, y ) ) return;		// event handling for nv2D GUIs

  if( state == GLUT_DOWN ) {
    if ( button == GLUT_LEFT_BUTTON )		dragging = DRAG_LEFT;
    else if ( button == GLUT_RIGHT_BUTTON ) dragging = DRAG_RIGHT;	
    last_x = x;
    last_y = y;	
  } else if ( state==GLUT_UP ) {
    dragging = DRAG_OFF;
  }
}
void glut_program(void)
{
	//update camera
	float elapsedTime = timeCounter.getElapsedTimef();
	timeCounter.reset();
	cam.update(elapsedTime, -(300.0f-lastMY), 400.0f-lastMX);
	lastMX=400.0f;
	lastMY=300.0f;
	glutWarpPointer(400,300);
}
예제 #9
0
void AppWindow::mouse ( NVPWindow::MouseButton button, ButtonAction action, int mods, int x, int y )
{
	Vector3DF cangs, ctp;
	float cdist;
	Camera3D* cam = scene.getCamera ();
	cangs = cam->getAng();
	ctp = cam->getToPos();
	cdist = cam->getOrbitDist();

	if ( action==NVPWindow::BUTTON_PRESS && guiMouseDown ( x, y ) ) return;

	if( action==NVPWindow::BUTTON_PRESS ) {		
		dragging = (int) button;		
		last_x = x;
		last_y = y;	
	} else if ( action==NVPWindow::BUTTON_RELEASE ) {
		dragging = -1;
	}
}
예제 #10
0
void mouse(double x, double y){
	if(rotating){
		vec3 beg = screenToSphere(start.x, start.y);
		vec3 end = screenToSphere(x,HEIGHT-y);
		glm::vec3 axis = glm::normalize(glm::cross(beg,end));
		float phi = glm::distance(beg, end)/4;
		glm::vec3 newAxis = glm::normalize(glm::mat3(glm::inverse(glm::toMat4(trans.r))*glm::inverse(camera.getView()))*axis);
		trans.r = glm::rotate(trans.r, glm::degrees(phi)*0.3f, newAxis);
		start = gd->getMousePos();
	}
	if(translating){
		glm::vec2 delta = gd->getMousePos() - panStart;
		delta.x /= WIDTH; delta.y /= HEIGHT;
		glm::vec3 newDelta = glm::mat3(glm::inverse(glm::toMat4(trans.r))*glm::inverse(camera.getView()))*glm::vec3(delta.x,delta.y,0.0);
		trans.t = trans.t + newDelta*3.0f;
		panStart = gd->getMousePos();
	}
	camera.apply(trans);
}
void glut_keyboardUp(unsigned char key,int x,int y)
{
	switch(key)
	{
	case 'q':
	case 'a':
		cam.setLeft(false);
		break;
	case 'd':
		cam.setRight(false);
		break;
	case 'w':
	case 'z':
		cam.setForward(false);
		break;
	case 's':
		cam.setBackward(false);
		break;
	case ' ':
		cam.setUp(false);
		break;
	case 'c':
		cam.setDown(false);
		break;

	default:
		break;
	}
}
예제 #12
0
int main (int argc, char **argv)
{
  //Initialize GLUT
  initGlut( argc, argv );
  
  Kernel kernel;
  kernel.enableVerticalSync( false );
  printf( "Kernel loaded\n" );
  
  //Setup camera
  cam3D.setCenter( center );
  cam3D.translate( 0,0,200 );
  cam3D.orbitV( Util::DegToRad( -20 ), true );
  cam3D.orbitH( Util::DegToRad( +45 ), true );
  cam3D.setNearClipPlane( 10.0f );
  cam3D.setFarClipPlane( 1000.0f );
  
  //VertColorMaterial mat;
  //StandardMaterial mat;
  PhongMaterial mat;
  mat.setSpecularity( 0.5 );
  
  //StandardMaterial mat;
  //mat.setCullBack( false );
  //mat.setUseLighting( false );
  /*
  polyActor = new SPolyActor;
  polyActor->setMaterial( &mat );
  polyActor->setMesh( polyMesh );
  
  triActor = new TriMeshActor;
  triActor->setMaterial( &mat );
  triActor->setMesh( triMesh );
  */
  
  lblFps.setLocation( Vector2( 0.0f, (Float)resY ));
  lblFps.setColor( Vector3( 1.0f, 1.0f, 1.0f ));
  
  //Find model center
  findCenter();
  cam3D.setCenter( center );

  //Run application
  atexit( cleanup );
  glutMainLoop();
  cleanup();

  return EXIT_SUCCESS;
}
예제 #13
0
void BaseEntity::paintGL( Camera3D& camera, QMatrix4x4& projection )
{
    m_program->bind();

    m_program->setUniformValue( m_worldEye, camera.toMatrix() );
    m_program->setUniformValue( m_eyeClip, projection );

    m_vao->bind();
    m_texture->bind();

    m_program->setUniformValue( m_modelWorld, Transform.toMatrix() );

    glDrawArrays( GL_TRIANGLES, 0, m_numVertices );

    m_texture->release();
    m_vao->release();
    m_program->release();
}
예제 #14
0
void drag3D(int x, int y)
{
  if (down3D) {

    //printf ("Eye1:"); printVector (cam3D.getEye());
    //printf ("Look:"); printVector (cam3D.getLook());
    //printf ("Side:"); printVector (cam3D.getSide());
    //printf ("\n");
    
    //printf ("------------------------\n");
    //printMatrix (cam3D.getMatrix());
    
    Vector2 diff = Vector2((Float)x,(Float)y) - lastMouse3D;
    float eyeDist = (cam3D.getEye() - center).norm();
    
    Float angleH = diff.x * (2*PI) / 400;
    Float angleV = diff.y * (2*PI) / 400;
    Float panH = -diff.x * ( eyeDist * 0.002f );
    Float panV =  diff.y * ( eyeDist * 0.002f );
    Float zoom = -diff.y * ( eyeDist * 0.01f );
    lastMouse3D.set( (Float)x, (Float)y );
    
    switch (cameraMode)
    {  
    case CAMERA_MODE_ZOOM:

      cam3D.zoom (zoom);
      break;
      
    case CAMERA_MODE_ORBIT:
      
      cam3D.setCenter (center);
      cam3D.orbitH (angleH, true);
      cam3D.orbitV (angleV, true);
      break;

    case CAMERA_MODE_PAN:

      cam3D.panH (panH);
      cam3D.panV (panV);
      break;
    }
    
    postRedisplay ();
  }
}
예제 #15
0
void Skybox::paintGL( Camera3D& camera, QMatrix4x4& projection )
{
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LEQUAL );
    glDepthMask( GL_TRUE );
    glDisable( GL_CULL_FACE );

    program->bind();

    program->setUniformValue( worldEye, camera.toMatrix() );
    program->setUniformValue( eyeClip, projection );

    vao->bind();
    texture->bind();

    program->setUniformValue( modelWorld, transform.toMatrix() );

    glDrawArrays( GL_TRIANGLES, 0, numVertices );

    texture->release();
    vao->release();
    program->release();
}
예제 #16
0
void RunUniverse(const char *file)
{
    ifstream in;
    in.open(file);
    int cameras, i, j, maxiterations;
    double initstep, maxdistance, errscale;
    double position[4];
    double cameralook[16];
    string error;
    string output;
    int skip = 0;
    int coordinate;
    double M, a;
    Camera3D *cam;
    RungeKuttaForm *solver;
    BlackHole *bh;

    int pixh, pixv;
    double fovh, fovv, zoomh1, zoomh2, zoomv1, zoomv2;

    solver = RungeKutta::DormandPrince;
    /*solver = RungeKutta::Midpoint;
    solver = RungeKutta::Kutta;
    solver = RungeKutta::BogackiSchampine;
    solver = RungeKutta::CashKarp;
    solver = RungeKutta::Fehlberg;/**/

    in >> error;
    in >> output;

    in >> cameras;
    in >> initstep;
    in >> errscale;
    errscale *= 100;
    cout << "cameras: " << cameras << ". error: " << error << ". output: " << output << "." << endl;

    in >> M;
    in >> a;

    bh = new BlackHole(M, a);

    for(i = 0; i < cameras; i++)
    {
        in >> maxiterations;
        in >> maxdistance;

        in >> pixh;
        in >> pixv;
        in >> fovh;
        in >> fovv;
        in >> zoomh1;
        in >> zoomh2;
        in >> zoomv1;
        in >> zoomv2;
        in >> coordinate;

        for(j = 0; j < 4; j++) in >> position[j];

        for(j = 0; j < 16; j++) in >> cameralook[j];

        cam = new Camera3D(bh, position, cameralook, coordinate, CAMERA_FLAT, pixh, pixv, fovh, fovv, zoomh1, zoomh2, zoomv1, zoomv2);

        if(skip<1) {
            cam->Snapshot(solver, ((string)"c:\\dosgames\\kerr schild\\" + output +  stringify(i) + ".txt").c_str(), maxiterations>MAXSTEPS?MAXSTEPS:maxiterations, maxdistance, initstep, errscale, coordinate, CoordinateTest);
            cout << "snapshot complete!" << endl << flush;
        } else {skip--;}

        cout << "Image " << i << " complete!" << endl << flush;
        delete cam;
    }

    in.close();
}
예제 #17
0
int main (int argc, char **argv)
{
  //Initialize GLUT
  initGlut( argc, argv );
  
  Kernel kernel;
  kernel.enableVerticalSync( false );
  renderer = kernel.getRenderer();
  printf( "Kernel loaded\n" );

  StandardMaterial matRedLogo;
  matRedLogo.setSpecularity( 0.5 );
  matRedLogo.setDiffuseColor( Vector3(1,0,0) );
  matRedLogo.setAmbientColor( matRedLogo.getDiffuseColor() * .8f );

  StandardMaterial matWhiteLogo;
  matWhiteLogo.setSpecularity( 0.5 );
  matWhiteLogo.setAmbientColor( matWhiteLogo.getDiffuseColor() * .8f );

  StandardMaterial matWhite;
  matWhite.setSpecularity( 0.5 );

  StandardMaterial matBlue;
  matBlue.setSpecularity( 0.5 );
  matBlue.setDiffuseColor( Vector3(0,0.5,1) );

  StandardMaterial matGreen;
  matGreen.setSpecularity( 0.5 );
  matGreen.setDiffuseColor( Vector3(0,0.6,0) );

  StandardMaterial matYellow;
  matYellow.setSpecularity( 0.5 );
  matYellow.setDiffuseColor( Vector3(1,1,0.7) );

  StandardMaterial matBlack;
  matBlack.setSpecularity( 0.5 );
  matBlack.setDiffuseColor( Vector3(0.2,0.2,0.2) );

  MultiMaterial mm;
  mm.setNumSubMaterials( 5 );
  mm.setSubMaterial( 0, &matBlue );
  mm.setSubMaterial( 1, &matYellow );
  mm.setSubMaterial( 2, &matWhite );
  mm.setSubMaterial( 3, &matBlack );
  mm.setSubMaterial( 4, &matBlue );

  MultiMaterial mm2;
  mm2.setNumSubMaterials( 5 );
  mm2.setSubMaterial( 0, &matGreen );
  mm2.setSubMaterial( 1, &matYellow );
  mm2.setSubMaterial( 2, &matWhite );
  mm2.setSubMaterial( 3, &matBlack );
  mm2.setSubMaterial( 4, &matGreen );

  MultiMaterial mmLogo;
  mmLogo.setNumSubMaterials( 2 );
  mmLogo.setSubMaterial( 0, &matWhiteLogo );
  mmLogo.setSubMaterial( 1, &matRedLogo );

  //Setup Logo scene

  sceneLogo = new Scene;

  loadLogo( "logo.pak" );
  actLogo = new TriMeshActor;
  actLogo->setMesh( mshLogo );
  actLogo->translate( 200, 0, 0 );
  actLogo->setMaterial( &mmLogo );
  sceneLogo->addChild( actLogo );

  camLogo = new Camera3D;
  camLogo->translate( 0,0,-600 );
  camLogo->setNearClipPlane( 1.0f );
  camLogo->setFarClipPlane( 3000.0f );

  lightLogo = new SpotLight( Vector3(0,0,-500), Vector3(0,0,1), 60, 50 );
  lightLogo->setCastShadows( true );
  sceneLogo->addChild( lightLogo );

  //Setup Bub scene

  loadPackage( "bub.pak" );
  scene = new Scene;
  
  skinActor = new SkinMeshActor;
  skinActor->setMaterial( &mm );
  skinActor->setMesh( character );
  skinActor->translate( 60, 0, 0 );
  scene->addChild( skinActor );

  skinActor2 = new SkinMeshActor;
  skinActor2->setMaterial( &mm2 );
  skinActor2->setMesh( character );
  skinActor2->translate( -60, 0, 0 );
  scene->addChild( skinActor2 );

  TriMesh *cubeMesh = new CubeMesh;
  TriMeshActor *cube = new TriMeshActor;
  cube->setMaterial( &matWhiteLogo );
  cube->setMesh( cubeMesh );
  cube->scale( 300, 10, 300 );
  cube->translate( 0, -70, 0 );
  scene->addChild( cube );

  StandardMaterial axesMat;
  axesMat.setUseLighting( false );
  AxisActor *axes = new AxisActor;
  axes->scale( 100 );
  axes->setMaterial( &axesMat );
  //scene->addChild( axes );

  cam3D.setCenter( center );
  cam3D.translate( 0,0,-400 );
  cam3D.orbitV( Util::DegToRad( 20 ), true );
  cam3D.orbitH( Util::DegToRad( 30 ), true );
  cam3D.setNearClipPlane( 1.0f );
  cam3D.setFarClipPlane( 3000.0f );

  light = new SpotLight( Vector3(-200,200,-200), Vector3(1,-1,1), 60, 59 );
  light->setCastShadows( true );
  //light->setDiffuseColor( Vector3( 1,.2,.2 ) );
  scene->addChild( light );

  Light* l = new SpotLight( Vector3(200,200,-200), Vector3(-1,-1,1), 60, 0 );
  l->setCastShadows( true );
  //l->setDiffuseColor( Vector3( .2,.2,1 ) );
  scene->addChild( l );

  //Start with Logo scene
  sceneRender = sceneLogo;
  lightRender = lightLogo;
  camRender = camLogo;

  //sceneRender = scene;
  //lightRender = light;
  //camRender = &cam3D;

  ///////////////////////////////////////
  //Test triangulation
  PolyMesh p;
  int numVerts = 6;
  ArrayList< PolyMesh::Vertex* > verts;
  for (int v=0; v<numVerts; ++v)
    verts.pushBack( p.addVertex() );
  p.addFace( verts.buffer(), numVerts );

  verts[0]->point.set( 0,0,0 );
  verts[1]->point.set( 1,0,0 );
  verts[2]->point.set( 1,1,0 );
  verts[3]->point.set( 2,1,0 );
  verts[4]->point.set( 2,2,0 );
  verts[5]->point.set( 0,2,0 );
  p.triangulate();

  PolyMeshActor *pa = new PolyMeshActor;
  pa->setMesh( &p );
  pa->scale( 100, 100, 100 );
  //scene->addChild( pa );

  /////////////////////////////////
  
  lblFps.setLocation( Vector2( 0.0f, (Float)resY ));
  lblFps.setColor( Vector3( 1.0f, 1.0f, 1.0f ));
  
  //Find model center
  findCenter();
  cam3D.setCenter( center );

  //Run application
  atexit( cleanup );
  glutMainLoop();
  cleanup();

  return EXIT_SUCCESS;
}
void glut_render(void)
{
	//setup camera
	static Matrix4 viewMat;
	static Matrix4 MVP;
	cam.getViewMatrix(viewMat);
	MVP = projMat * viewMat;

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(MVP.toFloatPtr());

	const float screenRatio = (float)screenHeight/(float)screenWidth;

	//begin frame
	glClearColor(0.0,0.0,0.0,0.0);
	glClearDepth(1.0);
	glClear(GL_COLOR_BUFFER_BIT);

#ifdef GL_TIMER_QUERY_PERFORMANCE_MEASURE
	glBeginQuery(GL_TIME_ELAPSED,query);
#endif

	//render lines using additive blending and selected rendering path
	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);



	///////////// TODO RENDER
	glColor3f(1.0f,1.0f,1.0f);
//	glutWireTeapot(1.0);

	switch(renderingMethod)
	{
	case 0:
		testInstancing->render(TEST_INSTANCING_MAX_INSTANCE,NULL,MVP.toFloatPtr(),viewMat.toFloatPtr(),projMat.toFloatPtr());
		break;
	case 1:
		testInstancing->render(TEST_INSTANCING_MAX_INSTANCE,trianglePosition,MVP.toFloatPtr(),viewMat.toFloatPtr(),projMat.toFloatPtr());
		break;
	case 2:
		testInstancing->renderInstancing(TEST_INSTANCING_MAX_INSTANCE,NULL,MVP.toFloatPtr(),viewMat.toFloatPtr(),projMat.toFloatPtr());
		break;
	case 3:
		testInstancing->renderInstancing(TEST_INSTANCING_MAX_INSTANCE,trianglePosition,MVP.toFloatPtr(),viewMat.toFloatPtr(),projMat.toFloatPtr());
		break;
	default:
		break;
	}


#ifdef GL_TIMER_QUERY_PERFORMANCE_MEASURE
	glEndQuery(GL_TIME_ELAPSED);
	int done=0;
	while (!done)
	{
		glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &done);
	}
	// get the query result
	glGetQueryObjectui64v(query, GL_QUERY_RESULT, &elapsed_time);
	deltaTimeAccu+=elapsed_time;
	deltaTimeAccuCount++;
#endif


	//end of frame
	glFlush();
	glutSwapBuffers();
	glutPostRedisplay();

#ifdef _DEBUG
	GLenum err = glGetError();
	if(err!=GL_NONE)
	{
		//
		printf("OpenGL error!\n");
	}
#endif
}
예제 #19
0
void drawOverlay ()
{
	Vector4DF clr;

	Matrix4F proj, view, model;
	proj.Scale ( 2.0/window_width, -2.0/window_height, 1 );		
	model.Translate ( cam.getToPos().x, cam.getToPos().y, 1 );
	view.Scale ( cam.getToPos().z, 1, 1 );
	view *= model;
	model.Identity ();

	//----- 2D Drawing (visualizer space)	
	setview2D ( model.GetDataF(), view.GetDataF(), proj.GetDataF() );
	setorder2D ( false, 1 );
	updatestatic2D ( 0 );		// update model/view/proj matrices of each static draw layer
	updatestatic2D ( 1 );
	updatestatic2D ( 2 );
	updatestatic2D ( 3 );
		
	// Selector Bar
	start2D ();					
	  drawRect ( mSelectID*10, 0, mSelectID*10+10, NUM_BIN*25, 1,1,1,1 );

	// Same-State Highlights (yellow)
	int minE = (((0-window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10;
	int maxE = (((window_width - window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10;
	minE = ( minE < 0 ) ? 0 : minE;
	maxE = ( maxE >= mEvents.size() ) ? mEvents.size() : maxE;
	for (int n=0; n < mEvents.size(); n++ ) {
		if ( mEvents[n].bin_id[mSelectBin] == mEvents[mSelectID].bin_id[mSelectBin] && n > minE && n < maxE ) {
			drawRect ( n*10, mSelectBin*25, n*10+10, mSelectBin*25+24, 1,1,0,1 );
			drawRect ( n*10+1, mSelectBin*25+1, n*10+9, mSelectBin*25+23, 1,1,0,1 );
		}
	}
	end2D ();
	
	//----- 2D Drawing (screen space)	
	setview2D ( window_width, window_height );	// change to screen space
	setorder2D ( true, -0.00001 );
	
	start2D ();					// dynamic draw
	int panel_width = 200;
	float xoff = window_width - panel_width;
	float yoff = cam.getToPos().y + (window_height/2);

	// Left panel - Bin Text 
	char name[128];
	char msg[1024];

	int frame = mEvents[mSelectID].frame; 
	frame = (frame < 0 || frame >= mFrames.size() ) ? 0 : frame;
	Frame& f = mFrames[ frame ];

	drawFill ( 0, yoff, +panel_width, yoff + NUM_BIN*25+250, 0.15,0.15,0.2,0.75 );
	
	drawText ( 10, yoff-85, "Frame #:", 1,1,1,1 );
	drawText ( 10, yoff-70, "Frame Draws:", 1,1,1,1 );
	drawText ( 10, yoff-55, "Frame Prims:", 1,1,1,1 );
	drawText ( 10, yoff-40, "Frame Transfer:", 1,1,1,1 );	
	drawText ( 10, yoff-20, "Frame States:", 1,1,1,1 );	
	sprintf ( msg, "%d", frame );					drawText ( 100, yoff - 85, msg, 1,1,1,1 );	
	sprintf ( msg, "%d", f.totalDraw );				drawText ( 100, yoff - 70, msg, 1,1,1,1 );
	sprintf ( msg, "%d", f.totalPrim );				drawText ( 100, yoff - 55, msg, 1,1,1,1 );
	sprintf ( msg, "%d bytes", f.totalTransfer );	drawText ( 100, yoff - 40, msg, 1,1,1,1 );

	setText ( 0.8, 0 );
	drawText ( 100, yoff - 20, "Modify", 1,0,0,1 );
	drawText ( 125, yoff - 10, "Switch", 1,0.5,0,1 );
	drawText ( 150, yoff - 20, "Reuse", 0,1,0,1 );
	drawText ( 175, yoff - 10, "Unique", 1,1,1,1 );
	drawTri ( 100, yoff-10, 100+10, yoff-10, 100, yoff, 1, 0,0, 1);
	drawTri ( 125, yoff-10, 125+10, yoff-10, 125, yoff, 1,.5,0, 1);
	drawTri ( 150, yoff-10, 150+10, yoff-10, 150, yoff, 0, 1,0, 1);
	setText ( 1.0, -0.5 );

	for (int b=0; b < NUM_BIN; b++ ) {
		strncpy ( name, binNames[b].c_str(), 128 );
		drawText ( 8, yoff + b*25+12, name, 1,1,1,1 );

		clr.x = float(f.binChange[b]) / f.totalDraw;	if ( clr.x > 1 ) clr.x = 1;
		sprintf ( msg, "%d", f.binChange[b] );	drawText ( 100, yoff + b*25+12-2, msg, clr.x*0.7+0.3, 0,0,1 );	
		
		clr.x = float(f.binSwitch[b]) / f.totalDraw;	if ( clr.x > 1 ) clr.x= 1;
		sprintf ( msg, "%d", f.binSwitch[b] );	drawText ( 125, yoff + b*25+12+2, msg, clr.x*0.7+0.3,clr.x*.4+0.2,0,1 );
		
		clr.x = float(f.binReuse[b]) / f.totalDraw; 	if ( clr.x > 1 ) clr.x= 1;
		sprintf ( msg, "%d", f.binReuse[b] );	drawText ( 150, yoff + b*25+12-2, msg, 0, clr.x*0.7+0.3, 0,1 );

		sprintf ( msg, "%d", f.binUnique[b] );	drawText ( 175, yoff + b*25+12+2, msg, .7, .7, .7,1 );
	}

	int ys = NUM_BIN*25;
	float ypos; 
	sprintf ( msg, "%d", mMaxPrim/4 ); 
	drawLine ( 0, yoff + ys+25, 200, yoff+ys+25, .6, .6, .6, 1);	
	drawText ( 10, yoff+ys+25+15, msg, .8,.8,.8,1 );
	drawText ( 10, yoff + ys+80, "# Prims", 1, 1, 1, 1 );
	drawText ( 10, yoff+ys+125, "0", .8,.8,.8,1 );
	drawLine ( 0, yoff + ys+125, 200, yoff+ys+125, .6, .6, .6, 1);
	ypos = mEvents[ mSelectID ].bin_id[ BIN_DRAW ] * 400 / mMaxPrim;		// prim count	
	clr = getClr ( mEvents[ mSelectID ].bin_id[9] + 9*16384 );
	if ( ypos > 100 ) ypos = 100;			
	sprintf ( msg, "%d", mEvents[ mSelectID ].bin_id[BIN_DRAW] );
	drawLine ( 150, yoff+ys+(125-ypos), 200, yoff+ys+(125-ypos), clr.x,clr.y,clr.z,1 );
	drawText ( 150, yoff+ys+(125-ypos), msg, clr.x,clr.y,clr.z,1 );

	sprintf ( msg, "%d", mMaxSize ); 
	drawLine ( 0, yoff + ys+150, 200, yoff+ys+150, .6, .6, .6, 1);
	drawText ( 10, yoff+ys+150+15, msg, .8,.8,.8,1 );
	drawText ( 10, yoff + ys+200, "Transfer (bytes)" , 1, 1, 1, 1);
	drawText ( 10, yoff+ys+250, "0", .8,.8,.8,1 );
	drawLine ( 0, yoff + ys+250, 200, yoff+ys+250, .6, .6, .6, 1);
	ypos = mEvents[ mSelectID ].bin_size [ BIN_SIZE ] * 100 / mMaxSize;		// prim count
	if ( ypos > 100 ) ypos = 100;	
	sprintf ( msg, "%d", mEvents[ mSelectID ].bin_size [BIN_SIZE] );
	drawLine ( 150, yoff+ys+(250-ypos), 200, yoff+ys+(250-ypos), 1,1,1,1 );
	drawText ( 150, yoff+ys+(250-ypos), msg, 1,1,1,1 );
		
	// Right panel - Call Text		
	drawFill ( xoff, yoff, xoff + panel_width, yoff + NUM_BIN*25+250, 0.15,0.15,0.2,0.75 );	
	int cid;
	glColor3f ( 1, 1, 1);
	
	for (int c = 0; c < mEvents[ mSelectID ].call_num; c++ ) {	
		cid = mEvents[ mSelectID ].call_start + c;		
		clr = getClr ( mCalls[cid].val_id + mCalls[cid].bin_id*16384 );
		clr.w = 1;
		drawFill ( xoff+100, yoff + c*15, xoff+125, yoff+c*15+13, clr.x, clr.y, clr.z, clr.w );

		sprintf ( msg, "%s", mCalls[cid].name.c_str() );  
		drawText ( xoff+5, yoff + c*15+15, msg, 1,1,1,1 );

		sprintf ( msg, "%02d  %d %d", mCalls[cid].bin_id, mCalls[cid].size, mCalls[cid].val_id );
		drawText ( xoff+130, yoff + c*15+15, msg, 1,1,1,1 );
	}
	end2D ();
	
	

	#ifdef USE_DX
		g_pContext->OMSetDepthStencilState( g_pDepthStencilState, 1 );
	#endif
}
예제 #20
0
void drawMatrix ()
{
	Vector3DF id_clr;
	float ypos, yposl;
	int b, num = (int) mEvents.size();	

	Matrix4F proj, view, model;
	proj.Scale ( 2.0/window_width, -2.0/window_height, 1 );		
	model.Translate ( cam.getToPos().x, cam.getToPos().y, 1 );
	view.Scale ( cam.getToPos().z, 1, 1 );
	view *= model;
	model.Identity ();

	//----- 2D Drawing (visualizer space)		
	setview2D ( model.GetDataF(), view.GetDataF(), proj.GetDataF() );
	setorder2D ( false, 1 );

	// Event ID	bars	
	static2D ();	
	int fl = -1;
	char msg[100];
	for (int n=0; n < num; n++ ) {
		if ( mEvents[n].frame != fl ) {
			sprintf ( msg, "frame %d", mEvents[n].frame ); drawText ( n*10, -2, msg, 1,1,1,1 );
		}
		for (b=0; b < NUM_BIN; b++) {
			if ( mEvents[n].bin_id[b] == -1  ) {
				id_clr.Set ( 1, 1, 1 );
			} else if ( mEvents[n].bin_change[b] == 0 ) {
				id_clr.Set ( .2, .2, .2 );
			} else {
				id_clr = getClr ( mEvents[n].bin_id[b] + b*16384 );
			}
			drawFill ( n*10.0, b*25, n*10+10.0, b*25+24, id_clr.x, id_clr.y, id_clr.z, 1 );						
		}
		fl = mEvents[n].frame;
	}
	end2D ();

	// Change State bars
	static2D ();
	for (int n=0; n < num; n++ ) {
		for (b=0; b < NUM_BIN; b++) {
			if ( mEvents[n].bin_id[b] != -1 ) {
				switch ( mEvents[n].bin_change[b] ) {
				case BIN_NOTUSED:		id_clr.Set ( .2, .2, .2 );	break;		
				case BIN_CREATE:		id_clr.Set ( 1, 0, 0 );		break;
				case BIN_CHANGE:		id_clr.Set ( 1, 0, 0 );		break;
				case BIN_SWITCH:		id_clr.Set ( 1, .5, 0 );	break;
				case BIN_REUSE:		id_clr.Set ( 0, 1, 0 );		break;
				};				
				drawTri ( n*10, b*25, n*10+10, b*25, n*10, b*25+10, id_clr.x, id_clr.y, id_clr.z, 1 );
			}
		}
	}
	end2D ();

	int ys = NUM_BIN*25;
		
	// Prim count bars
	static2D();
	b = BIN_DRAW;
	for (int n=0; n < num; n++ ) {
		id_clr = getClr ( mEvents[n].bin_id[9] + 9*16384 );	
		ypos = mEvents[n].bin_id[ b ] * 400 / mMaxPrim;		// prim count
		if ( ypos > 100 ) ypos = 100;		
		drawFill ( n*10, ys+(125-ypos), n*10+10, ys+125, id_clr.x, id_clr.y, id_clr.z, 1 );
	}
	end2D ();
	
	// Mem transfer line
	static2D();
	yposl = 0;
	b = BIN_SIZE;
	for (int n=0; n < num; n++ ) {
		id_clr.Set(1,1,1);		
		ypos = mEvents[n].bin_size[ b ] * 100 / mMaxSize;		// size (bytes)
		if ( ypos > 100 ) ypos = 100;		
		drawLine ( n*10+5, ys+(250-ypos), n*10-5, ys+(250-yposl), 1, 1, 1, 1 );
		yposl = ypos;
	}
	drawLine ( 5, ys+250, num*10-5, ys+250, .5, .5, .5, 1 );
	end2D ();
}
예제 #21
0
int main (int argc, char **argv)
{  
  //Initialize GLUT
  initGlut(argc, argv);
  
  Kernel kernel;
  kernel.enableVerticalSync( false );
  renderer = kernel.getRenderer();
  printf( "Kernel loaded\n" );
  
  //Load shape model
  LoaderObj ldr;
  File f( "zekko.obj" );
  ldr.setUVMeshClass( Class( ETexMesh ));
  
  int start = GE::Time::GetTicks();
  ldr.loadFile( f.getPathName() );
  int end = GE::Time::GetTicks();
  printf( "Time: %d\n", end - start );
  
  PolyMesh *dmesh;
  uvmesh = (ETexMesh*) ldr.getFirstResource( Class(TexMesh) );
  dmesh = (PolyMesh*) ldr.getFirstResource( Class(PolyMesh) );
  zekko = (PolyMeshActor*) ldr.getFirstObject( Class(PolyMeshActor) );
  if (dmesh == NULL) return EXIT_FAILURE;
  if (uvmesh == NULL) return EXIT_FAILURE;
  if (zekko == NULL) return EXIT_FAILURE;
  
  //Check if UV mesh type correct
  printf( "uvmesh = %s\n", StringOf( ClassOf( zekko->getTexMesh() )));
  
  printf( "uvmesh %s ETexMesh\n",
          SafeCast( ETexMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s TexMesh\n",
          SafeCast( TexMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s Resource\n",
          SafeCast( Resource, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s PolyMesh\n",
          SafeCast( PolyMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  //Setup camera
  cam3D.translate( 0,35,-100 );
  cam3D.setCenter( center );
  //cam3D.setNearClipPlane(100.0f);
  //cam3D.setFarClipPlane(100000.0f);
  
  //Find model center
  findCenter();
  
  //Set half bunny green
  for (PolyMesh::FaceIter f(dmesh); !f.end(); ++f) {
    //f->smoothGroups = 0x1;
    if (f->firstHedge()->dstVertex()->point.y > center.y)
      dmesh->setMaterialID( *f, 1 ); }

  //Convert to static mesh
  //dmesh->updateNormals();
  smesh.fromPoly( dmesh, uvmesh );
  
  //Load texture image
  imgDiff.readFile( "texture.jpg", "" );
  
  //Create texture from image
  texDiff = new Texture;
  texDiff->fromImage( &imgDiff );
  
  //Load specularity image
  Image imgSpec;
  imgSpec.readFile( "specularity.jpg", "" );

  //Create specularity texture
  texSpec = new Texture();
  texSpec->fromImage(&imgSpec);
  
  //Create material using texture
  PhongMaterial mat;
  mat.setDiffuseTexture( texDiff );
  //mat.setSpecularityTexture( texSpec );
  mat.setDiffuseColor( Vector3( 1,0.0f,0.0f ));
  mat.setAmbientColor( Vector3( 0.2f,0.2f,0.2f ));
  mat.setSpecularity( 1.0f );
  mat.setGlossiness( 0.2f );
  
  PhongMaterial mat2;
  mat2.setDiffuseTexture( texDiff );
  //mat2.setSpecularityTexture( texSpec );
  mat2.setDiffuseColor( Vector3( 0.0f, 1.0f, 0.0f ));
  mat2.setAmbientColor( Vector3( 0.2f, 0.2f, 0.2f ));
  mat2.setSpecularity( 1.0f );
  mat2.setGlossiness( 0.2f );
  
  MultiMaterial mm;
  mm.setNumSubMaterials( 2 );
  mm.setSubMaterial( 0, &mat );
  mm.setSubMaterial( 1, &mat2 );
  zekko->setMaterial( &mm );

  scene = new Scene;
  scene->addChild( zekko );

  //Light *light = new SpotLight( Vector3(-200,200,-200), Vector3(1,-1,1), 60, 0 );
  Light *light = new HeadLight;
  scene->addChild( light );
  
  lblFps.setLocation( Vector2( 0.0f,(Float)resY ));
  lblFps.setColor( Vector3( 1.0f,1.0f,1.0f ));
  
  //Run application
  atexit( cleanup );
  glutMainLoop();
  cleanup();

  return EXIT_SUCCESS;
}
예제 #22
0
void render(){
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	camera.look();	
	
	glColor4f(1,1,1,0.5);
	glBegin(GL_LINES);
		for(int i = 0; i <= W; i++){
			glm::vec2 p = g.gridToWorld(glm::vec2(i,0)); p -= g.cellSize*0.5f;
			glVertex2f(p.x, p.y); 
			p = g.gridToWorld(glm::vec2(i,H)); p -= g.cellSize*0.5f;
			glVertex2f(p.x, p.y);
		}
		for(int i = 0; i <= H; i++){
			glm::vec2 p = g.gridToWorld(glm::vec2(0,i)); p -= g.cellSize*0.5f;
			glVertex2f(p.x, p.y); 
			p = g.gridToWorld(glm::vec2(W,i)); p -= g.cellSize*0.5f;
			glVertex2f(p.x, p.y);
		}
	glEnd();

	glPointSize(5.0);
	glBegin(GL_POINTS);
		glColor3f(1,0,1);
		for(int i = 0; i < W; i++)
			for(int j = 0; j < H; j++){
				glm::vec2 p = g.gridToWorld(glm::vec2(i,j));
				glVertex2f(p.x,p.y);
			}
			
		for(int i = 0; i < W; i++)
			for(int j = 0; j < H; j++){
				float c = g(i,j);
				glColor3f(c,c,c);
				glm::vec2 p = g.gridToWorld(glm::vec2(i,j));
				if(c > 0.0)
					glVertex3f(p.x,p.y,0.1);
				else glVertex2f(p.x,p.y);
			}
			
		//std::cerr << g.sample(1*g.cellSize,1*g.cellSize) << std::endl;
		//glColor3f(1,1,1);
		//glVertex3f(1*g.cellSize,1*g.cellSize,0.1);
		float step = 1.0/5.0;
		float s1 = -g.cellSize;
		while(s1 < ((float)W)*g.cellSize){
			float s2 = -g.cellSize;
			while(s2 < ((float)H)*g.cellSize){
				float c = g.sample(s1,s2);
				glColor3f(c,c,c);
				glVertex2f(s1,s2);
				s2 += step;
			}
			s1 += step;
		}
	glEnd();
}
예제 #23
0
void mouseScroll(double x, double y){
	if(y < 0.0)
		trans.s *= 0.95;
	else 	trans.s *= 1.05;
	camera.apply(trans);
}
예제 #24
0
bool AppWindow::init ()
{
	// Get comnmand line
	std::string str = getCmdLine();
	if ( str == "" )
		str = "-i lucy.scn -s 8";

	std::vector<std::string>	args;
	while ( str.length() > 0) {
		args.push_back ( strSplit ( str, " " ) );		
	}
	std::string filename = "";
	for (int n=0; n < args.size(); n++ ) {
		if ( args[n].compare ( "-p" ) == 0 ) {		// added path
			scene.AddPath ( std::string( args[n+1] ) );			
		}
		if ( args[n].compare ( "-i" ) == 0 ) {		// input file (scn)
			filename = args[n+1];
		}
		if ( args[n].compare ( "-t" ) == 0 ) {		// timing output
			gTimingFile = "timing.csv";
		}
		if ( args[n].compare ( "-s" ) == 0 ) {		// # samples
			num_samples = atoi ( args[n+1].c_str() );
		}
	}

	// Write timing file
	gTimingFP = 0x0;
	if ( gTimingFile != "" ) {
		char name[1024];
		strcpy ( name, gTimingFile.c_str() );
		gTimingFP = fopen ( name, "wt" );
	}

	nvprintf  ( "OpenGL + OptiX Compositing Demo\n" );
	nvprintf  ( "Copyright (c) 2014, NVIDIA Corporation\n" );	

	//-------- GUI
	addGui (  20,  20, 200, 24, "Frame Time (ms)",		GUI_PRINT,  GUI_FLOAT,	&frameTime, 0, 0 );

	//-------- Scene 
	
	// Create camera
	nvprintf  ( "Creating camera...\n" );
	Camera3D* cam = scene.AddCamera ();
	cam->setOrbit ( Vector3DF(45,30,0), Vector3DF(0,0,0), 120, 120 );
	cam->setNearFar ( 1, 1000 );
	cam->setFov ( 71.635 );
	cam->updateMatricies ();

	// Create model(s)
	nvprintf ( "Creating model(s)...\n" );
	nvprintf ( "  Project path: %s\n", std::string(PROJECT_ABSDIRECTORY).c_str() );
	scene.AddPath ( "..\\assets\\" );
	scene.AddPath ( "..\\shaders\\" );
	scene.AddPath ( std::string(PROJECT_RELDIRECTORY) );
	scene.AddPath ( std::string(PROJECT_RELDIRECTORY) + "\\assets\\" );
	scene.AddPath ( std::string(PROJECT_RELDIRECTORY) + "\\shaders\\" );
	scene.AddPath ( std::string(PROJECT_ABSDIRECTORY) );
	scene.AddPath ( std::string(PROJECT_ABSDIRECTORY) + "\\assets\\" );
	scene.AddPath ( std::string(PROJECT_ABSDIRECTORY) + "\\shaders\\" );
	scene.LoadFile ( filename );
	
	// Initialize fonts
	/* init2D ( "data/arial_24" );
	setText ( 0.5, -0.5 );
	setview2D ( getWidth(), getHeight() );
	setorder2D ( true, -0.00001 );*/		

	//MoveWindow ( 5, 5, window_width, window_height );

	// Setup OpenGL default render
	nvprintf  ( "Creating OpenGL shader...\n" );
	renderAddShaderGL    ( scene, "render_GL.vert.glsl", "render_GL.frag.glsl" );

	// Setup OptiX
	#ifdef BUILD_OPTIX
		nvprintf  ( "Creating Optix shader..\n" );
		renderAddShaderOptix ( scene, "render_Optix.vert.glsl", "render_Optix.frag.glsl" );
		nvprintf  ( "Initializing Optix..\n" );
		renderInitializeOptix ( getWidth(), getHeight() );
		nvprintf  ( "Adding models to Optix..\n" );
		int mat_id = renderAddMaterialOptix ( scene, "optix_shadow_rays.ptx" );
		
		for (int n=0; n < scene.getNumModels(); n++ )
			renderAddModelOptix ( scene.getModel(n), mat_id );

		nvprintf  ( "Validating Optix..\n" );				
		renderValidateOptix ();
	#endif

	// Setup OptiX Prime
	#ifdef BUILD_OPTIX_PRIME
		nvprintf  ( "Creating Optix Prime shader..\n" );		
		renderAddShaderOptixPrime ( scene, "render_Optix.vert.glsl", "render_Optix.frag.glsl" );
		nvprintf  ( "Initializing Optix Prime..\n" );
		renderInitializeOptixPrime ( scene, getWidth(), getHeight() );
		nvprintf  ( "Adding models to Optix..\n" );		
		for (int n=0; n < 1; n++ )
			renderAddModelOptixPrime ( scene.getModel(n) );
	#endif

	draw_mode = MODE_OPENGL;
	#ifdef BUILD_OPTIX
		draw_mode = MODE_OPTIX;
	#else
		nvprintf ( "***** ERROR:\n" );
		nvprintf ( " OptiX 3.6.3 was not found.\n");
		nvprintf ( " Please specify CUDA_LOCATION variable for CUDA 5.5 during cmake generate step.\n" );
		nvprintf ( " Running sample with OpenGL only. No hard shadows will appear.\n");
		nvprintf ( "*****\n\n" );
	#endif
	cam_mode = MODE_CAMERA;
	
	PERF_INIT ( 64, true, false, false, 0, "" );		// 32/64bit, CPU?, GPU?, Cons out?, Level, Log file	

	return "OpenGL + OptiX Compositing";
}
예제 #25
0
void AppWindow::motion ( int x, int y )
{
	int dx = last_x - x;
	int dy = y - last_y;

	// Handle GUI interaction in nvGui by calling guiMouseDrag
	if ( guiMouseDrag ( x, y ) ) return;

	// Camera interaction
	Camera3D* cam = scene.getCamera ();	
	switch ( cam_mode ) {
	case MODE_CAMERA:
		if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT ) {
			Vector4DF angs = cam->getAng();
			angs.x += dx*.1;
			angs.y += dy*.1;
			cam->setOrbit ( angs, cam->getToPos(), cam->getOrbitDist(), cam->getOrbitDist() );
			//cam->moveOrbit ( dx*.1, dy*.1, 0, 0 );
		} else if ( dragging == NVPWindow::MOUSE_BUTTON_MIDDLE ) {
			cam->moveRelative ( dx*.1, dy*.1, 0 );		
		} else if ( dragging == NVPWindow::MOUSE_BUTTON_RIGHT ) {
			float orb = cam->getOrbitDist() + dy*0.1;
			cam->setOrbit ( cam->getAng(), cam->getToPos(), orb, orb);			
		} 
		break;
	case MODE_FOV:
		if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT  ) {
			cam->setFov ( cam->getFov() + dy*.1 );
		}
		break;
	case MODE_LIGHT:				
		Light* light = scene.getLight();
		if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT  ) {
			light->moveOrbit ( dx*0.1, dy*0.1, 0, 0 );
		} else if ( dragging == NVPWindow::MOUSE_BUTTON_RIGHT ) {
			light->moveOrbit ( 0, 0, dy*0.1, 0 );
		}
		break;	
	}
	last_x = x;
	last_y = y;	
}