2014-10-30 22:54:19 +00:00
|
|
|
#include "level.hh"
|
2015-02-13 16:14:29 +00:00
|
|
|
#include "loader.hh"
|
2014-12-12 15:24:47 +00:00
|
|
|
#include <string>
|
2014-10-30 22:54:19 +00:00
|
|
|
|
2015-06-03 00:12:00 +00:00
|
|
|
Level::Level(std::string xmlFilePath, float farPlane) {
|
2015-02-04 16:16:06 +00:00
|
|
|
// default value
|
2014-11-21 23:39:58 +00:00
|
|
|
skydomeSize = 50.0f;
|
2015-02-06 17:00:14 +00:00
|
|
|
physics = Physics();
|
2015-02-13 16:14:29 +00:00
|
|
|
this->xmlFilePath = xmlFilePath;
|
2015-06-03 00:12:00 +00:00
|
|
|
this->farPlane = farPlane;
|
2014-10-30 22:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Level::Level() {
|
|
|
|
}
|
2015-02-04 16:16:06 +00:00
|
|
|
|
2014-10-30 22:54:19 +00:00
|
|
|
Level::~Level() {
|
2015-02-04 16:16:06 +00:00
|
|
|
if (luaState!=nullptr) {
|
|
|
|
lua_close(luaState);
|
|
|
|
}
|
2015-03-09 13:59:22 +00:00
|
|
|
delete(waterPlane);
|
2014-10-30 22:54:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 13:45:44 +00:00
|
|
|
void Level::load() {
|
2015-01-09 15:51:28 +00:00
|
|
|
//Intialize lua state
|
|
|
|
// Check if there's an existing state and close it
|
2015-02-04 16:16:06 +00:00
|
|
|
if(luaState != nullptr){
|
|
|
|
lua_close(luaState);
|
|
|
|
luaState = nullptr;
|
2015-01-09 15:51:28 +00:00
|
|
|
}
|
|
|
|
// Create a new lua state
|
2015-02-04 16:16:06 +00:00
|
|
|
luaState = luaL_newstate();
|
|
|
|
luaL_openlibs(luaState);
|
2015-01-13 16:50:15 +00:00
|
|
|
//Expose the class Level and its functions to Lua
|
2015-02-04 16:16:06 +00:00
|
|
|
luabridge::getGlobalNamespace(luaState)
|
2015-01-09 15:51:28 +00:00
|
|
|
.beginClass<Level>("Level")
|
2015-02-04 16:16:06 +00:00
|
|
|
.addFunction("getObjectCount", &Level::getPhysicsObjectsVectorSize)
|
2015-01-17 12:30:33 +00:00
|
|
|
.addFunction("moveObject", &Level::moveObject)
|
2015-03-04 14:52:28 +00:00
|
|
|
.addFunction("resetPlayer", &Level::resetPlayer)
|
2015-03-04 17:10:49 +00:00
|
|
|
.addFunction("movePlayer", &Level::movePlayer)
|
2015-03-06 12:22:04 +00:00
|
|
|
.addFunction("setSunDirection", &Level::setSunDirection)
|
2015-03-06 16:44:34 +00:00
|
|
|
.addFunction("forceMove", &Level::forceMove)
|
2015-03-06 15:19:57 +00:00
|
|
|
.addFunction("activateEndgame", &Level::activateEndgame)
|
2015-03-07 12:41:35 +00:00
|
|
|
.addFunction("preloadLightPosition", &Level::preloadLightPosition)
|
|
|
|
.addFunction("addLightByParameters", &Level::addLightByParameters)
|
|
|
|
.addFunction("deleteFourLights", &Level::deleteFourLights)
|
2015-01-09 15:51:28 +00:00
|
|
|
.endClass();
|
2015-01-13 16:50:15 +00:00
|
|
|
//Push the level to Lua as a global variable
|
2015-02-04 16:16:06 +00:00
|
|
|
luabridge::push(luaState, this);
|
|
|
|
lua_setglobal(luaState, "level");
|
2015-02-13 12:46:41 +00:00
|
|
|
|
2014-11-14 21:55:29 +00:00
|
|
|
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
|
2014-10-30 22:54:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 19:14:54 +00:00
|
|
|
int Level::checkMaxSurroundingLights() {
|
|
|
|
int maxSurroundingLights = 0;
|
|
|
|
for(unsigned int i = 0; i<lights.size(); i++) {
|
|
|
|
int thisSurroundingLights = 0;
|
|
|
|
for(unsigned int j = 0; j<lights.size(); j++) {
|
|
|
|
if (glm::distance(lights.at(i)->getPosition(), lights.at(j)->getPosition()) < skydomeSize) {
|
|
|
|
thisSurroundingLights++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (thisSurroundingLights > maxSurroundingLights) {
|
|
|
|
maxSurroundingLights = thisSurroundingLights;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return maxSurroundingLights;
|
|
|
|
}
|
|
|
|
|
2015-03-21 20:46:58 +00:00
|
|
|
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
2015-05-31 22:57:36 +00:00
|
|
|
glm::vec3 center, int chunkRenderDistance, glm::mat4* viewProjectionMatrix,
|
2015-03-21 20:46:58 +00:00
|
|
|
std::vector<glm::mat4>* shadowVPs) {
|
2015-05-31 22:57:36 +00:00
|
|
|
std::vector<Chunk*> nearChunks = getSurroundingChunks(center, chunkRenderDistance);
|
2015-05-28 09:23:54 +00:00
|
|
|
for(unsigned int i = 0; i<nearChunks.size(); i++) {
|
|
|
|
nearChunks.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
|
2014-10-30 22:54:19 +00:00
|
|
|
}
|
2015-03-18 07:54:38 +00:00
|
|
|
for (unsigned int i = 0; i<crossChunkObjects.size(); i++) {
|
2015-05-28 09:23:54 +00:00
|
|
|
crossChunkObjects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
|
2015-03-18 07:54:38 +00:00
|
|
|
}
|
2014-10-30 22:54:19 +00:00
|
|
|
}
|
2014-10-30 22:59:03 +00:00
|
|
|
|
2015-03-21 14:05:22 +00:00
|
|
|
void Level::enqueueObjects(Graphics* graphics) {
|
2015-05-31 22:57:36 +00:00
|
|
|
std::vector<Chunk*> nearChunks = getSurroundingChunks(cameraCenter->getPosition(), -1);
|
2015-05-28 09:23:54 +00:00
|
|
|
for(unsigned int i = 0; i<nearChunks.size(); i++) {
|
|
|
|
graphics->enqueueObjects(nearChunks.at(i)->getSortedObjects());
|
2015-03-20 22:45:28 +00:00
|
|
|
}
|
2015-03-21 14:05:22 +00:00
|
|
|
graphics->enqueueObjects(&sortedCrossChunkObjects);
|
|
|
|
}
|
|
|
|
|
2015-05-31 22:57:36 +00:00
|
|
|
std::vector<Chunk*> Level::getSurroundingChunks(glm::vec3 center, int chunkRenderDistance) {
|
2015-05-27 08:27:08 +00:00
|
|
|
int renderDistance = 0;
|
2015-05-28 09:23:27 +00:00
|
|
|
if (chunkRenderDistance < 0) {
|
|
|
|
if ((int)farPlane % chunkSize == 0) {
|
|
|
|
renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
renderDistance = ((((int)skydomeSize)+chunkSize/2)/chunkSize) + 1;
|
|
|
|
}
|
2015-05-27 08:27:08 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-05-28 09:23:27 +00:00
|
|
|
renderDistance = chunkRenderDistance;
|
2015-05-27 08:27:08 +00:00
|
|
|
}
|
2015-05-31 22:57:36 +00:00
|
|
|
int xPosition = ((int)center.x + (terrain.getHeightmapWidth()/2))/chunkSize;
|
|
|
|
int zPosition = ((int)center.z + (terrain.getHeightmapHeight()/2))/chunkSize;
|
2015-05-27 08:27:08 +00:00
|
|
|
int xStart = xPosition - renderDistance;
|
|
|
|
unsigned int xEnd = xPosition + renderDistance;
|
|
|
|
int zStart = zPosition - renderDistance;
|
|
|
|
unsigned int zEnd = zPosition + renderDistance;
|
|
|
|
if (xStart < 0) {
|
|
|
|
xStart = 0;
|
|
|
|
}
|
|
|
|
if (zStart < 0) {
|
|
|
|
zStart = 0;
|
|
|
|
}
|
|
|
|
if (xEnd >= chunks.size()) {
|
|
|
|
xEnd = chunks.size()-1;
|
|
|
|
}
|
|
|
|
if (zEnd >= chunks.at(0).size()) {
|
|
|
|
zEnd = chunks.at(0).size()-1;
|
|
|
|
}
|
2015-05-28 09:16:30 +00:00
|
|
|
std::vector<Chunk*> vector = std::vector<Chunk*>((xEnd - xStart + 1)*(zEnd - zStart + 1));
|
2015-05-27 08:27:08 +00:00
|
|
|
int counter = 0;
|
|
|
|
for(unsigned int i = xStart; i<=xEnd; i++) {
|
|
|
|
for(unsigned int j = zStart; j<=zEnd; j++) {
|
|
|
|
vector.at(counter) = &chunks.at(i).at(j);
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
2015-03-21 17:44:08 +00:00
|
|
|
void Level::sortObjects(int textureCount) {
|
2015-03-21 14:05:22 +00:00
|
|
|
for(unsigned int i = 0; i<chunks.size(); i++) {
|
|
|
|
for(unsigned int j = 0; j<chunks.at(i).size(); j++) {
|
2015-03-21 17:44:08 +00:00
|
|
|
chunks.at(i).at(j).sortObjects(textureCount);
|
2015-03-21 14:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// init
|
2015-03-21 17:44:08 +00:00
|
|
|
sortedCrossChunkObjects = std::vector<std::vector<Object*>>(textureCount);
|
2015-03-21 14:05:22 +00:00
|
|
|
for(unsigned int i = 0; i<sortedCrossChunkObjects.size(); i++) {
|
|
|
|
sortedCrossChunkObjects.at(i) = std::vector<Object*>();
|
|
|
|
}
|
2015-03-20 22:45:28 +00:00
|
|
|
for(unsigned int i = 0; i<crossChunkObjects.size(); i++) {
|
2015-03-21 17:44:08 +00:00
|
|
|
sortedCrossChunkObjects.at(crossChunkObjects.at(i)->getMaterial()->getTextureUnit() - 2)
|
2015-03-21 14:05:22 +00:00
|
|
|
.push_back(crossChunkObjects.at(i));
|
2015-03-20 22:45:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:14:14 +00:00
|
|
|
void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,
|
|
|
|
KeyboardState* keyboardState) {
|
2015-02-27 11:56:02 +00:00
|
|
|
|
2014-11-14 21:55:29 +00:00
|
|
|
// Ignore first two mouse updates, because they are incorrect
|
2014-11-25 15:01:13 +00:00
|
|
|
// DON'T try to move this functionallity elsewhere
|
2014-11-14 21:55:29 +00:00
|
|
|
static int i = 0;
|
2015-03-04 14:33:31 +00:00
|
|
|
if (i <20) {
|
2014-11-14 21:55:29 +00:00
|
|
|
i++;
|
2015-03-04 14:33:31 +00:00
|
|
|
mouseDelta.x=mouseDelta.y=0;
|
2014-11-14 21:55:29 +00:00
|
|
|
}
|
2014-11-17 12:12:51 +00:00
|
|
|
|
2015-04-25 20:56:11 +00:00
|
|
|
const int runs = 4;
|
2015-03-04 14:33:31 +00:00
|
|
|
|
|
|
|
if(i>=20)
|
|
|
|
{
|
|
|
|
mouseDelta.x = -mouseDelta.x;
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:04:46 +00:00
|
|
|
for(int j = runs; j > 0; j--)
|
2014-11-28 11:06:17 +00:00
|
|
|
{
|
2015-03-04 14:04:46 +00:00
|
|
|
physics.takeUpdateStep(runTimeSinceLastUpdate/runs);
|
2015-03-04 14:33:31 +00:00
|
|
|
|
|
|
|
camera.updateRotation(mouseDelta/100.0f/(float)runs);
|
|
|
|
physics.updateCameraPos(mouseDelta, 50/runs, camera.getDistance());
|
2015-03-04 14:04:46 +00:00
|
|
|
|
2015-03-04 14:33:31 +00:00
|
|
|
camera.setPosition(physics.getCameraPosition());
|
|
|
|
camera.setDirection(physics.getCameraToPlayer());
|
|
|
|
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->wPressed){
|
2015-03-04 14:04:46 +00:00
|
|
|
physics.rollForward(camera.getVector(),strength/runs);
|
|
|
|
}
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->aPressed) {
|
2015-03-04 14:04:46 +00:00
|
|
|
physics.rollLeft(camera.getVector(),strength/runs);
|
|
|
|
}
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->sPressed) {
|
2015-03-04 14:04:46 +00:00
|
|
|
physics.rollBack(camera.getVector(),strength/runs);
|
|
|
|
}
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->dPressed){
|
2015-03-04 14:04:46 +00:00
|
|
|
physics.rollRight(camera.getVector(),strength/runs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->f1Pressed) {
|
2015-03-09 17:35:11 +00:00
|
|
|
physics.forcePlayer(glm::vec3(17.5, 21.0, 87.0));
|
|
|
|
}
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->f2Pressed) {
|
2015-03-09 17:35:11 +00:00
|
|
|
physics.forcePlayer(glm::vec3(-78.5, 21.75, 4.5));
|
|
|
|
}
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->f3Pressed) {
|
2015-03-09 17:35:11 +00:00
|
|
|
physics.forcePlayer(glm::vec3(-169.5, 21.5, 58.5));
|
|
|
|
}
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->f4Pressed) {
|
2015-03-09 17:35:11 +00:00
|
|
|
physics.forcePlayer(glm::vec3(-180.5, 21.75, 58.5));
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->kPressed)
|
2015-03-04 14:04:46 +00:00
|
|
|
camera.setIsPhysicsCamera(true);
|
2015-03-12 18:14:14 +00:00
|
|
|
if(keyboardState->lPressed)
|
2015-03-04 14:04:46 +00:00
|
|
|
camera.setIsPhysicsCamera(false);
|
|
|
|
|
|
|
|
cameraCenter->setPosition(physics.getPos(0));
|
|
|
|
cameraCenter->setRotation(physics.getRotation(0));
|
|
|
|
|
|
|
|
for(unsigned i = 0; i < physicsObjects.size();i++)
|
|
|
|
{
|
|
|
|
physicsObjects[i]->setPosition(physics.getPos(i));
|
|
|
|
physicsObjects[i]->setRotation(physics.getRotation(i));
|
|
|
|
}
|
|
|
|
|
2015-03-04 20:28:46 +00:00
|
|
|
skydome.setPosition(glm::vec3(cameraCenter->getPosition().x,
|
2015-03-04 14:04:46 +00:00
|
|
|
0.0f, cameraCenter->getPosition().z));
|
2015-03-02 13:28:19 +00:00
|
|
|
|
2015-03-04 14:04:46 +00:00
|
|
|
if (runTime > 2.0f) {
|
|
|
|
for(unsigned int i = 0; i<triggers.size(); i++) {
|
|
|
|
triggers.at(i).triggerUpdate();
|
|
|
|
}
|
2015-03-02 13:28:19 +00:00
|
|
|
}
|
2014-11-12 23:40:28 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 22:59:03 +00:00
|
|
|
glm::vec3 Level::getAmbientLight() {
|
|
|
|
return ambientLight;
|
|
|
|
}
|
|
|
|
|
2015-05-31 19:17:46 +00:00
|
|
|
std::vector<shared_ptr<Light>>* Level::getLights() {
|
2014-12-15 00:12:51 +00:00
|
|
|
return &lights;
|
2014-10-30 22:59:03 +00:00
|
|
|
}
|
2014-11-13 00:22:33 +00:00
|
|
|
|
2014-11-15 13:54:44 +00:00
|
|
|
Camera* Level::getCamera() {
|
|
|
|
return &camera;
|
2014-11-13 00:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object* Level::getCameraCenter() {
|
|
|
|
return cameraCenter;
|
|
|
|
}
|
2014-11-17 16:51:15 +00:00
|
|
|
|
|
|
|
Light* Level::getDirectionalLight() {
|
|
|
|
return &directionalLight;
|
|
|
|
}
|
2014-11-19 00:57:38 +00:00
|
|
|
|
2015-03-08 23:39:59 +00:00
|
|
|
glm::vec4 Level::getFogColourDay() {
|
|
|
|
return fogColourDay;
|
|
|
|
}
|
|
|
|
|
|
|
|
glm::vec4 Level::getFogColourRise() {
|
|
|
|
return fogColourRise;
|
|
|
|
}
|
|
|
|
|
|
|
|
glm::vec4 Level::getFogColourNight() {
|
|
|
|
return fogColourNight;
|
2014-11-19 00:58:48 +00:00
|
|
|
}
|
|
|
|
|
2014-11-19 00:57:38 +00:00
|
|
|
glm::vec3 Level::getCameraPosition() {
|
|
|
|
return cameraCenter->getPosition() + camera.getVector();
|
|
|
|
}
|
2014-11-21 01:38:03 +00:00
|
|
|
|
2014-11-21 23:39:58 +00:00
|
|
|
void Level::setSkydomeSize(float size) {
|
|
|
|
skydomeSize = size;
|
2014-11-21 01:38:03 +00:00
|
|
|
}
|
2014-12-15 17:43:10 +00:00
|
|
|
|
2015-02-04 16:16:06 +00:00
|
|
|
float Level::getSkydomeSize() {
|
|
|
|
return this->skydomeSize;
|
|
|
|
}
|
2014-12-15 17:43:10 +00:00
|
|
|
|
2015-03-16 15:58:50 +00:00
|
|
|
std::vector<Object*>* Level::getAllObjects() {
|
|
|
|
return &allObjects;
|
2014-12-16 11:19:48 +00:00
|
|
|
}
|
2015-01-13 12:52:22 +00:00
|
|
|
|
2015-02-04 16:16:06 +00:00
|
|
|
std::vector<Object*>* Level::getPhysicsObjects() {
|
|
|
|
return &physicsObjects;
|
|
|
|
}
|
|
|
|
|
2015-02-02 11:43:32 +00:00
|
|
|
void Level::moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos){
|
|
|
|
glm::vec3 position = glm::vec3(xPos, yPos, zPos);
|
|
|
|
physics.removePositionConstraint(objectIndex);
|
|
|
|
physics.addPositionConstraint(objectIndex, strength, position);
|
2015-02-13 12:46:41 +00:00
|
|
|
}
|
2015-02-02 11:43:32 +00:00
|
|
|
|
2015-02-13 16:14:29 +00:00
|
|
|
void Level::resetPlayer(){
|
|
|
|
Loader loader = Loader();
|
|
|
|
glm::vec3 newPosition = loader.reloadPlayerPosition(xmlFilePath, this);
|
2015-03-04 17:10:49 +00:00
|
|
|
physics.forcePlayer(newPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::movePlayer(float xPosition, float yPosition, float zPosition){
|
|
|
|
glm::vec3 newPosition = glm::vec3(xPosition, yPosition, zPosition);
|
|
|
|
physics.forcePlayer(newPosition);
|
2015-03-04 14:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setPlayerIndex(int index){
|
|
|
|
playerIndex = index;
|
2015-02-13 16:14:29 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 16:16:06 +00:00
|
|
|
void Level::setStrength(float strength) {
|
|
|
|
this->strength = strength;
|
2015-01-13 12:52:22 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 20:28:46 +00:00
|
|
|
void Level::setSkydomeObject(Skydome object){
|
2015-02-04 16:16:06 +00:00
|
|
|
this->skydome = object;
|
|
|
|
}
|
|
|
|
|
2015-03-18 07:54:38 +00:00
|
|
|
void Level::addObject(Object* object, bool crossesChunks) {
|
2015-03-16 15:58:50 +00:00
|
|
|
allObjects.push_back(object);
|
2015-03-18 07:54:38 +00:00
|
|
|
if (crossesChunks) {
|
|
|
|
crossChunkObjects.push_back(object);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int xPosition = ((int)object->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize;
|
|
|
|
int zPosition = ((int)object->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize;
|
|
|
|
chunks.at(xPosition).at(zPosition).addObject(object);
|
|
|
|
}
|
2015-03-17 13:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Level::addToSpecificChunk(Object* object, int xPosition, int zPosition) {
|
|
|
|
chunks.at(xPosition).at(zPosition).addObject(object);
|
2015-02-04 16:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Level::addPhysicsObject(Object* object) {
|
|
|
|
physicsObjects.push_back(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setAmbientLight(glm::vec3 colour) {
|
|
|
|
this->ambientLight = colour;
|
|
|
|
}
|
|
|
|
|
2015-03-08 23:39:59 +00:00
|
|
|
void Level::setFogColourDay(glm::vec4 colour) {
|
|
|
|
this->fogColourDay = colour;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setFogColourRise(glm::vec4 colour) {
|
|
|
|
this->fogColourRise = colour;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setFogColourNight(glm::vec4 colour) {
|
|
|
|
this->fogColourNight = colour;
|
2015-02-04 16:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setDirectionalLight(Light light) {
|
|
|
|
this->directionalLight = light;
|
|
|
|
}
|
|
|
|
|
2015-03-06 12:22:04 +00:00
|
|
|
void Level::setSunDirection(float x, float y, float z){
|
|
|
|
glm::vec3 lightPosition = glm::vec3(x,y,z);
|
|
|
|
glm::vec3 lightColour = this->directionalLight.getColour();
|
|
|
|
float lightIntensity = this->directionalLight.getIntensity();
|
|
|
|
this->directionalLight = Light(lightPosition, lightColour, lightIntensity);
|
|
|
|
}
|
|
|
|
|
2015-02-04 16:16:06 +00:00
|
|
|
Physics* Level::getPhysics() {
|
|
|
|
return &physics;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Level::getPhysicsObjectsVectorSize() {
|
|
|
|
return physicsObjects.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setCameraCenter(Object* object) {
|
|
|
|
this->cameraCenter = object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::addLight(Light light) {
|
2015-05-31 19:17:46 +00:00
|
|
|
shared_ptr<Light> add_light = shared_ptr<Light>(new Light(light));
|
2015-03-24 18:50:26 +00:00
|
|
|
this->lights.push_back(add_light);
|
2015-02-04 16:16:06 +00:00
|
|
|
}
|
2015-01-13 12:52:22 +00:00
|
|
|
|
2015-03-07 12:41:35 +00:00
|
|
|
void Level::preloadLightPosition(float xPos, float yPos, float zPos){
|
|
|
|
nextLightPosition = glm::vec3(xPos, yPos, zPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::addLightByParameters(float redColour, float greenColour, float blueColour, float intensity, float flameYOffset, float flameHeight, float flameWidth){
|
|
|
|
glm::vec3 colour = glm::vec3(redColour, greenColour, blueColour);
|
2015-05-31 19:17:46 +00:00
|
|
|
this->addLight(Light(nextLightPosition, colour, intensity, flameYOffset, flameHeight, flameWidth));
|
2015-03-07 12:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Level::deleteFourLights(){
|
|
|
|
int indice = lights.size()-4;
|
|
|
|
lights.erase(lights.begin() + indice);
|
|
|
|
lights.erase(lights.begin() + indice);
|
|
|
|
lights.erase(lights.begin() + indice);
|
|
|
|
lights.erase(lights.begin() + indice);
|
|
|
|
}
|
|
|
|
|
2015-02-04 16:16:06 +00:00
|
|
|
void Level::addTrigger(Trigger trigger) {
|
|
|
|
this->triggers.push_back(trigger);
|
|
|
|
}
|
2015-01-13 12:52:22 +00:00
|
|
|
|
2015-02-04 16:16:06 +00:00
|
|
|
lua_State* Level::getLuaState() {
|
|
|
|
return luaState;
|
|
|
|
}
|
2015-01-13 12:52:22 +00:00
|
|
|
|
2015-02-04 16:16:06 +00:00
|
|
|
Terrain* Level::getTerrain() {
|
|
|
|
return &terrain;
|
|
|
|
}
|
2015-03-04 15:08:03 +00:00
|
|
|
|
2015-03-04 20:28:46 +00:00
|
|
|
Skydome* Level::getSkydome() {
|
|
|
|
return &skydome;
|
2015-03-04 15:08:03 +00:00
|
|
|
}
|
2015-03-06 16:44:34 +00:00
|
|
|
|
|
|
|
void Level::forceMove(float x, float y, float z, unsigned indice){
|
|
|
|
glm::vec3 position = glm::vec3(x,y,z);
|
|
|
|
physics.forceMove(position, indice);
|
|
|
|
}
|
2015-03-06 16:49:21 +00:00
|
|
|
|
2015-03-06 15:19:57 +00:00
|
|
|
void Level::activateEndgame(){
|
|
|
|
physics.activateEndgame();
|
|
|
|
}
|
2015-03-09 13:28:09 +00:00
|
|
|
|
|
|
|
void Level::setWaterPlane(Object* water) {
|
|
|
|
this->waterPlane = water;
|
|
|
|
}
|
2015-03-14 12:00:47 +00:00
|
|
|
|
|
|
|
void Level::setTerrain(Terrain terrain) {
|
|
|
|
this->terrain = terrain;
|
|
|
|
}
|
2015-03-15 17:06:24 +00:00
|
|
|
|
|
|
|
void Level::printPosition() {
|
|
|
|
printf("Player position: %2.2f, %2.2f, %2.2f\n", cameraCenter->getPosition().x,
|
|
|
|
cameraCenter->getPosition().y, cameraCenter->getPosition().z);
|
|
|
|
}
|
2015-03-16 15:58:50 +00:00
|
|
|
|
|
|
|
void Level::generateChunks(int chunkSize) {
|
2015-03-17 11:08:49 +00:00
|
|
|
this->chunkSize = chunkSize;
|
2015-03-17 08:39:42 +00:00
|
|
|
int numberChunksX = 0;
|
2015-03-17 11:08:49 +00:00
|
|
|
if (terrain.getHeightmapWidth() % chunkSize == 0) {
|
|
|
|
numberChunksX = terrain.getHeightmapWidth()/chunkSize;
|
2015-03-17 08:39:42 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-03-17 11:08:49 +00:00
|
|
|
numberChunksX = (terrain.getHeightmapWidth()/chunkSize) + 1;
|
2015-03-17 08:39:42 +00:00
|
|
|
}
|
|
|
|
int numberChunksZ = 0;
|
|
|
|
if (terrain.getHeightmapHeight() % chunkSize == 0) {
|
|
|
|
numberChunksZ = terrain.getHeightmapHeight()/chunkSize;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
numberChunksZ = (terrain.getHeightmapHeight()/chunkSize) + 1;
|
|
|
|
}
|
|
|
|
chunks = std::vector<std::vector<Chunk>> (numberChunksX);
|
|
|
|
for(int i = 0; i<numberChunksX; i++) {
|
|
|
|
std::vector<Chunk> zChunks = std::vector<Chunk>(numberChunksZ);
|
|
|
|
for(int j = 0; j<numberChunksZ; j++) {
|
|
|
|
zChunks.at(j) = Chunk();
|
|
|
|
}
|
|
|
|
chunks.at(i) = zChunks;
|
|
|
|
}
|
2015-03-16 15:58:50 +00:00
|
|
|
}
|
2015-03-17 11:08:49 +00:00
|
|
|
|
|
|
|
std::vector<std::vector<Chunk>>* Level::getChunks() {
|
|
|
|
return &chunks;
|
|
|
|
}
|
2015-03-21 18:02:24 +00:00
|
|
|
|
|
|
|
Object* Level::getWaterPlane() {
|
|
|
|
return waterPlane;
|
|
|
|
}
|
2015-03-24 18:50:26 +00:00
|
|
|
|
2015-05-31 19:17:46 +00:00
|
|
|
bool Level::compareLightDistances(shared_ptr<Light> a, shared_ptr<Light> b) {
|
2015-03-24 18:50:26 +00:00
|
|
|
if (glm::distance(cameraCenter->getPosition(), a->getPosition()) <
|
|
|
|
glm::distance(cameraCenter->getPosition(), b->getPosition())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 19:37:58 +00:00
|
|
|
std::vector<shared_ptr<Light>>* Level::getClosestLights(unsigned int maximumAmount) {
|
2015-05-31 19:17:46 +00:00
|
|
|
closestLights = std::vector<shared_ptr<Light>>(lights);
|
2015-03-24 18:50:26 +00:00
|
|
|
std::sort(closestLights.begin(),
|
|
|
|
closestLights.end(),
|
2015-05-31 19:17:46 +00:00
|
|
|
[this](shared_ptr<Light> a, shared_ptr<Light> b) {return compareLightDistances(a, b); });
|
2015-06-02 19:37:58 +00:00
|
|
|
if (lights.size() > maximumAmount) {
|
2015-05-31 19:17:46 +00:00
|
|
|
closestLights = std::vector<shared_ptr<Light>>(&closestLights[0],
|
2015-06-02 19:37:58 +00:00
|
|
|
&closestLights[maximumAmount]);
|
2015-03-24 18:50:26 +00:00
|
|
|
}
|
2015-06-01 22:18:22 +00:00
|
|
|
// sort pointers for faster comparisons
|
|
|
|
std::sort(closestLights.begin(), closestLights.end());
|
2015-03-24 18:50:26 +00:00
|
|
|
return &closestLights;
|
|
|
|
}
|