Merging level.cc und level.hh.

This commit is contained in:
Steffen Fündgens 2015-03-06 17:49:21 +01:00
commit 7d480d654f
10 changed files with 54 additions and 17 deletions

View File

@ -12879,7 +12879,7 @@
<zPosition>34</zPosition> <zPosition>34</zPosition>
<targetIdGreen>-</targetIdGreen> <targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue> <targetIdBlue>-</targetIdBlue>
<distance>10</distance> <distance>2</distance>
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>sunStart.lua</luaScript> <luaScript>sunStart.lua</luaScript>
@ -12891,11 +12891,11 @@
<name>sunUpdate</name> <name>sunUpdate</name>
<undo>false</undo> <undo>false</undo>
<xPosition>-216</xPosition> <xPosition>-216</xPosition>
<yPosition>20</yPosition> <yPosition>27.5</yPosition>
<zPosition>34</zPosition> <zPosition>34</zPosition>
<targetIdGreen>-</targetIdGreen> <targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue> <targetIdBlue>-</targetIdBlue>
<distance>10</distance> <distance>12</distance>
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>sunUpdate.lua</luaScript> <luaScript>sunUpdate.lua</luaScript>
@ -13088,7 +13088,7 @@
</skydome> </skydome>
<waterPlane> <waterPlane>
<yPosition>15</yPosition> <yPosition>14.5</yPosition>
<texture>skydomeNew.png</texture> <texture>skydomeNew.png</texture>
</waterPlane> </waterPlane>

View File

@ -13,12 +13,12 @@ function trigger(objectToChange)
if(global.triggeredOpenFirstDoor == true) then if(global.triggeredOpenFirstDoor == true) then
if(global.openedSecondDoor == true) then if(global.openedSecondDoor == true) then
if(global.triggeredOpenThirdDoor == true) then if(global.triggeredOpenThirdDoor == true) then
level:movePlayer(-169.5,22.5,58.5) level:movePlayer(-169.5,21.5,58.5)
else else
level:movePlayer(-78.5,22.5,4.5) level:movePlayer(-78.5,21.75,4.5)
end end
else else
level:movePlayer(17.5,22.5,87.0) level:movePlayer(17.5,21.0,87.0)
end end
else else
level:resetPlayer() level:resetPlayer()

View File

@ -13,7 +13,7 @@ function trigger(objectToChange)
local time = os.clock() local time = os.clock()
global.sunStartTime = time global.sunStartTime = time
global.triggeredSunStart = true global.triggeredSunStart = true
level:activateEndgame()
print("sunStart") print("sunStart")
end end
end end

View File

@ -7,7 +7,7 @@ function trigger(objectToChange)
return return
end end
local maxTimeDiff = 5 local maxTimeDiff = 20
local timeDiff = os.clock()- global.sunStartTime local timeDiff = os.clock()- global.sunStartTime
if(timeDiff > maxTimeDiff)then if(timeDiff > maxTimeDiff)then
timeDiff = maxTimeDiff timeDiff = maxTimeDiff

View File

@ -14,7 +14,7 @@ uniform vec3 cameraCenter;
uniform vec3 sunColor; uniform vec3 sunColor;
uniform vec3 directionalVector; uniform vec3 directionalVector;
const float sunSize = 40.0; const float sunSize = 20.0;
void main() { void main() {
vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0); vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0);

View File

@ -17,6 +17,6 @@ out vec4 sunPosition;
void main() { void main() {
fragPosition = modelMatrix * vec4(aPosition, 1.0); fragPosition = modelMatrix * vec4(aPosition, 1.0);
vTexCoord = aTexCoord; 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); gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
} }

View File

@ -42,6 +42,7 @@ void Level::load() {
.addFunction("movePlayer", &Level::movePlayer) .addFunction("movePlayer", &Level::movePlayer)
.addFunction("setSunDirection", &Level::setSunDirection) .addFunction("setSunDirection", &Level::setSunDirection)
.addFunction("forceMove", &Level::forceMove) .addFunction("forceMove", &Level::forceMove)
.addFunction("activateEndgame", &Level::activateEndgame)
.endClass(); .endClass();
//Push the level to Lua as a global variable //Push the level to Lua as a global variable
luabridge::push(luaState, this); luabridge::push(luaState, this);
@ -278,3 +279,7 @@ void Level::forceMove(float x, float y, float z, unsigned indice){
glm::vec3 position = glm::vec3(x,y,z); glm::vec3 position = glm::vec3(x,y,z);
physics.forceMove(position, indice); physics.forceMove(position, indice);
} }
void Level::activateEndgame(){
physics.activateEndgame();
}

View File

@ -62,6 +62,7 @@ class Level {
void movePlayer(float xPosition, float yPosition, float zPosition); void movePlayer(float xPosition, float yPosition, float zPosition);
void setPlayerIndex(int index); void setPlayerIndex(int index);
void forceMove(float x, float y, float z, unsigned indice); void forceMove(float x, float y, float z, unsigned indice);
void activateEndgame();
private: private:
lua_State* luaState=nullptr; lua_State* luaState=nullptr;
std::vector<Object*> objects; std::vector<Object*> objects;

View File

@ -44,15 +44,18 @@ 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.normalize();
position *= cameraDistance; position *= cameraDistance;
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
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
@ -66,6 +69,9 @@ void Physics::takeUpdateStep(float timeDiff)
cameraBody->clearForces(); cameraBody->clearForces();
cameraBody->applyCentralForce(currentForce*1.0/force); cameraBody->applyCentralForce(currentForce*1.0/force);
} }
world->stepSimulation(timeDiff); world->stepSimulation(timeDiff);
} }
else else
@ -75,12 +81,14 @@ void Physics::takeUpdateStep(float timeDiff)
btVector3 currentPos = playerBall->getCenterOfMassPosition(); btVector3 currentPos = playerBall->getCenterOfMassPosition();
currentPos -= btVector3(0,0.005f,0); currentPos -= btVector3(0,0.005f,0);
playerBall->setCenterOfMassTransform(btTransform(playerBall->getOrientation(),currentPos)); 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->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(startPosition.x(),startPosition.y() - 3,startPosition.z())));
playerBall->setLinearVelocity(btVector3(0,0,0)); playerBall->setLinearVelocity(btVector3(0,0,0));
playerBall->setAngularVelocity(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; sinking = false;
} }
} }
@ -557,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 //use the crossproduct to correctly apply a torque to the palyer if function called
void Physics::rollForward(glm::vec3 camPos,float strength) void Physics::rollForward(glm::vec3 camPos,float strength)
{ {
if(!simulationActive)
return;
btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition();
pos.setY(0); pos.setY(0);
pos.normalize(); pos.normalize();
@ -567,6 +577,8 @@ void Physics::rollForward(glm::vec3 camPos,float strength)
void Physics::rollBack(glm::vec3 camPos,float strength) void Physics::rollBack(glm::vec3 camPos,float strength)
{ {
if(!simulationActive)
return;
btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition();
pos.setY(0); pos.setY(0);
pos.normalize(); pos.normalize();
@ -577,6 +589,8 @@ void Physics::rollBack(glm::vec3 camPos,float strength)
void Physics::rollLeft(glm::vec3 camPos,float strength) void Physics::rollLeft(glm::vec3 camPos,float strength)
{ {
if(!simulationActive)
return;
btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition();
pos.setY(0); pos.setY(0);
pos.normalize(); pos.normalize();
@ -586,6 +600,8 @@ void Physics::rollLeft(glm::vec3 camPos,float strength)
void Physics::rollRight(glm::vec3 camPos,float strength) void Physics::rollRight(glm::vec3 camPos,float strength)
{ {
if(!simulationActive)
return;
btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); btVector3 pos = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition();
pos.setY(0); pos.setY(0);
pos.normalize(); pos.normalize();
@ -630,6 +646,19 @@ void Physics::forceMoveCamera(btVector3 newPosition)
cameraBody->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),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 void Physics::kill() //delete dynamically allocated memory
{ {
if (world == NULL) { if (world == NULL) {

View File

@ -77,6 +77,7 @@ class Physics {
void prepareCollisionDetection(); void prepareCollisionDetection();
bool playerWithGround(); bool playerWithGround();
bool playerWithObject(); bool playerWithObject();
void activateEndgame();
void forcePlayer(glm::vec3 newPosition); void forcePlayer(glm::vec3 newPosition);
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;}; struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
@ -86,6 +87,7 @@ class Physics {
float resetHight = 0; float resetHight = 0;
bool simulationActive = true; bool simulationActive = true;
bool sinking = true; bool sinking = true;
bool endgame = false;
btVector3 currentDirection = btVector3(1,1,1); btVector3 currentDirection = btVector3(1,1,1);
btRigidBody* playerBall; //allows for easier access to the ball btRigidBody* playerBall; //allows for easier access to the ball
btRigidBody* terrainBody; //duh btRigidBody* terrainBody; //duh