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

This commit is contained in:
Fabian Klemp 2015-03-04 16:08:11 +01:00
commit 98e8d10cdd
11 changed files with 98 additions and 21 deletions

View File

@ -264,6 +264,7 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
XMLElement* trigger = doc->NewElement("trigger"); XMLElement* trigger = doc->NewElement("trigger");
newComposition->InsertEndChild(trigger); newComposition->InsertEndChild(trigger);
XMLElement* name = doc->NewElement("name"); XMLElement* name = doc->NewElement("name");
XMLElement* undo = doc->NewElement("undo");
XMLElement* xPosition = doc->NewElement("xPosition"); XMLElement* xPosition = doc->NewElement("xPosition");
XMLElement* yPosition = doc->NewElement("yPosition"); XMLElement* yPosition = doc->NewElement("yPosition");
XMLElement* zPosition = doc->NewElement("zPosition"); XMLElement* zPosition = doc->NewElement("zPosition");
@ -278,6 +279,7 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
XMLElement* toChangeObjNum = doc->NewElement("toChangeObjNum"); XMLElement* toChangeObjNum = doc->NewElement("toChangeObjNum");
name->SetText("-"); name->SetText("-");
undo->SetText("false");
xPosition->SetText("0"); xPosition->SetText("0");
yPosition->SetText("0"); yPosition->SetText("0");
zPosition->SetText("0"); zPosition->SetText("0");
@ -292,6 +294,7 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
toChangeObjNum->SetText("0"); toChangeObjNum->SetText("0");
trigger->InsertEndChild(name); trigger->InsertEndChild(name);
trigger->InsertEndChild(undo);
trigger->InsertEndChild(xPosition); trigger->InsertEndChild(xPosition);
trigger->InsertEndChild(yPosition); trigger->InsertEndChild(yPosition);
trigger->InsertEndChild(zPosition); trigger->InsertEndChild(zPosition);

View File

@ -76,6 +76,8 @@
<bColour>0.3</bColour> <bColour>0.3</bColour>
<intensity>4.0</intensity> <intensity>4.0</intensity>
<flameOffset>-1.5</flameOffset> <flameOffset>-1.5</flameOffset>
<flameHeight>3.0</flameHeight>
<flameWidth>0.8</flameWidth>
</light> </light>
</composition> </composition>

View File

@ -11776,18 +11776,19 @@
<idBlue>105</idBlue> <idBlue>105</idBlue>
<typeID>20</typeID> <typeID>20</typeID>
<trigger> <trigger>
<name>-</name> <name>resetPlayer</name>
<undo>false</undo>
<xPosition>0</xPosition> <xPosition>0</xPosition>
<yPosition>0</yPosition> <yPosition>-100000</yPosition>
<zPosition>0</zPosition> <zPosition>0</zPosition>
<targetIdGreen>-</targetIdGreen> <targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue> <targetIdBlue>-</targetIdBlue>
<distance>1.0</distance> <distance>100015</distance>
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>-</luaScript> <luaScript>resetPlayer.lua</luaScript>
<toChangeIdGreen>0</toChangeIdGreen> <toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue> <toChangeIdBlue>105</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
</composition> </composition>

View File

@ -0,0 +1,17 @@
local global = require( "global" )
if(global.triggeredResetPlayer == nil) then
global.triggeredResetPlayer = false
end
function trigger(objectToChange)
if(global.triggeredResetPlayer == false) then
if(not level) then
print("No level found in Lua!")
return
end
level:resetPlayer()
--global.triggeredResetPlayer = true
print("reset player")
end
end

View File

@ -38,6 +38,7 @@ void Level::load() {
.addFunction("deleteObject", &Level::deleteObject) .addFunction("deleteObject", &Level::deleteObject)
.addFunction("getObjectCount", &Level::getPhysicsObjectsVectorSize) .addFunction("getObjectCount", &Level::getPhysicsObjectsVectorSize)
.addFunction("moveObject", &Level::moveObject) .addFunction("moveObject", &Level::moveObject)
.addFunction("resetPlayer", &Level::resetPlayer)
.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);
@ -63,23 +64,28 @@ void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseD
// Ignore first two mouse updates, because they are incorrect // Ignore first two mouse updates, because they are incorrect
// DON'T try to move this functionallity elsewhere // DON'T try to move this functionallity elsewhere
static int i = 0; static int i = 0;
if (i <2) { if (i <20) {
i++; i++;
mouseDelta.x=mouseDelta.y=0;
} }
int runs = 2; int runs = 2;
if(i>=20)
{
mouseDelta.x = -mouseDelta.x;
}
for(int j = runs; j > 0; j--) for(int j = runs; j > 0; j--)
{ {
physics.takeUpdateStep(runTimeSinceLastUpdate/runs); physics.takeUpdateStep(runTimeSinceLastUpdate/runs);
if(i>=2)
{ camera.updateRotation(mouseDelta/100.0f/(float)runs);
mouseDelta.x = -mouseDelta.x; physics.updateCameraPos(mouseDelta, 50/runs, camera.getDistance());
camera.updateRotation(mouseDelta/100.0f/(float)runs);
physics.updateCameraPos(mouseDelta, 50/runs, camera.getDistance());
camera.setPosition(physics.getCameraPosition()); camera.setPosition(physics.getCameraPosition());
camera.setDirection(physics.getCameraToPlayer()); camera.setDirection(physics.getCameraToPlayer());
}
if(wPressed){ if(wPressed){
physics.rollForward(camera.getVector(),strength/runs); physics.rollForward(camera.getVector(),strength/runs);
} }
@ -182,7 +188,12 @@ void Level::deleteObject(int objectIndex){
void Level::resetPlayer(){ void Level::resetPlayer(){
Loader loader = Loader(); Loader loader = Loader();
glm::vec3 newPosition = loader.reloadPlayerPosition(xmlFilePath, this); glm::vec3 newPosition = loader.reloadPlayerPosition(xmlFilePath, this);
//TODO cameraCenter.setPosition(newPosition); physics.forceMove(newPosition, playerIndex);
physics.forceMoveCamera(newPosition + glm::vec3(1,0,0));
}
void Level::setPlayerIndex(int index){
playerIndex = index;
} }
void Level::setStrength(float strength) { void Level::setStrength(float strength) {

View File

@ -57,6 +57,7 @@ class Level {
lua_State* getLuaState(); lua_State* getLuaState();
Terrain* getTerrain(); Terrain* getTerrain();
void resetPlayer(); void resetPlayer();
void setPlayerIndex(int index);
private: private:
lua_State* luaState=nullptr; lua_State* luaState=nullptr;
std::vector<Object*> objects; std::vector<Object*> objects;
@ -67,6 +68,7 @@ class Level {
glm::vec4 fogColour; glm::vec4 fogColour;
Light directionalLight; Light directionalLight;
Object* cameraCenter; Object* cameraCenter;
int playerIndex;
Object* skydome; Object* skydome;
Physics physics; Physics physics;
Camera camera; Camera camera;

View File

@ -1,10 +1,12 @@
#include "light.hh" #include "light.hh"
Light::Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset) Light::Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset, float flameHeight, float flameWidth)
: Entity(position, glm::vec3(0.0f, 0.0f, 0.0f)) { : Entity(position, glm::vec3(0.0f, 0.0f, 0.0f)) {
this->colour = colour; this->colour = colour;
this->intensity = intensity; this->intensity = intensity;
this->flameYOffset = flameYOffset; this->flameYOffset = flameYOffset;
this->flameHeight = flameHeight;
this->flameWidth = flameWidth;
} }
Light::Light() { Light::Light() {

View File

@ -6,7 +6,7 @@
class Light : public Entity { class Light : public Entity {
public: public:
Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset = 0.0f); Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset = 0.0f, float flameHeight = 0.0f, float flameWidth = 0.0f);
Light(); Light();
glm::vec3 getColour(); glm::vec3 getColour();
float getIntensity(); float getIntensity();
@ -14,6 +14,8 @@ class Light : public Entity {
~Light(); ~Light();
private: private:
float flameYOffset; float flameYOffset;
float flameHeight;
float flameWidth;
float intensity; float intensity;
glm::vec3 colour; glm::vec3 colour;
}; };

View File

@ -258,6 +258,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
if(compositionType == 20){ if(compositionType == 20){
level->setCameraCenter(object); level->setCameraCenter(object);
level->setPlayerIndex(objectIdentifier[1]);
} }
}//objectData found }//objectData found
}//finding the objectData }//finding the objectData
@ -298,7 +299,9 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
if (flameOffset != NULL){ if (flameOffset != NULL){
float offset = 0; float offset = 0;
errorCheck(flameOffset->QueryFloatText(&offset)); errorCheck(flameOffset->QueryFloatText(&offset));
Light light = Light(lightPosition, lightColour, lightIntensity, offset); float flameHeight = queryBool(xmlLight, "flameHeight");
float flameWidth = queryBool(xmlLight, "flameWidth");
Light light = Light(lightPosition, lightColour, lightIntensity, offset, flameHeight, flameWidth);
level->addLight(light); level->addLight(light);
} }
else { else {

View File

@ -414,9 +414,29 @@ void Physics::addSphere(float rad, Entity entity, float mass, float dampningL, f
throw std::invalid_argument( "Bodies out of Sync" ); throw std::invalid_argument( "Bodies out of Sync" );
} }
void Physics::prepareCollisionDetection()
{
playerTerrainCol = playerObjectColision = false;
int numManifods = world->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifods;i++)
{
}
}
bool Physics::playerWithGround()
{
return playerTerrainCol;
}
bool Physics::playerWithObject()
{
return playerObjectColision;
}
void Physics::addCamera() //Camera Creator automatically called when player is created void Physics::addCamera() //Camera Creator automatically called when player is created
{ {
btSphereShape* sphere = new btSphereShape(0.5f); //we use this to make a more interesting camera, that does not interpenetrate with the terrain/objects btSphereShape* sphere = new btSphereShape(0.2f); //we use this to make a more interesting camera, that does not interpenetrate with the terrain/objects
btVector3 inertia(0,0,0); //rotation handled elsewhere (as it always has to look at the player) btVector3 inertia(0,0,0); //rotation handled elsewhere (as it always has to look at the player)
@ -481,7 +501,7 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis
this->cameraDistance = distance; this->cameraDistance = distance;
//note: in mouseMovement x and y are flipped in contrast to bullet //note: in mouseMovement x and y are flipped in contrast to bullet
btVector3 dodo = btVector3(0,1,0).cross(btVector3(currentDirection.x(),0,currentDirection.z())); btVector3 dodo = btVector3(0,1,0).cross(btVector3(currentDirection.x(),0,currentDirection.z()));
currentDirection = currentDirection.rotate(dodo,-mouseMovement.x / 100);//mathhelper 3.14159265359 currentDirection = currentDirection.rotate(dodo,-mouseMovement.x / 50);//mathhelper 3.14159265359
btVector3 compare = currentDirection; btVector3 compare = currentDirection;
compare.setY(0); compare.setY(0);
@ -496,7 +516,7 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis
currentDirection = compare; currentDirection = compare;
} }
currentDirection = currentDirection.rotate(btVector3(0,1,0),mouseMovement.y/100); currentDirection = currentDirection.rotate(btVector3(0,1,0),-mouseMovement.y/100);
currentDirection.normalize(); currentDirection.normalize();
} }
@ -557,6 +577,14 @@ void Physics::addStaticGroundPlane()
void Physics::forceMove(glm::vec3 newPosition, unsigned indice)//ugly, but needed for reset 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))); bodies[indice]->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
bodies[indice]->setLinearVelocity(btVector3(0,0,0));
}
void Physics::forcePlayer(glm::vec3 newPosition)//ugly, but needed for reset
{
playerBall->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
playerBall->setLinearVelocity(btVector3(0,0,0));
forceMoveCamera(newPosition + glm::vec3(currentDirection.x()*cameraDistance,currentDirection.y()*cameraDistance,currentDirection.z()*cameraDistance));
} }
void Physics::forceMoveCamera(glm::vec3 newPosition) void Physics::forceMoveCamera(glm::vec3 newPosition)

View File

@ -74,6 +74,10 @@ class Physics {
void forceMove(glm::vec3 newPosition, unsigned indice); void forceMove(glm::vec3 newPosition, unsigned indice);
void forceMoveCamera(glm::vec3 newPosition); void forceMoveCamera(glm::vec3 newPosition);
void addConvexBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice, float scaling, bool rotate); void addConvexBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice, float scaling, bool rotate);
void prepareCollisionDetection();
bool playerWithGround();
bool playerWithObject();
void forcePlayer(glm::vec3 newPosition);
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;}; struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
@ -98,6 +102,8 @@ class Physics {
int counter = 0; int counter = 0;
std::string geometryPath; std::string geometryPath;
float cameraDistance = 5; //distance of the camera to the player. float cameraDistance = 5; //distance of the camera to the player.
bool playerTerrainCol = false;
bool playerObjectColision = false;
}; };
enum collisionTypes{ enum collisionTypes{