TEST(Mesh,CompareRealSpace) { alps::gf::real_space_index_mesh::container_type points1(boost::extents[20][3]); alps::gf::real_space_index_mesh::container_type points2(boost::extents[20][3]); alps::gf::real_space_index_mesh::container_type points3(boost::extents[20][3]); alps::gf::real_space_index_mesh::container_type points4(boost::extents[3][20]); for (int i=0; i<points1.num_elements(); ++i) { *(points1.origin()+i)=i; *(points2.origin()+i)=i; *(points3.origin()+i)=i+1; *(points4.origin()+i)=i; } alps::gf::real_space_index_mesh mesh1(points1); alps::gf::real_space_index_mesh mesh2(points2); alps::gf::real_space_index_mesh mesh3(points3); alps::gf::real_space_index_mesh mesh4(points4); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_TRUE(mesh1!=mesh4); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); EXPECT_FALSE(mesh1==mesh4); }
TEST(Mesh,CompareIndex) { alps::gf::index_mesh mesh1(20); alps::gf::index_mesh mesh2(20); alps::gf::index_mesh mesh3(19); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); }
TEST(Mesh,CompareITime) { alps::gf::itime_mesh mesh1(5.0, 20); alps::gf::itime_mesh mesh2(5.0, 20); alps::gf::itime_mesh mesh3(4.0, 20); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); }
TEST(Mesh,CompareMatsubara) { alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_NEGATIVE> mesh1(5.0, 20); alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_NEGATIVE> mesh2(5.0, 20); alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_NEGATIVE> mesh3(4.0, 20); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); }
Scene * D3D::BuildScene(IDirect3DDevice9 *d3dDevice) { // Setup some materials - we'll use these for // making the same mesh appear in multiple // colors D3DMATERIAL9 colors[8]; D3DUtil_InitMaterial( colors[0], 1.0f, 1.0f, 1.0f, 1.0f ); // white D3DUtil_InitMaterial( colors[1], 0.0f, 1.0f, 1.0f, 1.0f ); // cyan D3DUtil_InitMaterial( colors[2], 1.0f, 0.0f, 0.0f, 1.0f ); // red D3DUtil_InitMaterial( colors[3], 0.0f, 1.0f, 0.0f, 1.0f ); // green D3DUtil_InitMaterial( colors[4], 0.0f, 0.0f, 1.0f, 1.0f ); // blue D3DUtil_InitMaterial( colors[5], 0.4f, 0.4f, 0.4f, 0.4f ); // 40% grey D3DUtil_InitMaterial( colors[6], 0.25f, 0.25f, 0.25f, 0.25f ); // 25% grey D3DUtil_InitMaterial( colors[7], 0.65f, 0.65f, 0.65f, 0.65f ); // 65% grey // The identity matrix is always useful D3DXMATRIX ident; D3DXMatrixIdentity(&ident); // We'll use these rotations for some teapots and grid objects D3DXMATRIX rotateX, rotateY, rotateZ; // Create the root, and the camera. // Remeber how to use smart pointers?? I hope so! boost::shared_ptr<TransformNode> root(new TransformNode(&ident)); boost::shared_ptr<CameraNode> camera(new CameraNode(&ident)); root->m_children.push_back(camera); // We'll put the camera in the scene at (20,20,20) looking back at the Origin D3DXMATRIX rotOnly, result, inverse; float cameraYaw = - (3.0f * D3DX_PI) / 4.0f; float cameraPitch = D3DX_PI / 4.0f; D3DXQUATERNION q; D3DXQuaternionIdentity(&q); D3DXQuaternionRotationYawPitchRoll(&q, cameraYaw, cameraPitch, 0.0); D3DXMatrixRotationQuaternion(&rotOnly, &q); D3DXMATRIX trans; D3DXMatrixTranslation(&trans, 15.0f, 15.0f, 15.0f); D3DXMatrixMultiply(&result, &rotOnly, &trans); D3DXMatrixInverse(&inverse, NULL, &result); camera->VSetTransform(&result, &inverse); D3DXMatrixRotationZ(&rotateZ, D3DX_PI / 2.0f); D3DXMatrixRotationX(&rotateX, -D3DX_PI / 2.0f); D3DXVECTOR3 target(30, 2, 15); // ID3DXMesh *teapot; if( SUCCEEDED( D3DXCreateTeapot( d3dDevice, &teapot, NULL ) ) ) { // Teapot #1 - a white one at (x=6,y=2,z=4) D3DXMatrixTranslation(&trans,6,2,4); boost::shared_ptr<SceneNode> mesh1(new MeshNode(teapot, &trans, colors[2])); root->m_children.push_back(mesh1); // Teapot #2 - a cyan one at (x=3,y=2,z=1) // with a D3DXMatrixTranslation(&trans, 3,2,1); D3DXMATRIX result; D3DXMatrixMultiply(&result, &rotateZ, &trans); boost::shared_ptr<SceneNode> mesh2(new MeshNode(teapot, &result, colors[1])); root->m_children.push_back(mesh2); // Teapot #3 - another white one at (x=30, y=2, z=15) D3DXMATRIX rotateY90; D3DXMatrixRotationY(&rotateY90, D3DX_PI / 2.0f); D3DXMatrixTranslation(&trans, target.x, target.y, target.z); D3DXMatrixMultiply(&result, &rotateY90, &trans); boost::shared_ptr<SceneNode> mesh3(new MeshNode(teapot, &result, colors[0])); root->m_children.push_back(mesh3); // We can release the teapot now, mesh1 and mesh2 AddRef'd it. SAFE_RELEASE(teapot); } ID3DXMesh *sphere; if ( SUCCEEDED( D3DXCreateSphere( d3dDevice, .25, 16, 16, &sphere, NULL) ) ) { // We're going to create a spiral of spheres... // starting at (x=3, y=0, z=3), and spiraling // upward about a local Y axis. D3DXMatrixTranslation(&trans, 3,0,3); boost::shared_ptr<SceneNode> sphere1(new MeshNode(sphere, &trans, colors[4]) ); root->m_children.push_back(sphere1); // Here's the local rotation and translation. // We'll rotate about Y, and then translate // up (along Y) and forward (along Z). D3DXMatrixRotationY(&rotateY, D3DX_PI / 8.0f); D3DXMATRIX trans2; D3DXMatrixTranslation(&trans2, 0, 0.5, 0.5); D3DXMatrixMultiply(&result, &trans2, &rotateY); for (int i=0; i<25; i++) { // If you didn't think smart pointers were cool - // watch this! No leaked memory.... // Notice this is a heirarchy.... boost::shared_ptr<SceneNode> sphere2(new MeshNode(sphere, &result, colors[i%5]) ); sphere1->m_children.push_back(sphere2); sphere1 = sphere2; } // We can release the sphere now, all the cylinders AddRef'd it. SAFE_RELEASE(sphere); } // D3DXMatrixTranslation(&trans,-25,20,20); //D3DXMatrixScaling(&trans, -10, -10, -10); ScaleMtrl scale; scale.x = -50.0f; scale.y = -50.0f; scale.z = -50.0f; boost::shared_ptr<SceneNode> xmesh1(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh1); root->m_children.push_back(xmesh1); /*D3DXMatrixTranslation(&trans,-45,20,20); boost::shared_ptr<SceneNode> xmesh11(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh11);*/ XMeshNode *mm = new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale); D3DXMatrixTranslation(&trans,10,10,10); //D3DXMatrixScaling(&trans, -10, -10, -10); //ScaleMtrl scale; scale.x = 100.0f; scale.y = 100.0f; scale.z = 100.0f; boost::shared_ptr<SceneNode> xmesh2( new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh2); /*D3DXMatrixTranslation(&trans,20,20,20); boost::shared_ptr<SceneNode> xmesh3(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmesh3);*/ int col = 10; int row= 10; int zoom = 10; const int COUNT = 13; for(int i = 0; i < COUNT; i++) { for (int j = 0; j< COUNT; j++) { for(int z = 0; z< COUNT; z++) { D3DXMatrixTranslation(&trans, col + i, row + j , zoom + z); boost::shared_ptr<SceneNode> xmeshNew(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmeshNew); } } } //D3DXMatrixScaling(&trans, 10, 10, 10); // Here are the grids...they make it easy for us to // see where the coordinates are in 3D space. boost::shared_ptr<SceneNode> grid1(new Grid(40, 0x00404040, L"Textures\\grid.dds", &ident)); root->m_children.push_back(grid1); boost::shared_ptr<SceneNode> grid2(new Grid(40, 0x00004000, L"Textures\\grid.dds", &rotateX)); root->m_children.push_back(grid2); boost::shared_ptr<SceneNode> grid3(new Grid(40, 0x00000040, L"Textures\\grid.dds", &rotateZ)); root->m_children.push_back(grid3); // Here's the sky node that never worked!!!! boost::shared_ptr<SkyNode> sky(new SkyNode(_T("Sky2"), camera)); root->m_children.push_back(sky); D3DXMatrixTranslation(&trans,15,2,15); D3DXMatrixRotationY(&rotateY, D3DX_PI / 4.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow1(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow1); D3DXMatrixRotationY(&rotateY, D3DX_PI / 2.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow2(new ArrowNode(2, &result, colors[5], d3dDevice)); root->m_children.push_back(arrow2); D3DXMatrixMultiply(&result, &rotateX, &trans); boost::shared_ptr<SceneNode> arrow3(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow3); // Everything has been attached to the root. Now // we attach the root to the scene. Scene *scene = new Scene(d3dDevice, root); scene->Restore(); // A movement controller is going to control the camera, // but it could be constructed with any of the objects you see in this // function. You can have your very own remote controlled sphere. What fun... boost::shared_ptr<MovementController> m_pMovementController(new MovementController(camera, cameraYaw, cameraPitch)); scene->m_pMovementController = m_pMovementController; return scene; }
Mesh createMesh3D(const Mesh & mesh, const RVector & z, int topLayer, int bottomLayer){ Mesh mesh3(3); if (z.size() < 2){ std::cout << "Warning!: " << WHERE_AM_I << "extrusion vector size need z be greater than 1" << std::endl; } bool first = true; for (Index iz = 0; iz < z.size(); iz ++){ for (Index ic = 0; ic < mesh.nodeCount(); ic ++){ int marker = 0; if (first) marker = mesh.node(ic).marker(); mesh3.createNode(mesh.node(ic).pos() + RVector3(0.0, 0.0, z[iz]), marker); } first = false; } std::vector < Node * > nodes; for (Index iz = 1; iz < z.size(); iz ++){ first = true; for (Index ic = 0; ic < mesh.cellCount(); ic ++){ uint nC = mesh.cell(ic).nodeCount(); nodes.resize(nC * 2) ; for (Index k = 0; k < nC; k ++){ nodes[k] = & mesh3.node((iz-1) * mesh.nodeCount() + mesh.cell(ic).node(k).id()); } for (Index k = 0; k < nC; k ++){ nodes[nC + k] = & mesh3.node(iz * mesh.nodeCount() + mesh.cell(ic).node(k).id()); } mesh3.createCell(nodes, mesh.cell(ic).marker()); if (iz == 1){ // create top layer boundaries // in revers direction so the outer normal shows downward into the mesh std::vector < Node * > nBound(nC); for (Index k = 0; k < nC; k ++) nBound[nC - k - 1] = nodes[k]; mesh3.createBoundary(nBound, topLayer); } if (iz == z.size()-1){ // create bottom layer boundaries std::vector < Node * > nBound(nC); for (Index k = 0; k < nC; k ++) nBound[k] = nodes[nC + k]; mesh3.createBoundary(nBound, bottomLayer); } } first = false; } nodes.resize(4); for (Index iz = 1; iz < z.size(); iz ++){ for (Index ib = 0; ib < mesh.boundaryCount(); ib ++){ if (mesh.boundary(ib).marker() != 0){ nodes[0] = & mesh3.node((iz-1) * mesh.nodeCount() + mesh.boundary(ib).node(0).id()); nodes[1] = & mesh3.node((iz-1) * mesh.nodeCount() + mesh.boundary(ib).node(1).id()); nodes[3] = & mesh3.node(iz * mesh.nodeCount() + mesh.boundary(ib).node(0).id()); nodes[2] = & mesh3.node(iz * mesh.nodeCount() + mesh.boundary(ib).node(1).id()); mesh3.createBoundary(nodes, mesh.boundary(ib).marker()); } } } return mesh3; }
void NGLScene::initializeGL() { // we must call this first before any other GL commands to load and link the // gl commands from the lib, if this is not done program will crash ngl::NGLInit::instance(); glClearColor(0.4f, 0.4f, 0.4f, 1.0f); // Grey Background // enable depth testing for drawing glEnable(GL_DEPTH_TEST); // enable multisampling for smoother drawing glEnable(GL_MULTISAMPLE); // Now we will create a basic Camera from the graphics library // This is a static camera so it only needs to be set once // First create Values for the camera position ngl::Vec3 from(0,10,40); ngl::Vec3 to(0,10,0); ngl::Vec3 up(0,1,0); // first we create a mesh from an obj passing in the obj file and texture std::unique_ptr<ngl::Obj>mesh1( new ngl::Obj("models/BrucePose1.obj")); m_meshes.push_back(std::move(mesh1)); std::unique_ptr<ngl::Obj> mesh2( new ngl::Obj("models/BrucePose2.obj")); m_meshes.push_back(std::move(mesh2)); std::unique_ptr<ngl::Obj>mesh3( new ngl::Obj("models/BrucePose3.obj")); m_meshes.push_back(std::move(mesh3)); createMorphMesh(); m_view=ngl::lookAt(from,to,up); // set the shape using FOV 45 Aspect Ratio based on Width and Height // The final two are near and far clipping planes of 0.5 and 10 m_project=ngl::perspective(45,(float)720.0/576.0,0.05,350); // now to load the shader and set the values // grab an instance of shader manager ngl::ShaderLib *shader=ngl::ShaderLib::instance(); // we are creating a shader called PerFragADS shader->createShaderProgram("PerFragADS"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("PerFragADSVertex",ngl::ShaderType::VERTEX); shader->attachShader("PerFragADSFragment",ngl::ShaderType::FRAGMENT); // attach the source shader->loadShaderSource("PerFragADSVertex","shaders/PerFragASDVert.glsl"); shader->loadShaderSource("PerFragADSFragment","shaders/PerFragASDFrag.glsl"); // compile the shaders shader->compileShader("PerFragADSVertex"); shader->compileShader("PerFragADSFragment"); // add them to the program shader->attachShaderToProgram("PerFragADS","PerFragADSVertex"); shader->attachShaderToProgram("PerFragADS","PerFragADSFragment"); // now we have associated this data we can link the shader shader->linkProgramObject("PerFragADS"); // and make it active ready to load values (*shader)["PerFragADS"]->use(); // now we need to set the material and light values /* *struct MaterialInfo { // Ambient reflectivity vec3 Ka; // Diffuse reflectivity vec3 Kd; // Specular reflectivity vec3 Ks; // Specular shininess factor float shininess; };*/ shader->setUniform("material.Ka",0.1f,0.1f,0.1f); // red diffuse shader->setUniform("material.Kd",0.8f,0.8f,0.8f); // white spec shader->setUniform("material.Ks",1.0f,1.0f,1.0f); shader->setUniform("material.shininess",1000.0f); // now for the lights values (all set to white) /*struct LightInfo { // Light position in eye coords. vec4 position; // Ambient light intensity vec3 La; // Diffuse light intensity vec3 Ld; // Specular light intensity vec3 Ls; };*/ shader->setUniform("light.position",ngl::Vec3(2,20,2)); shader->setUniform("light.La",0.1f,0.1f,0.1f); shader->setUniform("light.Ld",1.0f,1.0f,1.0f); shader->setUniform("light.Ls",0.9f,0.9f,0.9f); glEnable(GL_DEPTH_TEST); // for removal of hidden surfaces // as re-size is not explicitly called we need to do this. glViewport(0,0,width(),height()); m_text.reset( new ngl::Text(QFont("Arial",16))); m_text->setScreenSize(width(),height()); }