From 39a0883466ea8ec5149c89854d3e414f4fc1d14a Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 6 Mar 2015 16:14:59 +0100 Subject: [PATCH 1/5] Fixed y value of the sun. --- data/shader/skydome.fsh | 2 +- data/shader/skydome.vsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/shader/skydome.fsh b/data/shader/skydome.fsh index 7d3f4e2..68f52d2 100644 --- a/data/shader/skydome.fsh +++ b/data/shader/skydome.fsh @@ -14,7 +14,7 @@ uniform vec3 cameraCenter; uniform vec3 sunColor; uniform vec3 directionalVector; -const float sunSize = 40.0; +const float sunSize = 20.0; void main() { vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/data/shader/skydome.vsh b/data/shader/skydome.vsh index 2dc7b65..0fa520e 100644 --- a/data/shader/skydome.vsh +++ b/data/shader/skydome.vsh @@ -17,6 +17,6 @@ out vec4 sunPosition; void main() { fragPosition = modelMatrix * vec4(aPosition, 1.0); vTexCoord = aTexCoord; - sunPosition = (normalize(vec4(directionalVector, 0.0)) * skydomeSize) + vec4(cameraCenter, 1.0); + sunPosition = (normalize(vec4(directionalVector, 0.0)) * skydomeSize) + vec4(cameraCenter.x, 0, cameraCenter.z, 1.0); gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0); } From cb762be52b34eea7b06ad60d72e466a8ec112580 Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 6 Mar 2015 16:19:57 +0100 Subject: [PATCH 2/5] Added endgame. --- data/levels/Level1.xml | 6 +++--- data/levels/scripts/sunStart.lua | 2 +- data/levels/scripts/sunUpdate.lua | 2 +- level.cc | 5 +++++ level.hh | 1 + physics.cc | 27 +++++++++++++++++++++++---- physics.hh | 2 ++ 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml index f48c5b2..03f01d1 100644 --- a/data/levels/Level1.xml +++ b/data/levels/Level1.xml @@ -11944,7 +11944,7 @@ 34 - - - 10 + 2 false 0 sunStart.lua @@ -11956,11 +11956,11 @@ sunUpdate false -216 - 20 + 27.5 34 - - - 10 + 12 false 0 sunUpdate.lua diff --git a/data/levels/scripts/sunStart.lua b/data/levels/scripts/sunStart.lua index c7865c0..f2d55fb 100644 --- a/data/levels/scripts/sunStart.lua +++ b/data/levels/scripts/sunStart.lua @@ -13,7 +13,7 @@ function trigger(objectToChange) local time = os.clock() global.sunStartTime = time global.triggeredSunStart = true - + level:activateEndgame() print("sunStart") end end diff --git a/data/levels/scripts/sunUpdate.lua b/data/levels/scripts/sunUpdate.lua index 972c629..9160ad9 100644 --- a/data/levels/scripts/sunUpdate.lua +++ b/data/levels/scripts/sunUpdate.lua @@ -7,7 +7,7 @@ function trigger(objectToChange) return end - local maxTimeDiff = 5 + local maxTimeDiff = 20 local timeDiff = os.clock()- global.sunStartTime if(timeDiff > maxTimeDiff)then timeDiff = maxTimeDiff diff --git a/level.cc b/level.cc index 6ac2f8f..754aa5a 100644 --- a/level.cc +++ b/level.cc @@ -41,6 +41,7 @@ void Level::load() { .addFunction("resetPlayer", &Level::resetPlayer) .addFunction("movePlayer", &Level::movePlayer) .addFunction("setSunDirection", &Level::setSunDirection) + .addFunction("activateEndgame", &Level::activateEndgame) .endClass(); //Push the level to Lua as a global variable luabridge::push(luaState, this); @@ -272,3 +273,7 @@ Terrain* Level::getTerrain() { Skydome* Level::getSkydome() { return &skydome; } + +void Level::activateEndgame(){ + physics.activateEndgame(); +} diff --git a/level.hh b/level.hh index e18db48..f5979fd 100644 --- a/level.hh +++ b/level.hh @@ -61,6 +61,7 @@ class Level { void resetPlayer(); void movePlayer(float xPosition, float yPosition, float zPosition); void setPlayerIndex(int index); + void activateEndgame(); private: lua_State* luaState=nullptr; std::vector objects; diff --git a/physics.cc b/physics.cc index c3b5a86..3fc24c9 100644 --- a/physics.cc +++ b/physics.cc @@ -44,14 +44,17 @@ void Physics::takeUpdateStep(float timeDiff) } } + if(endgame) + { + currentDirection = playerBall->getCenterOfMassPosition(); + currentDirection.setY(0); + currentDirection.normalize(); + } + btVector3 position = currentDirection; - btVector3 position = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); //gets a vector from the player to the camera - position = currentDirection; position.normalize(); position *= cameraDistance; 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 btVector3 dir = cameraBody->getCenterOfMassPosition() - position; float str = 50 * dir.length() / cameraBody->getInvMass(); //getInvMass() returns the inverted mass @@ -66,6 +69,9 @@ void Physics::takeUpdateStep(float timeDiff) position.normalize(); cameraBody->setLinearVelocity(position*20); } + + + world->stepSimulation(timeDiff); } else @@ -630,6 +636,19 @@ void Physics::forceMoveCamera(btVector3 newPosition) cameraBody->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),newPosition)); } +void Physics::activateEndgame() +{ + if(endgame) + return; + endgame = true; + positionConstraint cons; + cons.body = playerBall; + cons.strength = 1; + cons.position = playerBall->getCenterOfMassPosition() + btVector3(0,15,0); + playerBall->setGravity(btVector3(0,0,0)); + allPositionConstraints.push_back(cons); +} + void Physics::kill() //delete dynamically allocated memory { if (world == NULL) { diff --git a/physics.hh b/physics.hh index 49d9571..98fbe53 100644 --- a/physics.hh +++ b/physics.hh @@ -77,6 +77,7 @@ class Physics { void prepareCollisionDetection(); bool playerWithGround(); bool playerWithObject(); + void activateEndgame(); void forcePlayer(glm::vec3 newPosition); struct positionConstraint{btRigidBody* body; float strength; btVector3 position;}; @@ -86,6 +87,7 @@ class Physics { float resetHight = 0; bool simulationActive = true; bool sinking = true; + bool endgame = false; btVector3 currentDirection = btVector3(1,1,1); btRigidBody* playerBall; //allows for easier access to the ball btRigidBody* terrainBody; //duh From 60a127eefc0696cadf0ccc96f67fed35bc28806b Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 6 Mar 2015 16:56:20 +0100 Subject: [PATCH 3/5] fixed problem where pressing buttons while respawning would lead to overflow and segmentation fault --- physics.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/physics.cc b/physics.cc index 3fc24c9..5686bf3 100644 --- a/physics.cc +++ b/physics.cc @@ -81,12 +81,14 @@ void Physics::takeUpdateStep(float timeDiff) btVector3 currentPos = playerBall->getCenterOfMassPosition(); currentPos -= btVector3(0,0.003f,0); playerBall->setCenterOfMassTransform(btTransform(playerBall->getOrientation(),currentPos)); - if(playerBall->getCenterOfMassPosition().y() < resetHight - 3) + if(playerBall->getCenterOfMassPosition().y() < resetHight - 1.5f) { playerBall->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(startPosition.x(),startPosition.y() - 3,startPosition.z()))); playerBall->setLinearVelocity(btVector3(0,0,0)); playerBall->setAngularVelocity(btVector3(0,0,0)); - forceMoveCamera(startPosition + btVector3(currentDirection.x()*cameraDistance,currentDirection.y()*cameraDistance,currentDirection.z()*cameraDistance)); + currentDirection = btVector3(1,1,1); + currentDirection.normalize(); + forceMoveCamera(startPosition + currentDirection*cameraDistance); sinking = false; } } @@ -563,6 +565,8 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis //use the crossproduct to correctly apply a torque to the palyer if function called void Physics::rollForward(glm::vec3 camPos,float strength) { + if(!simulationActive) + return; btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); pos.setY(0); pos.normalize(); @@ -573,6 +577,8 @@ void Physics::rollForward(glm::vec3 camPos,float strength) void Physics::rollBack(glm::vec3 camPos,float strength) { + if(!simulationActive) + return; btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); pos.setY(0); pos.normalize(); @@ -583,6 +589,8 @@ void Physics::rollBack(glm::vec3 camPos,float strength) void Physics::rollLeft(glm::vec3 camPos,float strength) { + if(!simulationActive) + return; btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); pos.setY(0); pos.normalize(); @@ -592,6 +600,8 @@ void Physics::rollLeft(glm::vec3 camPos,float strength) void Physics::rollRight(glm::vec3 camPos,float strength) { + if(!simulationActive) + return; btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); pos.setY(0); pos.normalize(); From 49f612fe67fc7efacdddebad28d35157c3a9d1fa Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 6 Mar 2015 16:57:10 +0100 Subject: [PATCH 4/5] changed waterlevel --- data/levels/Level1.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml index fc1a854..bbf7b6a 100644 --- a/data/levels/Level1.xml +++ b/data/levels/Level1.xml @@ -12157,7 +12157,7 @@ - 15 + 14.5 skydomeNew.png From 3d5289da458cf3a4d76ff92c3cd3ff63b9924079 Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 6 Mar 2015 16:57:38 +0100 Subject: [PATCH 5/5] corrrected reset position --- data/levels/scripts/resetPlayer.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/levels/scripts/resetPlayer.lua b/data/levels/scripts/resetPlayer.lua index 6262557..4e24cf7 100644 --- a/data/levels/scripts/resetPlayer.lua +++ b/data/levels/scripts/resetPlayer.lua @@ -13,12 +13,12 @@ function trigger(objectToChange) if(global.triggeredOpenFirstDoor == true) then if(global.openedSecondDoor == true) then if(global.triggeredOpenThirdDoor == true) then - level:movePlayer(-169.5,22.5,58.5) + level:movePlayer(-169.5,21.5,58.5) else - level:movePlayer(-78.5,22.5,4.5) + level:movePlayer(-78.5,21.75,4.5) end else - level:movePlayer(17.5,22.5,87.0) + level:movePlayer(17.5,21.0,87.0) end else level:resetPlayer()