Exemplo n.º 1
0
void QoccHarnessWindow::createActions()
{
    newAction = new QAction(tr("&New"), this);
    newAction->setShortcut(tr("Ctrl+N"));
    newAction->setStatusTip(tr("Create a new file"));
    connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));

    openAction = new QAction(tr("&Open..."), this);
    openAction->setShortcut(tr("Ctrl+O"));
    openAction->setStatusTip(tr("Open an existing file"));
    connect(openAction, SIGNAL(triggered()), this, SLOT(open()));

    saveAction = new QAction(tr("&Save"), this);
    saveAction->setShortcut(tr("Ctrl+S"));
    saveAction->setStatusTip(tr("Save the document to disk"));
    connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));

    printAction = new QAction(tr("&Print..."), this);
    printAction->setShortcut(tr("Ctrl+P"));
    printAction->setStatusTip(tr("Print the document"));
    connect(printAction, SIGNAL(triggered()), this, SLOT(print()));

    exitAction = new QAction(tr("E&xit"), this);
    exitAction->setShortcut(tr("Ctrl+X"));
    exitAction->setStatusTip(tr("Exit the application"));
    connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));

    undoAction = new QAction(tr("&Undo"), this);
    undoAction->setShortcut(tr("Ctrl+Z"));
    undoAction->setStatusTip(tr("Undo the last operation"));
    connect(undoAction, SIGNAL(triggered()), this, SLOT(undo()));

    redoAction = new QAction(tr("&Redo"), this);
    redoAction->setShortcut(tr("Ctrl+Y"));
    redoAction->setStatusTip(tr("Redo the last operation"));
    connect(redoAction, SIGNAL(triggered()), this, SLOT(redo()));

    cutAction = new QAction(tr("Cu&t"), this);
    cutAction->setShortcut(tr("Ctrl+X"));
    cutAction->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
    connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));

    copyAction = new QAction(tr("&Copy"), this);
    copyAction->setShortcut(tr("Ctrl+C"));
    copyAction->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
    connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));

    pasteAction = new QAction(tr("&Paste"), this);
    pasteAction->setShortcut(tr("Ctrl+V"));
    pasteAction->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
    connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));

    aboutAction = new QAction(tr("&About"), this);
    aboutAction->setStatusTip(tr("Show the application's About box"));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));

    aboutQtAction = new QAction(tr("About &Qt"), this);
    aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(aboutQt()));

	// Now for the QtOCCViewWidget slots.
/*
	fitAction = new QAction(tr("&Fit Window"), this);
	fitAction->setShortcut(tr("Ctrl+F"));
    fitAction->setStatusTip(tr("Fit to window"));
    connect(fitAction, SIGNAL(triggered()), myOCC, SLOT(fitExtents()));
*/
	fitAllAction = new QAction(tr("&Fit All"), this);
	fitAllAction->setShortcut(tr("Ctrl+F"));
    fitAllAction->setStatusTip(tr("Fit contents to viewport"));
    connect(fitAllAction, SIGNAL(triggered()), myOCC, SLOT(fitAll()));

	zoomAction = new QAction(tr("&Zoom"), this);
	zoomAction->setStatusTip(tr("Zoom in window"));
    connect(zoomAction, SIGNAL(triggered()), myOCC, SLOT(fitArea()));

	panAction = new QAction(tr("&Pan"), this);
    panAction->setStatusTip(tr("Window panning"));
    connect(panAction, SIGNAL(triggered()), myOCC, SLOT(pan()));

	rotAction = new QAction(tr("&Rotate"), this);
	rotAction->setShortcut(tr("Ctrl+R"));
    rotAction->setStatusTip(tr("Window rotation"));
    connect(rotAction, SIGNAL(triggered()), myOCC, SLOT(rotation()));

	gridToggleAction = new QAction(tr("Toggle &Grid"), this);
	gridToggleAction->setShortcut(tr("Ctrl+G"));
    gridToggleAction->setStatusTip(tr("Turn the grid on or off"));
    connect(gridToggleAction, SIGNAL(triggered()), myVC, SLOT(gridToggle()));

/*	gridOffAction = new QAction(tr("Gri&d Off"), this);
	gridOffAction->setShortcut(tr("Ctrl+D"));
    gridOffAction->setStatusTip(tr("Turn the grid on"));
    connect(gridOffAction, SIGNAL(triggered()), myVC, SLOT(gridOff()));
*/
	gridXYAction = new QAction(tr("XY Grid"), this);
    gridXYAction->setStatusTip(tr("Grid on XY Plane"));
	//gridOffAction->setShortcut(tr("Ctrl+Z"));
    connect(gridXYAction, SIGNAL(triggered()), myVC, SLOT(gridXY()));

	gridXZAction = new QAction(tr("XZ Grid"), this);
    gridXZAction->setStatusTip(tr("Grid on XZ Plane"));
	//gridXZAction->setShortcut(tr("Ctrl+Y"));
    connect(gridXZAction, SIGNAL(triggered()), myVC, SLOT(gridXZ()));

	gridYZAction = new QAction(tr("YZ Grid"), this);
	gridYZAction->setStatusTip(tr("Grid on YZ Plane"));
	//gridOffAction->setShortcut(tr("Ctrl+Z"));
    connect(gridYZAction, SIGNAL(triggered()), myVC, SLOT(gridYZ()));

	gridRectAction = new QAction(tr("Rectangular"), this);
	gridRectAction->setStatusTip(tr("Retangular grid"));
	//gridOffAction->setShortcut(tr("Ctrl+Z"));
    connect(gridRectAction, SIGNAL(triggered()), myVC, SLOT(gridRect()));

	gridCircAction = new QAction(tr("Circular"), this);
	gridCircAction->setStatusTip(tr("Circular grid"));
	//gridOffAction->setShortcut(tr("Ctrl+Z"));
    connect(gridCircAction, SIGNAL(triggered()), myVC, SLOT(gridCirc()));

	// Standard View

	viewFrontAction = new QAction(tr("Front"), this);
	viewFrontAction->setStatusTip(tr("View From Front"));
    connect(viewFrontAction, SIGNAL(triggered()), myOCC, SLOT(viewFront()));

	viewBackAction = new QAction(tr("Back"), this);
	viewBackAction->setStatusTip(tr("View From Back"));
    connect(viewBackAction, SIGNAL(triggered()), myOCC, SLOT(viewBack()));

	viewTopAction = new QAction(tr("Top"), this);
	viewTopAction->setStatusTip(tr("View From Top"));
    connect(viewTopAction, SIGNAL(triggered()), myOCC, SLOT(viewTop()));

	viewBottomAction = new QAction(tr("Bottom"), this);
	viewBottomAction->setStatusTip(tr("View From Bottom"));
    connect(viewBottomAction, SIGNAL(triggered()), myOCC, SLOT(viewBottom()));

	viewLeftAction = new QAction(tr("Left"), this);
	viewLeftAction->setStatusTip(tr("View From Left"));
    connect(viewLeftAction, SIGNAL(triggered()), myOCC, SLOT(viewLeft()));

	viewRightAction = new QAction(tr("Right"), this);
	viewRightAction->setStatusTip(tr("View From Right"));
    connect(viewRightAction, SIGNAL(triggered()), myOCC, SLOT(viewRight()));

	viewAxoAction = new QAction(tr("&Axonometric Fit"), this);
	viewAxoAction->setStatusTip(tr("Axonometric view and fit all"));
    viewAxoAction->setShortcut(tr("Ctrl+A"));
    connect(viewAxoAction, SIGNAL(triggered()), myOCC, SLOT(viewAxo()));

	viewGridAction = new QAction(tr("Grid"), this);
	viewGridAction->setStatusTip(tr("View from grid"));
    connect(viewGridAction, SIGNAL(triggered()), myOCC, SLOT(viewGrid()));

	viewResetAction = new QAction(tr("Reset"), this);
	viewResetAction->setStatusTip(tr("Reset the view"));
    connect(viewResetAction, SIGNAL(triggered()), myOCC, SLOT(viewReset()));

	backgroundAction = new QAction( tr("&Background"), this );
	backgroundAction->setStatusTip(tr("Change the background colour"));
	connect(backgroundAction, SIGNAL(triggered()), myOCC, SLOT(background()));

	// The co-ordinates from the view
	connect( myOCC, SIGNAL(mouseMoved(V3d_Coordinate,V3d_Coordinate,V3d_Coordinate)),
		     this,   SLOT(xyzPosition(V3d_Coordinate,V3d_Coordinate,V3d_Coordinate)) );

	// Add a point from the view
	connect( myOCC, SIGNAL(pointClicked(V3d_Coordinate,V3d_Coordinate,V3d_Coordinate)),
		     this,   SLOT (addPoint    (V3d_Coordinate,V3d_Coordinate,V3d_Coordinate)) );

	connect( myOCC, SIGNAL(sendStatus(const QString)),
		     this,  SLOT  (statusMessage(const QString)) );

	// And the bottle example

	bottleAction = new QAction(tr("Load &Bottle"), this);
	bottleAction->setShortcut(tr("Ctrl+B"));
    bottleAction->setStatusTip(tr("Bottle sample."));
    connect(bottleAction, SIGNAL(triggered()), this, SLOT(bottle()));

}
Exemplo n.º 2
0
int main(){
	
	int BOTTLE_COUNT = 7;

	// =========== LOAD IMAGES ==========

	sf::Texture odd_tile_image, even_tile_image, dice_img, bottle_label, bottle_two_label;

	bottle_label.loadFromFile("label.png");
	bottle_two_label.loadFromFile("label.png");

	sf::String dice_file = "dice.jpg";
	sf::String odd_tile_file = "odd_tile.jpg";
	sf::String even_tile_file = "even_tile.jpg";
	if (!odd_tile_image.loadFromFile(odd_tile_file)){
		std::cout << "Could not load " << odd_tile_file.getData();
	}
	if (!even_tile_image.loadFromFile(even_tile_file)){
		std::cout << "Could not load " << even_tile_file.getData();
	}
	if (!dice_img.loadFromFile(dice_file)){
		std::cout << "Could not load " << dice_file.getData();
	}
	// =========== END LOAD IMAGES ==========

	int width = 1024, height = 960;
	sf::ContextSettings Settings;
	Settings.depthBits = 24; // Request a 24 bits depth buffer
	Settings.stencilBits = 8;  // Request a 8 bits stencil buffer
	Settings.antialiasingLevel = 2;  // Request 2 levels of antialiasing
	sf::RenderWindow window(sf::VideoMode(width, height, 32), "C00170460 - Keith Byrne CA2", sf::Style::Close, Settings);
	window.setFramerateLimit(60);
	sf::Clock Clock;


	// Help message

	sf::Font font;
	font.loadFromFile("C:\\Windows\\Fonts\\arial.TTF");

	

	std::string instructions;
	instructions += "W A S D for Camera Movement\n";
	instructions += "NUMPAD 4 6 8 2 for left/right/up/down Torch Movement\n";
	instructions += "SPACEBAR for torch light switch\n";
	instructions += "LEFT CTRL for torch light colour switch\n";
	instructions += "P for global light switch.";

	sf::Text help;
	help.setFont(font);
	help.setString(instructions);
	help.setColor(sf::Color::White);
	help.setCharacterSize(20);
	help.setPosition(20, 40);

	bool global_switch = true;

	// Camera Setup
	Camera camera(1, // forward speed
		5, // rotation speed
			Vector<float>(0, 5, -15),      // position
				Vector<float>(0, 0, 20),    // forward
					Vector<float>::YAXIS);       // up

	glClearDepth(1.f);
	glClearColor(0.0f, 0.0f, 1.0f, 1.0f); //background colour
	glEnable(GL_DEPTH_TEST);
	glClear(GL_DEPTH_BUFFER_BIT);
	glDepthMask(GL_TRUE);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// Setup a perspective projection & Camera position 
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);

	//set up a 3D Perspective View volume
	gluPerspective(90.f, (float)width / height, 1.f, 50.0f);//fov, aspect, zNear, zFar 

	double t = 0.0;
	double tetha;
	double fi_tetha = (2 * M_PI) / 60;

	// Dice
	Dice dice(2,						//3D Cube dimension
		Vector<float>(0, 0, -2));		//Initial positioning

	auto dice_rotation_vector = Vector<float>::YAXIS;
	{
		auto xVector = dice.getXVector();
		auto yVector = dice.getYVector();
		auto zv = dice.getZVector();
		auto xv = xVector.rotateAroundAxis(zv, 45);
		xv = xv.rotateAroundAxis(xVector, -45);
		auto yv = yVector.rotateAroundAxis(zv, 45);
		yv = yv.rotateAroundAxis(xVector, -45);
		dice.setXYVectors(xv, yv);
	}

	dice.initDiceTexture(&dice_img);
	dice.setColor({ 1, 1, 1, 0.2f});

	std::vector<Bottle> bottles;
	int modulo_factor = BOTTLE_COUNT / 3;

#pragma region Bottle Set A
	//Create six packesque bottle arrangement
	for (int i = 0; i < BOTTLE_COUNT - 1; i++){

		//Bottle instantiation as follows
		//Position (x,y,z) global construct
		//Tapering object radius array (bottom to top)
		//Object heights (liquid, etc..)
		//Thickness
		//Liquid measure
		float x_pos = -10;
		float y_pos = 0.5f;
		float z_pos = -10;

		if (i % modulo_factor == 0)
		{
			z_pos = -7.5;
			z_pos += i;
			x_pos = -7.5;
			Bottle bottle(Vector<float>(x_pos, y_pos, z_pos),
			{ 1, 1, .95f, .85f, .7f, .5f, .4f, .4f },
			{ 3.85f, .2f, .2f, .2f, .2f, 2, 1 },
			.1f, 4.2f);

			bottle.label = Label(1, 3, 200, Vector<float>(x_pos, y_pos + 1.0f, z_pos));
			bottle.label.slices = 500;

			//Set label global colour to full opacity 
			bottle.outerColour = { 1.0f, 1.0f, 1.0f, 0.3f };
			bottle.innerColour = { 1.0f, 1.0f, 1.0f, 0.3f };

			bottle.liquidColour = { 1.000f, 0.843f, 0.000f, 0.6f };
			bottle.labelColour = { 0, 0, 0, 1 };

			bottle.label.setTexture(&bottle_label, bottle.label.generateTextureVertices());
			bottle.init();
			bottles.push_back(bottle);
		}
		else
		{
			z_pos += i;
			Bottle bottle(Vector<float>(x_pos, y_pos, z_pos),
			{ 1, 1, .95f, .85f, .7f, .5f, .4f, .4f },
			{ 3.85f, .2f, .2f, .2f, .2f, 2, 1 },
			.1f, 4.2f);     // thickness of bottle, height of liquid

			bottle.label = Label(1, 3, 200, Vector<float>(x_pos, y_pos + 1.0f, z_pos));
			bottle.label.slices = 500;

			//Set label global colour to full opacity 
			bottle.outerColour = { 1.0f, 1.0f, 1.0f, 0.3f };
			bottle.innerColour = { 1.0f, 1.0f, 1.0f, 0.3f };

			bottle.liquidColour = { 1.000f, 0.843f, 0.000f, 0.6f };
			bottle.labelColour = { 0, 0, 0, 1 };

			bottle.label.setTexture(&bottle_label, bottle.label.generateTextureVertices());
			bottle.init();
			bottles.push_back(bottle);
		}

	}
#pragma endregion

	// Torch
	Torch torch(0.5f, 1,      // radius 1, radius 2, height
		Vector<float>(-5, 10, 0), // position
		GL_LIGHT1); // light
	torch.setYVector(Vector<float>(0, -1, 0));
	torch.addColor({ 1, 1, 1, 1 });
	torch.addColor({ 1, 1, 0, 1 });
	torch.addColor({ 0, 1, 1, 1 });
	torch.addColor({ 0, 1, 0, 1 });
	torch.setColor(0);

	torch.setfv(GL_DIFFUSE, { .8f, .8f, .8f, .8f });
	torch.setfv(GL_SPECULAR, { 1, 1, 1, 1 });
	torch.setf(GL_SPOT_CUTOFF, 30);
	torch.setf(GL_SPOT_EXPONENT, 5);
	torch.setf(GL_CONSTANT_ATTENUATION, .001);
	torch.setf(GL_LINEAR_ATTENUATION, .001);
	torch.setf(GL_QUADRATIC_ATTENUATION, .01);

	// Odd/Even tiled floor setup. 200x200
	Floor floor(Vector<int>(200, 200),
		Vector<float>(1, 1),          
		Vector<float>(-100, -100),    
		odd_tile_image,		//Map odd floor texture
		even_tile_image);	//Map even floor texture


	//Setup HSR
	glClearDepth(1.0f);
	glClearColor(0.00f, 0.00f, 0.1f, 1.0f); //background colour
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_AUTO_NORMAL);
	glEnable(GL_NORMALIZE);
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	glShadeModel(GL_SMOOTH);

	//Lighting Config
	glEnable(GL_LIGHTING);
	GLfloat global_ambient[] = { 0.2f, 0.2f, 0.2f, 0.2f };
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

	Light globalLight(GL_LIGHT0);
	globalLight.setfv(GL_AMBIENT, { .0f, .0f, .0f, 0.05f });
	globalLight.setfv(GL_DIFFUSE, { .0f, .0f, .0f, 0.05f });
	globalLight.setfv(GL_SPECULAR, { .0f, .0f, .0f, 0.05f });
	globalLight.setfv(GL_POSITION, { -50, -50, 0, 1 });
	//globalLight.enable();

	Light masterLight(GL_LIGHT2);
	masterLight.setfv(GL_AMBIENT, { .5f, .5f, 1.0f, 0.4f });
	masterLight.setfv(GL_DIFFUSE, { .1f, .1f, .1f, .0f });
	masterLight.setfv(GL_SPECULAR, { 1, 1, 1, 0.1f });
	masterLight.setfv(GL_POSITION, { 0, -50, 0, 1 });
	//masterLight.enable();
	global_switch = false;

	// Material
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	GLfloat materialSpecular[4] = { 1, 1, 1, 1 };
	GLfloat materialAmbient[4] = { .1f, .1f, .1f, .1f };
	GLfloat materialDiffuse[4] = { .8f, .8f, .8f, .8f };
	glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular);
	glMaterialfv(GL_FRONT, GL_AMBIENT, materialAmbient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, materialDiffuse);
	glMateriali(GL_FRONT, GL_SHININESS, 100);

	// Start game loop 
	while (window.isOpen()){
		// Process events 
		sf::Event Event;
		while (window.pollEvent(Event))
		{
			// Close window : exit 
			if (Event.type == sf::Event::Closed)
				window.close();
			// Escape key : exit 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
				window.close();

			//update the camera
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::P)){
				if (global_switch == true)
				{
					masterLight.disable();
					global_switch = false;
				}
				else{
					masterLight.enable();
					global_switch = true;
				}
			}

			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::PageUp)){
				for (int i = 0; i < BOTTLE_COUNT - 1; i++)
				{
					float liquid = bottles[i].liquid;
					liquid += 0.5f;
					bottles[i].incrementLiquid();
				}
			}

			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::PageDown)){
				for (int i = 0; i < BOTTLE_COUNT - 1; i++)
				{
					float liquid = bottles[i].heights[0];
					liquid -= 0.5f;
					bottles[i].decrementLiquid();
				}
			}

			torch.update(Event);

			
		}

		camera.updateKeyboardEvent();
		torch.updateKeyboardEvent();
		
		//Prepare for drawing
		// Clear color and depth buffer
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


		// Apply some transformations
		//initialise the worldview matrix
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		//get the viewing transform from the camera
		camera.ViewingTransform();

		//make the world spin
		//TODO:probably should remove this in final
		static float ang = 0.0;
		//ang+=0.01f;
		//glRotatef(ang*2,0,1,0);//spin about y-axis

		auto light_position = torch.getPosition();
		auto yVector = torch.getYVector();

		//make sure light object follows absolute position and direction of torch source
		torch.setfv(GL_POSITION, { light_position.x, light_position.y, light_position.z, 1 });
		torch.setfv(GL_SPOT_DIRECTION, { yVector.x, yVector.y, yVector.z });

		
		window.draw(floor);
		dice.rotate(dice_rotation_vector, 5);
		window.draw(dice);
		

		for (int i = 0; i < BOTTLE_COUNT-1; i++){
			bottles[i].rotate(Vector<float>(1, 1, 2), 2);
			window.draw(bottles[i]);
		}

		window.draw(torch);
		

		window.pushGLStates();
		window.draw(help);
		window.popGLStates();

			//Render all objects to display
			window.display();
	}
	return EXIT_SUCCESS;
}