Fixed resizing of models.

This commit is contained in:
Warwick 2022-08-12 12:37:01 +01:00
parent 73346ebab9
commit 8a699ae422
4 changed files with 12 additions and 12 deletions

View file

@ -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 y = 0; y < ti.yRange[1] - ti.yRange[0]; y++) {
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++]);
}
yArray.push_back(xArray);

View file

@ -15,7 +15,7 @@ void MarchingCubeChunkRenderer::draw(ShaderLoader &shader) {
for (int x = ti.xRange[0]; x < ti.xRange[1]; x++) {
for (int y = ti.yRange[0]; y < ti.yRange[1]; y++) {
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)->draw(shader);
}

View file

@ -18,19 +18,22 @@ void Model::translate(glm::vec3 translation) {
glm::vec3 position = trans * this->position;
// 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
this->position = model * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
}
void Model::resize(glm::vec3 scale) {
// set worldspace postition
glm::mat4 transMatrix =
glm::translate(glm::mat4(1.0f), glm::vec3(this->position));
this->scale = scale;
// Store objects position.
glm::vec3 pos = this->position;
// Reset models position so scale scales the object not it's transformation
this->setPositionToOrigin();
// Scale the model
this->model = glm::scale(this->model, scale);
// Return model to position.
this->setPosition(pos);
// set model transform
this->model = glm::scale(transMatrix, glm::vec3(this->scale));
this->scale = scale;
}
void Model::rotate(float angle, glm::vec3 axis) {
this->model = glm::rotate(this->model, angle, axis);

View file

@ -16,7 +16,7 @@ Terrain::Terrain() : renderer(nullptr) {
// Create chunks renderer.
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);
}