void CalSpringSystem::update(float deltaTime) { // get the attached meshes vector std::vector<CalMesh *>& vectorMesh = m_pModel->getVectorMesh(); // loop through all the attached meshes std::vector<CalMesh *>::iterator iteratorMesh; for(iteratorMesh = vectorMesh.begin(); iteratorMesh != vectorMesh.end(); ++iteratorMesh) { // get the ssubmesh vector of the mesh std::vector<CalSubmesh *>& vectorSubmesh = (*iteratorMesh)->getVectorSubmesh(); // loop through all the submeshes of the mesh std::vector<CalSubmesh *>::iterator iteratorSubmesh; for(iteratorSubmesh = vectorSubmesh.begin(); iteratorSubmesh != vectorSubmesh.end(); ++iteratorSubmesh) { // check if the submesh contains a spring system if((*iteratorSubmesh)->getCoreSubmesh()->getSpringCount() > 0 && (*iteratorSubmesh)->hasInternalData()) { // calculate the new forces on each unbound vertex calculateForces(*iteratorSubmesh, deltaTime); // calculate the vertices influenced by the spring system calculateVertices(*iteratorSubmesh, deltaTime); } } } }
Collision BoxCircleCollider::collide(EntityW::EntitySp entity1, EntityW::EntitySp entity2) { auto transform1 = entity1->get<TransformComponent>(); auto transform2 = entity2->get<TransformComponent>(); auto collision1 = entity1->get<CollisionComponent>(); auto collision2 = entity2->get<CollisionComponent>(); auto collisionShape1 = std::static_pointer_cast<RectCollisionShape>( collision1->shape); auto collisionShape2 = std::static_pointer_cast<CircleCollisionShape>(collision2->shape); Vector2 circleCenter = transform2->position + collisionShape2->center(); std::vector<Vector2> vertices = collisionShape1->calculateVertices(transform1); Vector2 axis; float minDistance = 10000000000; for (int i = 0; i < 4; i++) { Vector2 vertex = vertices[i]; Vector2 distanceVector = circleCenter - vertex; float distance = fabs(glm::length(distanceVector)); if (distance < minDistance) { minDistance = distance; axis = distanceVector; } } axis = glm::normalize(axis); return sat(entity1, entity2, { Vector2(1., 0.), Vector2(0., 1.), axis }); }
void Entity::moveForward() { if (speed.x > MAX_SPEED) speed.x = MAX_SPEED; if (speed.x < -MAX_SPEED) speed.x = -MAX_SPEED; if (speed.y > MAX_SPEED) speed.y = MAX_SPEED; if (speed.y < -MAX_SPEED) speed.y = -MAX_SPEED; setPosition(center.x + speed.x, center.y + speed.y); calculateVertices(); }
void CalPhysique::update() { // get the attached meshes vector std::vector<CalMesh *>& vectorMesh = m_pModel->getVectorMesh(); // loop through all the attached meshes std::vector<CalMesh *>::iterator iteratorMesh; for(iteratorMesh = vectorMesh.begin(); iteratorMesh != vectorMesh.end(); ++iteratorMesh) { // get the submesh vector of the mesh std::vector<CalSubmesh *>& vectorSubmesh = (*iteratorMesh)->getVectorSubmesh(); // loop through all the submeshes of the mesh std::vector<CalSubmesh *>::iterator iteratorSubmesh; for(iteratorSubmesh = vectorSubmesh.begin(); iteratorSubmesh != vectorSubmesh.end(); ++iteratorSubmesh) { // check if the submesh handles vertex data internally if((*iteratorSubmesh)->hasInternalData()) { // calculate the transformed vertices and store them in the submesh std::vector<CalVector>& vectorVertex = (*iteratorSubmesh)->getVectorVertex(); calculateVertices(*iteratorSubmesh, (float *)&vectorVertex[0]); // calculate the transformed normals and store them in the submesh std::vector<CalVector>& vectorNormal = (*iteratorSubmesh)->getVectorNormal(); calculateNormals(*iteratorSubmesh, (float *)&vectorNormal[0]); unsigned mapId; for(mapId=0;mapId< (*iteratorSubmesh)->getVectorVectorTangentSpace().size();mapId++) { if((*iteratorSubmesh)->isTangentsEnabled(mapId)) { std::vector<CalSubmesh::TangentSpace>& vectorTangentSpace = (*iteratorSubmesh)->getVectorVectorTangentSpace()[mapId]; calculateTangentSpaces(*iteratorSubmesh, mapId,(float *)&vectorTangentSpace[0]); } } } } } }
void Entity::adjustAngle(float delta) { angle += delta; calculateVertices(); }