Smooth triangles! And support for them in the OBJ File parser.
Also add an interesting tea party scene!
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <math.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <triangle.h>
|
||||
#include <smoothtriangle.h>
|
||||
|
||||
TEST(OBJFileTest, Ignoring_unrecognised_lines)
|
||||
{
|
||||
@@ -118,4 +119,58 @@ TEST(OBJFileTest, Triangle_in_groups)
|
||||
ASSERT_EQ(t2->p1, parser.vertices(1));
|
||||
ASSERT_EQ(t2->p2, parser.vertices(3));
|
||||
ASSERT_EQ(t2->p3, parser.vertices(4));
|
||||
}
|
||||
|
||||
TEST(OBJFileTest, Vertex_normal_record)
|
||||
{
|
||||
const char file[] = "vn 0 0 1\n"
|
||||
"vn 0.707 0 -0.707\n"
|
||||
"vn 1 2 3\n";
|
||||
|
||||
OBJFile parser = OBJFile();
|
||||
parser.parseOBJFile(file);
|
||||
|
||||
ASSERT_EQ(parser.verticesNormal(1), Vector(0, 0, 1));
|
||||
ASSERT_EQ(parser.verticesNormal(2), Vector(0.707, 0, -0.707));
|
||||
ASSERT_EQ(parser.verticesNormal(3), Vector(1, 2, 3));
|
||||
}
|
||||
|
||||
TEST(OBJFileTest, Faces_with_normal)
|
||||
{
|
||||
const char file[] = "v 0 1 0\n"
|
||||
"v -1 0 0\n"
|
||||
"v 1 0 0\n"
|
||||
"\n"
|
||||
"vn -1 0 0\n"
|
||||
"vn 1 0 0\n"
|
||||
"vn 0 1 0\n"
|
||||
"\n"
|
||||
"f 1//3 2//1 3//2\n"
|
||||
"f 1/0/3 2/102/1 3/14/2\n";
|
||||
|
||||
OBJFile parser = OBJFile();
|
||||
parser.parseOBJFile(file);
|
||||
|
||||
Group *g0 = parser.groups(0);
|
||||
|
||||
SmoothTriangle *t1 = (SmoothTriangle *)(*g0)[0];
|
||||
SmoothTriangle *t2 = (SmoothTriangle *)(*g0)[1];
|
||||
|
||||
ASSERT_EQ(t1->p1, parser.vertices(1));
|
||||
ASSERT_EQ(t1->p2, parser.vertices(2));
|
||||
ASSERT_EQ(t1->p3, parser.vertices(3));
|
||||
|
||||
ASSERT_EQ(t1->n1, parser.verticesNormal(3));
|
||||
ASSERT_EQ(t1->n2, parser.verticesNormal(1));
|
||||
ASSERT_EQ(t1->n3, parser.verticesNormal(2));
|
||||
|
||||
ASSERT_EQ(t2->p1, parser.vertices(1));
|
||||
ASSERT_EQ(t2->p2, parser.vertices(2));
|
||||
ASSERT_EQ(t2->p3, parser.vertices(3));
|
||||
|
||||
ASSERT_EQ(t2->n1, parser.verticesNormal(3));
|
||||
ASSERT_EQ(t2->n2, parser.verticesNormal(1));
|
||||
ASSERT_EQ(t2->n3, parser.verticesNormal(2));
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user