void StringElement::buildParticlesAndSprings() { Vector2d xAxis = getEndPosition() - getStartPosition(); double length = xAxis.norm(); int requiredMasses = static_cast<int>(ceil(length / stdMaxMassDistance) + 1.0); double massDistance = length / requiredMasses; xAxis.normalize(); for (int i = 0; i < requiredMasses; i++) { Vector2d massPosition = getStartPosition() + (xAxis * (i * massDistance)); particles.push_back(createParticle(stdMassValue, stdMassRadius, massPosition)); } for (int i = 0; i < requiredMasses - 1; i++) { springs.push_back(new Spring(*particles[i], *particles[i + 1], stdK)); } if (getFromConnectionPoint().isConnected()) { ConnectionPoint::particle_list connectionParticles = getFromConnectionPoint().getConnectionParticles(); for (ConnectionPoint::particle_list::iterator it = connectionParticles.begin(); it != connectionParticles.end(); ++it) { springs.push_back(new Spring(*particles[0], **it, stdK)); } } if (getToConnectionPoint().isConnected()) { ConnectionPoint::particle_list connectionParticles = getToConnectionPoint().getConnectionParticles(); for (ConnectionPoint::particle_list::iterator it = connectionParticles.begin(); it != connectionParticles.end(); ++it) { springs.push_back(new Spring(*particles[particles.size() - 1], **it, stdK)); } } }
// directed (one end is wider than the other) vector<Poly> dir_thick_line(const Vector2d &from, const Vector2d &to, double fr_width, double to_width) { vector<Poly> p; if (fr_width < 0.001 || to_width < 0.001) return p; if (to.squared_distance(from) < 0.001) return p; if ((fr_width < 0) != (to_width < 0)) return p; Poly poly; Vector2d fdir = (to-from); fdir.normalize(); Vector2d tdir = fdir; fdir *= fr_width/4.; tdir *= to_width/4.; Vector2d fr_dirp(-fdir.y(), fdir.x()); Vector2d to_dirp(-tdir.y(), tdir.x()); poly.addVertex(from-fdir-fr_dirp); poly.addVertex(from-fdir+fr_dirp); poly.addVertex(to+tdir+to_dirp); poly.addVertex(to+tdir-to_dirp); p.push_back(poly); return p; //return Clipping::getOffset(poly, distance/4, jmiter, 0); // slow: // poly.addVertex(from); // poly.addVertex(to); // return Clipping::getOffset(poly, distance/2, jround, distance/2.); }
double TP_trendofdelivery_tp_sentido::getAngle(const Vector2d &u, const Vector2d &v, const double &t) { Vector2d w = v - u; Vector2d k = w.normal(); k = k.normalize() * t; k = k + v; return k.angle(w); }
inline Vector2d Vector2d::normalized() const { Vector2d toReturn = *this; toReturn.normalize(); return toReturn; }
void CPlayer::onMove( Vector2d dir ) { Vector2d v; dir=dir.normalize(); v.x=(getCenter().x+dir.x*size.x); v.y=(getCenter().y+dir.y*size.y); setGoalPoint(v); CMoveObject::onMove(dir); }
Vector3d OrbifoldData::collapseX333(const Vector3d& pt, Vector3d& out_dir) const { const double SQRT_3_OVER_2 = 0.8660254037844386; const double SQRT_3_OVER_3 = 0.5773502691896257; const Vector2d o = -direction_info[0].base; const Vector2d e = Vector2d(pt.x(), pt.z()) - direction_info[0].base; Vector2d d = (e-o); d.normalize(); // Mirror 0 on the bottom const StaticDirectionInfo sdi1 = { Vector2d{0, 1}, Vector2d{1, 0}, { 0, 1, 2 } }; // Mirror 1 on the right const StaticDirectionInfo sdi2 = { Vector2d{SQRT_3_OVER_2, 0.5}, Vector2d{-0.5, SQRT_3_OVER_2}, { 0, 1, 2 } }; // Mirror 2 on the left const StaticDirectionInfo sdi3 = { Vector2d{-SQRT_3_OVER_2, 0.5}, Vector2d{0.5, SQRT_3_OVER_2}, { 2, 1, 0 } }; // The number of mirrors intersected in each direction const unsigned n1 = countMirrorsHomogeneous(o, e, d, sdi1, direction_info[0]); const unsigned n2 = countMirrorsHomogeneous(o, e, d, sdi2, direction_info[0]); const unsigned n3 = countMirrorsHomogeneous(o, e, d, sdi3, direction_info[0]); // These values will be negative if the path from the origin to the point is going // opposite to the normal of the mirror const double sign1 = sign<double>(dot(d, sdi1.o)); const double sign2 = sign<double>(dot(d, sdi2.o)); const double sign3 = sign<double>(dot(d, sdi3.o)); const double translate_x = (sdi1.o[0]*sign1*n1 + sdi2.o[0]*sign2*n2 + sdi3.o[0]*sign3*n3); const double translate_z = (sdi1.o[1]*sign1*n1 + sdi2.o[1]*sign2*n2 + sdi3.o[1]*sign3*n3); Vector3d ret = pt; ret.x() -= translate_x * scale.x() * SQRT_3_OVER_3; ret.y() = pt.y(); ret.z() -= translate_z * scale.x() * SQRT_3_OVER_3; if(n1 % 2 != 0) { out_dir.z() *= -1; ret.z() *= -1; } if(n2 % 2 != 0) { reflect(sdi2.o, ret, out_dir); } if(n3 % 2 != 0) { reflect(sdi3.o, ret, out_dir); } return ret; }
void ComponentAIProjectile::update() { /*if(!GameManager::getInstance()->getMapManager()->isEmpty(parent->position)) { parent->kill(); }*/ Vector2d direction = parent->velocity; direction.normalize(); parent->position += direction * (Math::random(-50,50)/100.0); }
// make vertices at least epsilon apart int cleandist(vector<Vector2d> &vert, double epsilon) { uint n_vert = vert.size(); double sqeps = epsilon * epsilon; uint n_moved = 0; if (vert[0].squared_distance(vert[n_vert-1]) < sqeps){ const Vector2d center = (vert[0]+vert[n_vert-1])/2; Vector2d dir = vert[0]-center; dir.normalize(); vert[0] = center + dir*epsilon; n_moved++; } for (uint i = 1; i < n_vert ; i++) { if (vert[i].squared_distance(vert[i-1]) < sqeps){ const Vector2d center = (vert[i]+vert[i-1])/2; Vector2d dir = vert[i]-center; dir.normalize(); vert[i] = center + dir*epsilon; n_moved++; } } return n_moved; }
Vector2d ComponentSteering::followLeader(GameObject* leader) { Vector2d tv = leader->velocity; Vector2d force; // Calculate the behind point tv *= -1; tv.normalize(); tv *= 10; Vector2d behindLeader = leader->position + tv; // Creates a force to arrive at the behind point force = force + arrive(behindLeader); return force; }
vector<Poly> thick_line(const Vector2d &from, const Vector2d &to, double width) { vector<Poly> p; if (width < 0.001) return p; if (to.squared_distance(from) < 0.001) return p; Poly poly; Vector2d dir = (to-from); dir.normalize(); dir *= width/4.; Vector2d dirp(-dir.y(),dir.x()); poly.addVertex(from-dir-dirp); poly.addVertex(from-dir+dirp); poly.addVertex(to+dir+dirp); poly.addVertex(to+dir-dirp); p.push_back(poly); return Clipping::getOffset(poly, width/4, jmiter, 0); // slow: // poly.addVertex(from); // poly.addVertex(to); // return Clipping::getOffset(poly, distance/2, jround, distance/2.); }
// Comprueba colision entre Colliders. Dos objetos se tocan/colisionan void CollisionManager::checkCollisionBetween (ComponentCollider* currentCollider, ComponentCollider* targetCollider) { GameObject *targetGameObject = targetCollider->getGameObject(); //if(targetGameObject->isDead()) //{ // return; // } // Direccion entre objetos //Al hacerlo en una linea nos ahorramos crear un vector2d muchas veces float distance = (targetGameObject->position - currentCollider->getGameObject()->position).getSqrLength(); float sqrCollisionRadius = currentCollider->getSqrCollisionRadius(); float sqrTargetRadius = targetCollider->getSqrCollisionRadius(); // Colisionan. Se activa una colision en los dos objetos involucrados if(distance <= sqrCollisionRadius + sqrTargetRadius) { if(distance == 0) { targetGameObject->position += Vector2d(0,0.01); distance = (targetGameObject->position - currentCollider->getGameObject()->position).getSqrLength(); } Vector2d direction = targetGameObject->position - currentCollider->getGameObject()->position; direction.normalize(); direction *= Math::sqrt(Math::abs(distance - (sqrCollisionRadius + sqrTargetRadius))); // La colision se envia con un objeto que es con el cual choca Collision collision; collision.collider = targetGameObject; collision.direction = direction; currentCollider->onCollision(collision); //La colision deberia llegar a los dos, si no, deberia ser checkVision... collision.collider = currentCollider->getGameObject(); collision.direction = direction * -1; targetCollider->onCollision(collision); } }
Vector2d signed_distance_2d::closestPointOnLineSegment(Vector2d point, Vector2d p1, Vector2d p2) { // We are working with line representation L = {u*z + d | z is a real number, u is normalized} // u and d are in R^2 (2D vectors) // Get Unit vector in direction of edge Vector2d u = p1 - p2; if ((u.cwiseAbs()).sum() != 0) { u.normalize(); // Assuming u has nonzero length } else { u << 0, 0; } Vector2d d = p1; // d can be any point on the line. p1 or p2 will do double t = (point - d).dot(u); // Find if point is on line segment or if it needs to be projected to an end of segment // Do this in projected 1D space. Find t for both p1 and p2, and compare to t from the point. double p1t = (p1 - d).dot(u); double p2t = (p2 - d).dot(u); if (t <= min(p1t, p2t)) { t = min(p1t, p2t); } else if (t >= max(p1t, p2t)) { t = max(p1t, p2t); } Vector2d proj = u.array() * t; proj += d; // Sanity check Vector2d a = perpendicularAxis(u); double c = a.dot(p1); // Constant, a'*x + d = 0 double eps = 1e-5; if (abs(a.dot(proj) - c) > eps) { std::cout << "Warning: Projection on line is not on line with tolerance " << eps << std::endl; } return proj; }
// Douglas-Peucker algorithm vector<Vector2d> simplified(const vector<Vector2d> &vert, double epsilon) { if (epsilon == 0) return vert; uint n_vert = vert.size(); if (n_vert<3) return vert; double dmax = 0; //Find the point with the maximum distance from line start-end uint index = 0; Vector2d normal = normalV(vert.back()-vert.front()); normal.normalize(); if( (normal.length()==0) || ((abs(normal.length())-1)>epsilon) ) return vert; for (uint i = 1; i < n_vert-1 ; i++) { double dist = abs((vert[i]-vert.front()).dot(normal)); if (dist >= epsilon && dist > dmax) { index = i; dmax = dist; } } vector<Vector2d> newvert; if (index > 0) // there is a point > epsilon { // divide at max dist point and cleanup both parts recursively vector<Vector2d> part1; part1.insert(part1.end(), vert.begin(), vert.begin()+index+1); vector<Vector2d> c1 = simplified(part1, epsilon); vector<Vector2d> part2; part2.insert(part2.end(), vert.begin()+index, vert.end()); vector<Vector2d> c2 = simplified(part2, epsilon); newvert.insert(newvert.end(), c1.begin(), c1.end()-1); newvert.insert(newvert.end(), c2.begin(), c2.end()); } else { // all points are nearer than espilon newvert.push_back(vert.front()); newvert.push_back(vert.back()); } return newvert; }
vector<Segment> Shape::getCutlines(const Matrix4d &T, double z, vector<Vector2d> &vertices, double &max_gradient, vector<Triangle> &support_triangles, double supportangle, double thickness) const { Vector2d lineStart; Vector2d lineEnd; vector<Segment> lines; // we know our own tranform: Matrix4d transform = T * transform3D.transform ; int count = (int)triangles.size(); // #ifdef _OPENMP // #pragma omp parallel for schedule(dynamic) // #endif for (int i = 0; i < count; i++) { Segment line(-1,-1); int num_cutpoints = triangles[i].CutWithPlane(z, transform, lineStart, lineEnd); if (num_cutpoints == 0) { if (supportangle >= 0 && thickness > 0) { if (triangles[i].isInZrange(z-thickness, z, transform)) { const double slope = -triangles[i].slopeAngle(transform); if (slope >= supportangle) { support_triangles.push_back(triangles[i].transformed(transform)); } } } continue; } if (num_cutpoints > 0) { int havev = find_vertex(vertices, lineStart); if (havev >= 0) line.start = havev; else { line.start = vertices.size(); vertices.push_back(lineStart); } if (abs(triangles[i].Normal.z()) > max_gradient) max_gradient = abs(triangles[i].Normal.z()); if (supportangle >= 0) { const double slope = -triangles[i].slopeAngle(transform); if (slope >= supportangle) support_triangles.push_back(triangles[i].transformed(transform)); } } if (num_cutpoints > 1) { int havev = find_vertex(vertices, lineEnd); if (havev >= 0) line.end = havev; else { line.end = vertices.size(); vertices.push_back(lineEnd); } } // Check segment normal against triangle normal. Flip segment, as needed. if (line.start != -1 && line.end != -1 && line.end != line.start) { // if we found a intersecting triangle Vector3d Norm = triangles[i].transformed(transform).Normal; Vector2d triangleNormal = Vector2d(Norm.x(), Norm.y()); Vector2d segment = (lineEnd - lineStart); Vector2d segmentNormal(-segment.y(),segment.x()); triangleNormal.normalize(); segmentNormal.normalize(); if( (triangleNormal-segmentNormal).squared_length() > 0.2){ // if normals do not align, flip the segment int iswap=line.start;line.start=line.end;line.end=iswap; } // cerr << "line "<<line.start << "-"<<line.end << endl; lines.push_back(line); } } return lines; }
void ComponentAIBomber::attackSquad(GameObject* targetPlayer) { int i=0; std::list<GameObject*>::iterator it; int lengthFrontRow = -1; int lengthBackRow = -1; if(defenders.size()/4 == 0 && defenders.size() > 0) { lengthBackRow = defenders.size()%4; if(lengthBackRow == 0) { lengthBackRow = 4; } } else { lengthBackRow = 4; lengthFrontRow = defenders.size()%4; if(lengthFrontRow == 0) { lengthFrontRow = 4; } } int separationBack = 20; int separationFront = 15; for (it=defenders.begin(); it!=defenders.end(); ++it) { if(!(*it)->isDead()) { Vector2d tv = targetPlayer->position - parent->position; //tv = Vector2d::getVector2dByAngle(parent->rotation); tv.normalize(); if(i < 4) { int total = separationBack * (lengthBackRow-1); tv.rotateBy(i%lengthBackRow*separationBack - total/2,Vector2d(0,0)); tv.normalize(); tv *= 15+10*i/lengthBackRow; } else { int total = separationFront * (lengthFrontRow-1); tv.rotateBy(i%lengthFrontRow*separationFront - total/2,Vector2d(0,0)); tv.normalize(); tv *= 15+10*i/lengthBackRow; } //angulo igual a nueva pos mirando hacia player (*it)->position = parent->position + tv; float desiredRotation = (players.front()->position - (*it)->position).getAngle(); float newRotation = (*it)->rotation - desiredRotation; newRotation = Math::warpAngle(newRotation); if(Math::abs(newRotation) < 0.001) { (*it)->rotation = desiredRotation; } else { (*it)->rotation -= newRotation * 0.2; } /*if(!GameManager::getInstance()->isServer()) { GameManager::getInstance()->getGraphicsEngine()->drawDebugLine(parent->position.asVector3d(),(*it)->position.asVector3d()); }*/ } i++; } }
const CollisionResult CollisionManager::test( const Polygon& a, const Polygon& b, const Vector2d& v ) { // A place to store our collision result. CollisionResult result; result.colliding = true; // Do a radius test first. if ( (a.getPosition()-a.getPosition()).getMagnitude() > (a.getRadius() + a.getRadius()) ){ result.colliding = false; return result; } // The minimum distance required to separate the two polygons. float mintranslation = FLT_MAX; // Loop through both polygon's vertices and test them. for( unsigned int i = 0; i < a.getVertexCount() + b.getVertexCount(); ++i ) { // Get the edge, polygons are stored as point clouds, so we have to subtract two points to get an edge. Vector2d edge; if( i < a.getVertexCount() ) edge = a.getVertex( i ) - a.getVertex( i+1 ); else edge = b.getVertex( i - a.getVertexCount() ) - b.getVertex( i - a.getVertexCount()+1 ); // Get a perpendicular ( right-hand ) to the edge. edge = Vector2d( -edge.getY(), edge.getX() ); edge.normalize(); // Project the two polygons onto the edge. float minA,maxA,minB,maxB; projectPolygon( edge, a, minA, maxA ); projectPolygon( edge, b, minB, maxB ); // Get the distance of separation. float distance = intervalDistance(minA, maxA, minB, maxB); // If the distance is greater than 0, they aren't overlapping, so let's try a velocity. if (distance > 0){ float velocityProjection = edge * v; // Get the projection of object A during the movement if (velocityProjection < 0) minA += velocityProjection; else maxA += velocityProjection; // Do the same as above, but now with velocity projected. float distance = intervalDistance(minA, maxA, minB, maxB); } // If the distance is greater than 0, they aren't overlapping nor will they collide, so break. if (distance > 0){ result.colliding = false; break; } // Check to see if this is the minimum translation so far. if( abs(distance) < mintranslation ){ mintranslation = abs(distance); result.separation = edge; } } // Calculate the minimum translation vector if a collision occured. if( result.colliding == true ){ // multiply it by the minimum translation distance. result.separation *= mintranslation; //make sure it's facing the right way. if (result.separation * (a.getPosition() - b.getPosition()) < 0) result.separation = -result.separation; } return result; }
Vector2d Vector2d::normalize(const Vector2d& v) { Vector2d tmp = v; tmp.normalize(); return tmp; }
Vector3d OrbifoldData::collapseX632(const Vector3d& pt, Vector3d& out_dir) const { const double SQRT_3_OVER_2 = 0.8660254037844386; const double SQRT_3_OVER_4 = 0.8660254037844386 * 0.5; const double SQRT_3_OVER_3 = 0.5773502691896257; const double SQRT_3_OVER_6 = 0.5773502691896257 * 0.5; const double ONE_THIRD = (1.0/3.0); const double ONE_SIXTH = (1.0/6.0); const Vector2d o = -direction_info[0].base; const Vector2d e = Vector2d(pt.x(), pt.z()) - direction_info[0].base; Vector2d d = (e-o); d.normalize(); // Homogeneous const StaticDirectionInfo sdi1 = { Vector2d{-0.5, SQRT_3_OVER_2}, Vector2d{SQRT_3_OVER_2, 0.5}, { 1, 1, 1 } }; const StaticDirectionInfo sdi2 = { Vector2d{0.5, SQRT_3_OVER_2}, Vector2d{SQRT_3_OVER_2, -0.5}, { 1, 1, 1 } }; const StaticDirectionInfo sdi3 = { Vector2d{-1, 0}, Vector2d{0, 1}, { 1, 1, 1 } }; // Heterogeneous const StaticDirectionInfo sdi4 = { Vector2d{0, 1}, Vector2d{1, 0}, { 2, 0, 2 } }; const StaticDirectionInfo sdi5 = { Vector2d{-SQRT_3_OVER_2, 0.5}, Vector2d{0.5, SQRT_3_OVER_2}, { 2, 0, 2 } }; const StaticDirectionInfo sdi6 = { Vector2d{SQRT_3_OVER_2, 0.5}, Vector2d{0.5, -SQRT_3_OVER_2}, { 2, 0, 2 } }; // These values will be negative if the path from the origin to the point is going // opposite to the normal of the mirror const double sign1 = sign<double>(dot(d, sdi1.o)); const double sign2 = sign<double>(dot(d, sdi2.o)); const double sign3 = sign<double>(dot(d, sdi3.o)); const double sign4 = sign<double>(dot(d, sdi4.o)); const double sign5 = sign<double>(dot(d, sdi5.o)); const double sign6 = sign<double>(dot(d, sdi6.o)); Vector2d p(0, 0); const unsigned n1 = countMirrorsHomogeneous(o, e, d, sdi1, direction_info[1]); p += static_cast<double>(n1)*sign1*ONE_THIRD * sdi1.o; const unsigned n2 = countMirrorsHomogeneous(o, e, d, sdi2, direction_info[1]); p += static_cast<double>(n2)*sign2*ONE_THIRD * sdi2.o; const unsigned n3 = countMirrorsHomogeneous(o, e, d, sdi3, direction_info[1]); p += static_cast<double>(n3)*sign3*ONE_THIRD * sdi3.o; unsigned mc1[3] = {0, 0, 0}; countMirrorsHeterogeneous(o, e, d, sdi4, direction_info[0], mc1); p += sign4*(mc1[0]*SQRT_3_OVER_3 + mc1[1]*ONE_THIRD + mc1[2]*ONE_THIRD) * sdi4.o; const unsigned n4 = mc1[0] + mc1[1] + mc1[2]; unsigned mc2[3] = {0, 0, 0}; countMirrorsHeterogeneous(o, e, d, sdi5, direction_info[0], mc2); p += sign5*(mc2[0]*SQRT_3_OVER_3 + mc2[1]*ONE_THIRD + mc2[2]*ONE_THIRD) * sdi5.o; const unsigned n5 = mc2[0] + mc2[1] + mc2[2]; unsigned mc3[3] = {0, 0, 0}; countMirrorsHeterogeneous(o, e, d, sdi6, direction_info[0], mc3); p += sign6*(mc3[0]*SQRT_3_OVER_3 + mc3[1]*ONE_THIRD + mc3[2]*ONE_THIRD) * sdi6.o; const unsigned n6 = mc3[0] + mc3[1] + mc3[2]; p *= scale.x(); Vector3d ret = pt; ret.x() -= p.x(); ret.z() -= p.y(); if(n1 % 2 != 0) { reflect(sdi1.o, ret, out_dir); } if(n2 % 2 != 0) { reflect(sdi2.o, ret, out_dir); } if(n3 % 2 != 0) { reflect(sdi3.o, ret, out_dir); } if(n4 % 2 != 0) { reflect(sdi4.o, ret, out_dir); } if(n5 % 2 != 0) { reflect(sdi5.o, ret, out_dir); } if(n6 % 2 != 0) { reflect(sdi6.o, ret, out_dir); } return ret; }
Vector2d<T> Vector2d<T>::normalized() const { Vector2d<T> vector = *(this); return vector.normalize(); }
void ComponentWallConstruction::buildingPhase() { parent->position = graphicsEngine->getMousePositionOnGround(); Vector2d pos = aiAux->getFrame(parent->position); lastPosition = aiAux->getFrameCenter(pos.y,pos.x); bresenham(); begin->setRotation((lastPosition-firstPosition).getAngle()); end->setPosition(lastPosition); end->setRotation((firstPosition-lastPosition).getAngle()); if(aiAux->checkMap(aiAux->getFrame(lastPosition).y,aiAux->getFrame(lastPosition).x) == 'W' || lastPosition.getSqrDistanceFrom(Vector2d(900,0)) < 122500) { canBuild = false; } else { canBuild = true; } float distance = firstPosition.getDistanceFrom(lastPosition); Vector2d center = lastPosition+((firstPosition-lastPosition).normalize() * distance/2); float scale = (distance-10)/15; if(scale>0) { wall->setPosition(center); wall->setScale(Vector3d(scale,1,1)); wall->setRotation((lastPosition-firstPosition).getAngle()); } else { wall->setPosition(Vector2d(5000,5000)); } if(firstPosition == lastPosition) { canBuild = false; } if(canBuild) { Vector2d direction = firstPosition - lastPosition; direction.normalize(); direction *= 5; Vector2d downright = (firstPosition+direction*4/5*-1).rotateBy(90,firstPosition+direction); Vector2d downleft = (firstPosition+direction*4/5*-1).rotateBy(-90,firstPosition+direction); Vector2d upright = (lastPosition+direction*4/5).rotateBy(-90,lastPosition-direction); Vector2d upleft = (lastPosition+direction*4/5).rotateBy(90,lastPosition-direction); /*if(!GameManager::getInstance()->isServer()) { GameManager::getInstance()->getGraphicsEngine()->drawDebugLine(upright.asVector3d(),downright.asVector3d()); GameManager::getInstance()->getGraphicsEngine()->drawDebugLine(downright.asVector3d(),downleft.asVector3d()); GameManager::getInstance()->getGraphicsEngine()->drawDebugLine(downleft.asVector3d(),upleft.asVector3d()); GameManager::getInstance()->getGraphicsEngine()->drawDebugLine(upleft.asVector3d(),upright.asVector3d()); }*/ std::vector<GameObject*> list = GameManager::getInstance()->getCollisionManager()->getGameObjectBetween(upright, upleft, downright, downleft); if(list.size() > 0) { canBuild = false; } } if(canBuild) { begin->setColor(2); end->setColor(2); } else { begin->setColor(0); end->setColor(0); } Vector2d textPosition = Vector2d(30,-30) + lastPosition; priceToShow->setText((std::to_wstring(price*distance)).c_str()); priceToShow->setPosition(textPosition); if(GameManager::getInstance()->getEventManager()->mouseState.leftButtonDown) { if(canBuild) { Message message; message.type = Message::TRY_BUY; message.value = price*distance; message.gameObject = parent; GameManager::getInstance()->getGameObjectManager()->getMainPlayer()->broadcastMessage(message); } } }
void ComponentAIBomber::defenderSquad() { //GameManager::getInstance()->getGraphicsEngine()->drawDebugLine(parent->position.asVector3d(), (parent->position + (Vector2d::getVector2dByAngle(-parent->rotation) * -30)).asVector3d(),2); int i=0; std::list<GameObject*>::iterator it; int cantRow = defenders.size(); int separationBack = 260/defenders.size(); for (it=defenders.begin(); it!=defenders.end(); ++it) { if(!(*it)->isDead()) { Vector2d tv = Vector2d::getVector2dByAngle(-parent->rotation) * -1; //tv = Vector2d::getVector2dByAngle(parent->rotation); int angle = 260/cantRow; tv.normalize(); int total = separationBack * (defenders.size()-1); tv.rotateBy(i*separationBack - total/2,Vector2d(0,0)); tv.normalize(); tv *= 15; //angulo igual a nueva pos mirando hacia player (*it)->position = parent->position + tv; if(players.empty()) { float desiredRotation = parent->rotation; float newRotation = (*it)->rotation - desiredRotation; newRotation = Math::warpAngle(newRotation); if(Math::abs(newRotation) < 0.001) { (*it)->rotation = desiredRotation; } else { (*it)->rotation -= newRotation * 0.2; } } else { float desiredRotation = (players.front()->position - (*it)->position).getAngle(); float newRotation = (*it)->rotation - desiredRotation; newRotation = Math::warpAngle(newRotation); if(Math::abs(newRotation) < 0.001) { (*it)->rotation = desiredRotation; } else { (*it)->rotation -= newRotation * 0.2; } } /*if(!GameManager::getInstance()->isServer()) { GameManager::getInstance()->getGraphicsEngine()->drawDebugLine(parent->position.asVector3d(),(*it)->position.asVector3d()); }*/ } i++; } }