void GraphicTestWindow::onPaint(int width, int height) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); _image.setTextureCoordinate(1, 3); _image.setSize(_image.originalSize()); _image.draw(); _rect.setColor(QColor(0, 255, 0)); _rect.setRect(50, 100, 500, 75); _rect.draw(); _rect.setColor(QColor(0, 255, 255)); _rect.setRect(50, 175, 500, 25); _rect.draw(); int textCount = 1; int quadCount = 1; QString textContent("Change the text from the settings"); if(_settings) { quadCount = _settings->quadCount(); textCount = _settings->textCount(); textContent = _settings->textContent(); } for(int i = 0; i < textCount; i++) { PhGraphicText text1(&_font1, textContent); text1.setRect(i % 200, i / 200, 500, 100); text1.setColor(QColor(128, 255, 0)); text1.setZ(5); text1.draw(); } _font1.setFontFile(_settings->font1File()); _font1.select(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glColor3f(0, 0, 1); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); //Begining the cube's drawing { for(int i = 0; i < quadCount; i++) { glTexCoord3f(0, 0, 1); glVertex3i(0, 0, 0); glTexCoord3f(1, 0, 1); glVertex3i(width, 0, 0); glTexCoord3f(1, 1, 1); glVertex3i(width, height, 0); glTexCoord3f(0, 1, 1); glVertex3i(0, height, 0); } } glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); // _text.setX(_text.getX() + 4); // if(_text.getX() > this.width()) // _text.setX(0); // if((_text.getX()+_text.getWidth()) < 0) // _text.setX(this.width()); PhGraphicSolidRect rect3(0, 800, 400, 300); rect3.setColor(Qt::blue); rect3.draw(); PhGraphicLoop vLoop; vLoop.setPosition(100, 500, 3); vLoop.setSize(220, 200); vLoop.setThickness(30); vLoop.setCrossSize(100); vLoop.setColor(QColor(255, 0, 255)); vLoop.draw(); PhGraphicLoop hLoop; hLoop.setHorizontalLoop(true); hLoop.setPosition(0, 800, 3); hLoop.setSize(300, 50); hLoop.setThickness(20); hLoop.setCrossSize(60); hLoop.setColor(QColor(255, 0, 255)); hLoop.draw(); //_yuvRect.draw(); PhGraphicDisc disc(300, 300, 100); disc.setColor(Qt::yellow); disc.draw(); for (int i = 0; i < 5; ++i) { PhGraphicDashedLine line(i, 0, 50*i, 300, 30); line.setColor(Qt::green); line.setZ(4); line.draw(); } PhGraphicArrow arrow1(PhGraphicArrow::DownLeftToUpRight, 150, 250, 200, 100); arrow1.setColor(Qt::red); arrow1.setZ(5); arrow1.draw(); PhGraphicArrow arrow2(PhGraphicArrow::UpLefToDownRight, 150, 400, 200, 100); arrow2.setColor(Qt::red); arrow2.setZ(5); arrow2.draw(); _yuvRect.draw(); _rgbRect.draw(); _font2.setFontFile(_settings->font2File()); _font2.select(); PhGraphicText text2(&_font2, "eéaàiîoô"); int textWidth = 500; text2.setRect(_x, 300, textWidth, 100); text2.setColor(QColor(255, 0, 0)); text2.setZ(1); text2.draw(); _x += 4; if(_x > width) _x = -textWidth; }
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; }
/*Arc consistency use*/ void CSP::arcConsistency(const State state) { int value; /*for each unassigned value, reset the domain to become '1,2,3,4,5,6,7,8,9'*/ for (int j = 0; j < 81; j++) { if ((variables[j / 9][j % 9].assignement == 0) && (variables[j / 9][j % 9].domain.size() != 9)) { variables[j / 9][j % 9].domain.clear(); for (int i = 1; i < 10; i++) { variables[j / 9][j % 9].domain.push_back(i); } } } /*create the Q to store all the arcs of assigned cell*/ queue<Arrow> Q; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { /*if the cell has been assigned, just remove all the value in the domian but only left the assigned value*/ if ((state.values[i][j] != 0)&&(variables[i][j].assignement!=0)) { value = state.values[i][j]; if (variables[i][j].domain.size() != 1) { variables[i][j].domain.clear(); variables[i][j].domain.push_back(value); } /*for each assigned cell, creat an arrow from the cell which is in the same row of assigned cell to the assigned cell*/ for (int a = 0; a < 9; a++) { if (a != j) { Arrow arrow(i * 9 + j, i * 9 + a); Q.push(arrow); Arrow arrow1(i * 9 + a,i * 9 + j ); Q.push(arrow1); } } /*for each assigned cell, creat an arrow from the cell which is in the same column of assigned cell to the assigned cell*/ for (int a = 0; a < 9; a++) { if (a != i) { Arrow arrow(i * 9 + j, a * 9 + j); Q.push(arrow); Arrow arrow1(a * 9 + j, i * 9 + j); Q.push(arrow1); } } /*for each assigned cell, creat an arrow from the cell which is in the same block of assigned cell to the assigned cell*/ for (int a = (i / 3) * 3; a < (i / 3) * 3 + 3; a++) { for (int b = (j / 3) * 3; b < (j / 3) * 3 + 3; b++) { if ( (a != i) && (b != j)) { Arrow arrow(i * 9 + j, a * 9 + b); Q.push(arrow); Arrow arrow1(a * 9 + b, i * 9 + j); Q.push(arrow1); } } } } } } /*the code is the same as the teacher taught in class*/ while (!Q.empty()) { /*record the updated cell*/ delete_sign = 0; Arrow cur = Q.front(); Q.pop(); int value; /*check whether the tail has deleted value*/ int size1,size2; /*if the head has only one value, the tail must delete the value if the tail has the same one*/ if (variables[cur.head / 9][cur.head % 9].domain.size() == 1) { size1 = variables[cur.tail / 9][cur.tail % 9].domain.size(); value = variables[cur.head / 9][cur.head % 9].domain[0]; variables[cur.tail / 9][cur.tail % 9].domain.erase(remove(variables[cur.tail / 9][cur.tail % 9].domain.begin(), variables[cur.tail / 9][cur.tail % 9].domain.end(), value), variables[cur.tail / 9][cur.tail % 9].domain.end()); size2 = variables[cur.tail / 9][cur.tail % 9].domain.size(); /*the tail deletes value*/ if(size1 != size2) delete_sign = 1; } else if (variables[cur.head / 9][cur.head % 9].domain.size() == 0) { size1 = variables[cur.tail / 9][cur.tail % 9].domain.size(); variables[cur.tail / 9][cur.tail % 9].domain.clear(); size2 = variables[cur.tail / 9][cur.tail % 9].domain.size(); /*the tail deletes value*/ if (size1 != size2) delete_sign = 1; } /*if the tail deletes value*/ /*add all the neighbor cells of tail into the Q to check arc consistency*/ if (delete_sign == 1) { /*add the same row*/ for (int a = 0; a < 9; a++) { if (a != cur.tail%9) { Arrow arrow(cur.tail, (cur.tail/9)*9+a); Q.push(arrow); Arrow arrow1((cur.tail / 9) * 9 + a,cur.tail ); Q.push(arrow1); } } /*add the same column*/ for (int a = 0; a < 9; a++) { if (a != cur.tail / 9) { Arrow arrow(cur.tail, a * 9 + cur.tail % 9); Q.push(arrow); Arrow arrow1(a * 9 + cur.tail % 9,cur.tail ); Q.push(arrow1); } } /*add the same block*/ for (int a = (cur.tail / 9 / 3) * 3; a < (cur.tail / 9 / 3) * 3 + 3; a++) { for (int b = (cur.tail % 9 / 3) * 3; b < (cur.tail % 9 / 3) * 3 + 3; b++) { if ((a != cur.tail / 9) && (b != cur.tail % 9)) { Arrow arrow(cur.tail, a*9+b); Q.push(arrow); Arrow arrow1(a * 9 + b,cur.tail ); Q.push(arrow1); } } } } } }