void NGLScene::updateMember(Member &io_toUpdate) { ngl::Vec3 alignment = calcAlignment(io_toUpdate) * 10; ngl::Vec3 cohesion = /*followSphere->getPosition() - */calcCohesion(io_toUpdate) *10; ngl::Vec3 separation = calcSeparation(io_toUpdate); ngl::Vec3 newVelocity = (followSphere->getPosition()) - (io_toUpdate.getPosition() + (ngl::Vec3(alignment + cohesion + separation))); for(unsigned int i = 0; i<ShapeStore.ShapeList.size(); i++) { float shapeDist = calcDistance(getMemberPosition(ShapeStore.ShapeList[i]), io_toUpdate.getPosition()); if(abs(shapeDist) < 8.0f) { newVelocity += (io_toUpdate.getPosition() - getMemberPosition(ShapeStore.ShapeList[i])) * 100; } } if(newVelocity.lengthSquared() != 0.0f) { newVelocity.normalize(); } //std::cout<<"x = "<<newVelocity.m_x<<" y = "<<newVelocity.m_y<<" z = "<<newVelocity.m_z<<"\n"; // if(newVelocity.m_x < 0.0f) // { // newVelocity.m_x = -newVelocity.m_x; // } // if(newVelocity.m_y < 0.0f) // { // newVelocity.m_y = -newVelocity.m_y; // } // if(newVelocity.m_z < 0.0f) // { // newVelocity.m_z = -newVelocity.m_z; // } float dist = ngl::Vec3(followSphere->getPosition() - io_toUpdate.getPosition()).length(); if (dist > 15.0f) { io_toUpdate.setForwardVector(followSphere->getPosition()); io_toUpdate.calcSideVector(); } else { io_toUpdate.setSideVector(followSphere->getPosition()); io_toUpdate.calcForwardVector(); } io_toUpdate.getForwardVector().normalize(); if(io_toUpdate.getForwardVector().m_x <0.0f) { io_toUpdate.setForwardVector(ngl::Vec3(-io_toUpdate.getForwardVector().m_x, io_toUpdate.getForwardVector().m_y, io_toUpdate.getForwardVector().m_z)); } if(io_toUpdate.getForwardVector().m_y <0.0f) { io_toUpdate.setForwardVector(ngl::Vec3(io_toUpdate.getForwardVector().m_x, -io_toUpdate.getForwardVector().m_y, io_toUpdate.getForwardVector().m_z)); } if(io_toUpdate.getForwardVector().m_z <0.0f) { io_toUpdate.setForwardVector(ngl::Vec3(io_toUpdate.getForwardVector().m_x, io_toUpdate.getForwardVector().m_y, -io_toUpdate.getForwardVector().m_z)); } io_toUpdate.setVelocity(newVelocity * 0.0001f * (io_toUpdate.getForwardVector() + io_toUpdate.getPosition()) , false); if(io_toUpdate.getVelocity().m_x > 0.5f) { io_toUpdate.setVelocity(ngl::Vec3(0.5f, io_toUpdate.getVelocity().m_y, io_toUpdate.getVelocity().m_z), true); } else if(io_toUpdate.getVelocity().m_x < -0.5f) { io_toUpdate.setVelocity(ngl::Vec3(-0.5f, io_toUpdate.getVelocity().m_y, io_toUpdate.getVelocity().m_z), true); } if(io_toUpdate.getVelocity().m_y > 0.5f) { io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x, 0.5f, io_toUpdate.getVelocity().m_z), true); } else if(io_toUpdate.getVelocity().m_y < -0.5f) { io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x, -0.5f, io_toUpdate.getVelocity().m_z), true); } if(io_toUpdate.getVelocity().m_z > 0.5f) { io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x, io_toUpdate.getVelocity().m_y, 0.5f), true); } else if(io_toUpdate.getVelocity().m_z < -0.5f) { io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x, io_toUpdate.getVelocity().m_y, -0.5f), true); } //io_toUpdate.setVelocity(newVelocity * 0.0001f * io_toUpdate.getForwardVector() , false); io_toUpdate.setPosition(io_toUpdate.getVelocity(), false); }