Merge branch 'master' of github.com:Faerbit/swp

This commit is contained in:
Steffen Fündgens 2015-02-13 18:10:55 +01:00
commit 162a54757b
3 changed files with 33 additions and 8 deletions

View File

@ -204,8 +204,10 @@ void Graphics::updateClosestLights() {
std::sort(closestLights.begin(), std::sort(closestLights.begin(),
closestLights.end(), closestLights.end(),
[this](Light a, Light b) {return compareLightDistances(a, b); }); [this](Light a, Light b) {return compareLightDistances(a, b); });
closestLights = std::vector<Light>(&closestLights[0], if (level->getLights()->size() > 32) {
&closestLights[31]); closestLights = std::vector<Light>(&closestLights[0],
&closestLights[31]);
}
} }
void Graphics::updateShaderLights() { void Graphics::updateShaderLights() {

View File

@ -48,12 +48,22 @@ void Physics::takeUpdateStep(float timeDiff)
position += playerBall->getCenterOfMassPosition(); //is the position cameraDistance away from the player in the direction of the camera position += playerBall->getCenterOfMassPosition(); //is the position cameraDistance away from the player in the direction of the camera
//prevent the camera from being dragged along on the ground //prevent the camera from being dragged along on the ground
if (position.getY() < playerBall->getCenterOfMassPosition().getY() + 1) if (position.getY() < playerBall->getCenterOfMassPosition().getY() + cameraDistance/2)
position.setY(playerBall->getCenterOfMassPosition().getY() + 1); position.setY(playerBall->getCenterOfMassPosition().getY() + cameraDistance/2);
btVector3 dir = cameraBody->getCenterOfMassPosition() - position; btVector3 dir = cameraBody->getCenterOfMassPosition() - position;
float str = 50 * dir.length() / cameraBody->getInvMass(); //getInvMass() returns the inverted mass float str = 50 * dir.length() / cameraBody->getInvMass(); //getInvMass() returns the inverted mass
cameraBody->applyCentralForce(-dir*str); //scale the force by camera mass
/*if(dir.length() > -0.1f && dir.length() < 0.1f)
{
cameraBody->setLinearVelocity(btVector3(0,0,0));
world->stepSimulation(timeDiff);
return;
}*/
cameraBody->setLinearVelocity(btVector3(0,0,0));
cameraBody->applyCentralForce(-dir*str*10) ; //scale the force by camera mass
counter=0; counter=0;
float speed = cameraBody->getLinearVelocity().length(); float speed = cameraBody->getLinearVelocity().length();
if(speed>20.0f) if(speed>20.0f)
@ -408,7 +418,7 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis
change.normalize(); //normalize so that the distance between camera and body does not matter change.normalize(); //normalize so that the distance between camera and body does not matter
change *= (mouseMovement.y); //we start with left/right movement because this needs to be calculated via a crossproduct, and the up down value would alter that change *= (mouseMovement.y); //we start with left/right movement because this needs to be calculated via a crossproduct, and the up down value would alter that
change = btCross(btVector3(0,1,0),change); change = btCross(btVector3(0,1,0),change);
change.setY(mouseMovement.x/5); //scaleing because otherwise oup/down much stronger then left right change.setY(mouseMovement.x); //scaleing because otherwise oup/down much stronger then left right
change *= strength / cameraBody->getInvMass(); change *= strength / cameraBody->getInvMass();
cameraBody->applyCentralForce(change); cameraBody->applyCentralForce(change);
@ -467,6 +477,17 @@ void Physics::addStaticGroundPlane()
} //not needed anymoer, but still good for debugging } //not needed anymoer, but still good for debugging
void Physics::forceMove(glm::vec3 newPosition, unsigned indice)//ugly, but needed for reset
{
bodies[indice]->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
}
void Physics::forceMoveCamera(glm::vec3 newPosition)
{
cameraBody->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
}
void Physics::kill() //delete dynamically allocated memory void Physics::kill() //delete dynamically allocated memory
{ {
if (world == NULL) { if (world == NULL) {

View File

@ -68,6 +68,8 @@ class Physics {
glm::vec3 getCameraToPlayer(); glm::vec3 getCameraToPlayer();
void kill(); void kill();
void addButtonFrame(Entity entity); void addButtonFrame(Entity entity);
void forceMove(glm::vec3 newPosition, unsigned indice);
void forceMoveCamera(glm::vec3 newPosition);
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;}; struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};