void MyPrimitive::GeneratePlane(float a_fSize, vector3 a_v3Color) { if (a_fSize < 0.01f) a_fSize = 0.01f; Release(); Init(); float fValue = 0.5f * a_fSize; vector3 pointA(-fValue, -fValue, 0.0f); //0 vector3 pointB(fValue, -fValue, 0.0f); //1 vector3 pointC(fValue, fValue, 0.0f); //2 vector3 pointD(-fValue, fValue, 0.0f); //3 vector3 pointE(fValue, -fValue, -0.001f); //1 vector3 pointF(-fValue, -fValue, -0.001f); //0 vector3 pointG(fValue, fValue, -0.001f); //2 vector3 pointH(-fValue, fValue, -0.001f); //3 //F AddQuad(pointA, pointB, pointD, pointC); //Double sided AddQuad(pointE, pointF, pointG, pointH); CompileObject(a_v3Color); }
/** * recenters the points of a constant distance towards the center * * @param y bottom most point * @param z left most point * @param x right most point * @param t top most point * @return {@link vector<Ref<ResultPoint> >} describing the corners of the rectangular * region. The first and last points are opposed on the diagonal, as * are the second and third. The first point will be the topmost * point and the last, the bottommost. The second point will be * leftmost and the third, the rightmost */ vector<Ref<ResultPoint> > WhiteRectangleDetector::centerEdges(Ref<ResultPoint> y, Ref<ResultPoint> z, Ref<ResultPoint> x, Ref<ResultPoint> t) { // // t t // z x // x OR z // y y // float yi = y->getX(); float yj = y->getY(); float zi = z->getX(); float zj = z->getY(); float xi = x->getX(); float xj = x->getY(); float ti = t->getX(); float tj = t->getY(); std::vector<Ref<ResultPoint> > corners(4); if (yi < (float)width_/2) { Ref<ResultPoint> pointA(new ResultPoint(ti - CORR, tj + CORR)); Ref<ResultPoint> pointB(new ResultPoint(zi + CORR, zj + CORR)); Ref<ResultPoint> pointC(new ResultPoint(xi - CORR, xj - CORR)); Ref<ResultPoint> pointD(new ResultPoint(yi + CORR, yj - CORR)); corners[0].reset(pointA); corners[1].reset(pointB); corners[2].reset(pointC); corners[3].reset(pointD); } else { Ref<ResultPoint> pointA(new ResultPoint(ti + CORR, tj + CORR)); Ref<ResultPoint> pointB(new ResultPoint(zi + CORR, zj - CORR)); Ref<ResultPoint> pointC(new ResultPoint(xi - CORR, xj + CORR)); Ref<ResultPoint> pointD(new ResultPoint(yi - CORR, yj - CORR)); corners[0].reset(pointA); corners[1].reset(pointB); corners[2].reset(pointC); corners[3].reset(pointD); } return corners; }
int main(int argc, char *argv[]) { std::cout << "///////////////////// POINT //////////////////////////////////" << std::endl; Point newPoint(0,1,2); std::cout << "x : " << newPoint.x() << std::endl; std::cout << "y : " << newPoint.y() << std::endl; std::cout << "z : " << newPoint.z() << std::endl; newPoint.setY(5); Point pointB; std::cout << "y : " << pointB.y() << std::endl; if (! newPoint.isNotEqual(pointB)) std::cout << "equal" << std::endl; else std::cout << "nonEqual" << std::endl; std::cout << "///////////////////// VECTOR //////////////////////////////////" << std::endl; Vector newVector, vect; newVector.setCoordonne(-8.0, 5.0, 6.0); Vector vec2(newPoint, pointB); Vector vec3(newVector, vec2); std::cout << "x2 : " << vec2.x() << std::endl; std::cout << "y2 : " << vec2.y() << std::endl; std::cout << "z2 : " << vec2.z() << std::endl; if (vect.vecteurNull()) std::cout << "vec Null" << std::endl; else std::cout << "vec Non NUll" << std::endl; if (newVector.vecteurNull()) std::cout << "newVector Null" << std::endl; else std::cout << "newVector Non NUll" << std::endl; std::cout << "dot => " << newVector.dot(vec2) << std::endl; std::cout << "x3 : " << vec3.x() << std::endl; std::cout << "y3 : " << vec3.y() << std::endl; std::cout << "z3 : " << vec3.z() << std::endl; std::cout << "///////////////////// RAY //////////////////////////////////" << std::endl; Ray newRay(pointB,newPoint); std::cout << "origine : " << newRay.P0().x() << ", " << newRay.P0().y() << ", " << newRay.P0().z()<< std::endl; std::cout << "direction : " << newRay.P1().x() << ", " << newRay.P1().y() << ", " << newRay.P1().z() << std::endl; std::cout << "///////////////////// Triangle //////////////////////////////////" << std::endl; Point pointC(6,8,5); Point V2(0,-1,-10); Point V0(5,-50,59); Point V1(9,0,-25); Triangle newTriangle(V0,V1,V2); std::cout << "coordonnee : " << newTriangle.V0().x() << ", " << newTriangle.V1().y() << ", "<< newTriangle.V2().z() << std::endl; std::cout << "///////////////////// Point/Triangle //////////////////////////////////" << std::endl; Point I; std::cout << newRay.P0().x() + 6 * newVector.x() << std::endl; std::cout << newRay.P0().y() + 6 * newVector.y() << std::endl; std::cout << newRay.P0().z() + 6 * newVector.z() << std::endl; I.setCoordonne(newRay.P0().x() + 6 * newVector.x(), newRay.P0().y() + 6 * newVector.y(), newRay.P0().z() + 6 * newVector.z()); std::cout << "coucou" << std::endl; std::cout << "///////////////////// test intersect //////////////////////////////////" << std::endl; int test; test = intersect3D_RayTriangle(newRay, newTriangle, I); std::cout << "I : " << I.x() << ", " << I.y() <<", "<< I.z() << "\n test : " << test << std::endl; std::cout << "///////////////////// VECTOR/Triangle //////////////////////////////////" << std::endl; Vector newVector2(newTriangle.V0(), newTriangle.V1()); std::cout << "x : " << newVector2.x() << std::endl; std::cout << "y : " << newVector2.y() << std::endl; std::cout << "z : " << newVector2.z() << std::endl; return 0; }
void MyPrimitive::GenerateSphere(float a_fRadius, int a_nSubdivisions, vector3 a_vColor) { //Sets minimum and maximum of subdivisions if (a_nSubdivisions < 1) { GenerateCube(a_fRadius * 2, a_vColor); return; } if (a_nSubdivisions > 6) a_nSubdivisions = 6; //Clean up Memory Release(); Init(); //Your Code Goes Here instead of the next three lines float fValue = 0.5f; vector3 pointA(-fValue, -fValue, fValue); //0 vector3 pointB(fValue, -fValue, fValue); //1 vector3 pointC(-fValue, fValue, fValue); //2 //left to right List of vector3 std::vector<vector3> vectorAB; vectorAB.push_back(pointA); for (int i = 0; i < a_nSubdivisions; i++) { vector3 temp(pointB - pointA); temp /= a_nSubdivisions + 1; temp *= (i + 1); vectorAB.push_back(temp + pointA); } vectorAB.push_back(pointB); //height increments float fHeight = pointC.y - pointA.y; fHeight /= a_nSubdivisions + 1; //List of Lists std::vector<std::vector<vector3>> list; list.push_back(vectorAB); for (int j = 0; j < a_nSubdivisions + 1; j++) { std::vector<vector3> temp = list[0]; float increment = fHeight * (j + 1); for (int i = 0; i < a_nSubdivisions + 2; i++) { temp[i].y += increment; } list.push_back(temp); } //Creating the patch of quads for (int j = 0; j < a_nSubdivisions + 1; j++) { for (int i = 0; i < a_nSubdivisions + 1; i++) { AddQuad(list[j][i], list[j][i + 1], list[j + 1][i], list[j + 1][i + 1]); } } int nVertices = static_cast<int>(m_lVertexPos.size()); //normalizing the vectors to make them round for (int i = 0; i < nVertices; i++) { m_lVertexPos[i] = glm::normalize(m_lVertexPos[i]); m_lVertexPos[i] *= a_fRadius; } //RightSideFace std::vector<vector3> right; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), 90.0f, vector3(0.0f, 1.0f, 0.0f)); right.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(right[i]); } //LeftSideFace std::vector<vector3> left; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), -90.0f, vector3(0.0f, 1.0f, 0.0f)); left.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(left[i]); } //BackSideFace std::vector<vector3> back; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), 180.0f, vector3(0.0f, 1.0f, 0.0f)); back.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(back[i]); } //TopSideFace std::vector<vector3> top; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), -90.0f, vector3(1.0f, 0.0f, 0.0f)); top.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(top[i]); } //BottomSideFace std::vector<vector3> bottom; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), 90.0f, vector3(1.0f, 0.0f, 0.0f)); bottom.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(bottom[i]); } //Compile the object in this color and assign it this name CompileObject(a_vColor); }
TEST(intersection, triangle_tetrahedron) { TIntersectionType it; double area; // create tetrahedron TPoint point0(0.00, 0.00, 0.00); TPoint point1(3.00, 0.00, 0.00); TPoint point2(0.00, 3.00, 0.00); TPoint point3(0.00, 0.00, 3.00); TTetrahedron tetrahedron(point0, point1, point2, point3); // triangle is in tetrahedron TPoint pointA(0.50, 0.50, 0.50); TPoint pointB(0.50, 1.50, 0.50); TPoint pointC(1.50, 0.50, 0.50); TTriangle triangle(pointA, pointB, pointC); xprintf(Msg, "Test - triangle is in tetrahedron\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.5); // triangle is greater than tetrahedron, intersection is triangle pointA.SetCoord(-3.0, 2.0, 2.0); pointB.SetCoord(2.0, -3.0, 2.0); pointC.SetCoord(2.0, 2.0, 2.0); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - triangle is greater than tetrahedron, intersection is triangle\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.5); // intersection is tetragon pointA.SetCoord(-0.50, 0.50, 1.00); pointB.SetCoord(2.00, 0.50, 1.00); pointC.SetCoord(2.00, 3.00, 1.00); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is tetragon\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.875); // intersection is pentagon pointA.SetCoord(-1.0, 2.00, 1.00); pointB.SetCoord(1.50, 2.00, 1.00); pointC.SetCoord(1.50,-0.5 , 1.00); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is pentagon\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.5+0.5+0.5*3.0/4.0); // intersection is hexagon (plane parallel to x-y) pointA.SetCoord(2.00, 2.00, 0.50); pointB.SetCoord(2.00, -1.00, 0.50); pointC.SetCoord(-1.00, 2.00, 0.50); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is hexagon (plane parallel to x-y)\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 2.375); // intersection is hexagon pointA.SetCoord(0.25, 2.00, 1.00); pointB.SetCoord(2.25, 1.00, -1.00); pointC.SetCoord(0.25, -1.00, 3.00); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is hexagon\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 3.477919); }