int main(int argc, char **argv) { carve::poly::Polyhedron *input = readPLY(argv[1]); double offset = strtod(argv[2], NULL); TestScene *scene = new TestScene(argc, argv, 3); glNewList(scene->draw_list_base, GL_COMPILE); doOffset(input, offset); glEndList(); glNewList(scene->draw_list_base + 1, GL_COMPILE); drawPolyhedron(input, .6, .6, .6, 1.0, false); glEndList(); glNewList(scene->draw_list_base + 2, GL_COMPILE); drawPolyhedronWireframe(input); glEndList(); scene->draw_flags[0] = true; scene->draw_flags[1] = true; scene->draw_flags[2] = true; scene->run(); delete scene; return 0; }
void Entity::move(sfld::Vector2f direction, int frameTime, float magnitude){ EntityList* list = entityManager_->getEntities(); for (auto& it : *list){ if (it.get() != this){ float dist = sfld::Vector2f(it->getPosition() - getPosition()).length(); if (!it->isWalkthrough()){ if (dist <= TILE_SIZE*1.5f){ //need accurate collisions here MTV mtv(Collision::getCollision(getSprite(), getShape(), it->getSprite(), it->getShape())); if (!(mtv.axis == MTV::NONE.axis && mtv.overlap == MTV::NONE.overlap)){; //collided sfld::Vector2f n = mtv.axis; sfld::Vector2f comp_u(0, 0); if (direction.dot(n) < 0){ if (n != sfld::Vector2f(0, 0)){ comp_u = n * (direction.dot(n) / n.dot(n)); //component of hit axis in dir } } direction = direction - comp_u; collided(it.get()); if (it->getDynamic() == DYNAMIC_STATIC){ //because then it won't resolve its own collisions it->collided(this); } } } } else{//otherwise, it's a circle, and we are only concerned with checking if they touch, no more if (dist <= TILE_SIZE*1.5f){ MTV mtv(Collision::getCollision(getSprite(), getShape(), it->getSprite(), it->getShape())); if (!(mtv.axis == MTV::NONE.axis && mtv.overlap == MTV::NONE.overlap)){ collided(it.get()); if (it->getDynamic() == DYNAMIC_STATIC){ //because then it won't resolve its own collisions it->collided(this); } } } } } } if (direction != sf::Vector2f(0, 0) && !rotating_){ //lastdir = dir; sprite_.setRotation(maths::toDegrees(atan2(direction.y, direction.x))); } doOffset(direction*(float)frameTime*magnitude); }