blob: 06b88291467690f2292efbb7ab718b3f08cf01b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include "arap.h"
#include "graphics/meshloader.h"
#include <iostream>
#include <set>
#include <map>
#include <vector>
using namespace std;
using namespace Eigen;
ARAP::ARAP() {}
void ARAP::init(Eigen::Vector3f &coeffMin, Eigen::Vector3f &coeffMax)
{
vector<Vector3f> vertices;
vector<Vector3i> triangles;
// If this doesn't work for you, remember to change your working directory
if (MeshLoader::loadTriMesh("meshes/cactus.obj", vertices, triangles)) {
m_shape.init(vertices, triangles);
}
// Students, please don't touch this code: get min and max for viewport stuff
MatrixX3f all_vertices = MatrixX3f(vertices.size(), 3);
int i = 0;
for (unsigned long i = 0; i < vertices.size(); ++i) {
all_vertices.row(i) = vertices[i];
}
coeffMin = all_vertices.colwise().minCoeff();
coeffMax = all_vertices.colwise().maxCoeff();
}
// Move an anchored vertex, defined by its index, to targetPosition
void ARAP::move(int vertex, Vector3f targetPosition)
{
std::vector<Eigen::Vector3f> new_vertices = m_shape.getVertices();
const std::unordered_set<int>& anchors = m_shape.getAnchors();
// TODO: implement ARAP here
new_vertices[vertex] = targetPosition;
// Here are some helpful controls for the application
//
// - You start in first-person camera mode
// - WASD to move, left-click and drag to rotate
// - R and F to move vertically up and down
//
// - C to change to orbit camera mode
//
// - Right-click (and, optionally, drag) to anchor/unanchor points
// - Left-click an anchored point to move it around
//
// - Minus and equal keys (click repeatedly) to change the size of the vertices
m_shape.setVertices(new_vertices);
}
|