Merge branch 'master' of https://github.com/Faerbit/swp
This commit is contained in:
commit
c403814cd6
BIN
Levels/Textures/seamlessTerrain.png
Normal file
BIN
Levels/Textures/seamlessTerrain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 MiB |
@ -14,6 +14,9 @@ uniform float specularFactor;
|
||||
uniform vec3 camera;
|
||||
uniform float shininess;
|
||||
uniform int lightCount;
|
||||
uniform vec3 directionalLightVector;
|
||||
uniform vec3 directionalColor;
|
||||
uniform float directionalIntensity;
|
||||
uniform vec3 lightSources[128];
|
||||
uniform vec3 lightColors[128];
|
||||
uniform float lightIntensities[128];
|
||||
@ -23,6 +26,15 @@ void main()
|
||||
vec3 ambientColor = ambientFactor * ambientColor;
|
||||
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
|
||||
vec3 specularColor = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
if(length(directionalLightVector)>0.0f) {
|
||||
vec3 directionalVector = normalize(directionalLightVector);
|
||||
diffuseColor += dot(normalize(vNormal), directionalVector)
|
||||
*diffuseFactor*directionalIntensity*directionalColor;
|
||||
vec3 cameraVector = normalize(camera - vec3(fragPosition));
|
||||
specularColor += clamp(pow((dot((cameraVector+directionalVector),normalize(vNormal))/(length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
|
||||
*specularFactor*directionalIntensity*directionalColor;
|
||||
}
|
||||
for(int i = 0; i<lightCount; i++) {
|
||||
float distance = distance(lightSources[i], vec3(fragPosition));
|
||||
// only take lights into account with meaningful contribution
|
||||
@ -38,6 +50,6 @@ void main()
|
||||
}
|
||||
vec3 finalColor = specularColor + diffuseColor + ambientColor;
|
||||
|
||||
vec3 texture = texture(uTexture, vTexCoord).rgb;
|
||||
oColor = vec4(finalColor*texture, 1.0 );
|
||||
vec4 texture = texture(uTexture, vTexCoord).rgba;
|
||||
oColor = vec4(finalColor, 1.0f)*texture;
|
||||
}
|
||||
|
@ -129,6 +129,15 @@ void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader)
|
||||
glUniform1fv(shader->getUniformLocation("lightIntensities"),
|
||||
sizeof(lightIntensities), (GLfloat*) lightIntensities);
|
||||
}
|
||||
// set directional Light
|
||||
if(level->getDirectionalLight()) {
|
||||
shader->setUniform("directionalLightVector",
|
||||
level->getDirectionalLight()->getPosition());
|
||||
shader->setUniform("directionalColor",
|
||||
level->getDirectionalLight()->getColour());
|
||||
shader->setUniform("directionalIntensity",
|
||||
level->getDirectionalLight()->getIntensity());
|
||||
}
|
||||
|
||||
// set Material Parameters
|
||||
shader->setUniform("ambientColor", level->getAmbientLight());
|
||||
|
48
level.cc
48
level.cc
@ -25,52 +25,50 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
// load a texture:
|
||||
Material material = Material("marbleTexture.png", 0.1f, 0.5f, 0.5f, 3.0f);
|
||||
//Create object
|
||||
Object object = Object(model, material, glm::vec3(0.0f, 5.0f, 0.0f),
|
||||
Object object = Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||
//add player to phy
|
||||
this->physics.addPlayer(0.75f,0.0f,5.0f,0.0f,1.0f,0);
|
||||
this->physics.addPlayer(1.25f,0.0f,10.0f,0.0f,1.0f,0);
|
||||
objects.push_back(object);
|
||||
|
||||
physics.addStaticGroundPlane();
|
||||
//physics.addStaticGroundPlane();
|
||||
|
||||
Model torchModel = Model("torch.obj", 0.75f);
|
||||
Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f);
|
||||
//Create object
|
||||
Object torchObject = Object(torchModel, torchMaterial, glm::vec3(-3.0f, 5.0f, 0.0f),
|
||||
Object torchObject = Object(torchModel, torchMaterial, glm::vec3(-3.0f, 6.0f, 0.0f),
|
||||
glm::vec3(0.0f, 1.0472f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||
objects.push_back(torchObject);
|
||||
|
||||
Model blockModel = Model("Block.obj", 1.0f);
|
||||
Material blockMaterial = Material("blockTexture.png", 0.1f, 0.6, 0.4f, 2.0f);
|
||||
Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 5.0f, 2.0f),
|
||||
Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
shader);
|
||||
objects.push_back(blockObject);
|
||||
|
||||
Model columnModel = Model("Column.obj", 1.0f);
|
||||
Material columnMaterial = Material("columnTexture.png", 0.1f, 0.6, 0.4f, 2.0f);
|
||||
Object columnObject = Object(columnModel, columnMaterial, glm::vec3(-2.0f, 5.0f, -2.0f),
|
||||
Object columnObject = Object(columnModel, columnMaterial, glm::vec3(-2.0f, 7.0f, -2.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
shader);
|
||||
objects.push_back(columnObject);
|
||||
|
||||
//set lighting parameters
|
||||
ambientLight = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||
Light light = Light(glm::vec3(-3.0f, 6.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f);
|
||||
directionalLight = Light(glm::vec3(-0.5f, 0.0f, -0.5f), glm::vec3(1.0f, 1.0f, 0.0f), 0.4f);
|
||||
Light light = Light(glm::vec3(-3.0f, 7.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f);
|
||||
lights.push_back(light);
|
||||
Light light2 = Light(glm::vec3(3.0f, 6.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f);
|
||||
Light light2 = Light(glm::vec3(3.0f, 6.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f);
|
||||
lights.push_back(light2);
|
||||
Light light3 = Light(glm::vec3(0.0f, 5.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 1.0f), 4.0f);
|
||||
lights.push_back(light3);
|
||||
|
||||
|
||||
// load terrain
|
||||
this->terrain.load();
|
||||
Model terrainModel = Model(this->terrain.getModel());
|
||||
// load a texture:
|
||||
Material terrainMaterial = Material("terrainTexture.png", 0.1f, 0.8f, 0.2f, 3.0f);
|
||||
Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f);
|
||||
//Create object
|
||||
Object terrainObject = Object(terrainModel, terrainMaterial,
|
||||
glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()),
|
||||
@ -78,6 +76,9 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||
objects.push_back(terrainObject);
|
||||
cameraCenter = &objects[0];
|
||||
|
||||
//addTerrainPhysic
|
||||
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
|
||||
}
|
||||
|
||||
void Level::render() {
|
||||
@ -86,7 +87,7 @@ void Level::render() {
|
||||
}
|
||||
}
|
||||
|
||||
void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool dPressed, bool sPressed) {
|
||||
void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed) {
|
||||
// rotate bunny
|
||||
//cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f));
|
||||
// Ignore first two mouse updates, because they are incorrect
|
||||
@ -95,18 +96,27 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
mouseDelta.x = -mouseDelta.x;
|
||||
camera.updateRotation(mouseDelta/100.0f);
|
||||
}
|
||||
|
||||
if(wPressed)
|
||||
{
|
||||
//physics.rollForward(camera.getRotation);
|
||||
if(wPressed){
|
||||
physics.rollForward(camera.getVector(),1.0f);
|
||||
}
|
||||
if(aPressed) {
|
||||
physics.rollLeft(camera.getVector(),1.0f);
|
||||
}
|
||||
if(sPressed) {
|
||||
physics.rollBack(camera.getVector(),1.0f);
|
||||
}
|
||||
if(dPressed){
|
||||
physics.rollRight(camera.getVector(),1.0f);
|
||||
}
|
||||
|
||||
physics.takeUpdateStep(runTime);
|
||||
|
||||
objects[0].setPosition(physics.getPos(0));
|
||||
lights[2].setPosition(physics.getPos(0));
|
||||
objects[0].setRotation(physics.getRotation(0));
|
||||
}
|
||||
|
||||
glm::vec3 Level::getAmbientLight() {
|
||||
@ -124,3 +134,7 @@ Camera* Level::getCamera() {
|
||||
Object* Level::getCameraCenter() {
|
||||
return cameraCenter;
|
||||
}
|
||||
|
||||
Light* Level::getDirectionalLight() {
|
||||
return &directionalLight;
|
||||
}
|
||||
|
2
level.hh
2
level.hh
@ -19,6 +19,7 @@ class Level {
|
||||
void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed);
|
||||
void render();
|
||||
glm::vec3 getAmbientLight();
|
||||
Light* getDirectionalLight();
|
||||
std::vector<Light> getLights();
|
||||
Object* getCameraCenter();
|
||||
Camera* getCamera();
|
||||
@ -27,6 +28,7 @@ class Level {
|
||||
std::vector<Object> objects;
|
||||
std::vector<Light> lights;
|
||||
glm::vec3 ambientLight;
|
||||
Light directionalLight;
|
||||
Object* cameraCenter;
|
||||
Physics physics;
|
||||
Camera camera;
|
||||
|
7
light.cc
7
light.cc
@ -1,11 +1,14 @@
|
||||
#include "light.hh"
|
||||
|
||||
Light::Light(glm::vec3 position, glm::vec3 rotation, glm::vec3 colour, float intensity)
|
||||
: Entity(position, rotation) {
|
||||
Light::Light(glm::vec3 position, glm::vec3 colour, float intensity)
|
||||
: Entity(position, glm::vec3(0.0f, 0.0f, 0.0f)) {
|
||||
this->colour = colour;
|
||||
this->intensity = intensity;
|
||||
}
|
||||
|
||||
Light::Light() {
|
||||
}
|
||||
|
||||
Light::~Light() {
|
||||
}
|
||||
|
||||
|
3
light.hh
3
light.hh
@ -6,7 +6,8 @@
|
||||
|
||||
class Light : public Entity {
|
||||
public:
|
||||
Light(glm::vec3 position, glm::vec3 rotation, glm::vec3 colour, float intensity);
|
||||
Light(glm::vec3 position, glm::vec3 colour, float intensity);
|
||||
Light();
|
||||
glm::vec3 getColour();
|
||||
float getIntensity();
|
||||
~Light();
|
||||
|
12
main.cc
12
main.cc
@ -112,6 +112,8 @@ int main( int argc, char *argv[] )
|
||||
//
|
||||
glClearColor( 0.0, 0.0, 0.0, 1.0 );
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
app.init();
|
||||
|
||||
int frameCount = 0;
|
||||
@ -122,15 +124,16 @@ int main( int argc, char *argv[] )
|
||||
|
||||
double lastUpdate=0.0f;
|
||||
|
||||
int stateW = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_W);
|
||||
int stateA = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_A);
|
||||
int stateS = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_S);
|
||||
int stateD = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_D);
|
||||
|
||||
do {
|
||||
|
||||
double now = glfwGetTime()- startTimeInSeconds;
|
||||
|
||||
int stateW = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_W);
|
||||
int stateA = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_A);
|
||||
int stateS = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_S);
|
||||
int stateD = glfwGetKey(app.getGraphics()->getWindow(), GLFW_KEY_D);
|
||||
|
||||
if (showNextFPS <= now) {
|
||||
std::stringstream sstream (std::stringstream::in | std::stringstream::out);
|
||||
sstream << std::setprecision(1) << std::fixed
|
||||
@ -158,6 +161,7 @@ int main( int argc, char *argv[] )
|
||||
glfwSwapBuffers(app.getGraphics()->getWindow());
|
||||
glfwPollEvents();
|
||||
frameCount++;
|
||||
|
||||
} // Check if the window was closed
|
||||
while( !glfwWindowShouldClose(app.getGraphics()->getWindow()) );
|
||||
|
||||
|
58
physics.cc
58
physics.cc
@ -32,21 +32,32 @@ void Physics::init()
|
||||
|
||||
void Physics::takeUpdateStep(float timeDiff)
|
||||
{
|
||||
|
||||
world->stepSimulation(timeDiff);
|
||||
}
|
||||
|
||||
void Physics::addTerrain(int width, int length, float** heightData)
|
||||
{
|
||||
|
||||
float* heightfield = new float[width * length];
|
||||
int highest = -999999, j = 0, i = 0;
|
||||
for (i = 0; i < width; i++)
|
||||
{
|
||||
for (j = 0; j < length; j++) {
|
||||
heightfield[j*length+i] = heightData[i][j];
|
||||
heightfield[i*length+j] = heightData[j][i];
|
||||
|
||||
if (heightData[j][i] > highest)
|
||||
highest = heightData[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
heightfield[j*length+i] = heightData[i][j];
|
||||
if (heightData[i][j] > highest)
|
||||
highest = heightData[i][j];
|
||||
}
|
||||
*/
|
||||
|
||||
btHeightfieldTerrainShape* terrianShape = new btHeightfieldTerrainShape(width,length,heightData,highest,1,true,false);
|
||||
btHeightfieldTerrainShape* terrianShape = new btHeightfieldTerrainShape(length,width,heightfield,highest,1,true,false);
|
||||
|
||||
btRigidBody* tBody = new btRigidBody(0,new btDefaultMotionState(),terrianShape);
|
||||
|
||||
@ -55,7 +66,7 @@ void Physics::addTerrain(int width, int length, float** heightData)
|
||||
//tBody->getWoorldTransform().setRotation(btQuaternion(0,0,0,1));
|
||||
|
||||
terrainBody = tBody;
|
||||
|
||||
|
||||
world->addRigidBody(terrainBody);
|
||||
|
||||
/*
|
||||
@ -101,11 +112,14 @@ void Physics::addPlayer(float rad, float x, float y, float z, float mass, unsign
|
||||
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
|
||||
|
||||
playerBall = new btRigidBody(info);
|
||||
|
||||
|
||||
playerBall->setDamping(0.1f,0.3f);
|
||||
|
||||
world->addRigidBody(playerBall);
|
||||
|
||||
bodies.push_back(playerBall);
|
||||
|
||||
|
||||
playerBall->setSleepingThresholds(0,0);
|
||||
if(bodies.size() == indice)
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
|
||||
@ -127,13 +141,15 @@ void Physics::addSphere(float rad, float x, float y, float z, float mass, unsign
|
||||
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(x,y,z)));
|
||||
|
||||
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
|
||||
//info.
|
||||
|
||||
btRigidBody* body = new btRigidBody(info);
|
||||
|
||||
world->addRigidBody(body);
|
||||
|
||||
bodies.push_back(body);
|
||||
|
||||
|
||||
body->setSleepingThresholds(0,0);
|
||||
|
||||
if(bodies.size() == indice)
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
@ -158,16 +174,30 @@ glm::mat4 Physics::getRotation(int i)
|
||||
return matrix;
|
||||
}
|
||||
|
||||
void Physics::rollForward(glm::vec3 camPos)
|
||||
void Physics::rollForward(glm::vec3 camPos,float strength)
|
||||
{
|
||||
btVector3 pos(camPos.x,camPos.y,camPos.z);
|
||||
pos -= playerBody->getCenterOfMassPosition();
|
||||
pos.cross(btVector3(0,1,0));
|
||||
btVector3 pos(camPos.x,0,camPos.z);
|
||||
pos = btCross(pos,btVector3(0,1,0));
|
||||
playerBall->applyTorque(pos);
|
||||
}
|
||||
|
||||
/* glm::vec3 saveVector= glm::vec3(1,0,0) * rotCamera;
|
||||
saveVector = glm::cross(glm::vec3(0,1,0),saveVector);
|
||||
playerBall->applyTorque(btVector3(saveVector[0],saveVector[1],saveVector[2]));*/
|
||||
void Physics::rollBack(glm::vec3 camPos,float strength)
|
||||
{
|
||||
btVector3 pos(camPos.x,0,camPos.z);
|
||||
pos = btCross(btVector3(0,1,0),pos);
|
||||
playerBall->applyTorque(pos);
|
||||
}
|
||||
|
||||
void Physics::rollLeft(glm::vec3 camPos,float strength)
|
||||
{
|
||||
btVector3 pos(camPos.x,0,camPos.z);
|
||||
playerBall->applyTorque(pos);
|
||||
}
|
||||
|
||||
void Physics::rollRight(glm::vec3 camPos,float strength)
|
||||
{
|
||||
btVector3 pos(camPos.x,0,camPos.z);
|
||||
playerBall->applyTorque(-pos);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -37,6 +37,9 @@ class Physics {
|
||||
void init();
|
||||
void takeUpdateStep(float timeDiff);
|
||||
void rollForward(glm::vec3 camPos, float strength);
|
||||
void rollLeft(glm::vec3 camPos, float strength);
|
||||
void rollRight(glm::vec3 camPos, float strength);
|
||||
void rollBack(glm::vec3 camPos, float strength);
|
||||
glm::vec3 getPos(int i);
|
||||
glm::mat4 getRotation(int i);
|
||||
void rollForward(glm::vec3 camPos);
|
||||
|
Loading…
Reference in New Issue
Block a user