Put Box In Level

This commit is contained in:
Jasper 2014-11-21 16:22:36 +01:00
parent fa60d52676
commit 3d936df227
2 changed files with 23 additions and 19 deletions

View File

@ -21,16 +21,14 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
// currently hard coded should later read this stuff out of a file // currently hard coded should later read this stuff out of a file
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f); this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
// load the geometry of the stanford bunny and build a VAO:
//add player
Model model = Model("MarbleSmooth.obj", 0.75f); Model model = Model("MarbleSmooth.obj", 0.75f);
// load a texture:
Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f); Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f);
//Create object
Object object = Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f), Object object = Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader); glm::vec3(0.0f, 0.0f, 0.0f), shader);
//add player to phy
this->physics.addPlayer(1.25f,object,1.0f,0);
objects.push_back(object); objects.push_back(object);
this->physics.addPlayer(1.25f,object,8.0f,1);
Model skyboxModel = Model("skybox.obj", skyboxSize); Model skyboxModel = Model("skybox.obj", skyboxSize);
Material skyboxMaterial = Material("skybox.png", 0.7f, 0.0f, 0.0f, 0.0f); Material skyboxMaterial = Material("skybox.png", 0.7f, 0.0f, 0.0f, 0.0f);
@ -38,8 +36,6 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
glm::vec3(0.0f, 0.0f, 0.0f), shader); glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(skyboxObject); objects.push_back(skyboxObject);
//physics.addStaticGroundPlane();
Model torchModel = Model("torch.obj", 0.75f); Model torchModel = Model("torch.obj", 0.75f);
Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f); Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f);
//Create object //Create object
@ -52,6 +48,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f), Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader); glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(blockObject); objects.push_back(blockObject);
physics.addBox(1,1,1,blockObject,0,2);
Model columnModel = Model("Column.obj", 1.0f); Model columnModel = Model("Column.obj", 1.0f);
Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f); Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f);
@ -59,6 +56,9 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
glm::vec3(0.0f, 0.0f, 0.0f), shader); glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(columnObject); objects.push_back(columnObject);
//make non physics objects
//set lighting parameters //set lighting parameters
ambientLight = glm::vec3(1.0f, 1.0f, 1.0f); ambientLight = glm::vec3(1.0f, 1.0f, 1.0f);
fogColor = glm::vec4(0.10f, 0.14f, 0.14f, 1.0f); fogColor = glm::vec4(0.10f, 0.14f, 0.14f, 1.0f);
@ -104,23 +104,26 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
camera.updateRotation(mouseDelta/100.0f); camera.updateRotation(mouseDelta/100.0f);
} }
float str = 20;
if(wPressed){ if(wPressed){
physics.rollForward(camera.getVector(),1.0f); physics.rollForward(camera.getVector(),str);
} }
if(aPressed) { if(aPressed) {
physics.rollLeft(camera.getVector(),1.0f); physics.rollLeft(camera.getVector(),str);
} }
if(sPressed) { if(sPressed) {
physics.rollBack(camera.getVector(),1.0f); physics.rollBack(camera.getVector(),str);
} }
if(dPressed){ if(dPressed){
physics.rollRight(camera.getVector(),1.0f); physics.rollRight(camera.getVector(),str);
} }
physics.takeUpdateStep(runTime); physics.takeUpdateStep(runTime);
objects[0].setPosition(physics.getPos(0)); objects[0].setPosition(physics.getPos(0));
objects[0].setRotation(physics.getRotation(0)); objects[0].setRotation(physics.getRotation(0));
skybox->setPosition(glm::vec3(cameraCenter->getPosition().x, skybox->setPosition(glm::vec3(cameraCenter->getPosition().x,
0.0f, cameraCenter->getPosition().z)); 0.0f, cameraCenter->getPosition().z));
} }

View File

@ -77,7 +77,7 @@ void Physics::addStaticGroundPlane()
void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice) void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice)
{ {
if(bodies.size() != indice) if(bodies.size() == indice)
throw std::invalid_argument( "Bodies out of Sync" ); throw std::invalid_argument( "Bodies out of Sync" );
btSphereShape* sphere = new btSphereShape(rad); btSphereShape* sphere = new btSphereShape(rad);
@ -100,14 +100,15 @@ void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice)
bodies.push_back(playerBall); bodies.push_back(playerBall);
playerBall->setSleepingThresholds(0,0); playerBall->setSleepingThresholds(0,0);
if(bodies.size() == indice) if(bodies.size() != indice)
throw std::invalid_argument( "Bodies out of Sync" ); throw std::invalid_argument( "Bodies out of Sync" );
} }
void Physics::addBox(float width, float height, float length, Entity entity, float mass, unsigned indice) void Physics::addBox(float width, float height, float length, Entity entity, float mass, unsigned indice)
{ {
if(bodies.size() != indice)
if(bodies.size() == indice)
throw std::invalid_argument( "Bodies out of Sync" ); throw std::invalid_argument( "Bodies out of Sync" );
btBoxShape* box = new btBoxShape(btVector3(width/2,height/2,length/2)); btBoxShape* box = new btBoxShape(btVector3(width/2,height/2,length/2));
@ -140,7 +141,7 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo
void Physics::addSphere(float rad, Entity entity, float mass, unsigned indice) void Physics::addSphere(float rad, Entity entity, float mass, unsigned indice)
{ {
if(bodies.size() != indice) if(bodies.size() == indice)
throw std::invalid_argument( "Bodies out of Sync" ); throw std::invalid_argument( "Bodies out of Sync" );
btSphereShape* sphere = new btSphereShape(rad); btSphereShape* sphere = new btSphereShape(rad);
@ -165,7 +166,7 @@ void Physics::addSphere(float rad, Entity entity, float mass, unsigned indice)
body->setSleepingThresholds(0,0); body->setSleepingThresholds(0,0);
if(bodies.size() == indice) if(bodies.size() != indice)
throw std::invalid_argument( "Bodies out of Sync" ); throw std::invalid_argument( "Bodies out of Sync" );
} }