Merging stuff.
This commit is contained in:
commit
e2e31e11e4
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
binaries
|
binaries
|
||||||
build
|
build
|
||||||
Makefile
|
Makefile
|
||||||
|
CMakeLists.txt.user
|
||||||
|
*.cbp
|
||||||
|
22
camera.cc
22
camera.cc
@ -1,12 +1,12 @@
|
|||||||
#include "camera.hh"
|
#include "camera.hh"
|
||||||
|
|
||||||
Camera::Camera(glm::vec3 rotation, float distance) {
|
Camera::Camera(glm::vec2 rotation, float distance) {
|
||||||
this->rotation = rotation;
|
this->rotation = rotation;
|
||||||
this->distance = distance;
|
this->distance = distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera::Camera() {
|
Camera::Camera() {
|
||||||
rotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
rotation = glm::vec2(0.0f, 0.0f);
|
||||||
distance = 1.0f;
|
distance = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,14 +21,24 @@ void Camera::setDistance(float distance) {
|
|||||||
this->distance = distance;
|
this->distance = distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Camera::getRotation() {
|
glm::vec2 Camera::getRotation() {
|
||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::setRotation(glm::vec3 rotation) {
|
void Camera::setRotation(glm::vec2 rotation) {
|
||||||
this->rotation = rotation;
|
this->rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::updateRotation(glm::vec3 rotation) {
|
void Camera::updateRotation(glm::vec2 rotation) {
|
||||||
this->rotation += rotation;;
|
if((this->rotation.x + rotation.x) >= 1.57f) {
|
||||||
|
this->rotation.x = 1.57;
|
||||||
|
this->rotation.y += rotation.y;
|
||||||
|
}
|
||||||
|
else if ((this->rotation.x + rotation.x) <= -1.57f) {
|
||||||
|
this->rotation.x = -1.57f;
|
||||||
|
this->rotation.y += rotation.y;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this-> rotation += rotation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
10
camera.hh
10
camera.hh
@ -5,17 +5,17 @@
|
|||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
public:
|
public:
|
||||||
Camera(glm::vec3 rotation, float distance);
|
Camera(glm::vec2 rotation, float distance);
|
||||||
Camera();
|
Camera();
|
||||||
~Camera();
|
~Camera();
|
||||||
float getDistance();
|
float getDistance();
|
||||||
void setDistance(float distance);
|
void setDistance(float distance);
|
||||||
glm::vec3 getRotation();
|
glm::vec2 getRotation();
|
||||||
void setRotation(glm::vec3 rotation);
|
void setRotation(glm::vec2 rotation);
|
||||||
void updateRotation(glm::vec3 rotation); //adds to current rotation
|
void updateRotation(glm::vec2 rotation); //adds to current rotation
|
||||||
private:
|
private:
|
||||||
float distance;
|
float distance;
|
||||||
glm::vec3 rotation;
|
glm::vec2 rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
13
entity.cc
13
entity.cc
@ -1,6 +1,11 @@
|
|||||||
#include "entity.hh"
|
#include "entity.hh"
|
||||||
|
|
||||||
Entity::Entity(glm::vec3 position, glm::vec3 rotation) {
|
Entity::Entity(glm::vec3 position, glm::vec3 rotation) {
|
||||||
|
this->position = position;
|
||||||
|
setRotation(rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity::Entity(glm::vec3 position, glm::mat4 rotation) {
|
||||||
this->position = position;
|
this->position = position;
|
||||||
this->rotation = rotation;
|
this->rotation = rotation;
|
||||||
}
|
}
|
||||||
@ -15,7 +20,7 @@ glm::vec3 Entity::getPosition() {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Entity::getRotation() {
|
glm::mat4 Entity::getRotation() {
|
||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,5 +29,11 @@ void Entity::setPosition(glm::vec3 position) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Entity::setRotation(glm::vec3 rotation) {
|
void Entity::setRotation(glm::vec3 rotation) {
|
||||||
|
this->rotation = glm::rotate(rotation.x, glm::vec3(1.0f, 0.0f, 0.0f))
|
||||||
|
* glm::rotate(rotation.y, glm::vec3(0.0f, 1.0f, 0.0f))
|
||||||
|
* glm::rotate(rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entity::setRotation(glm::mat4 rotation) {
|
||||||
this->rotation = rotation;
|
this->rotation = rotation;
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,17 @@
|
|||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
Entity(glm::vec3 position, glm::vec3 rotation);
|
Entity(glm::vec3 position, glm::vec3 rotation);
|
||||||
|
Entity(glm::vec3 position, glm::mat4 rotation);
|
||||||
Entity();
|
Entity();
|
||||||
~Entity();
|
~Entity();
|
||||||
void setPosition(glm::vec3 positon);
|
void setPosition(glm::vec3 positon);
|
||||||
void setRotation(glm::vec3 rotation);
|
void setRotation(glm::vec3 rotation);
|
||||||
|
void setRotation(glm::mat4 rotation);
|
||||||
glm::vec3 getPosition();
|
glm::vec3 getPosition();
|
||||||
glm::vec3 getRotation();
|
glm::mat4 getRotation();
|
||||||
private:
|
private:
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 rotation;
|
glm::mat4 rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,6 +17,8 @@ subject to the following restrictions:
|
|||||||
#ifndef BT_OBJECT_ARRAY__
|
#ifndef BT_OBJECT_ARRAY__
|
||||||
#define BT_OBJECT_ARRAY__
|
#define BT_OBJECT_ARRAY__
|
||||||
|
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
|
|
||||||
#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
|
#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
|
||||||
#include "btAlignedAllocator.h"
|
#include "btAlignedAllocator.h"
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@ GLFWwindow* Graphics::getWindow() {
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::uvec2 Graphics::getWindowSize() {
|
||||||
|
return windowSize;
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::setGLFWHintsForOpenGLVersion( unsigned int _version )
|
void Graphics::setGLFWHintsForOpenGLVersion( unsigned int _version )
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -159,8 +163,8 @@ glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, fl
|
|||||||
glm::mat4 Graphics::buildViewMatrix(Level* level) {
|
glm::mat4 Graphics::buildViewMatrix(Level* level) {
|
||||||
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, level->getCamera().getDistance(), 0.0f);
|
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, level->getCamera().getDistance(), 0.0f);
|
||||||
// rotate vector
|
// rotate vector
|
||||||
glm::mat4 rotationMatrix = glm::rotate<float>(level->getCamera().getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f)) *
|
glm::mat4 rotationMatrix =
|
||||||
glm::rotate<float>(level->getCamera().getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate<float>(level->getCamera().getRotation()[2], glm::vec3(0.0f, 0.0f, 1.0f));
|
glm::rotate<float>(level->getCamera().getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) *glm::rotate<float>(level->getCamera().getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
cameraVector = rotationMatrix * cameraVector;
|
cameraVector = rotationMatrix * cameraVector;
|
||||||
//construct lookAt (cameraPosition = cameraCenter + cameraVector
|
//construct lookAt (cameraPosition = cameraCenter + cameraVector
|
||||||
return glm::lookAt(level->getCameraCenter()->getPosition() + glm::vec3(cameraVector), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
return glm::lookAt(level->getCameraCenter()->getPosition() + glm::vec3(cameraVector), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
22
level.cc
22
level.cc
@ -13,7 +13,7 @@ Level::~Level() {
|
|||||||
|
|
||||||
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||||
// currently hard coded should later read this stuff out of a file
|
// currently hard coded should later read this stuff out of a file
|
||||||
this->camera = Camera(glm::vec3(-0.8f, 0.0f, 0.0f), 3.0f);
|
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
|
||||||
// load the geometry of the stanford bunny and build a VAO:
|
// load the geometry of the stanford bunny and build a VAO:
|
||||||
Model model = Model("Bunny.obj", 0.25f);
|
Model model = Model("Bunny.obj", 0.25f);
|
||||||
// load a texture:
|
// load a texture:
|
||||||
@ -34,12 +34,13 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
|
|
||||||
// load terrain
|
// load terrain
|
||||||
this->terrain.load();
|
this->terrain.load();
|
||||||
Model terrainModel = this->terrain.getModel();
|
Model terrainModel = Model(this->terrain.getModel());
|
||||||
// load a texture:
|
// load a texture:
|
||||||
Material terrainMaterial = Material("clownfishBunny.png", 0.7f, 0.7f, 0.3f, 1.0f);
|
Material terrainMaterial = Material("clownfishBunny.png", 1.0f, 0.0f, 0.0f, 3.0f);
|
||||||
//Create object
|
//Create object
|
||||||
Object terrainObject = Object(terrainModel, terrainMaterial,
|
Object terrainObject = Object(terrainModel, terrainMaterial,
|
||||||
glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()),
|
//glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), -0.5f, -0.5f*(float)this->terrain.getHeightmapWidth()),
|
||||||
|
glm::vec3(-1.0f, 0.0f, -1.0f),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
@ -51,12 +52,19 @@ void Level::render() {
|
|||||||
for(unsigned int i = 0; i<objects.size(); i++) {
|
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||||
objects[i].render();
|
objects[i].render();
|
||||||
}
|
}
|
||||||
// this->terrain.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::update(float runTime) {
|
void Level::update(float runTime, glm::vec2 mouseDelta) {
|
||||||
// rotate bunny
|
// rotate bunny
|
||||||
cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f));
|
//cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f));
|
||||||
|
// Ignore first two mouse updates, because they are incorrect
|
||||||
|
static int i = 0;
|
||||||
|
if (i <2) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
camera.updateRotation(mouseDelta/100.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Level::getAmbientLight() {
|
glm::vec3 Level::getAmbientLight() {
|
||||||
|
2
level.hh
2
level.hh
@ -15,7 +15,7 @@ class Level {
|
|||||||
Level();
|
Level();
|
||||||
~Level();
|
~Level();
|
||||||
void load(ACGL::OpenGL::SharedShaderProgram shader); // Shader is necessary for correct texture assigning
|
void load(ACGL::OpenGL::SharedShaderProgram shader); // Shader is necessary for correct texture assigning
|
||||||
void update(float runTime);
|
void update(float runTime, glm::vec2 mouseDelta);
|
||||||
void render();
|
void render();
|
||||||
glm::vec3 getAmbientLight();
|
glm::vec3 getAmbientLight();
|
||||||
std::vector<Light> getLights();
|
std::vector<Light> getLights();
|
||||||
|
39
main.cc
39
main.cc
@ -16,13 +16,6 @@
|
|||||||
#include <ACGL/OpenGL/glloaders/extensions.hh>
|
#include <ACGL/OpenGL/glloaders/extensions.hh>
|
||||||
#include <ACGL/Base/Settings.hh>
|
#include <ACGL/Base/Settings.hh>
|
||||||
|
|
||||||
#include "model.hh"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace ACGL::OpenGL;
|
|
||||||
using namespace ACGL::Base;
|
|
||||||
using namespace ACGL::Utils;
|
|
||||||
|
|
||||||
Application::Application() {
|
Application::Application() {
|
||||||
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 100.0f);
|
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 100.0f);
|
||||||
}
|
}
|
||||||
@ -47,13 +40,17 @@ void Application::init()
|
|||||||
ACGL::Base::Settings::the()->setTexturePath("Geometry/");
|
ACGL::Base::Settings::the()->setTexturePath("Geometry/");
|
||||||
ACGL::Base::Settings::the()->setGeometryPath("Geometry/");
|
ACGL::Base::Settings::the()->setGeometryPath("Geometry/");
|
||||||
|
|
||||||
// load Model to give shader correct Attribute locations
|
// construct VAO to give shader correct Attribute locations
|
||||||
// TODO look up if this is really necessary, since this looks really stupid.
|
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
||||||
Model model = Model("Bunny.obj");
|
ab->defineAttribute("aPosition", GL_FLOAT, 3);
|
||||||
|
ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
|
||||||
|
ab->defineAttribute("aNormal", GL_FLOAT, 3);
|
||||||
|
ACGL::OpenGL::SharedVertexArrayObject vao = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
||||||
|
vao->attachAllAttributes(ab);
|
||||||
|
|
||||||
// look up all shader files starting with 'phong' and build a ShaderProgram from it:
|
// look up all shader files starting with 'phong' and build a ShaderProgram from it:
|
||||||
shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations(
|
shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations(
|
||||||
model.getReference()->getAttributeLocations()).create();
|
vao->getAttributeLocations()).create();
|
||||||
shader->use();
|
shader->use();
|
||||||
|
|
||||||
// load Level
|
// load Level
|
||||||
@ -63,11 +60,6 @@ void Application::init()
|
|||||||
openGLCriticalError();
|
openGLCriticalError();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************************************************************
|
|
||||||
* Returns true if a window with the desired context could get created.
|
|
||||||
* Requested OpenGL version gets set by ACGL defines.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int)
|
static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int)
|
||||||
{
|
{
|
||||||
if (_key == GLFW_KEY_ESCAPE && _action == GLFW_PRESS) {
|
if (_key == GLFW_KEY_ESCAPE && _action == GLFW_PRESS) {
|
||||||
@ -91,10 +83,12 @@ int main( int argc, char *argv[] )
|
|||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Set window title to binary name (without the path):
|
// Set window title to binary name (without the path):
|
||||||
//
|
//
|
||||||
std::vector<std::string> tmp = StringHelpers::split( std::string( argv[0] ), '/' );
|
std::vector<std::string> tmp = ACGL::Utils::StringHelpers::split( std::string( argv[0] ), '/' );
|
||||||
glfwSetWindowTitle(app.getGraphics()->getWindow(), tmp[tmp.size()-1].c_str() );
|
glfwSetWindowTitle(app.getGraphics()->getWindow(), tmp[tmp.size()-1].c_str() );
|
||||||
// Ensure we can capture the escape key being pressed below
|
// Ensure we can capture the escape key being pressed below
|
||||||
glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_STICKY_KEYS, 1);
|
glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_STICKY_KEYS, 1);
|
||||||
|
// Hide mouse cursor
|
||||||
|
glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
//glfwSetWindowSizeCallback(app.getGraphics(), resizeCallback);
|
//glfwSetWindowSizeCallback(app.getGraphics(), resizeCallback);
|
||||||
glfwSetKeyCallback(app.getGraphics()->getWindow(), keyCallback );
|
glfwSetKeyCallback(app.getGraphics()->getWindow(), keyCallback );
|
||||||
|
|
||||||
@ -118,15 +112,20 @@ int main( int argc, char *argv[] )
|
|||||||
double now = glfwGetTime();
|
double now = glfwGetTime();
|
||||||
|
|
||||||
if (showNextFPS <= now) {
|
if (showNextFPS <= now) {
|
||||||
stringstream sstream (stringstream::in | stringstream::out);
|
std::stringstream sstream (std::stringstream::in | std::stringstream::out);
|
||||||
sstream << setprecision(1) << std::fixed
|
sstream << std::setprecision(1) << std::fixed
|
||||||
<< tmp[tmp.size()-1] << " - FPS: " << frameCount / (now-showNextFPS + FPSdelay) << " " << 1000 * (now-showNextFPS + FPSdelay)/frameCount << " msec";
|
<< tmp[tmp.size()-1] << " - FPS: " << frameCount / (now-showNextFPS + FPSdelay) << " " << 1000 * (now-showNextFPS + FPSdelay)/frameCount << " msec";
|
||||||
glfwSetWindowTitle(app.getGraphics()->getWindow(), sstream.str().c_str() );
|
glfwSetWindowTitle(app.getGraphics()->getWindow(), sstream.str().c_str() );
|
||||||
showNextFPS = now + FPSdelay;
|
showNextFPS = now + FPSdelay;
|
||||||
frameCount = 0;
|
frameCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
app.getLevel()->update(now - startTimeInSeconds);
|
double xpos, ypos;
|
||||||
|
glfwGetCursorPos(app.getGraphics()->getWindow(), &xpos, &ypos);
|
||||||
|
glfwSetCursorPos(app.getGraphics()->getWindow(), app.getGraphics()->getWindowSize().x/2, app.getGraphics()->getWindowSize().y/2);
|
||||||
|
|
||||||
|
app.getLevel()->update(now - startTimeInSeconds, glm::vec2((float)ypos-app.getGraphics()->getWindowSize().y/2,
|
||||||
|
(float)xpos-app.getGraphics()->getWindowSize().x/2));
|
||||||
app.getGraphics()->render(app.getLevel(), app.getShader());
|
app.getGraphics()->render(app.getLevel(), app.getShader());
|
||||||
|
|
||||||
openGLCriticalError();
|
openGLCriticalError();
|
||||||
|
@ -24,9 +24,7 @@ void Object::render() {
|
|||||||
shader->setUniform("shininess", material.getShininess());
|
shader->setUniform("shininess", material.getShininess());
|
||||||
shader->setTexture("uTexture", material.getReference(), 0);
|
shader->setTexture("uTexture", material.getReference(), 0);
|
||||||
// set model matrix
|
// set model matrix
|
||||||
glm::mat4 rotationMatrix = glm::rotate<float>(this->getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f)) *
|
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
|
||||||
glm::rotate<float>(this->getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate<float>(this->getRotation()[2], glm::vec3(0.0f, 0.0f, 1.0f));
|
|
||||||
glm::mat4 modelMatrix = glm::translate(this->getPosition()) * rotationMatrix * glm::scale<float>(glm::vec3(model.getScale()));
|
|
||||||
shader->setUniform( "modelMatrix", modelMatrix);
|
shader->setUniform( "modelMatrix", modelMatrix);
|
||||||
// draw
|
// draw
|
||||||
model.getReference()->render();
|
model.getReference()->render();
|
||||||
|
90
terrain.cc
90
terrain.cc
@ -42,11 +42,12 @@ void Terrain::load() {
|
|||||||
void Terrain::makeTriangleMesh(){
|
void Terrain::makeTriangleMesh(){
|
||||||
|
|
||||||
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
||||||
ab->defineAttributeWithOffset("aPosition", GL_FLOAT, 3, 0);
|
// Do NOT change the order of this!
|
||||||
ab->defineAttributeWithOffset("aNormal", GL_FLOAT, 3, 3);
|
ab->defineAttribute("aPosition", GL_FLOAT, 3);
|
||||||
ab->defineAttributeWithOffset("aTexCoord", GL_FLOAT, 2, 6);
|
ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
|
||||||
|
ab->defineAttribute("aNormal", GL_FLOAT, 3);
|
||||||
|
|
||||||
unsigned int rowNum=0, columnNum=0, dataCount=0, floatsPerVertex=8; //initializing:
|
/* unsigned int rowNum=0, columnNum=0, dataCount=0, abNumFloats=8; //initializing:
|
||||||
bool movingRight = true, isUp = true;
|
bool movingRight = true, isUp = true;
|
||||||
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
|
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
|
||||||
float* abData = new float[numVertices * floatsPerVertex];
|
float* abData = new float[numVertices * floatsPerVertex];
|
||||||
@ -57,28 +58,32 @@ void Terrain::makeTriangleMesh(){
|
|||||||
if (isUp){
|
if (isUp){
|
||||||
rowNum = rowNum + 1;
|
rowNum = rowNum + 1;
|
||||||
isUp = false;
|
isUp = false;
|
||||||
}else if (movingRight){
|
}
|
||||||
|
else if (movingRight) {
|
||||||
if (columnNum == this->heightmapWidth - 1) {
|
if (columnNum == this->heightmapWidth - 1) {
|
||||||
set_abData(abData, dataCount, rowNum, columnNum);
|
set_abData(abData, dataCount, rowNum, columnNum);
|
||||||
dataCount += floatsPerVertex;
|
dataCount += abNumFloats;
|
||||||
set_abData(abData, dataCount, rowNum, columnNum);
|
set_abData(abData, dataCount, rowNum, columnNum);
|
||||||
dataCount += floatsPerVertex;
|
dataCount += abNumFloats;
|
||||||
movingRight = false;
|
movingRight = false;
|
||||||
rowNum = rowNum + 1;
|
rowNum = rowNum + 1;
|
||||||
} else{
|
}
|
||||||
|
else {
|
||||||
rowNum = rowNum - 1;
|
rowNum = rowNum - 1;
|
||||||
columnNum = columnNum + 1;
|
columnNum = columnNum + 1;
|
||||||
isUp = true;
|
isUp = true;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
if (columnNum == 0){
|
if (columnNum == 0){
|
||||||
set_abData(abData, dataCount, rowNum, columnNum);
|
set_abData(abData, dataCount, rowNum, columnNum);
|
||||||
dataCount += floatsPerVertex;
|
dataCount += abNumFloats;
|
||||||
set_abData(abData, dataCount, rowNum, columnNum);
|
set_abData(abData, dataCount, rowNum, columnNum);
|
||||||
dataCount += floatsPerVertex;
|
dataCount += abNumFloats;
|
||||||
movingRight = true;
|
movingRight = true;
|
||||||
rowNum = rowNum + 1;
|
rowNum = rowNum + 1;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
rowNum = rowNum - 1;
|
rowNum = rowNum - 1;
|
||||||
columnNum = columnNum - 1;
|
columnNum = columnNum - 1;
|
||||||
isUp = true;
|
isUp = true;
|
||||||
@ -86,24 +91,23 @@ void Terrain::makeTriangleMesh(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ab->setDataElements(numVertices, abData);
|
ab->setDataElements(numVertices, abData);*/
|
||||||
float* testData = new float[32];
|
float abData[32] = {0.0f, 0.0f, 0.0f,
|
||||||
testData[0]=0.0f;testData[1]=0.0f;testData[2]=0.0f;
|
1.0f, 0.0f,
|
||||||
testData[3]=0.0f;testData[4]=1.0f;testData[5]=0.0f;
|
0.0f, 1.0f, 0.0f,
|
||||||
testData[6]=0.0f;testData[7]=0.0f;
|
|
||||||
|
|
||||||
testData[8]=1.0f;testData[9]=0.2f;testData[10]=0.0f;
|
1.0f, 0.0f, 0.0f,
|
||||||
testData[11]=0.0f;testData[12]=1.0f;testData[13]=0.0f;
|
1.0f, 1.0f,
|
||||||
testData[14]=1024.0f;testData[15]=.0f;
|
0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
testData[16]=0.0f;testData[17]=0.2f;testData[18]=1.0f;
|
0.0f, 0.0f, 1.0f,
|
||||||
testData[19]=0.0f;testData[20]=1.0f;testData[21]=0.0f;
|
0.0f, 0.0f,
|
||||||
testData[22]=0.0f;testData[23]=1024.0f;
|
0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
testData[24]=1.0f;testData[25]=0.0f;testData[26]=1.0f;
|
1.0f, 0.0f, 1.0f,
|
||||||
testData[27]=0.0f;testData[28]=1.0f;testData[29]=0.0f;
|
0.0f, 1.0f,
|
||||||
testData[30]=1024.0f;testData[31]=1024.0f;
|
0.0f, 1.0f, 0.0f};
|
||||||
ab->setDataElements(numVertices, testData);
|
ab->setDataElements(4, abData);
|
||||||
this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
||||||
this->triangleMesh->bind();
|
this->triangleMesh->bind();
|
||||||
this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
|
this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
|
||||||
@ -118,12 +122,17 @@ void Terrain::set_abData(float* abData, unsigned int dataCount, unsigned int row
|
|||||||
abData[dataCount+1] = heightmap[rowNum][columnNum];
|
abData[dataCount+1] = heightmap[rowNum][columnNum];
|
||||||
abData[dataCount+2] = (float)columnNum;
|
abData[dataCount+2] = (float)columnNum;
|
||||||
|
|
||||||
|
//set Texture Coordinate
|
||||||
|
abData[dataCount+3] = (float)(rowNum % 2);
|
||||||
|
abData[dataCount+4] = (float)(columnNum % 2);
|
||||||
|
|
||||||
//setNormal
|
//setNormal
|
||||||
if (rowNum==0 || rowNum==(this->heightmapHeight-1) || columnNum==0 || columnNum==(this->heightmapWidth-1)){
|
if (rowNum==0 || rowNum==(this->heightmapHeight-1) || columnNum==0 || columnNum==(this->heightmapWidth-1)){
|
||||||
abData[dataCount+3] = 0.0;
|
|
||||||
abData[dataCount+4] = 1.0;
|
|
||||||
abData[dataCount+5] = 0.0;
|
abData[dataCount+5] = 0.0;
|
||||||
}else{
|
abData[dataCount+6] = 1.0;
|
||||||
|
abData[dataCount+7] = 0.0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
glm::vec3 sumNormals;
|
glm::vec3 sumNormals;
|
||||||
for (int i=-1; i<2; i+=1) {
|
for (int i=-1; i<2; i+=1) {
|
||||||
for (int j=-1; j<2; j+=1) {
|
for (int j=-1; j<2; j+=1) {
|
||||||
@ -137,14 +146,10 @@ void Terrain::set_abData(float* abData, unsigned int dataCount, unsigned int row
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sumNormals = sumNormals*0.111f;
|
sumNormals = sumNormals*0.111f;
|
||||||
abData[dataCount+3] = sumNormals[0];
|
abData[dataCount+5] = sumNormals[0];
|
||||||
abData[dataCount+4] = sumNormals[1];
|
abData[dataCount+6] = sumNormals[1];
|
||||||
abData[dataCount+5] = sumNormals[2];
|
abData[dataCount+7] = sumNormals[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
//set Texture Coordinate
|
|
||||||
abData[dataCount+6] = (float)(rowNum % 2);
|
|
||||||
abData[dataCount+7] = (float)(columnNum % 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Model Terrain::getModel(){
|
Model Terrain::getModel(){
|
||||||
@ -164,14 +169,3 @@ unsigned int Terrain::getHeightmapWidth(){
|
|||||||
//return this->heightmapWidth;
|
//return this->heightmapWidth;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user