Multiple objects now working, for exact implimentation check level.cc and comment in physics.hh. Additionally multiple comments have been added to physics.hh to support the use of these functions
This commit is contained in:
parent
d58147a935
commit
9d39bec46f
22
level.cc
22
level.cc
@ -28,10 +28,11 @@ void Level::load() {
|
||||
//add player
|
||||
Model model = Model("MarbleSmooth.obj", 0.75f);
|
||||
Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f);
|
||||
Object* object = new Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f),
|
||||
Object* object = new Object(model, material, glm::vec3(2.0f, 10.0f, 2.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
objects.push_back(object);
|
||||
this->physics.addPlayer(1.25f,*object,8.0f,1);
|
||||
physicObjects.push_back(object);
|
||||
this->physics.addPlayer(1.25f,*object,8.0f,physicObjects.size());
|
||||
cameraCenter = object;
|
||||
|
||||
Model skydomeModel = Model("skydome.obj", skydomeSize);
|
||||
@ -50,10 +51,17 @@ void Level::load() {
|
||||
|
||||
Model blockModel = Model("Block.obj", 1.0f);
|
||||
Material blockMaterial = Material("blockTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f);
|
||||
Object* blockObject = new Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f),
|
||||
Object* blockObject = new Object(blockModel, blockMaterial, glm::vec3(0.0f, 10.0f, 0.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
objects.push_back(blockObject);
|
||||
physics.addBox(1,1,1,*blockObject,0,2);
|
||||
physicObjects.push_back(blockObject);
|
||||
physics.addBox(1,3.0f,1,*blockObject,2,physicObjects.size());
|
||||
|
||||
Object* blockObject2 = new Object(blockModel, blockMaterial, glm::vec3(5.0f, 10.0f, 5.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
objects.push_back(blockObject2);
|
||||
physicObjects.push_back(blockObject2);
|
||||
physics.addBox(1,3.0f,1,*blockObject2,2,physicObjects.size());
|
||||
|
||||
Model columnModel = Model("Column.obj", 1.0f);
|
||||
Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f);
|
||||
@ -126,6 +134,12 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
|
||||
cameraCenter->setPosition(physics.getPos(0));
|
||||
cameraCenter->setRotation(physics.getRotation(0));
|
||||
|
||||
for(unsigned i = 0; i < physicObjects.size();i++)
|
||||
{
|
||||
physicObjects[i]->setPosition(physics.getPos(i));
|
||||
physicObjects[i]->setRotation(physics.getRotation(i));
|
||||
}
|
||||
|
||||
skydome->setPosition(glm::vec3(cameraCenter->getPosition().x,
|
||||
0.0f, cameraCenter->getPosition().z));
|
||||
}
|
||||
|
1
level.hh
1
level.hh
@ -29,6 +29,7 @@ class Level {
|
||||
private:
|
||||
std::string filePath;
|
||||
std::vector<Object*> objects;
|
||||
std::vector<Object*> physicObjects;
|
||||
std::vector<Light> lights;
|
||||
glm::vec3 ambientLight;
|
||||
glm::vec4 fogColor;
|
||||
|
15
physics.hh
15
physics.hh
@ -38,23 +38,22 @@ class Physics {
|
||||
Physics();
|
||||
~Physics();
|
||||
void init();
|
||||
void takeUpdateStep(float timeDiff);
|
||||
void rollForward(glm::vec3 camPos, float strength);
|
||||
void takeUpdateStep(float timeDiff); //must be used in level.update to proagate the physics
|
||||
void rollForward(glm::vec3 camPos, float strength); //self explainitory
|
||||
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);
|
||||
void addStaticGroundPlane();
|
||||
void addTerrain(int width, int length, float** heightData);
|
||||
void addPlayer(float rad, Entity entity, float mass, unsigned indice);
|
||||
void addSphere(float rad, Entity entity, float mass, unsigned indice);
|
||||
void addBox(float width, float height, float length, Entity entity, float mass, unsigned indice);
|
||||
void addPlayer(float rad, Entity entity, float mass, unsigned indice); //use these AFTER physicObjects.push_back(object)! if mass == 0 then the object is unmoveable
|
||||
void addSphere(float rad, Entity entity, float mass, unsigned indice); //The Indice should be set to physicObjects.size()
|
||||
void addBox(float width, float height, float length, Entity entity, float mass, unsigned indice); //this is used to ensuer that the system is synchronized
|
||||
|
||||
private:
|
||||
btRigidBody* playerBall;
|
||||
btRigidBody* terrainBody;
|
||||
btRigidBody* playerBall; //allows for quicker access to the ball
|
||||
btRigidBody* terrainBody; //duh
|
||||
std::vector<btRigidBody*> bodies; //list of all bodies. bodies are also in world, but save again to ease cleaning up process.
|
||||
btRigidBody* staticGroundBody;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user