diff --git a/src/geometries/Geometry.h b/src/geometries/Geometry.h index be4a452b7f07c2d7aa7e708d202225785b3971bb..5d57b9efcc72bb0aed034f30b8200b240b2117a4 100644 --- a/src/geometries/Geometry.h +++ b/src/geometries/Geometry.h @@ -16,7 +16,9 @@ public: virtual void Draw() = 0; - virtual VertexData GetVertexDataByUV(float u, float v) { throw std::bad_exception(); }; + virtual VertexData GetVertexDataByUV(float u, float v) { + return vtxData[std::rand()%vtxData.size()]; + }; ~Geometry(); }; diff --git a/src/geometries/PBDSimulation.cpp b/src/geometries/PBDSimulation.cpp index 1ce44f6bac5e2ad50ca2977e73fd1f9bef3ab392..8e25131a711d24ebcf8fb09ae0c95cd7ed26cfbe 100644 --- a/src/geometries/PBDSimulation.cpp +++ b/src/geometries/PBDSimulation.cpp @@ -15,16 +15,18 @@ PBDSimulation::PBDSimulation(HeadObject *_head, size_t _nr_sims, size_t _nr_segm // placing hair on the head propagateHead(); - collisionTriangles.emplace_back(0.5, -1, 1); - collisionTriangles.emplace_back(0.5, 1, 0); - collisionTriangles.emplace_back(0.5, -1, -1); + //TODO optimize this, it's smelly code right now + std::vector<VertexData> vtxData = head->getGeometry()->vtxData; + // %4 == 0, these should be guaranteed to be triangles + the normal vector of the face + for (size_t i = 0; i < vtxData.size(); i += 3) { + collisionTriangles.emplace_back(vtxData[i].position); + collisionTriangles.emplace_back(vtxData[i + 1].position); + collisionTriangles.emplace_back(vtxData[i + 2].position); + } + } void PBDSimulation::propagateHead() { - -// for(float u = .0f; u <= 1.f; u+=.05f) -// for(float v = .0f; v <= 1.f; v+=.05f) -// std::cout << head->GetVertexDataByUV(u, v) << std::endl; std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<float> dis(.3, .95); @@ -33,16 +35,12 @@ void PBDSimulation::propagateHead() { float currU = dis(gen); float currV = dis(gen); VertexData currPos = head->GetVertexDataByUV(currU, currV); - while (currPos.normal.y < .0f) { + while (currPos.normal.y > .0f) { currU = dis(gen); currV = dis(gen); currPos = head->GetVertexDataByUV(currU, currV); } -#ifdef DEBUG_UV - std::cout << vec2(currU, currV) << " -> "<< currPos <<std::endl; -#endif - vec3 color = util::getRandomRGBColorAround(vec3(222.0f, 101.0f, 32.0f), vec3(40.0f, 20.0f, 20.0f)); strands.emplace_back(CreateStrand(nrSegments, lSeg, currPos.position * vec3(1, -1, 1), color)); } @@ -76,8 +74,12 @@ void PBDSimulation::update(float dt) { if (i < strand.size() - 1) solve_bending_constraint(strand[i - 1], strand[i + 1], lSeg * 0.9f); if (i < strand.size() - 2 && i > 1) solve_bending_constraint(strand[i - 2], strand[i + 2], lSeg * 1.9f); - solve_collision_constraint(strand[i], - collisionTriangles[0], collisionTriangles[1], collisionTriangles[2]); +// for (size_t currTriangle = 0; currTriangle < collisionTriangles.size(); currTriangle += 3) +// solve_collision_constraint(strand[i], +// collisionTriangles[currTriangle], +// collisionTriangles[currTriangle + 1], +// collisionTriangles[currTriangle + 2] +// ); } } } @@ -118,7 +120,7 @@ void PBDSimulation::solve_bending_constraint(Particle *p1, Particle *p2, float d } void PBDSimulation::solve_collision_constraint(Particle *p, vec3 &q1, vec3 &q2, vec3 &q3) { - vec3 n = normalize(cross(q1 - q3, q1 - q2)); + vec3 n = normalize(cross(q1 - q2, q3 - q2)); if (dot(p->tmp_pos - q1, n) < 0) return; diff --git a/src/objects/HeadObject.cpp b/src/objects/HeadObject.cpp index ffa1fd6d706e68913f3a35a441539f91e8522b9d..30097a6639b25d54e3266e5fa6027f7162bba248 100644 --- a/src/objects/HeadObject.cpp +++ b/src/objects/HeadObject.cpp @@ -13,11 +13,11 @@ VertexData HeadObject::GetVertexDataByUV(float u, float v) { vD.position = vec3(WP.x, WP.y, WP.z); vD.normal = vec3(WN.x, WN.y, WN.z); -#ifdef DEBUG_UV - std::cout << vD << std::endl; -#endif - return vD; } +Geometry *HeadObject::getGeometry() { + return geometry; +} + diff --git a/src/objects/HeadObject.h b/src/objects/HeadObject.h index f5a22ac3ff8549cf0b9051893d75b3a9e0f1bfef..09c79b3afc8cb48c04fa3ce84bfa303b6697ea52 100644 --- a/src/objects/HeadObject.h +++ b/src/objects/HeadObject.h @@ -8,6 +8,8 @@ public: HeadObject(Shader *_shader, Geometry *_geometry, Material *_material, Texture *_texture); VertexData GetVertexDataByUV(float u, float v); + + Geometry* getGeometry(); }; diff --git a/src/rendering/Scene.cpp b/src/rendering/Scene.cpp index b13d76f2ef8d8c92564b69416689baef4432a9a5..f8398c86679a2bcdbf9de5c444df6b8f23845217 100644 --- a/src/rendering/Scene.cpp +++ b/src/rendering/Scene.cpp @@ -24,44 +24,45 @@ void Scene::Build() { auto sphere = new Sphere(); Shader *phongShader = new PhongShader(); Material *headMaterial = new Material; - headMaterial->kd = vec3(0.5f, 0.3f, .3f); - headMaterial->ks = vec3(.1, .05, .05); - headMaterial->ka = vec3(.2f, .2f, .2f); - headMaterial->shininess = 20; + headMaterial->kd = vec3(0.5f, 0.5f, 0.5f); + headMaterial->ks = vec3(.7f, .7f, .7f); + headMaterial->ka = vec3(.15f, .15f, .15f); + headMaterial->shininess = 10; - Texture *headTexture = new UniformColorTexture(.6f, .2f, 0); + Texture *headTexture = new UniformColorTexture(.25f, .25f, .35f); // Texture *headTexture = new CheckerBoardTexture(1, 0); - auto headObject = new HeadObject(phongShader, sphere, headMaterial, headTexture); +// auto headObject = new HeadObject(phongShader, sphere, headMaterial, headTexture); + auto headObject = new HeadObject(phongShader, new ObjGeometry("../data/sphere.obj"), headMaterial, headTexture); - headObject->Scale(vec3(.15, .1, .1)); + headObject->Scale(vec3(.35, .35, .35)); objects.push_back(headObject); auto PBDSim = new PBDSimulation(headObject, nrSims, nrSegments, lSeg); auto simulationObject = new HairSimObject(headObject, basicShader, PBDSim); sims.push_back(simulationObject); - auto testObject = - new Object(phongShader, - new ObjGeometry("../data/susanne.obj"), - headMaterial, - headTexture); - - objects.push_back(testObject); +// auto testObject = +// new Object(phongShader, +// new ObjGeometry("../data/sphere.obj"), +// headMaterial, +// headTexture); +// +// objects.push_back(testObject); // Lights - lights.resize(3); - lights[0].wLightPos = vec4(0, 1, 0, 0); // ideal point -> directional light source - lights[0].La = vec3(0.1f, 0.1f, 1); + lights.resize(1); + lights[0].wLightPos = vec4(0.0f, 3.0f, 1.5f, 0); // ideal point -> directional light source + lights[0].La = vec3(3.0f, 3.0f, 3.0f); lights[0].Le = vec3(1, 1, 1); - lights[1].wLightPos = vec4(-1, .2, 1, 0); // ideal point -> directional light source - lights[1].La = vec3(0.2f, 0.2f, 0.2f); - lights[1].Le = vec3(5, 3, 2); +// lights[1].wLightPos = vec4(2.0f, 3.0f, 1.0f, 0); // ideal point -> directional light source +// lights[1].La = vec3(0.2f, 0.2f, 0.2f); +// lights[1].Le = vec3(1, 1, 1); - lights[2].wLightPos = vec4(0, 0, 1, 0); // ideal point -> directional light source - lights[2].La = vec3(0.1f, 0.1f, 0.1f); - lights[2].Le = vec3(5, 3, 2); +// lights[2].wLightPos = vec4(0, 0, 1, 0); // ideal point -> directional light source +// lights[2].La = vec3(0.1f, 0.1f, 0.1f); +// lights[2].Le = vec3(1, 1, 1); } void Scene::Render() {