Пример #1
0
/**
 * Update object's queue connections and timer, depending on object's settings
 * \param[in] obj Object to updates
 */
static void updateObject(UAVObjHandle obj)
{
	UAVObjMetadata metadata;
	int32_t eventMask;

	// Get metadata
	UAVObjGetMetadata(obj, &metadata);

	// Setup object depending on update mode
	if (metadata.telemetryUpdateMode == UPDATEMODE_PERIODIC) {
		// Set update period
		setUpdatePeriod(obj, metadata.telemetryUpdatePeriod);
		// Connect queue
		eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
		if (UAVObjIsMetaobject(obj)) {
			eventMask |= EV_UNPACKED;	// we also need to act on remote updates (unpack events)
		}
		UAVObjConnectQueue(obj, priorityQueue, eventMask);
	} else if (metadata.telemetryUpdateMode == UPDATEMODE_ONCHANGE) {
		// Set update period
		setUpdatePeriod(obj, 0);
		// Connect queue
		eventMask = EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ;
		if (UAVObjIsMetaobject(obj)) {
			eventMask |= EV_UNPACKED;	// we also need to act on remote updates (unpack events)
		}
		UAVObjConnectQueue(obj, priorityQueue, eventMask);
	} else if (metadata.telemetryUpdateMode == UPDATEMODE_MANUAL) {
		// Set update period
		setUpdatePeriod(obj, 0);
		// Connect queue
		eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
		if (UAVObjIsMetaobject(obj)) {
			eventMask |= EV_UNPACKED;	// we also need to act on remote updates (unpack events)
		}
		UAVObjConnectQueue(obj, priorityQueue, eventMask);
	} else if (metadata.telemetryUpdateMode == UPDATEMODE_NEVER) {
		// Set update period
		setUpdatePeriod(obj, 0);
		// Disconnect queue
		UAVObjDisconnectQueue(obj, priorityQueue);
	}
}
Пример #2
0
// **************************************************************
void MainScene::init()
{
	// Enables vector normalization
	glEnable(GL_NORMALIZE);

	initGlobals();
	initCameras();
	initLights();

	unsigned long updatePeriod = 50;
	setUpdatePeriod(updatePeriod);

	display();
}
Пример #3
0
void XMLScene::init()
{
	glEnable(GL_LIGHTING);
	file->loadFile();
	data = new GameData();
	camera = file->camera;
	activeLights.clear();
	for(unsigned int i=0;i<file->sceneLights.size();i++)
		if(file->sceneLights[i]->isEnabled())
			activeLights.push_back(1);
		else activeLights.push_back(0);
		glMatrixMode(GL_MODELVIEW);
		//calcs tranformations on primitives
		file->sceneGraph->calcPrimitives();
		activeCamera->setX(0);
		activeCamera->setY(0);
		activeCamera->setZ(-20);
		activeCamera->setRotation(2,0);
		activeCamera->setRotation(1,0);
		activeCamera->setRotation(0,90);
		setUpdatePeriod(25);
		scoreBoard = new SceneCube();
}
Пример #4
0
void LightingScene::init() 
{
	// Enables lighting computations
	glEnable(GL_LIGHTING);

	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);  
	
	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientLight);  
	//glShadeModel(GL_FLAT);
	// Declares and enables two lights, with null ambient component

	light0 = new CGFlight(GL_LIGHT0, light0_pos);
	light0->setAmbient(ambientNull);

	light0->disable();
	light0->setSpecular(yellow);
	light0->enable();
	light0_state=true;


	light1 = new CGFlight(GL_LIGHT1, light1_pos);
	light1->setAmbient(ambientNull);
	
	light1->disable();
	light1->enable();
	light1_state=true;

	light2 = new CGFlight(GL_LIGHT2, light2_pos);
	light2->setAmbient(ambientNull);
	
	light2->disable();
	light2->setKc(0);
	light2->setKl(1);
	light2->setKq(0);
	light2->enable();
	light2_state=true;

	light3 = new CGFlight(GL_LIGHT3, light3_pos);
	light3->setAmbient(ambientNull);
	
	light3->disable();
	light3->setKc(0);
	light3->setKl(0);
	light3->setKq(0.2);
	light3->enable();
	light3_state=true;

	// Uncomment below to enable normalization of lighting normal vectors
	 glEnable (GL_NORMALIZE);

	//Declares scene elements
	 robot = new MyRobot(180,4,4,7);
	 sceneVar=0;
	 t = CGFapplication::getTime();
	 aviao=new MyPaperPlane(90,4,4,8);
	clock1= new MyClock();
	table = new myTable();
	floor = new Plane(10, 0, 0, 0 , 0, 2);
	wallWindow = new Plane(10, 0, 16,0-3.5, 8.53-3.5,1);
	wall = new Plane(10, 0, 16,0-3.5, 8.53-3.5,1);
	boardA = new Plane(BOARD_A_DIVISIONS,0, 512, 0, 512);
	boardB = new Plane(BOARD_B_DIVISIONS,0, 512, 0-70, 372-70);
	

	//Declares materials
	materialA = new CGFappearance(ambA,difA,specA,shininessA);
	materialB = new CGFappearance(ambB,difB,specB,shininessB);
	
	slidesAppearance = new CGFappearance(ambSA,difSA,specSA,shininessSA);
	slidesAppearance->setTexture("slides.png");

	boardAppearance = new CGFappearance(ambBA,difBA,specBA,shininessBA);
	boardAppearance->setTexture("board.png");
	boardAppearance->setTextureWrap(GL_CLAMP,GL_CLAMP);


	windowAppearance = new CGFappearance(ambW,difW,specW,shininessW);
	windowAppearance->setTexture("window.png");
	windowAppearance->setTextureWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);

	
		 
	floorAppearance = new CGFappearance(ambF,difF,specF,shininessF);
	floorAppearance->setTexture("floor.png");
	floorAppearance->setTextureWrap(GL_REPEAT, GL_REPEAT);

	
	setUpdatePeriod(100);

}
Пример #5
0
void LightingScene::init() 
{
	// Enables lighting computations
	glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);
	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);  
	
	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientNull);  
	
	// Declares and enables two lights, with null ambient component

	glShadeModel(GL_SMOOTH);


	light0 = new CGFlight(GL_LIGHT0, light0_pos);
	light0->setAmbient(ambientNull);
	light0->setSpecular(yellow);
	//light0->disable();
	light0->enable();

	light1 = new CGFlight(GL_LIGHT1, light1_pos);
	light1->setAmbient(ambientNull);
	
	//light1->disable();
	light1->enable();
	
	


	// Uncomment below to enable normalization of lighting normal vectors
	// glEnable (GL_NORMALIZE);

	//Declares scene elements
	table = new myTable();
	wall = new Plane();
	clock = new myClock();
	cylinder = new myCylinder(10,10, true);
	cylinder1 = new myCylinder(10,10,false);

	boardA = new Plane(BOARD_A_DIVISIONS);
	boardB = new Plane(BOARD_B_DIVISIONS);
	
	//Declares materials
	materialA = new CGFappearance(ambientNull,difA,specA,shininessA);
	materialB = new CGFappearance(ambientNull,difB,specB,shininessB);
	
	//Declares Textures
	tableAppearence = new CGFappearance(ambientNull,difA,specA,shininessA);
	tableAppearence->setTexture("table.png");
	tableAppearence->setTextureWrap(GL_REPEAT,GL_REPEAT);
	
	slidesAppearence = new CGFappearance(ambientNull,difSlides,specSlides,shininessSlides);
	slidesAppearence->setTexture("slides.png");
	slidesAppearence->setTextureWrap(GL_CLAMP,GL_CLAMP);
	
	boardAppearence = new CGFappearance(ambientNull,difBoard,specBoard,shininessBoard);
	boardAppearence->setTexture("board.png");
	boardAppearence->setTextureWrap(GL_CLAMP,GL_CLAMP);
	setUpdatePeriod(100);
}
Пример #6
0
void LightingScene::init() 
{
	cl = l0 = l1  = l2 = l3 = l4 = l5 = 1;
	wire = t0  = tp  =sceneVar = 0;
	texture = 0;

	// Enables lighting computations
	glEnable(GL_LIGHTING);

	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);  

	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientLight);  

	glShadeModel(GL_SMOOTH);
	// Declares and enables two lights, with null ambient component

	light0 = new CGFlight(GL_LIGHT0, light0_pos);
	light0->setAmbient(ambientNull);
	light0->setSpecular(yellow);


	light1 = new CGFlight(GL_LIGHT1, light1_pos);
	light1->setAmbient(ambientNull);


	light2 = new CGFlight(GL_LIGHT2, light2_pos);
	light2->setAmbient(ambientNull);
	light2->setKc(0);
	light2->setKl(1);
	light2->setKq(0);


	light3 = new CGFlight(GL_LIGHT3, light3_pos);
	light3->setAmbient(ambientNull);
	light3->setSpecular(yellow);
	light3->setKc(0);
	light3->setKl(0);
	light3->setKq(1);



	light4 = new CGFlight(GL_LIGHT4, light4_pos);
	light4->setAmbient(ambientNull);

	light5 = new CGFlight(GL_LIGHT5, light5_pos);
	light5->setAmbient(ambientNull);






	// Uncomment below to enable normalization of lighting normal vectors
	glEnable (GL_NORMALIZE);
	glEnable (GL_TEXTURE_2D);

	//Declares scene elements
	table = new myTable();
	wall = new Plane();
	boardA = new Plane(BOARD_A_DIVISIONS);
	boardB = new Plane(BOARD_B_DIVISIONS);
	cylinder1 = new myCylinder(8,20,true);
	cylinder2 = new myCylinder(8,20,false);
	clock = new myClock(12,5,true);
	lamp = new myLamp(100,20);
	robot = new myRobot(10);
	impostor = new myImpostor(150,150);
	holedWall = new myWall(5,5);
	//Declares materials
	materialA = new CGFappearance(ambA,difA,specA,shininessA);
	materialB = new CGFappearance(ambB,difB,specB,shininessB);
	slidesAppearance = new CGFappearance(ambsA,difsA,specsA,shininesssA);
	boardAppearance = new CGFappearance(ambbA,difbA,specbA,shininessbA);
	windowAppearance = new CGFappearance(ambbA,difbA,specbA,shininessbA);
	clockAppearance = new CGFappearance(ambcA,difcA,speccA,shininesscA);
	robotAppearance = new CGFappearance(ambM,difM,specM,shininessM);
	impostorAppearance = new CGFappearance(ambB,difB,specB,shininessB);

	floorAppearance = new CGFappearance(ambfA,diffA,specfA,shininessfA);

	slidesAppearance->setTexture("slides.png");

	boardAppearance->setTexture("board.png");
	boardAppearance->setTextureWrap(GL_CLAMP,GL_CLAMP);

	windowAppearance->setTexture("window.png");
	windowAppearance->setTextureWrap(GL_CLAMP,GL_CLAMP);

	clockAppearance->setTexture("clock.png");
	clockAppearance->setTextureWrap(GL_CLAMP,GL_CLAMP);

	floorAppearance->setTexture("floor.png");

	robotAppearance->setTexture("robot1.png");
	robotAppearance->setTextureWrap(GL_CLAMP,GL_CLAMP);

	impostorAppearance->setTexture("360.jpg");
	impostorAppearance->setTextureWrap(GL_CLAMP,GL_CLAMP);

	setUpdatePeriod(100);
}
Пример #7
0
void YafScene::init(){

	// Globals //

	// Background color //
	glClearColor( sg->getbgx(), sg->getbgy(), sg->getbgz(), sg->getbga() );

	// Drawmode //
	if( sg->getDrawmode() == "fill" )
		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
	else
		if( sg->getDrawmode() == "line" )
			glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
		else
			if( sg->getDrawmode() == "point" )
				glPolygonMode( GL_FRONT_AND_BACK, GL_POINT );

	// Shading //
	if( sg->getShading() == "flat" )
		glShadeModel( GL_FLAT );
	else
		glShadeModel( GL_SMOOTH );

	// Cullface //
	if( sg->getCullface() == "front" )
		glCullFace( GL_FRONT );
	else
		if( sg->getCullface() == "back" )
			glCullFace( GL_BACK );
		else
			if( sg->getCullface() == "both" )
				glCullFace( GL_FRONT_AND_BACK );

	// Cullorder //
	if( sg->getCullorder() == "CW" )
		glFrontFace( GL_CW );
	else
		glFrontFace( GL_CCW );

	// Lighting //

	// Doublesided //
	if( sg->getDoublesided() == "true" )
		glLightModelf( GL_LIGHT_MODEL_TWO_SIDE, 1 );
	else
		glLightModelf( GL_LIGHT_MODEL_TWO_SIDE, 0 );

	// Local //
	if( sg->getLocal() == "true" )
		glLightModelf( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 );
	else
		glLightModelf( GL_LIGHT_MODEL_LOCAL_VIEWER, 0 );

	// Enabled //
	if( sg->getLightingEnabled() == "true" )
		glEnable(GL_LIGHTING);

	// Ambient //
	glLightModelfv( GL_LIGHT_MODEL_AMBIENT, sg->getLightingAmbientValues() );	


	for( map<string, Camera*>::iterator it = sg->getCameras()->begin(); it != sg->getCameras()->end(); it++ ){	
		this->scene_cameras.push_back( it->second );
	}

	//sg->getLights()->at( sg->getInitialCamera() )->setToogled(1);
	sg->setActualCamera(4);

	// Defines a default normal
	glNormal3f(0,0,1);

	// Animation-related code
	unsigned long updatePeriod=30;
	setUpdatePeriod(updatePeriod);

	glutReshapeWindow( 1024, 768 );

	vector<Appearence*> stack;
	stack.clear();
	initGraph( this->sg->getRootid(), stack );
}
Пример #8
0
void LightingScene::init() 
{
	sceneVar=0;
	light0On = 1;
	light1On = 1;
	light2On = 0;
	light3On = 0;
	textureSelector = 1;
	wire = 0;
	landscapeSelector = 0;

	clockAnimation = true;
	// Enables lighting computations
	glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);
	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);  

	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientLight);  

	// Declares and enables two lights, with null ambient component

	glShadeModel(GL_SMOOTH);


	light0 = new CGFlight(GL_LIGHT0, light0_pos);
	light0->setAmbient(ambientNull);
	light0->setSpecular(yellow);

	if (light0On == 0)
		light0->disable();
	else
		light0->enable();


	light1 = new CGFlight(GL_LIGHT1, light1_pos);
	light1->setAmbient(ambientNull);

	if (light1On == 0)
		light1->disable();
	else
		light1->enable();


	light2 = new CGFlight(GL_LIGHT2, light2_pos);
	light2->setAmbient(ambientNull);

	if (light2On == 0)
		light2->disable();
	else
		light2->enable();



	light3 = new CGFlight(GL_LIGHT3, light3_pos);
	light3->setAmbient(ambientNull);
	light3->setSpecular(yellow);
	light3->setKc(0);
	light3->setKl(0);
	light3->setKq(1);

	if (light3On == 0)
		light3->disable();
	else
		light3->enable();


	dayLight =  new CGFlight(GL_LIGHT3, light5_pos);
	dayLight->setAmbient(white);
	dayLight->setSpecular(white);

	dayLight->enable();


	// Uncomment below to enable normalization of lighting normal vectors
	// glEnable (GL_NORMALIZE);

	//Declares scene elements
	table = new myTable();
	wall = new Plane();
	floor = new Plane();
	clock = new myClock();
	cylinder = new myCylinder(10,10, true);
	cylinder1 = new myCylinder(10,10,false);
	skybox = new myCylinder(60,10,true);
	robot = new myRobot(10);

	boardA = new Plane(BOARD_A_DIVISIONS);
	boardB = new Plane(BOARD_B_DIVISIONS);

	//Declares materials
	materialA = new CGFappearance(ambientNull,difA,specA,shininessA);
	materialB = new CGFappearance(ambientNull,difB,specB,shininessB);

	//Declares Textures
	tableAppearence = new CGFappearance(ambientNull,difA,specA,shininessA);
	tableAppearence->setTexture("table.png");
	tableAppearence->setTextureWrap(GL_REPEAT,GL_REPEAT);

	slidesAppearence = new CGFappearance(ambientNull,difSlides,specSlides,shininessSlides);
	slidesAppearence->setTexture("slides.png");
	slidesAppearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	boardAppearence = new CGFappearance(ambientNull,difBoard,specBoard,shininessBoard);
	boardAppearence->setTexture("board.png");
	boardAppearence->setTextureWrap(GL_CLAMP,GL_CLAMP);


	windowAppearence = new CGFappearance(ambientNull , difA , specA , shininessA);
	windowAppearence->setTexture("window.png");
	windowAppearence->setTextureWrap(GL_CLAMP, GL_CLAMP);

	floorAppearence = new CGFappearance(ambientNull, difA, specA , shininessA);
	floorAppearence->setTexture("floor.png");
	floorAppearence->setTextureWrap(GL_REPEAT, GL_REPEAT);

	clockAppearence = new CGFappearance (ambientNull , difA , specA, shininessA);
	clockAppearence->setTexture("clock.png");
	clockAppearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	robotAppearence = new CGFappearance (ambientNull, difA , specA, shininessA);
	robotAppearence->setTexture("robot1.jpg");
	robotAppearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	robot2Appearence = new CGFappearance (ambientNull, difA , specA, shininessA);
	robot2Appearence->setTexture("robot2.jpg");
	robot2Appearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	
	robot3Appearence = new CGFappearance (ambientNull, difA , specA, shininessA);
	robot3Appearence->setTexture("robot3.png");
	robot3Appearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	
	robot4Appearence = new CGFappearance (ambientNull, difA , specA, shininessA);
	robot4Appearence->setTexture("robot4.png");
	robot4Appearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	
	robot5Appearence = new CGFappearance (ambientNull, difA , specA, shininessA);
	robot5Appearence->setTexture("robot5.jpg");
	robot5Appearence->setTextureWrap(GL_CLAMP,GL_CLAMP);
	
	landscapeAppearence = new CGFappearance (globalAmbientLight, difA , specA, shininessA);
	/*landscapeAppearence->setTexture("panoramic.jpg");
	landscapeAppearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	landscape2Appearence = new CGFappearance (globalAmbientLight, difA , specA, shininessA);
	landscape2Appearence->setTexture("panoramic2.jpg");
	landscape2Appearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	
	landscape3Appearence = new CGFappearance (globalAmbientLight, difA , specA, shininessA);
	landscape3Appearence->setTexture("panoramic3.jpg");
	landscape3Appearence->setTextureWrap(GL_CLAMP,GL_CLAMP);

	
	landscape4Appearence = new CGFappearance (globalAmbientLight, difA , specA, shininessA);
	landscape4Appearence->setTexture("panoramic4.jpg");
	landscape4Appearence->setTextureWrap(GL_CLAMP,GL_CLAMP);
	*/
	setUpdatePeriod(1);
}
Пример #9
0
void LightingScene::init() 
{
	// Enables lighting computations
	glEnable(GL_LIGHTING);

	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);  

	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientLight);  

	//TPinterface

	sceneVar=0;
	state5=true;
	wire=false;

	// Declares and enables two lights, with null ambient component



	light0 = new CGFlight(GL_LIGHT0, light0_pos);
	light0->setAmbient(ambientNull);
	light0->setSpecular(yellow);
	//light0->disable();
	light0->enable();

	light1 = new CGFlight(GL_LIGHT1, light1_pos);
	light1->setAmbient(ambientNull);

	//light1->disable();
	light1->enable();

	//Light 2
	light2 = new CGFlight(GL_LIGHT2, light2_pos);
	light2->setAmbient(ambientNull);
	light2->setKc(0);
	light2->setKl(1);
	light2->setKq(0);
	//light2->disable();
	light2->enable();


	light3 = new CGFlight(GL_LIGHT3, light3_pos);
	light3->setAmbient(ambientNull);
	light3->setSpecular(yellow);
	light3->setKc(0);
	light3->setKl(0);
	light3->setKq(0.2);
	//light3->disable();
	light3->enable();

	newlight = new CGFlight(GL_LIGHT3, newlight_pos);
	newlight->setAmbient(ambientNull);
	newlight->setSpecular(yellow);
	newlight->setKc(0);
	newlight->setKl(0);
	newlight->setKq(0.2);
	newlight->enable();
	// Uncomment below to enable normalization of lighting normal vectors
	// glEnable (GL_NORMALIZE);

	//Declares scene elements
	table = new myTable();
	wall = new Plane();
	boardA = new Plane(BOARD_A_DIVISIONS);
	boardB = new Plane(BOARD_B_DIVISIONS);



	robot = new MyRobot();

	//Declares materials
	materialA = new CGFappearance(ambA,difA,specA,shininessA);
	materialB = new CGFappearance(ambB,difB,specB,shininessB);
	slidesAppearance = new CGFappearance("slides.png",GL_REPEAT,GL_REPEAT);
	boardAppearance = new CGFappearance("board.png",GL_CLAMP,GL_CLAMP);
	floorAppearance =new CGFappearance("floor.png",GL_REPEAT,GL_REPEAT);
	windowAppearance =new CGFappearance("window.png",GL_CLAMP,GL_CLAMP);
	clockAppearance = new CGFappearance("clock.png", GL_CLAMP, GL_CLAMP);

	blissAppearance = new CGFappearance("bliss.png",GL_CLAMP, GL_CLAMP);
	robotapp = new CGFappearance("robot1.png", GL_REPEAT,GL_REPEAT);
	robotapp1 = new CGFappearance("robot2.png",  GL_REPEAT,GL_REPEAT);
	robotapp2 = new CGFappearance("robot3.png", GL_REPEAT,GL_REPEAT);
	clearapp =new CGFappearance();
	slidesAppearance->setDiffuse(difA);
	slidesAppearance->setAmbient(ambA);
	slidesAppearance->setSpecular(specA);
	slidesAppearance->setShininess(shininessA);

	boardAppearance->setAmbient(ambC);
	boardAppearance->setDiffuse(difC);
	boardAppearance->setSpecular(specC);
	boardAppearance->setShininess(shininessC);

	setUpdatePeriod(100);

}
Пример #10
0
CGFscene::CGFscene() {
	iface=NULL;
	lastUpdate=CGFapplication::getTime();
	setUpdatePeriod(0);
	initCameras();
}
Пример #11
0
void LightingScene::init()
{
	sceneVar = 0;
	// Enables lighting computations
	glEnable(GL_LIGHTING);

	animate=1;
	updateTime=100;

	light0on = true;
	light1on = true;
	light2on = true;
	light3on = true;
	light4on = true;


	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientLight);

	// Declares and enables two lights, with null ambient component

	light0 = new CGFlight(GL_LIGHT0, light0_pos);
	light0->setAmbient(ambientNull);
	light0->setSpecular(yellow);


	light0->enable();
	//light0->enable();

	light1 = new CGFlight(GL_LIGHT1, light1_pos);
	light1->setAmbient(ambientNull);

	light1->enable();
	//light1->enable();


	light2 = new CGFlight(GL_LIGHT2, light2_pos);
	glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 0);
	glLightf(GL_LIGHT2, GL_LINEAR_ATTENUATION, 1);
	glLightf(GL_LIGHT2, GL_QUADRATIC_ATTENUATION, 0);
	light2->setAmbient(ambientNull);

	light2->enable();

	light3 = new CGFlight(GL_LIGHT3, light3_pos);
	glLightf(GL_LIGHT3, GL_CONSTANT_ATTENUATION, 0);
	glLightf(GL_LIGHT3, GL_LINEAR_ATTENUATION, 0);
	glLightf(GL_LIGHT3, GL_QUADRATIC_ATTENUATION, 1);
	light3->setAmbient(ambientNull);

	light3->enable();

	light4 =new CGFlight(GL_LIGHT4, light4_pos);
	glLightf(GL_LIGHT4, GL_CONSTANT_ATTENUATION, 1);
	light4->setAmbient(ambientNull);

	light4->enable();

	// Uncomment below to enable normalization of lighting normal vectors
	 glEnable (GL_NORMALIZE);

	//Declares scene elements
	table = new myTable();
	wall = new Plane(1,-0.5 ,2);
	impostor = new Plane(10,0,1);
	windowWall = new LeftWall(1,-0.5,2);
	boardA = new Plane(BOARD_A_DIVISIONS,0,1);
	boardB = new Plane(BOARD_B_DIVISIONS,0,1);

	//Declares materials
	materialA = new CGFappearance(ambA,difA,specA,shininessA);
	materialB = new CGFappearance(ambB,difB,specB,shininessB);

	float ambT[3] = {0.2, 0.2, 0.2};
	float difT[3] = {0.6, 0.6, 0.6};
	float specT[3] = {0.2, 0.2, 0.2};
	float shininessT = 10.f;

	float ambS[3] = {0.2, 0.2, 0.2};
	float difS[3] = {0.6, 0.6, 0.6};
	float specS[3] = {0.2, 0.2, 0.2};
	float shininessS = 10.f;

	float ambBd[3] = {0.2, 0.2, 0.2};
	float difBd[3] = {0.2, 0.2, 0.2};
	float specBd[3] = {0.5, 0.5, 0.5};
	float shininessBd = 120.f;
	tableAppearance = new CGFappearance(ambT,difT,specT,shininessT);
	tableAppearance->setTexture("table.png");


	slidesAppearance = new CGFappearance(ambS,difS,specS,shininessS);
	slidesAppearance->setTexture("slides.png");
	boardAppearance = new CGFappearance(ambBd,difBd,specBd,shininessBd);
	boardAppearance->setTexture("board.png");

	windowAppearance = new CGFappearance(ambT,difT,specT,shininessT);
	windowAppearance->setTexture("window.png");
	windowAppearance->setTextureWrap(GL_CLAMP, GL_CLAMP);

	floorAppearance = new CGFappearance(ambT,difT,specT,shininessT);
	floorAppearance->setTexture("floor.png");

	clockAppearance = new CGFappearance(ambT,difT,specT,shininessT);
	clockAppearance->setTexture("clock.png");
	//clockAppearance->setTextureWrap(GL_CLAMP, GL_CLAMP);

	robotAppearance = new CGFappearance(ambT,difT,specT,shininessT);
	robotAppearance->setTexture("robot1.jpg");

	earthAppearance = new CGFappearance(ambT,difT,specT,shininessT);
	earthAppearance->setTexture("earth.jpg");

	wallpaperAppearance = new CGFappearance(ambT,difT,specT,shininessT);
	wallpaperAppearance->setTexture("wallpaper.jpg");


	setUpdatePeriod(updateTime);
}
Пример #12
0
void Scene::init() {

	//background
	glClearColor(0,0,0,0);

	//shading
	glShadeModel(GL_SMOOTH);

	//cullface
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	//cullorder
	glFrontFace(GL_CCW);

	// Enables lighting computations
	glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);

	// Sets up some lighting parameters
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

	glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

	float ambient[4] = {1,1,1,1};
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
	setUpdatePeriod(30);

	root = new Node();

	textures["menuTex"] = new CGFtexture("../../YASF/imgs/menu.jpg");

	float colorA[4] = {1,1,1,1};
	float ambientA[4] = {1,1,1,1};
	float diffuseA[4] = {1,1,1,1};
	float specularA[4] = {1,1,1,1};
	appearances["menu"] = new Appearance(colorA, ambientA, diffuseA, specularA, 1, textures["menuTex"], 1, 1);
	appearances["menu_default"] = new Appearance(colorA, ambientA, diffuseA, specularA, 0);

	Node* menuRoot = new Node();
	root->addChildNode(menuRoot);

	//Menu
	Node* menuBase = new Node();
	float xy1[2] = {0,0};
	float xy2[2] = {5,4};
	Rect* menu = new Rect(xy1, xy2);
	menuBase->addChildPrimitive(menu);
	menuBase->setAppearance(appearances["menu"]);
	menuRoot->addChildNode(menuBase);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
		glLoadIdentity();
		glTranslated(-9002.5,0,0);
		GLfloat transformationMatrix[16];
		glGetFloatv(GL_MODELVIEW_MATRIX, transformationMatrix);
		menuRoot->setTransformations(transformationMatrix);
	glPopMatrix();

	//Minus
	Node* minus = new Node();
	float xy3[2] = {0.35, 0.2};
	float xy4[2] = {0.85, 0.7};
	Rect* minusRect = new Rect(xy3, xy4);
	minus->addChildPrimitive(minusRect);
	minus->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(minus);


	//Plus
	Node* plus = new Node();
	float xy5[2] = {0.85, 0.2};
	float xy6[2] = {1.35, 0.7};
	Rect* plusRect = new Rect(xy5, xy6);
	plus->addChildPrimitive(plusRect);
	plus->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(plus);


	//Replay
	Node* replay = new Node();
	float xy19[2] = {2.95, 0.2};
	float xy20[2] = {3.95, 0.7};
	Rect* replayRect = new Rect(xy19, xy20);
	replay->addChildPrimitive(replayRect);
	replay->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(replay);


	//PVP
	Node* pvp = new Node();
	float xy7[2] = {1.8, 2.1};
	float xy8[2] = {5, 2.8};
	Rect* pvpRect = new Rect(xy7, xy8);
	pvp->addChildPrimitive(pvpRect);
	pvp->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(pvp);


	//PVC
	Node* pvc = new Node();
	float xy9[2] = {1.8, 1.4};
	float xy10[2] = {5, 2.1};
	Rect* pvcRect = new Rect(xy9, xy10);
	pvc->addChildPrimitive(pvcRect);
	pvc->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(pvc);


	//CVC
	Node* cvc = new Node();
	float xy11[2] = {1.8, 0.7};
	float xy12[2] = {5, 1.4};
	Rect* cvcRect = new Rect(xy11, xy12);
	cvc->addChildPrimitive(cvcRect);
	cvc->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(cvc);


	//SET1
	Node* set1 = new Node();
	float xy13[2] = {0.15, 1.2};
	float xy14[2] = {0.65, 1.7};
	Rect* set1Rect = new Rect(xy13, xy14);
	set1->addChildPrimitive(set1Rect);
	set1->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(set1);


	//SET2
	Node* set2 = new Node();
	float xy15[2] = {0.65, 1.2};
	float xy16[2] = {1.1, 1.7};
	Rect* set2Rect = new Rect(xy15, xy16);
	set2->addChildPrimitive(set2Rect);
	set2->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(set2);


	//SET3
	Node* set3 = new Node();
	float xy17[2] = {1.1, 1.2};
	float xy18[2] = {1.6, 1.7};
	Rect* set3Rect = new Rect(xy17, xy18);
	set3->addChildPrimitive(set3Rect);
	set3->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(set3);


	//EASY
	Node* easy = new Node();
	float xy21[2] = {2.0, 2.95};
	float xy22[2] = {2.8, 3.35};
	Rect* easyRect = new Rect(xy21, xy22);
	easy->addChildPrimitive(easyRect);
	easy->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(easy);


	//MEDIUM
	Node* medium = new Node();
	float xy23[2] = {2.9, 2.95};
	float xy24[2] = {3.9, 3.35};
	Rect* mediumRect = new Rect(xy23, xy24);
	medium->addChildPrimitive(mediumRect);
	medium->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(medium);


	//hard
	Node* hard = new Node();
	float xy25[2] = {4.0, 2.95};
	float xy26[2] = {4.8, 3.35};
	Rect* hardRect = new Rect(xy25, xy26);
	hard->addChildPrimitive(hardRect);
	hard->setAppearance(appearances["menu_default"]);
	menuRoot->addChildNode(hard);

	// Transparent

	set1->setTransparent(true);
	set2->setTransparent(true);
	set3->setTransparent(true);
	minus->setTransparent(true);
	plus->setTransparent(true);
	pvp->setTransparent(true);
	pvc->setTransparent(true);
	cvc->setTransparent(true);
	replay->setTransparent(true);
	easy->setTransparent(true);
	medium->setTransparent(true);
	hard->setTransparent(true);

	// Picking

	int* picking = new int(2);

	picking[0] = -1;
	picking[1] = 1;
	set1->setPickingNames(vector<int>(picking, picking + 2));	
	picking[1] = 2;
	set2->setPickingNames(vector<int>(picking, picking + 2));
	picking[1] = 3;
	set3->setPickingNames(vector<int>(picking, picking + 2));

	picking[0] = -2;
	picking[1] = -1;
	minus->setPickingNames(vector<int>(picking, picking + 2));	
	picking[1] = 1;
	plus->setPickingNames(vector<int>(picking, picking + 2));	

	picking[0] = -3;
	picking[1] = 1;
	pvp->setPickingNames(vector<int>(picking, picking + 2));
	picking[1] = 2;
	pvc->setPickingNames(vector<int>(picking, picking + 2));
	picking[1] = 3;
	cvc->setPickingNames(vector<int>(picking, picking + 2));
	picking[1] = 4;
	replay->setPickingNames(vector<int>(picking, picking + 2));

	picking[0] = -4;
	picking[1] = 1;
	easy->setPickingNames(vector<int>(picking, picking + 2));
	picking[0] = -4;
	picking[1] = 2;
	medium->setPickingNames(vector<int>(picking, picking + 2));
	picking[0] = -4;
	picking[1] = 3;
	hard->setPickingNames(vector<int>(picking, picking + 2));

	//Cameras
	float pos1[3] = {-9000,2,2.5};
	float pos2[3] = {-9000,2,0};
	CGFscene::activeCamera = new CameraPerspective(1.0, 100.0, 90.0, pos1, pos2);
	

	//Lights
	float pos[3] = {5,2,5};
	float specular0[4] = {0,0,0,0};
	lightings["menu_omni"] = new LightOmni(GL_LIGHT0, "true", pos, ambientA, diffuseA, specular0);
}
Пример #13
0
void LightingScene::init() 
{

	mode=1;
	// Enables lighting computations
	glEnable(GL_LIGHTING);

	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);  
	
	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientLight);  
	
	// Declares and enables two lights, with null ambient component

	light0 = new CGFlight(GL_LIGHT0, light0_pos);
	light0->setAmbient(ambientNull);
	//light0->setSpecular(yellow);

	lightsState.clear();
	lights.clear();

	lights.push_back(light0);
	lightsState.push_back(1);
	light0->disable();
	light0->enable();

	light1 = new CGFlight(GL_LIGHT1, light1_pos);
	light1->setAmbient(ambientNull);
	
	lights.push_back(light1);
	lightsState.push_back(1);
	light1->disable();
	light1->enable();

	light2 = new CGFlight(GL_LIGHT2, light2_pos);
	light2->setAmbient(ambientNull);
	light2->setKc(0);
	light2->setKl(1);
	light2->setKq(0);
	
	lights.push_back(light2);
	lightsState.push_back(1);
	light2->disable();
	light2->enable();

	light3 = new CGFlight(GL_LIGHT3, light3_pos);
	light3->setAmbient(ambientNull);
	//light3->setSpecular(yellow);
	light3->setKc(0);
	light3->setKl(0);
	light3->setKq(1);

	lights.push_back(light3);
	lightsState.push_back(1);
	light3->disable();
	light3->enable();
	
	// Uncomment below to enable normalization of lighting normal vectors
	glEnable (GL_NORMALIZE);
		
	//Declares scene elements
	table = new myTable();
	wall = new Plane();
	boardA = new Plane(BOARD_A_DIVISIONS);
	boardB = new Plane(BOARD_B_DIVISIONS);
	cilindro = new myCylinder(10, 5, false);
	cilindro2 = new myCylinder(10, 5, true);
	semiEsfera = new mySphere(100, 10);
	relogio=new myClock();
	robot = new myRobot();
	robot->setRotation(200);
	robot->setX(7);
	robot->setY(0);
	robot->setZ(7);
	
	//Declares materials
	materialA = new CGFappearance(ambA,difA,specA,shininessA);
	materialB = new CGFappearance(ambB,difB,specB,shininessB);
	materialC = new CGFappearance(ambC,difC,specC,shininessC);
	materialD = new CGFappearance(ambD,difD,specD,shininessD);

	
	
	tableAppearance = new CGFappearance(ambTable, difTable, specTable, shininessTable);
	tableAppearance->setTexture("../textures/table.png");
	
	boardAppearance = new CGFappearance(ambBoard, difBoard, specBoard, shininessBoard);
	boardAppearance->setTexture("../textures/board.png");

	slidesAppearance = new CGFappearance(ambSlides, difSlides, specSlides, shininessSlides);
	slidesAppearance->setTexture("../textures/slides.png");

	windowAppearance = new CGFappearance(ambSlides, difSlides, specSlides, shininessSlides);
	windowAppearance->setTexture("../textures/window.png");
	
	landscapeAppearance = new CGFappearance(ambSlides, difSlides, specSlides, shininessSlides);
	landscapeAppearance->setTexture("../textures/landscape.jpg");

	floorAppearance = new CGFappearance(ambTable, difTable, specTable, shininessTable);
	floorAppearance->setTexture("../textures/floor.png");

	relogioAppearance = new CGFappearance(ambBoard, difBoard, specBoard, shininessBoard);
	relogioAppearance->setTexture("../textures/clock.png");

	robotAppearance = new CGFappearance(ambSlides, difSlides, specSlides, shininessSlides);
	robotAppearance->setTexture("../textures/robot1.jpg");

	// Flat Shading
	//glShadeModel(GL_FLAT);
	//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
	setUpdatePeriod(100);

	sceneVar = 0;
	
}
Пример #14
0
void ProjectScene::init() 
{

	vehicle=Vehicle();

	for (unsigned int i = 0; i < 8; i++)
		lights[i] = NULL;
	
	globals=Global();
	XMLSceneMod temp = XMLSceneMod("wall-e.xml", &sceneGraph, lights ,textures,appearances,animations,&cameras, activeCamera, &globals, flagShaders);
	
	glEnable(GL_LIGHTING);

	glEnable (GL_NORMALIZE);

	
	//mode
	//Defines Drawing computations
	if(strcmp(globals.getMode(), "fill") == 0)
		glPolygonMode(GL_FILL,GL_TRUE);
	else if(strcmp(globals.getMode(), "point") == 0)
		glPolygonMode(GL_POINT,GL_TRUE);
	else if(strcmp(globals.getMode(), "line") == 0)
		glPolygonMode(GL_LINE,GL_TRUE);
	//shading
	if(strcmp(globals.getShading(),"flat")==0)
		glShadeModel(GL_FLAT);
	else if (strcmp(globals.getShading(),"gouraud")==0)
	{
		glShadeModel(GL_SMOOTH);
	}
	
	
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	//background
	glClearColor(globals.getBackground()[0],globals.getBackground()[1],globals.getBackground()[2],globals.getBackground()[3]);
	
	//culling
	if(strcmp(globals.getFace(), "none") == 0)
			glDisable(GL_CULL_FACE);
	else if (strcmp(globals.getFace(), "front") == 0){
		glEnable(GL_CULL_FACE);
		glCullFace(GL_FRONT);
		}
	else if (strcmp(globals.getFace(), "back") == 0){
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
		}
	else if (strcmp(globals.getFace(), "both") == 0){
		glEnable(GL_CULL_FACE);
		glCullFace(GL_FRONT_AND_BACK);
	}

	//order
	if (strcmp(globals.getFace(), "ccw") == 0)
		glFrontFace(GL_CCW); 
	else if (strcmp(globals.getFace(), "cw") == 0)
		glFrontFace(GL_CW); 


	//doublesided
	if(globals.getDoublesided())
		glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	else
		glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

	//local
	if(globals.getLocal())
		glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
	else
		glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);

	//enabled
	if(globals.getEnabled())
		glEnable(GL_LIGHTING);



	// Sets up some lighting parameters
	// Computes lighting only using the front face normals and materials
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);  
	
	// Define ambient light (do not confuse with ambient component of individual lights)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globals.getAmbient());  
	

	/*
	for (unsigned int i = 0; i < 8; i++){
		if (lights[i] == NULL)
			break;
		cout << lights[i]->showLight();
	}*/

	this->processDisplayLists(this->sceneGraph.getRoot(), this->sceneGraph.getRoot());
	
		// Animation-related code
	unsigned long updatePeriod=50;
	setUpdatePeriod(updatePeriod);

}