This commit is contained in:
sfroitzheim 2015-03-04 17:09:25 +01:00
commit 2568a2a69f
14 changed files with 140 additions and 19 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

@ -11921,18 +11921,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>
@ -12114,7 +12115,7 @@
</terrain> </terrain>
<skydome> <skydome>
<texture>skydome.png</texture> <texture>skydomeNew.png</texture>
</skydome> </skydome>
<physics> <physics>

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

18
data/shader/skydome.fsh Normal file
View File

@ -0,0 +1,18 @@
#version 150
in vec2 vTexCoord;
in vec4 fragPosition;
out vec4 oColor;
uniform sampler2D uTexture;
uniform float farPlane;
uniform vec4 fogColor;
uniform vec3 cameraCenter;
void main() {
float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition));
float fogFactor = clamp((1.0 - ((farPlane - 35.0) -distanceCameraCenter)/30.0), 0.0, 1.0);
fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0);
oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor);
}

17
data/shader/skydome.vsh Normal file
View File

@ -0,0 +1,17 @@
#version 150
in vec3 aPosition;
in vec3 aNormal;
in vec2 aTexCoord;
uniform mat4 modelMatrix;
uniform mat4 modelViewProjectionMatrix;
out vec2 vTexCoord;
out vec4 fragPosition;
void main() {
fragPosition = modelMatrix * vec4(aPosition, 1.0);
vTexCoord = aTexCoord;
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
}

View File

@ -70,6 +70,9 @@ void Graphics::init(Level* level) {
lightingShader = ShaderProgramCreator("phong").attributeLocations( lightingShader = ShaderProgramCreator("phong").attributeLocations(
vao->getAttributeLocations()).create(); vao->getAttributeLocations()).create();
skydomeShader = ShaderProgramCreator("skydome").attributeLocations(
vao->getAttributeLocations()).create();
depthShader = ShaderProgramCreator("depth") depthShader = ShaderProgramCreator("depth")
.attributeLocations(vao->getAttributeLocations()).create(); .attributeLocations(vao->getAttributeLocations()).create();
@ -236,6 +239,17 @@ void Graphics::render(double time)
framebuffer_light->bind(); framebuffer_light->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//set view and projection matrix
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
//render skydome
skydomeShader->use();
// set fog Parameters
skydomeShader->setUniform("farPlane", farPlane);
skydomeShader->setUniform("fogColor", level->getFogColour());
skydomeShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition());
level->getSkydome()->render(skydomeShader, false, true, &lightingViewProjectionMatrix);
lightingShader->use(); lightingShader->use();
//set lighting parameters //set lighting parameters
@ -273,9 +287,6 @@ void Graphics::render(double time)
lightingShader->setUniform("ambientColor", level->getAmbientLight()); lightingShader->setUniform("ambientColor", level->getAmbientLight());
lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition()); lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition());
//set view and projection matrix
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
// render the level // render the level
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs); level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
@ -285,7 +296,6 @@ void Graphics::render(double time)
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
// draw with colors // draw with colors
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix); flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
flameShader->setUniform("modelViewProjectionMatrix", lightingViewProjectionMatrix); flameShader->setUniform("modelViewProjectionMatrix", lightingViewProjectionMatrix);

View File

@ -31,6 +31,7 @@ class Graphics {
float farPlane; float farPlane;
std::vector<Light> closestLights; std::vector<Light> closestLights;
SharedShaderProgram lightingShader; SharedShaderProgram lightingShader;
SharedShaderProgram skydomeShader;
SharedShaderProgram depthCubeShader; SharedShaderProgram depthCubeShader;
SharedShaderProgram depthShader; SharedShaderProgram depthShader;
SharedShaderProgram flameShader; SharedShaderProgram flameShader;

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);
@ -49,9 +50,11 @@ void Level::load() {
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) { glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
for(unsigned int i = 0; i<objects.size(); i++) { for(unsigned int i = 0; i<objects.size(); i++) {
// do not project shadow of skydome if (lightingPass) {
if(lightingPass || (objects.at(i) != skydome)) { objects.at(i)->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
objects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs); }
else {
objects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs);
} }
} }
} }
@ -185,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) {
@ -247,3 +255,7 @@ lua_State* Level::getLuaState() {
Terrain* Level::getTerrain() { Terrain* Level::getTerrain() {
return &terrain; return &terrain;
} }
Object* Level::getSkydome() {
return skydome;
}

View File

@ -36,6 +36,7 @@ class Level {
glm::vec4 getFogColour(); glm::vec4 getFogColour();
void setSkydomeSize(float size); void setSkydomeSize(float size);
float getSkydomeSize(); float getSkydomeSize();
Object* getSkydome();
std::vector<Object*>* getObjects(); std::vector<Object*>* getObjects();
std::vector<Object*>* getPhysicsObjects(); std::vector<Object*>* getPhysicsObjects();
void deleteObject(int objectIndex); void deleteObject(int objectIndex);
@ -56,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;
@ -66,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

@ -85,7 +85,6 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
Material skydomeMaterial = Material(skydomeTexture, 0.7f, 0.0f, 0.0f, 0.0f); Material skydomeMaterial = Material(skydomeTexture, 0.7f, 0.0f, 0.0f, 0.0f);
Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f), Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.0f), true); glm::vec3(0.0f, 0.0f, 0.0f), true);
level->addObject(skydomeObject);
level->setSkydomeObject(skydomeObject); level->setSkydomeObject(skydomeObject);
//load lighting parameters //load lighting parameters
@ -259,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

View File

@ -14,18 +14,22 @@ Object::~Object() {
} }
void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* additionalMatrices) { bool texturePass, glm::mat4* viewProjectionMatrix,
std::vector<glm::mat4>* additionalMatrices) {
if (!renderable) { if (!renderable) {
return; return;
} }
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale())); glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
if(texturePass) {
shader->setTexture("uTexture", material.getReference(), 0);
shader->setUniform("modelMatrix", modelMatrix);
}
if (lightingPass) { if (lightingPass) {
// set lightning parameters for this object // set lightning parameters for this object
shader->setUniform("ambientFactor", material.getAmbientFactor()); shader->setUniform("ambientFactor", material.getAmbientFactor());
shader->setUniform("diffuseFactor", material.getDiffuseFactor()); shader->setUniform("diffuseFactor", material.getDiffuseFactor());
shader->setUniform("specularFactor", material.getSpecularFactor()); shader->setUniform("specularFactor", material.getSpecularFactor());
shader->setUniform("shininess", material.getShininess()); shader->setUniform("shininess", material.getShininess());
shader->setTexture("uTexture", material.getReference(), 0);
// set model matrix // set model matrix
shader->setUniform("modelMatrix", modelMatrix); shader->setUniform("modelMatrix", modelMatrix);
// set shadowMVPs // set shadowMVPs

View File

@ -16,7 +16,8 @@ class Object : public Entity {
Object(); Object();
~Object(); ~Object();
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices); bool texturePass, glm::mat4* viewProjcetionMatrix,
std::vector<glm::mat4>* additionalMatrices=0);
private: private:
Model model; Model model;
Material material; Material material;

View File

@ -414,6 +414,26 @@ 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.2f); //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
@ -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{