Put Box In Level
This commit is contained in:
parent
fa60d52676
commit
3d936df227
29
level.cc
29
level.cc
@ -21,24 +21,20 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
|
||||
// currently hard coded should later read this stuff out of a file
|
||||
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);
|
||||
// load a texture:
|
||||
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),
|
||||
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);
|
||||
Material skyboxMaterial = Material("skybox.png", 0.7f, 0.0f, 0.0f, 0.0f);
|
||||
Object skyboxObject = Object(skyboxModel, skyboxMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||
objects.push_back(skyboxObject);
|
||||
|
||||
//physics.addStaticGroundPlane();
|
||||
|
||||
Model torchModel = Model("torch.obj", 0.75f);
|
||||
Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f);
|
||||
@ -52,6 +48,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||
objects.push_back(blockObject);
|
||||
physics.addBox(1,1,1,blockObject,0,2);
|
||||
|
||||
Model columnModel = Model("Column.obj", 1.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);
|
||||
objects.push_back(columnObject);
|
||||
|
||||
//make non physics objects
|
||||
|
||||
|
||||
//set lighting parameters
|
||||
ambientLight = glm::vec3(1.0f, 1.0f, 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);
|
||||
}
|
||||
|
||||
float str = 20;
|
||||
|
||||
if(wPressed){
|
||||
physics.rollForward(camera.getVector(),1.0f);
|
||||
physics.rollForward(camera.getVector(),str);
|
||||
}
|
||||
if(aPressed) {
|
||||
physics.rollLeft(camera.getVector(),1.0f);
|
||||
physics.rollLeft(camera.getVector(),str);
|
||||
}
|
||||
if(sPressed) {
|
||||
physics.rollBack(camera.getVector(),1.0f);
|
||||
physics.rollBack(camera.getVector(),str);
|
||||
}
|
||||
if(dPressed){
|
||||
physics.rollRight(camera.getVector(),1.0f);
|
||||
physics.rollRight(camera.getVector(),str);
|
||||
}
|
||||
|
||||
physics.takeUpdateStep(runTime);
|
||||
|
||||
objects[0].setPosition(physics.getPos(0));
|
||||
objects[0].setRotation(physics.getRotation(0));
|
||||
|
||||
skybox->setPosition(glm::vec3(cameraCenter->getPosition().x,
|
||||
0.0f, cameraCenter->getPosition().z));
|
||||
}
|
||||
|
13
physics.cc
13
physics.cc
@ -77,7 +77,7 @@ void Physics::addStaticGroundPlane()
|
||||
|
||||
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" );
|
||||
|
||||
btSphereShape* sphere = new btSphereShape(rad);
|
||||
@ -100,16 +100,17 @@ void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice)
|
||||
bodies.push_back(playerBall);
|
||||
|
||||
playerBall->setSleepingThresholds(0,0);
|
||||
if(bodies.size() == indice)
|
||||
if(bodies.size() != indice)
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
|
||||
}
|
||||
|
||||
void Physics::addBox(float width, float height, float length, Entity entity, float mass, unsigned indice)
|
||||
{
|
||||
if(bodies.size() != indice)
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
|
||||
if(bodies.size() == indice)
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
|
||||
btBoxShape* box = new btBoxShape(btVector3(width/2,height/2,length/2));
|
||||
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z)));
|
||||
|
||||
@ -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)
|
||||
{
|
||||
if(bodies.size() != indice)
|
||||
if(bodies.size() == indice)
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
|
||||
btSphereShape* sphere = new btSphereShape(rad);
|
||||
@ -165,7 +166,7 @@ void Physics::addSphere(float rad, Entity entity, float mass, unsigned indice)
|
||||
|
||||
body->setSleepingThresholds(0,0);
|
||||
|
||||
if(bodies.size() == indice)
|
||||
if(bodies.size() != indice)
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user