void test_algebraic_primitives3d<POINT>::do_tests(std::ostream& out) { typedef point_traits<POINT> pt; typedef dimension_dependent_primitives_3d<POINT> ap; POINT b = pt::Origin(3); int li = pt::LowerIndex(b); // should be the same for all points POINT e[3]; for(int i = 0; i < 3; ++i) { e[i] = pt::Origin(3); e[i][li + i] = 1; b[li+i] = 1; } for(int i = 0; i < 3; ++i) { int j = (i < 2 ? i+1 : 0); int k = (i > 0 ? i-1 : 2); out << "ap::det3(e["<<i<<"],e["<<k<<"],e["<<j<<"]) = " << ap::det3(e[i],e[k],e[j]) << '\n' << "ap::det3(e["<<i<<"],e["<<j<<"],e["<<k<<"]) = " << ap::det3(e[i],e[j],e[k]) << '\n' << "ap::vectorproduct(e["<<i<<"],e["<<j<<"]) = " << ap::vectorproduct(e[i],e[j]) << '\n' << "ap::vectorproduct(e["<<i<<"],e["<<k<<"]) = " << ap::vectorproduct(e[i],e[k]) << '\n'; } POINT x = pt::Origin(3); ap::solve3(e[0],e[1],e[2],x,b); out << x << '\n'; ap::solve3(e[0],e[2],e[1],x,b); out << x << '\n'; POINT inv[3]; for(int i = 0; i < 3; ++i) { inv[i] = pt::Origin(3); } out << "ap::inverse(e[0],e[1],e[2]) = "; ap::invert(e[0],e[1],e[2],inv[0],inv[1],inv[2]); out << inv[0] << " " << inv[1] << " " << inv[2] << '\n'; out << "ap::inverse(e[0],e[2],e[1]) = "; ap::invert(e[0],e[2],e[1],inv[0],inv[1],inv[2]); out << inv[0] << " " << inv[1] << " " << inv[2] << '\n'; out<< "ap::condition(e[0],e[1],e[2],ap::Norm_frobenius()) = " << ap::condition(e[0],e[1],e[2],typename ap::Norm_frobenius()) << "\n"; out<< "ap::condition(e[0],e[1],e[2],ap::Norm_1()) = " << ap::condition(e[0],e[1],e[2],typename ap::Norm_1()) << "\n"; out<< "ap::condition(e[0],e[1],e[2],ap::Norm_infinity()) = " << ap::condition(e[0],e[1],e[2],typename ap::Norm_infinity()) << "\n"; POINT a[3]; for(int i = 0; i < 3; ++i) { a[i] = pt::Origin(3); a[i][li+i] = i+1; } out << "ap::inverse(a[0],a[1],a[2]) = "; ap::invert(a[0],a[1],a[2],inv[0],inv[1],inv[2]); out << inv[0] << " " << inv[1] << " " << inv[2] << '\n'; out << "ap::inverse(a[0],a[1],a[2]) = "; ap::invert(a[0],a[2],a[1],inv[0],inv[1],inv[2]); out << inv[0] << " " << inv[1] << " " << inv[2] << '\n'; out << "ap::matrixnorm_frobenius(a[0],a[1],a[2]) = " << ap::matrixnorm_frobenius(a[0],a[1],a[2]) << '\n' << "ap::matrixnorm_1(a[0],a[1],a[2]) = " << ap::matrixnorm_1(a[0],a[1],a[2]) << '\n' << "ap::matrixnorm_infinity(a[0],a[1],a[2]) = " << ap::matrixnorm_infinity(a[0],a[1],a[2]) << '\n'; out<< "ap::condition(a[0],a[1],a[2],ap::Norm_frobenius()) = " << ap::condition(a[0],a[1],a[2],typename ap::Norm_frobenius()) << "\n"; out<< "ap::condition(a[0],a[1],a[2],ap::Norm_1()) = " << ap::condition(a[0],a[1],a[2],typename ap::Norm_1()) << "\n"; out<< "ap::condition(a[0],a[1],a[2],ap::Norm_infinity()) = " << ap::condition(a[0],a[1],a[2],typename ap::Norm_infinity()) << "\n"; // matrix type typename ap::matrix_type A(0); typename ap::matrix_type B(ap::matrix_type::UnitMatrix()); typename ap::matrix_type C = A*B; out << "A= " << A[li+0] << " " << A[li+1] << " " << A[li+2] << "\n" << "B= " << B[li+0] << " " << B[li+1] << " " << B[li+2] << "\n" << "C= " << C[li+0] << " " << C[li+1] << " " << C[li+2] << "\n"; A(li+0,li+0) = 1; A(li+1,li+1) = 2; A(li+2,li+2) = 3; out << "A= " << A[li+0] << " " << A[li+1] << " " << A[li+2] << "\n"; C = A*B; out << "C= " << C[li+0] << " " << C[li+1] << " " << C[li+2] << "\n"; typename ap::matrix_type D(0); D(li+0, li+1) = 1; D(li+1, li+2) = 1; out << "D= " << D[li+0] << " " << D[li+1] << " " << D[li+2] << "\n"; D *= D; out << "D= " << D[li+0] << " " << D[li+1] << " " << D[li+2] << "\n"; out << "det(A)= " << ap::det(A) << "\n" << "|A|_1 = " << ap::matrixnorm_1(A) << "\n" << "|A|_oo = " << ap::matrixnorm_infinity(A) << "\n" << "|A|_F = " << ap::matrixnorm_frobenius(A) << "\n"; typedef segment<POINT> segment3; typedef ray<POINT> ray3; typedef triangle<POINT> triangle3; typedef intersection_segment_triangle<segment3, triangle3> intersection_t; typedef intersection_ray_triangle<ray3, triangle3> intersection_rt; //------- intersection test #1 ----------- // S = [ (0.25,0.25,-1), (0.25,0.25, 1)] // T = [ (0,0,0), (1,0,0), (0,1,1)] // intersection (0.25,0.25,0) POINT p[2], q[3]; for(int i = 0; i < 2; ++i) { p[i] = pt::Origin(3); } for(int i = 0; i < 3; ++i) { q[i] = pt::Origin(3); } pt::z(p[1]) = 1; pt::z(p[0]) = -1; pt::x(p[0]) = pt::x(p[1]) = pt::y(p[0]) = pt::y(p[1]) = 0.25; pt::x(q[1]) = 1; pt::y(q[2]) = 1; check_intersections(p[0],p[1], q[0],q[1],q[2], out); //------- intersection test #2 ----------- // S = [ (0.25,0.25, 0.5), (0.25,0.25, 1)] // T = [ (0,0,0), (1,0,0), (0,1,1)] // intersection does not exist // segment: uses const& of POINT pt::z(p[0]) = 0.5; check_intersections(p[0],p[1], q[0],q[1],q[2], out); //------- intersection test #3 ----------- // S = [(0.5,0.5,0), (0.5,0.5,1)] // T = [(-0.5,-0.5,0), (-0.5, 0.5,1), (-0.5,-0.5,1) // intersection does not exist pt::x(p[0]) = pt::x(p[1]) = pt::y(p[0]) = pt::y(p[1]) = 0.5; pt::z(p[0]) = 0; pt::z(p[1]) = 1; pt::x(q[0]) = pt::x(q[1]) = pt::x(q[2]) = -0.5; pt::y(q[1]) = 0.5; pt::y(q[0]) = pt::y(q[2]) = -0.5; pt::z(q[0]) = 0; pt::z(q[1]) = pt::z(q[2]) = 1; check_intersections(p[0],p[1], q[0],q[1],q[2], out); //------- intersection test #4 ----------- // segmen/ray parallel to triangle { POINT p0(1,1,2), p1(1,0,2); POINT q0(0,0,0), q1(1,0,0), q2(0,1,0); check_intersections(p0,p1, q0,q1,q2,out); } //------- intersection test #5 ----------- // intersection on edge of triangle { POINT p0(.5,.5,-1), p1(.5,.5,1); POINT q0(0,0,0), q1(1,0,0), q2(0,1,0); check_intersections(p0,p1, q0,q1,q2,out); } std::vector<POINT> d1(e, e+1); std::vector<POINT> d2(e, e+2); std::vector<POINT> d3(1, e[0]+e[1]); std::vector<POINT> d4(2); d4[0]= e[0]+e[1]; d4[1] = e[1]+e[2]; std::vector<POINT> c1 = ap::basis_completion(d1); std::vector<POINT> c2 = ap::basis_completion(d2); std::vector<POINT> c3 = ap::basis_completion(d3); std::vector<POINT> c4 = ap::basis_completion(d4); out << "ap::basis_completion(" << d1[0] << ") = " << c1[0] << "; " << c1[1] << std::endl; out << "ap::basis_completion(" << d2[0] << "; " << d2[1] << ") = " << c2[0] << std::endl; out << "ap::basis_completion(" << d3[0] << ") = " << c3[0] << "; " << c3[1] << std::endl; out << "ap::basis_completion(" << d4[0] << "; " << d4[1] << ") = " << c4[0] << std::endl; }
int Game::update() { sf::RenderWindow window(sf::VideoMode(WINDOW_W, WINDOW_H), "SFML works!"); sf::Font font; if (!font.loadFromFile("Super Plumber Brothers.ttf") ) { return EXIT_FAILURE ; } sf::Text text,text2; text.setFont(font); text.setCharacterSize(24); text.setPosition(450,10); text2.setFont(font); text2.setCharacterSize(48); text2.setPosition(150,70); text2.setString("GAME OVER"); Clock clock; std::list<Active*>::iterator it; char buffer[20]; gameover = false; while (window.isOpen()) { float time = clock.getElapsedTime().asMicroseconds(); time = time/700; clock.restart(); sf::Event event; while (window.pollEvent(event)) { if(event.type == sf::Event::Closed) window.close(); if(event.type == Event::KeyPressed) if(event.key.code==Keyboard::Space) { active.push_back(Active::create(BULLET,player.getX(),player.getY())); } if(event.type == Event::KeyPressed) if(event.key.code==Keyboard::Escape) { if(pause) { pause = false; } else { pause = true; } } if(pause) { if(event.type == Event::KeyPressed) { if(event.key.code==Keyboard::Up) { menu.prev(); } if(event.key.code==Keyboard::Down) { menu.next(); } if(event.key.code==Keyboard::Return) switch(menu.getSelected()) { case 0: newGame(); break; case 1: window.close(); break; } } } } if(!gameover && !pause) { if(Keyboard::isKeyPressed(Keyboard::Up)) { if(player.isOnGround()) { player.jump(); } } if(rand()%100==0) active.push_back(Active::create(ENEMY,510+offsetx,163)); offsetx = player.getX()-PLAYER_X; map.update(offsetx); player.update(time, map); if(player.isLive() == false) gameover = true; for(it = active.begin(); it != active.end(); it++) (*it)->update(map, time, offsetx); score+=1; check_intersections(); } deleteActive(); window.clear(); if(!pause) { map.draw(window); player.draw(window); for(it = active.begin(); it != active.end(); it++) (*it)->draw(window, offsetx); sprintf(buffer,"%d",score); text.setString(buffer); window.draw(text); if(gameover) window.draw(text2); } else menu.draw(window); window.display(); } return 0; }