Use mesh center everywhere else
This commit is contained in:
parent
8655e39fba
commit
6e89298950
5 changed files with 37 additions and 11 deletions
|
@ -11,6 +11,7 @@ int main(int argc, char** argv) {
|
|||
render.init(&argc, argv, 640, 480, "Bouncing stuff");
|
||||
|
||||
Mesh mesh = ObjParser("mesh/cube.obj").parse();
|
||||
mesh.translate(Point(2.5, -1, 0.));
|
||||
render.add_mesh(&mesh);
|
||||
|
||||
render.run();
|
||||
|
|
20
mesh/cube_tr.obj
Normal file
20
mesh/cube_tr.obj
Normal file
|
@ -0,0 +1,20 @@
|
|||
v -3 -1 1
|
||||
v -1 -1 1
|
||||
v -3 1 1
|
||||
v -1 1 1
|
||||
v -3 1 -1
|
||||
v -1 1 -1
|
||||
v -3 -1 -1
|
||||
v -1 -1 -1
|
||||
f 1 2 4
|
||||
f 1 4 3
|
||||
f 3 4 6
|
||||
f 3 6 5
|
||||
f 5 6 8
|
||||
f 5 8 7
|
||||
f 7 8 2
|
||||
f 7 2 1
|
||||
f 2 8 6
|
||||
f 2 6 4
|
||||
f 7 1 3
|
||||
f 7 3 5
|
|
@ -34,11 +34,11 @@ void GlutRender::init(int* argc, char** argv,
|
|||
void GlutRender::cleanup() {
|
||||
}
|
||||
|
||||
void GlutRender::add_mesh(const Mesh* mesh) {
|
||||
void GlutRender::add_mesh(Mesh* mesh) {
|
||||
meshes.insert(mesh);
|
||||
}
|
||||
|
||||
void GlutRender::remove_mesh(const Mesh* mesh) {
|
||||
void GlutRender::remove_mesh(Mesh* mesh) {
|
||||
meshes.erase(mesh);
|
||||
}
|
||||
|
||||
|
@ -63,17 +63,20 @@ void GlutRender::display() {
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
for(const Mesh* mesh: meshes) {
|
||||
// Camera position and orientation
|
||||
glLoadIdentity();
|
||||
glTranslatef(.0f, .0f, -6.0f);
|
||||
glTranslatef(0., 0., -6.);
|
||||
|
||||
for(Mesh* mesh: meshes) {
|
||||
const Point& mesh_center = mesh->get_center();
|
||||
|
||||
const std::vector<Point>& points = mesh->get_vertices();
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(const Face& face: mesh->get_faces()) {
|
||||
const Point& p0 = face.pt(0, points),
|
||||
p1 = face.pt(1, points),
|
||||
p2 = face.pt(2, points);
|
||||
Point p0 = face.pt(0, points) + mesh_center,
|
||||
p1 = face.pt(1, points) + mesh_center,
|
||||
p2 = face.pt(2, points) + mesh_center;
|
||||
glColor3f(1.0f, 1.0f, 0.0f);
|
||||
glVertex3f(p0[0], p0[1], p0[2]);
|
||||
glVertex3f(p1[0], p1[1], p1[2]);
|
||||
|
|
|
@ -15,8 +15,8 @@ class GlutRender {
|
|||
void init(int* argc, char** argv,
|
||||
int wid, int hei, const char* win_name);
|
||||
void cleanup();
|
||||
void add_mesh(const Mesh* mesh);
|
||||
void remove_mesh(const Mesh* mesh);
|
||||
void add_mesh(Mesh* mesh);
|
||||
void remove_mesh(Mesh* mesh);
|
||||
void run();
|
||||
|
||||
private: //meth
|
||||
|
@ -29,5 +29,5 @@ class GlutRender {
|
|||
static void reshape_handle(int wid, int hei);
|
||||
static void display_handle();
|
||||
private:
|
||||
std::set<const Mesh*> meshes;
|
||||
std::set<Mesh*> meshes;
|
||||
};
|
||||
|
|
|
@ -34,6 +34,8 @@ Mesh ObjParser::parse() {
|
|||
}
|
||||
}
|
||||
|
||||
output.normalize_center(false);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue