예제 #1
1
파일: Main.cpp 프로젝트: uktuk/BurgEngine
int main()
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	// =======================================================
	//                   INITIALIZE
	// =======================================================
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

	GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGl Program", nullptr, nullptr);
	if (window == nullptr)
	{
		printf("Failed to create GLFW window\n");
		glfwTerminate();
		return false;
	}
	glfwMakeContextCurrent(window);

	glewExperimental = GL_TRUE;
	if (glewInit() != GLEW_OK)
	{
		printf("Failed to initialize GLEW\n");
		return false;
	}

	glViewport(0, 0, WIDTH, HEIGHT);
	glEnable(GL_DEPTH_TEST);

	glfwSetKeyCallback(window, Key_callback);
	glfwSetCursorPosCallback(window, mouse_callback);
	glfwSetScrollCallback(window, scroll_callback);


	// Build and compile our shader program
	Shader lightingShader("../Data/Shaders/vertexShaderLighting_nano.vs",
		"../Data/Shaders/fragmentShaderLighting_nano.frag", 2);

	Shader lampShader("../Data/Shaders/vertexShaderLighting_Lamp.vs",
		"../Data/Shaders/fragmentShaderLighting_Lamp.frag", 0);

	// set the application to capture the cursor
	glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

	glm::vec3 pointLightPositions[] =
	{
		glm::vec3(2.0f, 0.0f, 2.0f),
		glm::vec3(-2.0f, 0.0f, -2.0f),
	};



	DirLight dirlight(lightingShader, vect3(-0.2f, -1.0f, -0.3f), vect3(255, 255, 255), 0.5f);
	PointLight pointLight1(lightingShader, pointLightPositions[0], vect3(255, 255, 255), 0.5f);
	PointLight pointLight2(lightingShader, pointLightPositions[1], vect3(255, 255, 255), 0.5f);
	//PointLight pointLight3(lightingShader, pointLightPositions[2], vect3(255, 255, 255), 1.0f);
	//PointLight pointLight4(lightingShader, pointLightPositions[3], vect3(255, 255, 255), 1.0f);
	SpotLight spotLight(lightingShader, MainCamera.Position, MainCamera.Front, vect3(255, 255, 255), 1.0f);

	GLfloat time = glfwGetTime();
	Model nanosuit("../Data/Models/Box/OutPutModel.txt");
	time = glfwGetTime() - time;
	printf("Time to load: %f", time);

	nanosuit.SetPosition(glm::vec3(0.0f, 0.0f, 0.0f));
	
	// =======================================================
	//                  MAIN UPDATE LOOP
	// =======================================================
	//float count = 0;
	//GLfloat time = 0;

	while (!glfwWindowShouldClose(window))
	{

		// Update deltaTime
		GLfloat currentFrame = glfwGetTime();
		deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;

		// FPS check
		//if (time >= 1.0f)
		//{
		//	printf("FPS: %f", count);
		//	time = 0;
		//	count = 0;
		//}

		// check and call events
		glfwPollEvents();
		UpdateCamera();

		// Rendering commands here
		//glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
		glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// draw triangle
		lightingShader.Use();

		GLint viewPosLoc = lightingShader.GetUniformLocation("viewPos");
		glUniform3f(viewPosLoc, MainCamera.Position.x, MainCamera.Position.y, MainCamera.Position.z);

		// Directional light
		dirlight.Update();

		// Point lights		
		pointLight1.Update(0);
		pointLight2.Update(1);

		// SpotLight
		spotLight.SetPosDir(MainCamera.Position, MainCamera.Front);
		spotLight.Update();

		// Camera/View transformation
		glm::mat4 view;
		view = MainCamera.GetViewMatrix();

		// set the projection matrix (perspective)
		glm::mat4 projectionMatrix;

		// FOV, aspect ratio, near plane, far plane
		projectionMatrix = glm::perspective(glm::radians(MainCamera.Zoom), (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, farPlane);

		// specify matrices
		GLint modelLoc = lightingShader.GetUniformLocation("modelMat");

		GLint viewLoc = lightingShader.GetUniformLocation("viewMat");
		glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));

		GLint projLoc = lightingShader.GetUniformLocation("projectionMat");
		glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projectionMatrix));		

		//glm::mat4 model;
		//model = glm::translate(model, glm::vec3(0, -1.75f, 0.0f)); // Translate it down a bit so it's at the center of the scene
		//model += glm::translate(model, glm::vec3(0.2f, 0.0f, 0.0f));
		//model = glm::scale(model, glm::vec3(0.2f, 0.2f, 0.2f));	// It's a bit too big for our scene, so scale it down
		//glUniformMatrix4fv(glGetUniformLocation(lightingShader.Program, "modelMat"), 1, GL_FALSE, glm::value_ptr(model));

		nanosuit.Draw(lightingShader);

		
		// Swap the buffers
		glfwSwapBuffers(window);
	}

	// =======================================================
	//                     CLEANUP
	// =======================================================
	
	glfwTerminate();
	return 0;
}
예제 #2
0
	void m3math_test_object_t::test<4>()
	{
		LLMatrix3 llmat3_obj;
		LLVector3 vect1(2, 1, 4);
		LLVector3 vect2(3, 5, 7);
		LLVector3 vect3(6, 9, 7);
		llmat3_obj.setRows(vect1, vect2, vect3);
		
		ensure("LLVector3::getFwdRow failed ", vect1 == llmat3_obj.getFwdRow());
		ensure("LLVector3::getLeftRow failed ", vect2 == llmat3_obj.getLeftRow());
		ensure("LLVector3::getUpRow failed ", vect3 == llmat3_obj.getUpRow());
	}
예제 #3
0
	void m3math_test_object_t::test<3>()
	{
		LLMatrix3 llmat3_obj;
		LLVector3 vect1(2, 1, 4);
		LLVector3 vect2(3, 5, 7);
		LLVector3 vect3(6, 9, 7);
		llmat3_obj.setRows(vect1, vect2, vect3);
		ensure("LLVector3::setRows failed ", 2 == llmat3_obj.mMatrix[0][0] &&
						1 == llmat3_obj.mMatrix[0][1] &&
						4 == llmat3_obj.mMatrix[0][2] &&
						3 == llmat3_obj.mMatrix[1][0] &&
						5 == llmat3_obj.mMatrix[1][1] &&
						7 == llmat3_obj.mMatrix[1][2] &&
						6 == llmat3_obj.mMatrix[2][0] &&
						9 == llmat3_obj.mMatrix[2][1] &&
						7 == llmat3_obj.mMatrix[2][2]);
	}
예제 #4
0
	void llquat_test_object_t::test<3>()
	{
		LLMatrix3 llmat;

		LLVector3 vect1(3.4028234660000000f , 234.56f, 4234.442234f);
		LLVector3 vect2(741.434f, 23.00034f, 6567.223423f);
		LLVector3 vect3(566.003034f, 12.98705f, 234.764423f);
		llmat.setRows(vect1, vect2, vect3);

		ensure("LLMatrix3::setRows fn failed.", 3.4028234660000000f == llmat.mMatrix[0][0] &&
										234.56f == llmat.mMatrix[0][1] &&
										4234.442234f == llmat.mMatrix[0][2] &&
										741.434f == llmat.mMatrix[1][0] &&
										23.00034f == llmat.mMatrix[1][1] &&
										6567.223423f == llmat.mMatrix[1][2] &&
										566.003034f == llmat.mMatrix[2][0] &&
										12.98705f == llmat.mMatrix[2][1] &&
										234.764423f == llmat.mMatrix[2][2]);		
	}
예제 #5
0
int main() {
    int a = 1;
    int b = 2;
    int i;

    cout << "Should see 1 2 3 4 5\n";
    WCValOrderedVector<int> vect( 0 );
    vect.exceptions( WCExcept::check_all );
    test_except( vect.insert( a ), resize_required, "1" );
    vect.exceptions( 0 );
    for( i = 0; i < WCDEFAULT_VECTOR_RESIZE_GROW; i++ ){
	vect.insert( a );
    }
    vect.exceptions( WCExcept::check_all );
    test_except( vect.insert( a ), resize_required, "2" )

    WCValOrderedVector<int> vect2( 0, 4 );
    vect2.exceptions( WCExcept::check_all );
    test_except( vect2.insert( a ), resize_required, "3" );
    vect2.exceptions( 0 );

    for( i = 0; i < 4; i++ ){
	vect2.insert( a );
    }
    vect2.exceptions( WCExcept::check_all );
    test_except( vect2.insert( a ), resize_required, "4" );

    WCValOrderedVector<int> vect3( 4, 0 );
    for( i = 0; i < 4; i++ ){
	if( !vect3.insert( a ) ) cout << "insert failed\n";
    }
    if( vect3.insert( a ) ) cout << "insert did not fail\n";
    vect3.exceptions( WCExcept::check_all );
    test_except( vect3.insert( a ), resize_required, "5" );

    vect.clear();
    vect2.clear();
    vect3.clear();
    return 0;
}
예제 #6
0
int main ()
{
    // Test with integers.
    int myints[] = { 75, 23, 65, 42, 13 };
    MyList<int> lst(myints, (myints + 5));
    MyVector<int> vect(myints, (myints + 5));
	MyCollection<int>* p1 = &vect;
    MyCollection<int>* p2 = &lst;

    cout << "Start of integer vector: " << vect.starting_element() << endl;
    cout << "End of integer vector: " << vect.last_element() << endl;
    cout << "Integer vector[3]: " << vect.value_at_position(3) << endl;
    cout << "Integer vector contains the following elements: " << endl;
    vect.show_all();
    cout << endl;

    cout << "Start of integer list: " << lst.starting_element() << endl;
    cout << "End of integer list: " << lst.last_element() << endl;
    cout << "Integer list(3): " << lst.value_at_position(3) << endl;
    cout << "Integer list contains the following elements: " << endl;
    lst.show_all();
    cout << endl;

    cout << "Start of integer (collection) vector: " << p1->starting_element() << endl;
    cout << "End of integer (collection) vector: " << p1->last_element() << endl;
    cout << "Integer (collection) vector[3]: " << p1->value_at_position(3) << endl;
    cout << "Integer (collection) vector contains the following elements: " << endl;
    p1->show_all();
    cout << endl;

    cout << "Start of integer (collection) list: " << p2->starting_element() << endl;
    cout << "End of integer (collection) list: " << p2->last_element() << endl;
    cout << "Integer (collection) list(3): " << p2->value_at_position(3) << endl;
    cout << "Integer (collection) list contains the following elements: " << endl;
    p2->show_all();
    cout << endl;

    // Test with doubles.
    double mydoubles[] = { 7.0, 42.0, 13.0, 1.0, 2.0, 5.0 };
    MyVector<double> vect2(mydoubles, (mydoubles + 6));
	MyList<double> lst2(mydoubles, (mydoubles + 6));
    MyCollection<double>* p3 = &vect2;
    MyCollection<double>* p4 = &lst2;

    cout << "Start of double vector: " << p3->starting_element() << endl;
    cout << "End of double vector: " << p3->last_element() << endl;
    cout << "Double vector[3]: " << p3->value_at_position(3) << endl;
    cout << "Double vector contains the following elements: " << endl;
    p3->show_all();
    cout << endl;

    cout << "Start of double list: " << p4->starting_element() << endl;
    cout << "End of double list: " << p4->last_element() << endl;
    cout << "Double list(3): " << p4->value_at_position(3) << endl;
    cout << "Double list contains the following elements: " << endl;
    p4->show_all();
    cout << endl;

    // Test with floats.
    float myfloats[] = { 57.123, 32.567, 56.8, 31.99535 };
    MyList<float> lst3(myfloats, myfloats+4);
    MyVector<float> vect3(myfloats, myfloats+5);
    MyCollection<float>* p5 = &vect3;
    MyCollection<float>* p6 = &lst3;

    cout << "Start of float vector: " << p5->starting_element() << endl;
    cout << "End of float vector: " << p5->last_element() << endl;
    cout << "Float vector[3]: " << p5->value_at_position(3) << endl;
    cout << "Float vector contains the following elements: " << endl;
    p5->show_all();
    cout << endl;

    cout << "Start of float list: " << p6->starting_element() << endl;
    cout << "End of float list: " << p6->last_element() << endl;
    cout << "Float list(3): " << p6->value_at_position(3) << endl;
    cout << "Float list contains the following elements: " << endl;
    p6->show_all();
    cout << endl;

    return 0;
}
예제 #7
0
파일: main.cpp 프로젝트: lge88/OpenSees
int main(int argc, char **argv)
{
    bool fail = false;

    //
    //	now create a domain and a modelbuilder
    //  and build the model
    //
    FEM_ObjectBroker theBroker;
    Domain *theDomain = new Domain();

    FileDatastore *theDatabase
        = new FileDatastore("/tmp/database/test1",*theDomain,theBroker);
    FileDatastore &theDb = *theDatabase;

    opserr << "TESTING IDs: \n";

    ID id1(2);
    id1(0) = 1;
    id1(1) = 1;
    ID id0(2);
    id0(0) = 0;
    id0(1) = 0;
    ID id2(2);
    id2(0) = 2;
    id2(1) = 2;
    ID id3(2);
    id3(0) = 3;
    id3(1) = 3;
    ID id4(2);
    id4(0) = 4;
    id4(1) = 4;
    ID id5(2);
    id5(0) = 5;
    id5(1) = 5;
    ID id6(2);
    id6(0) = 6;
    id6(1) = 6;


    theDb.sendID(1,1,id1);
    theDb.sendID(1,2,id2);
    theDb.sendID(2,1,id3);
    theDb.sendID(2,2,id4);

    opserr << "RESULTS\n";
    ID recvID(2);
    theDb.recvID(1,1,recvID);
    opserr << "1: " << recvID;
    theDb.recvID(1,2,recvID);
    opserr << "2: " << recvID;
    theDb.recvID(2,1,recvID);
    opserr << "3: " << recvID;
    theDb.recvID(2,2,recvID);
    opserr << "4: " << recvID;

    theDb.sendID(1,1,id1);
    theDb.sendID(3,1,id3);
    theDb.sendID(2,1,id2);


    theDb.sendID(0,1,id0);
    theDb.sendID(1,2,id1);
    theDb.sendID(2,2,id2);
    theDb.sendID(3,1,id3);
    theDb.sendID(5,1,id5);
    theDb.sendID(4,1,id4);
    theDb.sendID(1,1,id1);




    theDb.recvID(3,1,id5);
    opserr << "3: " << id5;
    theDb.recvID(1,1,id5);
    opserr << "1: " << id5;
    theDb.recvID(2,1,id5);

    opserr << "2: " << id5;
    theDb.recvID(1,2,id5);
    opserr << "1: " << id5;
    theDb.recvID(2,2,id5);

    opserr << "3: " << id5;
    theDb.recvID(3,1,id5);
    opserr << "3: " << id5;

    theDb.recvID(4,1,id5);
    opserr << "4: " << id5;
    theDb.recvID(5,1,id5);
    opserr << "5: " << id5;

    opserr << "FAILURE: " << theDb.recvID(6,1,id5) << " returned\n";
    opserr << "FAILURE " <<  theDb.recvID(6,1,id5) << " returned\n";

    theDb.recvID(0,1,id5);
    opserr << "0: " << id5;
    theDb.recvID(5,1,id5);
    opserr << "5: " << id5;

    ID id64(4);
    id64(0) = 6;
    id64(1) = 6;
    id64(2) = 6;
    id64(3) = 6;
    theDb.sendID(6,1,id64);
    theDb.recvID(6,1,id64);
    opserr << id64;


    opserr << "TESTING MATRICES: \n";

    Matrix mat1(2,2);
    mat1(0,0) = 1.1;
    mat1(0,1) = 11.1;
    mat1(1,0) = 111.1;
    mat1(1,1) = 1111.1;

    Matrix mat2(2,2);
    mat2(0,0) = 2.2;
    mat2(0,1) = 22.2;
    mat2(1,0) = 222.2;
    mat2(1,1) = 2222.2;

    theDb.sendMatrix(2,1,mat2);
    theDb.sendMatrix(1,1,mat1);
    theDb.sendMatrix(3,2,mat2);
    theDb.sendMatrix(3,1,mat1);

    Matrix mat3(2,2);
    theDb.recvMatrix(1,1,mat3);
    opserr << mat1 << mat3 << endln;
    theDb.recvMatrix(2,1,mat3);
    opserr << mat2 << mat3 << endln;
    theDb.recvMatrix(3,2,mat3);
    opserr << mat2 << mat3 << endln;
    theDb.recvMatrix(3,1,mat3);
    opserr << mat1 << mat3 << endln;

    //    theDb.sendMatrix(2,1,mat1);
    theDb.recvMatrix(2,1,mat3);
    opserr << mat2 << mat3;



    opserr << "TESTING VECTORS: \n";

    Vector vect1(2);
    vect1(0) = 1.1;
    vect1(1) = 2.22;

    Vector vect2(2);
    vect2(0) = 3;
    vect2(1) = 4.2;

    Vector vect3(2);
    vect3(0) = 5;
    vect3(1) = 6;

    Vector vect4(2);
    vect4(0) = 7;
    vect4(1) = 8.8e12;

    theDb.sendVector(1,1,vect1);
    theDb.sendVector(1,2,vect2);
    theDb.sendVector(2,1,vect3);
    theDb.sendVector(2,2,vect4);

    opserr << "RESULTS\n";
    Vector vect5(2);
    theDb.recvVector(1,1,vect5);
    opserr << vect1 << vect5 << endln;
    theDb.recvVector(1,2,vect5);
    opserr << vect2 << vect5 << endln;
    theDb.recvVector(2,1,vect5);
    opserr << vect3 << vect5 << endln;
    theDb.recvVector(2,2,vect5);
    opserr << vect4 << vect5 << endln;

    theDb.sendVector(2,2,vect1);
    theDb.sendVector(2,1,vect2);
    theDb.sendVector(1,2,vect3);
    theDb.sendVector(1,1,vect4);

    theDb.recvVector(1,1,vect5);
    opserr << vect4 << vect5 << endln;
    theDb.recvVector(1,2,vect5);
    opserr << vect3 << vect5 << endln;
    theDb.recvVector(2,1,vect5);
    opserr << vect2 << vect5 << endln;
    theDb.recvVector(2,2,vect5);
    opserr << vect1 << vect5 << endln;


    theDb.sendVector(4,4,vect5);
    theDb.recvVector(4,4,vect5);
    opserr << vect5 << vect5 << endln;

    theDb.recvVector(5,5,vect5);
    opserr << "FAIL\n";

    theDatabase->commitState(0);

    /*  */

    /*
    theDb.sendID(2,2,id1);
    theDb.sendID(2,1,id2);
    theDb.sendID(1,2,id3);
    theDb.sendID(1,1,id4);

    theDb.recvID(1,1,id5);
    opserr << id5;
    theDb.recvID(1,2,id5);
    opserr << id5;
    theDb.recvID(2,1,id5);
    opserr << id5;
    theDb.recvID(2,2,id5);
    opserr << id5;

    theDb.sendID(4,4,id5);
    theDb.recvID(4,4,id5);
    opserr << id5;

    theDb.recvID(5,5,id5);
    opserr << id5;
    */

    /**************************

    **************************/
    /*

    */

//  theModelBuilder->buildFE_Model();
//  theDb.commitState(0);
//  theDb.restoreState(0);


    // theDb.restoreElements(0);

    /*
    theDb.restoreNode(1,0);
    theDb.restoreNode(2,0);
    theDb.restoreNode(3,0);
    theDb.restoreNode(4,0);
    theDb.restoreElement(0,0);
    theDb.restoreElement(1,0);
    theDb.restoreElement(2,0);
    */

    //  opserr << *theDomain;

    delete theDatabase;

    exit(0);
}