Fixed resizing of models.
This commit is contained in:
parent
73346ebab9
commit
8a699ae422
4 changed files with 12 additions and 12 deletions
|
|
@ -22,9 +22,6 @@ Chunk::Chunk(FastNoise::SmartNode<> &noiseGenerator, TerrainInfo ti) {
|
||||||
for (int z = 0; z < ti.zRange[1] - ti.zRange[0]; z++) {
|
for (int z = 0; z < ti.zRange[1] - ti.zRange[0]; z++) {
|
||||||
for (int y = 0; y < ti.yRange[1] - ti.yRange[0]; y++) {
|
for (int y = 0; y < ti.yRange[1] - ti.yRange[0]; y++) {
|
||||||
for (int x = 0; x < ti.xRange[1] - ti.xRange[0]; x++) {
|
for (int x = 0; x < ti.xRange[1] - ti.xRange[0]; x++) {
|
||||||
error.log(std::to_string(x) + " " + std::to_string(y) + " " +
|
|
||||||
std::to_string(z) + ": " +
|
|
||||||
std::to_string(noiseOutput[index]));
|
|
||||||
xArray.push_back(noiseOutput[index++]);
|
xArray.push_back(noiseOutput[index++]);
|
||||||
}
|
}
|
||||||
yArray.push_back(xArray);
|
yArray.push_back(xArray);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ void MarchingCubeChunkRenderer::draw(ShaderLoader &shader) {
|
||||||
for (int x = ti.xRange[0]; x < ti.xRange[1]; x++) {
|
for (int x = ti.xRange[0]; x < ti.xRange[1]; x++) {
|
||||||
for (int y = ti.yRange[0]; y < ti.yRange[1]; y++) {
|
for (int y = ti.yRange[0]; y < ti.yRange[1]; y++) {
|
||||||
for (int z = ti.zRange[0]; z < ti.zRange[1]; z++) {
|
for (int z = ti.zRange[0]; z < ti.zRange[1]; z++) {
|
||||||
if (chunk->getNoise(x, y, z) > 0.5) {
|
if (chunk->getNoise(x, y, z) > 0.2f) {
|
||||||
models.at(0)->setPosition(glm::vec3(x, y, z));
|
models.at(0)->setPosition(glm::vec3(x, y, z));
|
||||||
models.at(0)->draw(shader);
|
models.at(0)->draw(shader);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,22 @@ void Model::translate(glm::vec3 translation) {
|
||||||
glm::vec3 position = trans * this->position;
|
glm::vec3 position = trans * this->position;
|
||||||
|
|
||||||
// set model transform
|
// set model transform
|
||||||
this->model = glm::translate(glm::mat4(1.0f), glm::vec3(position));
|
this->model = trans * this->model;
|
||||||
|
|
||||||
// set position based on the current model
|
// set position based on the current model
|
||||||
this->position = model * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
this->position = model * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
void Model::resize(glm::vec3 scale) {
|
void Model::resize(glm::vec3 scale) {
|
||||||
// set worldspace postition
|
// Store objects position.
|
||||||
glm::mat4 transMatrix =
|
glm::vec3 pos = this->position;
|
||||||
glm::translate(glm::mat4(1.0f), glm::vec3(this->position));
|
// Reset models position so scale scales the object not it's transformation
|
||||||
this->scale = scale;
|
this->setPositionToOrigin();
|
||||||
|
// Scale the model
|
||||||
|
this->model = glm::scale(this->model, scale);
|
||||||
|
// Return model to position.
|
||||||
|
this->setPosition(pos);
|
||||||
|
|
||||||
// set model transform
|
this->scale = scale;
|
||||||
this->model = glm::scale(transMatrix, glm::vec3(this->scale));
|
|
||||||
}
|
}
|
||||||
void Model::rotate(float angle, glm::vec3 axis) {
|
void Model::rotate(float angle, glm::vec3 axis) {
|
||||||
this->model = glm::rotate(this->model, angle, axis);
|
this->model = glm::rotate(this->model, angle, axis);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ Terrain::Terrain() : renderer(nullptr) {
|
||||||
|
|
||||||
// Create chunks renderer.
|
// Create chunks renderer.
|
||||||
models = {new Model(ROOT_DIR "data/game-models/12/MetalFloor.obj")};
|
models = {new Model(ROOT_DIR "data/game-models/12/MetalFloor.obj")};
|
||||||
models.at(0)->resize(glm::vec3(0.1f, 0.1f, 0.1f));
|
models.at(0)->resize(glm::vec3(0.5f));
|
||||||
|
|
||||||
renderer = new MarchingCubeChunkRenderer(this->chunks, models);
|
renderer = new MarchingCubeChunkRenderer(this->chunks, models);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue