⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 光滑质点无网格法SPH并行计算程序
💻 CPP
字号:
//      ___                       ___           ___           ___       ___     //     /\__\          ___        /\__\         /\  \         /\__\     /\  \.   //    /::|  |        /\  \      /::|  |       /::\  \       /:/  /    /::\  \.  //   /:|:|  |        \:\  \    /:|:|  |      /:/\:\  \     /:/  /    /:/\:\  \. //  /:/|:|__|__      /::\__\  /:/|:|  |__   /:/  \:\  \   /:/  /    /::\~\:\  \.// /:/ |::::\__\  __/:/\/__/ /:/ |:| /\__\ /:/__/_\:\__\ /:/__/    /:/\:\ \:\__\.// \/__/~~/:/  / /\/:/  /    \/__|:|/:/  / \:\  /\ \/__/ \:\  \    \:\~\:\ \/__///       /:/  /  \::/__/         |:/:/  /   \:\ \:\__\    \:\  \    \:\ \:\__\. //      /:/  /    \:\__\         |::/  /     \:\/:/  /     \:\  \    \:\ \/__/  //     /:/  /      \/__/         /:/  /       \::/  /       \:\__\    \:\__\.   //     \/__/                     \/__/         \/__/         \/__/     \/__/    // // =============================================================================//                       Minimalist OpenGL Environment//                       Parallel Rendering Extension// =============================================================================//// Copyright 2007 Balazs Domonkos// // This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.// // This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// A simple 'Hello World! application using MinGLE// mingle.h should be included before all other// OpenGL headers//#include <mingle/mingle.h>#include <mingle-parallel.h>using namespace MinGLE;#include <GL/glut.h>#include <iostream>#include <math.h>class SceneRenderer : public WindowListener {protected:	BoxPartitioner<double> *mPartitioner;	BoxPartitioner<double>::Partition *mPartition;	bool mPartitionIsSet;public:	~SceneRenderer() {		delete mPartitioner;	}	virtual void onRegistered() {		// This initialization steps must be performed here		// in this event handling method since the window listener		// has to be added to the window to have valid mWindow		// attribute		// Create partitioner		mPartitioner = new BoxPartitioner<double>(1.0, 1.0, 1.0);		mPartitioner->chop(ParallelRenderingSupport::getRendererCount(mWindow) );		// Get partition for this renderer		mPartition				= mPartitioner->getPartition(ParallelRenderingSupport::getThisRenderer(mWindow) );		// Setup partition info for the parallel rendering system		// to enable automatic framelet and sort order calculation		ParallelRenderingSupport::setPartition(mWindow, mPartition);		mPartitionIsSet = true;	}	virtual bool onRender() {		glMatrixMode(GL_MODELVIEW);		glPushMatrix();		// Draw the volume piece		glTranslated(mPartition->offset[0]+0.5*mPartition->size[0],				mPartition->offset[1]+0.5*mPartition->size[1],				mPartition->offset[2]+0.5*mPartition->size[2]);		glScaled(mPartition->size[0], mPartition->size[1], mPartition->size[2]);		/*double color[3];		ParallelRenderingSupport::getUniqueColor(mWindow, color[0], color[1],				color[2]);		glColor3dv(color);*/		glColor4f(1.0, 1.0, 1.0, 1.0);		glutSolidCube(0.96);		glMatrixMode(GL_MODELVIEW);		glPopMatrix();		return true;	}	virtual bool onKeyEvent(int key, unsigned modifiers, KeyEventState state) {		switch (key) {		// Turn displaying bounding rect on/off		case 'r':			ParallelRenderingSupport::toggleDisplayDebug(mWindow,					ParallelRenderingSupport::DISPLAY_BOUNDING_RECT);			break;			// Turn displaying bounding box on/off		case 'b':			ParallelRenderingSupport::toggleDisplayDebug(mWindow,					ParallelRenderingSupport::DISPLAY_BOUNDING_BOX);			break;			// Turn displaying filling on/off		case 'f':			ParallelRenderingSupport::toggleDisplayDebug(mWindow,					ParallelRenderingSupport::DISPLAY_FILL);			break;			// Toggle partition based calculations		case 'p':			ParallelRenderingSupport::setPartition(mWindow,					(mPartitionIsSet=!mPartitionIsSet) ? mPartition : 0);			break;		}		return false;	}};// // Meaning of command line arguments:// (in general: <application> <sessionid> <hostcount> {hostlist}) // master mode: <application> <sessionid> <1+N> <master> <slave1> <slave2> ... <slaveN>  // slave mode:  <application> <sessionid> <1> <slaveI> int main(int argc, char **argv) {	// BoxPartitioner<unsigned> *mPartitioner = new BoxPartitioner<unsigned>(256, 256,256);	// mPartitioner->chop(200, 200, 200); mPartitioner->getRootBox()->_debug();	// return 0;	try {		// Initialize rendering system		System::initialize(&argc, argv);		// Initialize parallel rendering support (Paracomp)		ParallelRenderingSupport::initialize(&argc, argv, ParallelRenderingSupport::PARACOMP);		// Create window		Window *win = System::createWindow();		win->setRenderMode(WindowAttributes::RENDER_WHEN_IDLE);		// Add parallel rendering support to the window		// Mode master or slave is autodetected using the command line arguments		//ParallelRenderingSupport::addParallelSupport(win, ParallelRenderingSupport::DEPTH_OPERATOR);		ParallelRenderingSupport::addParallelSupport(win, ParallelRenderingSupport::ALPHA_BLEND_OPERATOR);		// Add keyhandler		win->registerWindowListener(new ApplicationKeyHandler());		// Register scene renderer		win->registerWindowListener(new SceneRenderer());		// Add navigator		win->registerWindowListener(new ExaminerNavigator());		// Setup OpenGL		glEnable(GL_DEPTH_TEST);		glShadeModel(GL_SMOOTH);		glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);		GLfloat lightPosition[] = {3.0f, 3.0f, 3.0f, 1.0f};		GLfloat diffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};		GLfloat specular[] = {1.0f, 1.0f, 1.0f , 1.0f};		glEnable(GL_LIGHTING);		glEnable(GL_LIGHT0);		glEnable(GL_COLOR_MATERIAL);		glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);		glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);		glLightfv(GL_LIGHT0, GL_SPECULAR, specular);		glMatrixMode(GL_MODELVIEW_MATRIX);		glTranslatef(0.1, 0.2, 0.3);		// Enter the event handing loop		System::enterMainLoop();	} catch(const Exception& e) {		std::cerr << "Error: " << e.mDescription << " (Thrown in " << e.mFile << ':'		<< e.mMethod << " line " << e.mLine << ')' << std::endl;	}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -