...
 
Commits (3)
......@@ -125,6 +125,8 @@ ELSEIF(APPLE)
${ASSIMP_ADDITIONAL_SEARCH_DIRS})
SET(ASSIMP_LIBRARY z ${ASSIMP_LIBRARY})
SET(ASSIMP_LIBRARIES ${ASSIMP_LIBRARY})
ELSE()
FIND_PATH(ASSIMP_INCLUDE_DIR assimp/defs.h
......@@ -136,6 +138,7 @@ ELSE()
${ASSIMP_ADDITIONAL_SEARCH_DIRS}
PATH_SUFFIXES dynamic)
SET(ASSIMP_LIBRARIES ${ASSIMP_LIBRARY})
ENDIF ()
......
cmake_minimum_required(VERSION 2.8)
include(${CMAKE_MODULE_PATH}/DefaultExecutable.cmake)
\ No newline at end of file
% This file contains the internal library dependencies in src/libraries
% Lines starting with % are comments and will be ignored
% To add a dependency, simply add a new line containing the name of the library
% Example: HelloLib
CVK_2
CVK_AnSim
\ No newline at end of file
#include <CVK_2/CVK_Framework.h>
#include <CVK_AnSim/CVK_AS_CoordinateSystem.h>
#include <CVK_AnSim/CVK_AS_HermiteSpline.h>
#include <CVK_AnSim/CVK_AS_Line.h>
#include <CVK_AnSim/CVK_AS_LineStrip.h>
#include <CVK_AnSim/CVK_AS_ShaderLineRender.h>
const int width = 640;
const int height = 480;
GLFWwindow* window;
// define Camera (Trackball)
CVK::Perspective projection(glm::radians(60.0f), width / float(height), 0.1f,
50.f);
CVK::Trackball* cam_trackball;
CVK::HermiteSpline* spline;
CVK::LineStrip* line;
//*************************************************************************************************************
float timeRunning = 0.0f;
float position = 0.0f;
float speed = 5.0f;
glm::vec3 renderPosition = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 tangent = glm::vec3(1.0f, 0.0f, 0.0f);
glm::vec3 normal = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 binormal = glm::vec3(0.0f, 0.0f, 1.0f);
//*************************************************************************************************************
void updateTeapot(float d_t) {
//*************************************************************************************************************
// TODO Aufgabe 5 (b)
// Berechnen Sie aus der verstrichenen Zeit und der Geschwindigkeit die
// Position des Teapots auf dem Spline und speichern Sie diese in der
// globalen Variable teapotPosition
//*************************************************************************************************************
timeRunning += d_t;
position = timeRunning * speed;
//*************************************************************************************************************
// TODO Aufgabe 5 (c)
// Berechnen Sie die Orientierung des Teapots mittels der Frenet Frame
// Methode.
//*************************************************************************************************************
}
void resizeCallback(GLFWwindow* window, int w, int h) {
cam_trackball->setWidthHeight(w, h);
cam_trackball->getProjection()->updateRatio(w / (float)h);
glViewport(0, 0, w, h);
}
void init_camera() {
// Camera
cam_trackball = new CVK::Trackball(window, width, height, &projection);
glm::vec3 center(0.0f, 0.0f, 0.0f);
cam_trackball->setCenter(&center);
cam_trackball->setRadius(5.0f);
CVK::State::getInstance()->setCamera(cam_trackball);
}
void initSpline() {
// Create a sample spline
spline = new CVK::HermiteSpline();
spline->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(-2.0, 0.0, 2.0), glm::vec3(6.0, 0.0, 0.0)));
spline->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(-2.0, 0.0, -2.0), glm::vec3(-6.0, 0.0, 0.0)));
spline->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(2.0, 2.0, 2.0), glm::vec3(6.0, 0.0, 0.0)));
spline->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(2.0, 2.0, -2.0), glm::vec3(-6.0, 0.0, 0.0)));
spline->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(2.0, 2.0, -2.0), glm::vec3(0.0, 0.0, 0.0)));
spline->generateRenderVertices();
// Create a line strip (in order to render the spline)
line = new CVK::LineStrip();
line->setColor(glm::vec4(1, 0, 0, 1));
for (int i = 0; i < spline->getVerticesPtr()->size(); i++) {
line->addPoint(spline->getVerticesPtr()->at(i));
}
//*************************************************************************************************************
renderPosition = (spline->getControlPointsPtr()->at(0))->getPosition();
spline->generateArcLengthTable(100);
//*************************************************************************************************************
}
int main() {
// Init GLFW and GLAD
glfwInit();
CVK::useOpenGL33CoreProfile();
window =
glfwCreateWindow(width, height, "AnSim Exercise 2", nullptr, nullptr);
glfwSetWindowPos(window, 100, 50);
glfwMakeContextCurrent(window);
glfwSetWindowSizeCallback(window, resizeCallback);
if (!gladLoadGL()) {
printf("Something went wrong!\n");
exit(-1);
}
CVK::State::getInstance()->setBackgroundColor(WHITE);
glm::vec3 BgCol = CVK::State::getInstance()->getBackgroundColor();
glClearColor(BgCol.r, BgCol.g, BgCol.b, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// load, compile and link Shader
CVK::ShaderPhong phongShader(
VERTEX_SHADER_BIT | FRAGMENT_SHADER_BIT,
{CVK::State::getInstance()->getShaderPath() + "/CVK_AnSim/Phong.vert",
CVK::State::getInstance()->getShaderPath() + "/CVK_AnSim/Phong.frag"});
CVK::ShaderLineRender lineShader(
VERTEX_SHADER_BIT | FRAGMENT_SHADER_BIT,
{CVK::State::getInstance()->getShaderPath() +
"/CVK_AnSim/ColorMVPShader.vert",
CVK::State::getInstance()->getShaderPath() +
"/CVK_AnSim/ColorMVPShader.frag"});
// Camera
init_camera();
// Light Sources
CVK::Light light = CVK::Light(glm::vec4(0.0, 10.0, 0.0, 1.0), GREY,
glm::vec3(0, 0, 0), 1.0f, 0.0f);
CVK::State::getInstance()->addLight(&light);
CVK::State::getInstance()->updateSceneSettings(DARKGREY, 0, WHITE, 1, 10,
1);
// Teapot
CVK::Node teapot("Teapot");
CVK::Material material = CVK::Material(RED, WHITE, 100.0f);
teapot.setMaterial(&material);
CVK::Teapot geometry = CVK::Teapot();
teapot.setGeometry(&geometry);
// Coordinatesystem
CVK::CoordinateSystem coordinatesys(glm::vec3(0.0f));
// Init spline (controllpoints and arc length table)
initSpline();
glLineWidth(6);
float deltaTime = 0.0f;
float oldTime = glfwGetTime();
while (!glfwWindowShouldClose(window)) {
float currentTime = glfwGetTime();
deltaTime = currentTime - oldTime;
oldTime = currentTime;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Update Camera
cam_trackball->update(deltaTime);
//*************************************************************************************************************
updateTeapot(deltaTime);
//*************************************************************************************************************
// Use phong shader to render the teapot
CVK::State::getInstance()->setShader(&phongShader);
CVK::State::getInstance()->setLight(0, &light);
phongShader.update();
//*************************************************************************************************************
// TODO Aufgabe 5 (d)
// Passen Sie die Modelmatrix und rendern Sie den Teapot an gewuenschter
// Position und Orientierung.
//*************************************************************************************************************
glm::mat4 modelmatrix = glm::mat4(1.0f);
modelmatrix = glm::scale(modelmatrix, glm::vec3(0.5f, 0.5f, 0.5f));
teapot.setModelMatrix(modelmatrix);
teapot.render();
// Draw coordinate system and hermite spline as line strip
CVK::State::getInstance()->setShader(&lineShader);
lineShader.update();
coordinatesys.render(&lineShader);
line->render(&lineShader);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
// Clean up
delete line;
delete spline;
return 0;
}
cmake_minimum_required(VERSION 2.8)
include(${CMAKE_MODULE_PATH}/DefaultExecutable.cmake)
\ No newline at end of file
% This file contains the internal library dependencies in src/libraries
% Lines starting with % are comments and will be ignored
% To add a dependency, simply add a new line containing the name of the library
% Example: HelloLib
CVK_2
CVK_AnSim
\ No newline at end of file
#include <CVK_2/CVK_Framework.h>
#include <CVK_AnSim/CVK_AS_CoordinateSystem.h>
#include <CVK_AnSim/CVK_AS_HermiteSpline.h>
#include <CVK_AnSim/CVK_AS_Line.h>
#include <CVK_AnSim/CVK_AS_LineStrip.h>
#include <CVK_AnSim/CVK_AS_ShaderLineRender.h>
const int width = 640;
const int height = 480;
GLFWwindow* window;
// define Camera (Trackball)
CVK::Perspective projection(glm::radians(60.0f), width / float(height), 0.1f,
50.f);
CVK::Trackball* cam_trackball;
CVK::HermiteSpline* mPath;
//*************************************************************************************************************
CVK::LineStrip* line;
//*************************************************************************************************************
void resizeCallback(GLFWwindow* window, int w, int h) {
cam_trackball->setWidthHeight(w, h);
cam_trackball->getProjection()->updateRatio(w / (float)h);
glViewport(0, 0, w, h);
}
void init_camera() {
// Camera
cam_trackball = new CVK::Trackball(window, width, height, &projection);
glm::vec3 center(0.0f, 0.0f, 0.0f);
cam_trackball->setCenter(&center);
cam_trackball->setRadius(5.0f);
CVK::State::getInstance()->setCamera(cam_trackball);
}
void init_scene() {
mPath = new CVK::HermiteSpline();
mPath->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(-5.0, 0.0, -5.0), glm::vec3(1.5, 5.0, 0.0)));
mPath->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(-3.0, 1.5, -1.0), glm::vec3(0.7, 4.0, 0.0)));
mPath->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(1.0, 2.0, 2.0), glm::vec3(0.3, -4.5, 0.0)));
mPath->addControlPoint(new CVK::HermiteSplineControlPoint(
glm::vec3(5.0, 1.0, 5.0), glm::vec3(-0.3, 3.5, 0.0)));
mPath->generateRenderVertices();
//*************************************************************************************************************
line = new CVK::LineStrip();
line->setColor(glm::vec4(1, 0, 0, 1));
for (unsigned int i = 0; i < mPath->getVerticesPtr()->size(); i++) {
line->addPoint(mPath->getVerticesPtr()->at(i));
}
//*************************************************************************************************************
}
void drawHermiteSpline(CVK::ShaderLineRender* shader) {
//*************************************************************************************************************
line->render(shader);
//*************************************************************************************************************
}
int main() {
// Init GLFW and GLAD
glfwInit();
CVK::useOpenGL33CoreProfile();
window = glfwCreateWindow(width, height, "AnSim Exercise 1", 0, 0);
glfwSetWindowPos(window, 100, 50);
glfwMakeContextCurrent(window);
glfwSetWindowSizeCallback(window, resizeCallback);
if (!gladLoadGL()) {
printf("Something went wrong!\n");
exit(-1);
}
CVK::State::getInstance()->setBackgroundColor(WHITE);
glm::vec3 BgCol = CVK::State::getInstance()->getBackgroundColor();
glClearColor(BgCol.r, BgCol.g, BgCol.b, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// load, compile and link Shader
CVK::ShaderLineRender lineShader(
VERTEX_SHADER_BIT | FRAGMENT_SHADER_BIT,
{CVK::State::getInstance()->getShaderPath() +
"/CVK_AnSim/ColorMVPShader.vert",
CVK::State::getInstance()->getShaderPath() +
"/CVK_AnSim/ColorMVPShader.frag"});
CVK::State::getInstance()->setShader(&lineShader);
init_camera();
init_scene();
glLineWidth(6);
CVK::CoordinateSystem coords = CVK::CoordinateSystem(glm::vec3(0.0f));
double time = glfwGetTime();
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Update Camera
double deltaTime = glfwGetTime() - time;
time = glfwGetTime();
cam_trackball->update(deltaTime);
CVK::State::getInstance()->setShader(&lineShader);
lineShader.update();
coords.render(&lineShader);
drawHermiteSpline(&lineShader);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
......@@ -30,11 +30,21 @@ class HermiteSpline {
}
std::vector<glm::vec3>* getVerticesPtr() { return &mVertices; }
//********************************************************************************
void generateArcLengthTable(int resolution);
void getParameterByArcLength(float length, float& u, int& patchNum);
void calculateFrenetFrame(float u, HermiteSplineControlPoint* c0,
HermiteSplineControlPoint* c1, glm::vec3& tangent,
glm::vec3& binormal, glm::vec3& normal);
//********************************************************************************
private:
std::vector<HermiteSplineControlPoint*> mControlPoints;
std::vector<glm::vec3> mVertices;
//********************************************************************************
std::vector<ArcLengthTableEntry> mArcLengthTable;
//********************************************************************************
void deCasteljau(float t, std::vector<glm::vec3>& cp, glm::vec3& point,
glm::vec3& tangent);
......
......@@ -20,7 +20,12 @@ void HermiteSpline::generateRenderVertices() {
void HermiteSpline::sampleHermiteSpline(HermiteSplineControlPoint* c0,
HermiteSplineControlPoint* c1,
int numVerts) {
// TODO
for (int i = 0; i < numVerts; i++) {
glm::vec3 position, tangent;
evaluateHermiteSpline(static_cast<float>(i) / (numVerts - 1), c0, c1,
position, tangent);
mVertices.push_back(position);
}
}
void HermiteSpline::evaluateHermiteSpline(float t,
......@@ -28,12 +33,62 @@ void HermiteSpline::evaluateHermiteSpline(float t,
HermiteSplineControlPoint* c1,
glm::vec3& point,
glm::vec3& tangent) {
// TODO
std::vector<glm::vec3> bp;
bp.push_back(c0->getPosition());
bp.push_back(c0->getPosition() + ONE_THIRD * c0->getDirection());
bp.push_back(c1->getPosition() - ONE_THIRD * c1->getDirection());
bp.push_back(c1->getPosition());
deCasteljau(t, bp, point, tangent);
}
void HermiteSpline::deCasteljau(float t, std::vector<glm::vec3>& cp,
glm::vec3& point, glm::vec3& tangent) {
// TODO
if (cp.size() == 2) {
point = (1 - t) * cp.at(0) + t * cp.at(1);
tangent = cp.at(1) - cp.at(0);
tangent = glm::normalize(tangent);
} else {
std::vector<glm::vec3> ncp;
auto it = cp.begin();
while (it != cp.end() - 1) {
ncp.push_back((1 - t) * (*it) + t * (*(it + 1)));
it++;
}
deCasteljau(t, ncp, point, tangent);
}
}
void HermiteSpline::generateArcLengthTable(int resolution) {
//********************************************************************************
// TODO Aufgabe 5 (a)
// Hier muss die Erstellung der Bogenlaengentabelle programmiert werden.
//********************************************************************************
}
void HermiteSpline::getParameterByArcLength(float length, float& u,
int& patchNum) {
//********************************************************************************
// TODO Aufgabe 5 (b)
// Hier soll der Parameter u und der entsprechende Spline fuer eine
// gegebene Bogenlaenge in der Tabelle gesucht. Ein binaeres
// Suchverfahren ist zu empfehlen.
//********************************************************************************
}
void HermiteSpline::calculateFrenetFrame(float u, HermiteSplineControlPoint* c0,
HermiteSplineControlPoint* c1,
glm::vec3& tangent,
glm::vec3& binormal,
glm::vec3& normal) {
//********************************************************************************
// TODO Aufgabe 5 (c)
// Hier soll der Frenet-Frame berechnet und in den uebergebenen
// Funktionsargumenten gespeichert werden. Tipp: Sie brauchen noch die
// zweite Ableitung einer Bezier-Kurve ...
//********************************************************************************
}
} // End namespace CVK