//Begin TriangleGen void TriangleGen::generator(const color4& color0, const color4& color1, const color4& color2) { //set vertices elements[0] = point4(-sqrt(3.0)/2.0, -0.5, 0.0, 1.0); elements[1] = point4(sqrt(3.0)/2.0, -0.5, 0.0, 1.0); elements[2] = point4(0.0, 1.0, 0.0, 1.0); //set colors elements[3] = color0; elements[4] = color1; elements[5] = color2; //set normals elements[6] = MatMath::zNORM; elements[7] = -MatMath::zNORM; //front triangle data[0] = elements[0]; data[1] = elements[1]; data[2] = elements[2]; //back triangle data[3] = elements[2]; data[4] = elements[1]; data[5] = elements[0]; //front colors data[6] = elements[3]; data[7] = elements[4]; data[8] = elements[5]; //back colors data[9] = elements[5]; data[10] = elements[4]; data[11] = elements[3]; //front normals data[12] = data[13] = data[14] = elements[6]; //back normals data[15] = data[16] = data[17] = elements[7]; //front indices indices[0] = 0; indices[1] = 1; indices[2] = 2; //back indices indices[3] = 3; indices[4] = 4; indices[5] = 5; }
//SquareGen void SquareGen::generate( const color4& color0, const color4& color1, const color4& color2, const color4& color3 ) { //set vertices elements[0] = point4(-1.0, -1.0, 0.0, 1.0); elements[1] = point4(1.0, -1.0, 0.0, 1.0); elements[2] = point4(1.0, 1.0, 0.0, 1.0); elements[3] = point4(-1.0, 1.0, 0.0, 1.0); //set colors elements[4] = color0; elements[5] = color1; elements[6] = color2; elements[7] = color3; //set normals elements[8] = MatMath::zNORM; elements[9] = -MatMath::zNORM; //front square data[0] = elements[0]; data[1] = elements[1]; data[2] = elements[2]; data[3] = elements[3]; //back square data[4] = elements[3]; data[5] = elements[2]; data[6] = elements[1]; data[7] = elements[0]; //front colors data[8] = elements[4]; data[9] = elements[5]; data[10] = elements[6]; data[11] = elements[7]; //back colors data[12] = elements[7]; data[13] = elements[6]; data[14] = elements[5]; data[15] = elements[4]; //front normals data[16] = data[17] = data[18] = data[19] = elements[8]; //back normals data[20] = data[21] = data[22] = data[23] = elements[9]; //front triangles indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 3; //back triangles indices[6] = 4; indices[7] = 5; indices[8] = 6; indices[9] = 4; indices[10] = 6; indices[11] = 7; }
vec4* Geometry::createUnitTriangle(){ int i = 0; vec4* ret = new vec4[3]; ret[i] = point4( -U_CUBE_C, -U_CUBE_C, U_CUBE_C, 1.0 ); i++; ret[i] = point4( 0, U_CUBE_C, U_CUBE_C, 1.0 ); i++; ret[i] = point4( U_CUBE_C, -U_CUBE_C, U_CUBE_C, 1.0 ); return ret; }
vec4* Geometry::createUnitPlane(){ int i = 0; vec4 * ret = new vec4[4]; ret[i] = point4( -U_CUBE_C, -U_CUBE_C, U_CUBE_C, 1.0 ); i++; ret[i] = point4( -U_CUBE_C, U_CUBE_C, U_CUBE_C, 1.0 ); i++; ret[i] = point4( U_CUBE_C, U_CUBE_C, U_CUBE_C, 1.0 ); i++; ret[i] = point4( U_CUBE_C, -U_CUBE_C, U_CUBE_C, 1.0 ); return ret; }
void poly4::makePoints3() { if (points4.size() == 0){ std::cout << "Error: poly4::makePoints3 called with empty points4. " << std::endl; exit(1); } if (projVec.isZero()){ std::cout << "poly4::makePoints3() requires a projection vector" <<std::endl; exit(1); } // std::cout << "projVec = " << projVec << std::endl; basis[0] = point4(1.,0.,0.,0.); basis[0] -= (basis[0]*projVec) * projVec; if (basis[0].isZero()){ basis[0] = point4(0.,1.,0.,0.); basis[0] -= (basis[0]*projVec) * projVec; if (basis[0].isZero()){ std::cout << " problem with isZero()??? " << std::endl; exit(1); } } basis[0].makeUnit(); basis[1] = point4(0.,0.,1.,0.); // std::cout << (basis[1]*projVec)* projVec << " " << (basis[1]*basis[0])*basis[0] << std::endl; basis[1] -= (basis[1]*projVec) * projVec; // std::cout << basis[1] << " : " << basis[1]*basis[0] << " " << basis[1]*projVec << std::endl; basis[1] -= (basis[1]*basis[0])*basis[0]; if (basis[1].isZero()){ basis[1] = point4(0.,0.,0.,1.); basis[1] -= (basis[1]*projVec)* projVec; basis[1] -= (basis[1]*basis[0])*basis[0]; if (basis[1].isZero()){ // std::cout << " problem with isZero()??? " << std::endl; exit(1); } } basis[1].makeUnit(); // std::cout << basis[1]*basis[0] << " " << basis[1]*projVec << std::endl; basis[2] = projVec.cross(basis[0],basis[1]); basis[2].makeUnit(); // std::cout << "basis : " << basis[0] << " " << basis[1] << " " << basis[2] << std::endl; // check orthogonality?? for (int i=0;i<points4.size();i++) points.push_back( point(basis[0]*points4[i],basis[1]*points4[i],basis[2]*points4[i])); // for (int i=0;i<points.size();i++) // std::cout << "p["<< i << "] : " << points[i] << std::endl; }
CCube::CCube(double size, bool drawFrontFace) { // Vertices of a unit cube centered at origin, sides aligned with axes vertex_positions[0] = point4( -size, -size, size, 1.0 ); vertex_positions[1] = point4( -size, size, size, 1.0 ); vertex_positions[2] = point4( size, size, size, 1.0 ); vertex_positions[3] = point4( size, -size, size, 1.0 ); vertex_positions[4] = point4( -size, -size, -size, 1.0 ); vertex_positions[5] = point4( -size, size, -size, 1.0 ); vertex_positions[6] = point4( size, size, -size, 1.0 ); vertex_positions[7] = point4( size, -size, -size, 1.0 ); int Index = 0; if(drawFrontFace) { quad( 1, 0, 3, 2 , vertex_positions, Index); } quad( 2, 3, 7, 6 , vertex_positions, Index); quad( 3, 0, 4, 7 , vertex_positions, Index); quad( 6, 5, 1, 2 , vertex_positions, Index); quad( 4, 5, 6, 7 , vertex_positions, Index); quad( 5, 4, 0, 1 , vertex_positions, Index); //Initialize the motion v = vec3(15.0, 0., 0.); w = vec3(1., 1., 1.); }
void Terrain::addTriangle(point4 p1, point4 p2, point4 p3, color4 high, color4 mid, color4 low, color4 brown){ point4 p1_new = point4(p1.x, p1.y, POSITIVE(p1.z), p1.w); point4 p2_new = point4(p2.x, p2.y, POSITIVE(p2.z), p2.w); point4 p3_new = point4(p3.x, p3.y, POSITIVE(p3.z), p3.w); vec4 u = p2_new - p1_new; vec4 v = p3_new - p1_new; vec3 normal = -normalize( cross(u, v) ); if (this->points.size() < this->num_points + 5){ this->points.resize(2*this->points.size()); this->normals.resize(2*this->points.size()); this->colors.resize(2*this->points.size()); } points[this->num_points] = p1_new; normals[this->num_points] = normal; if (p1.z == 0){ colors[this->num_points++] = low; } else if (p1.z > -0.5*this->range){ colors[this->num_points++] = mid; } else if (p1.z > -0.75*this->range){ colors[this->num_points++] = brown; } else { colors[this->num_points++] = high; } points[this->num_points] = p2_new; normals[this->num_points] = normal; if (p2.z == 0){ colors[this->num_points++] = low; } else if (p2.z > -0.5*this->range){ colors[this->num_points++] = mid; } else if (p3.z > -0.75*this->range){ colors[this->num_points++] = brown; } else { colors[this->num_points++] = high; } points[this->num_points] = p3_new; normals[this->num_points] = normal; if (p3.z == 0){ colors[this->num_points++] = low; } else if (p3.z > -0.5*this->range){ colors[this->num_points++] = mid; } else if (p3.z > -0.75*this->range){ colors[this->num_points++] = brown; } else { colors[this->num_points++] = high; } }
void TestOpDeselectPoint() { //check OpDESELECTPOINT ExecuteOperation mitk::Point3D point4(0.); doOp = new mitk::PointOperation(mitk::OpDESELECTPOINT, point4,4); pointSet->ExecuteOperation(doOp); CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpDESELECTPOINT ", false, pointSet->GetSelectInfo(4)); CPPUNIT_ASSERT_EQUAL_MESSAGE("check GetNumeberOfSelected ", true, pointSet->GetNumberOfSelected() == 0 ); /* if (pointSet->GetSelectInfo(4)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } delete doOp; std::cout<<"[PASSED]"<<std::endl; if(pointSet->GetNumberOfSelected() != 0) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; */ }
void MyPrimitive::GenerateTube(float a_fOuterRadius, float a_fInnerRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color) { if (a_nSubdivisions < 3) a_nSubdivisions = 3; if (a_nSubdivisions > 360) a_nSubdivisions = 360; Release(); Init(); for (int i = 0; i < a_nSubdivisions; i++) { float ang = (2 * PI) / a_nSubdivisions; vector3 point0(a_fOuterRadius*cos((i + 1)*ang), a_fHeight, a_fOuterRadius*sin((i + 1)*ang)); //1 vector3 point1(a_fOuterRadius*cos(i*ang), 0, a_fOuterRadius*sin(i*ang)); //2 vector3 point2(a_fOuterRadius*cos(i*ang), a_fHeight, a_fOuterRadius*sin(i*ang)); //0 vector3 point3(a_fOuterRadius*cos((i + 1)*ang), 0, a_fOuterRadius*sin((i + 1)*ang)); //3 vector3 point4(a_fInnerRadius*cos((i + 1)*ang), a_fHeight, a_fInnerRadius*sin((i + 1)*ang)); //1 vector3 point5(a_fInnerRadius*cos(i*ang), 0, a_fInnerRadius*sin(i*ang)); //2 vector3 point6(a_fInnerRadius*cos(i*ang), a_fHeight, a_fInnerRadius*sin(i*ang)); //0 vector3 point7(a_fInnerRadius*cos((i + 1)*ang), 0, a_fInnerRadius*sin((i + 1)*ang)); //3 AddQuad(point4, point0, point6, point2); //Top AddQuad(point0, point3, point2, point1); //Outer AddQuad(point7, point5, point3, point1); //Bottom AddQuad(point5, point7, point6,point4 ); // Inner } //Your code ends here CompileObject(a_v3Color); }
BaseIF* makeVane(const Real& thick, const RealVect& normal, const Real& innerRadius, const Real& outerRadius, const Real& offset, const Real& height) { RealVect zero(D_DECL(0.0,0.0,0.0)); RealVect xAxis(D_DECL(1.0,0.0,0.0)); bool inside = true; Vector<BaseIF*> vaneParts; // Each side of the vane (infinite) RealVect normal1(normal); RealVect point1(D_DECL(offset+height/2.0,-thick/2.0,0.0)); PlaneIF plane1(normal1,point1,inside); vaneParts.push_back(&plane1); RealVect normal2(-normal); RealVect point2(D_DECL(offset+height/2.0,thick/2.0,0.0)); PlaneIF plane2(normal2,point2,inside); vaneParts.push_back(&plane2); // Make sure we only get something to the right of the origin RealVect normal3(D_DECL(0.0,0.0,1.0)); RealVect point3(D_DECL(0.0,0.0,0.0)); PlaneIF plane3(normal3,point3,inside); vaneParts.push_back(&plane3); // Cut off the top and bottom RealVect normal4(D_DECL(1.0,0.0,0.0)); RealVect point4(D_DECL(offset,0.0,0.0)); PlaneIF plane4(normal4,point4,inside); vaneParts.push_back(&plane4); RealVect normal5(D_DECL(-1.0,0.0,0.0)); RealVect point5(D_DECL(offset+height,0.0,0.0)); PlaneIF plane5(normal5,point5,inside); vaneParts.push_back(&plane5); // The outside of the inner cylinder TiltedCylinderIF inner(innerRadius,xAxis,zero,!inside); vaneParts.push_back(&inner); // The inside of the outer cylinder TiltedCylinderIF outer(outerRadius,xAxis,zero,inside); vaneParts.push_back(&outer); IntersectionIF* vane = new IntersectionIF(vaneParts); return vane; }
void TestOpMovePointUp() { //check OpMOVEPOINTUP ExecuteOperation const int id = 4; mitk::Point3D point = pointSet->GetPoint(id); mitk::Point3D point4(0.); doOp = new mitk::PointOperation(mitk::OpMOVEPOINTUP, point4, id); pointSet->ExecuteOperation(doOp); mitk::Point3D tempPoint = pointSet->GetPoint(id-1); CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpMOVEPOINTUP ", true, tempPoint == point); /* if (tempPoint != point) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } delete doOp; std::cout<<"[PASSED]"<<std::endl; */ }
void Rectangle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec3 position = getPosition(); glm::vec2 dimensions = getDimensions(); glm::vec2 halfDimensions = dimensions * 0.5f; glm::quat rotation = getRotation(); auto batch = args->_batch; if (batch) { Transform transform; transform.setTranslation(position); transform.setRotation(rotation); batch->setModelTransform(transform); auto geometryCache = DependencyManager::get<GeometryCache>(); if (getIsSolid()) { glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->bindSimpleProgram(*batch); geometryCache->renderQuad(*batch, topLeft, bottomRight, rectangleColor); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); if (getIsDashedLine()) { glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f); glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->renderDashedLine(*batch, point1, point2, rectangleColor); geometryCache->renderDashedLine(*batch, point2, point3, rectangleColor); geometryCache->renderDashedLine(*batch, point3, point4, rectangleColor); geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor); } else { if (halfDimensions != _previousHalfDimensions) { QVector<glm::vec3> border; border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); geometryCache->updateVertices(_geometryCacheID, border, rectangleColor); _previousHalfDimensions = halfDimensions; } geometryCache->renderVertices(*batch, gpu::LINE_STRIP, _geometryCacheID); } } } }
// out: optimized model-shape // in: GRAY img // in: evtl zusaetzlicher param um scale-level/iter auszuwaehlen // calculates shape updates (deltaShape) for one or more iter/scales and returns... // assume we get a col-vec. cv::Mat optimize(cv::Mat modelShape, cv::Mat image) { for (int cascadeStep = 0; cascadeStep < model.getNumCascadeSteps(); ++cascadeStep) { //feature_current = obtain_features(double(TestImg), New_Shape, 'HOG', hogScale); vector<cv::Point2f> points; for (int i = 0; i < model.getNumLandmarks(); ++i) { // in case of HOG, need integers? points.emplace_back(cv::Point2f(modelShape.at<float>(i), modelShape.at<float>(i + model.getNumLandmarks()))); } Mat currentFeatures; double dynamicFaceSizeDistance = 0.0; if (true) { // adaptive // dynamic face-size: cv::Vec2f point1(modelShape.at<float>(8), modelShape.at<float>(8 + model.getNumLandmarks())); // reye_ic cv::Vec2f point2(modelShape.at<float>(9), modelShape.at<float>(9 + model.getNumLandmarks())); // leye_ic cv::Vec2f anchor1 = (point1 + point2) / 2.0f; cv::Vec2f point3(modelShape.at<float>(11), modelShape.at<float>(11 + model.getNumLandmarks())); // rmouth_oc cv::Vec2f point4(modelShape.at<float>(12), modelShape.at<float>(12 + model.getNumLandmarks())); // lmouth_oc cv::Vec2f anchor2 = (point3 + point4) / 2.0f; // dynamic window-size: // From the paper: patch size $ S_p(d) $ of the d-th regressor is $ S_p(d) = S_f / ( K * (1 + e^(d-D)) ) $ // D = numCascades (e.g. D=5, d goes from 1 to 5 (Matlab convention)) // K = fixed value for shrinking // S_f = the size of the face estimated from the previous updated shape s^(d-1). // For S_f, can use the IED, EMD, or max(IED, EMD). We use the EMD. dynamicFaceSizeDistance = cv::norm(anchor1 - anchor2); double windowSize = dynamicFaceSizeDistance / 2.0; // shrink value double windowSizeHalf = windowSize / 2.0; windowSizeHalf = std::round(windowSizeHalf * (1 / (1 + exp((cascadeStep + 1) - model.getNumCascadeSteps())))); // this is (step - numStages), numStages is 5 and step goes from 1 to 5. Because our step goes from 0 to 4, we add 1. int NUM_CELL = 3; // think about if this should go in the descriptorExtractor or not. Is it Hog specific? int windowSizeHalfi = static_cast<int>(windowSizeHalf) + NUM_CELL - (static_cast<int>(windowSizeHalf) % NUM_CELL); // make sure it's divisible by 3. However, this is not needed and not a good way currentFeatures = model.getDescriptorExtractor(cascadeStep)->getDescriptors(image, points, windowSizeHalfi); } else { // non-adaptive, the descriptorExtractor has all necessary params currentFeatures = model.getDescriptorExtractor(cascadeStep)->getDescriptors(image, points); } currentFeatures = currentFeatures.reshape(0, currentFeatures.cols * model.getNumLandmarks()).t(); //delta_shape = AAM.RF(1).Regressor(hogScale).A(1:end - 1, : )' * feature_current + AAM.RF(1).Regressor(hogScale).A(end,:)'; Mat regressorData = model.getRegressorData(cascadeStep); //Mat deltaShape = regressorData.rowRange(0, regressorData.rows - 1).t() * currentFeatures + regressorData.row(regressorData.rows - 1).t(); Mat deltaShape = currentFeatures * regressorData.rowRange(0, regressorData.rows - 1) + regressorData.row(regressorData.rows - 1); if (true) { // adaptive modelShape = modelShape + deltaShape.t() * dynamicFaceSizeDistance; } else { modelShape = modelShape + deltaShape.t(); } /* for (int i = 0; i < m.getNumLandmarks(); ++i) { cv::circle(landmarksImage, Point2f(modelShape.at<float>(i, 0), modelShape.at<float>(i + m.getNumLandmarks(), 0)), 6 - hogScale, Scalar(51.0f*(float)hogScale, 51.0f*(float)hogScale, 0.0f)); }*/ } return modelShape; };
void Terrain::storePointsTriangles(){ int i,j,k=0; float init_scale_factor = 0.5; int center_factor = (this->side_size-1)/2; for (i=0; i<this->side_size-1; i++){ for (j=0; j<this->side_size-1; j++){ point4 p1 = point4(i-center_factor,j-center_factor,terrain[i][j],1.0); point4 p2 = point4(i-center_factor,j+1-center_factor,terrain[i][j+1],1.0); point4 p3 = point4(i+1-center_factor,j+1-center_factor,terrain[i+1][j+1],1.0); point4 p4 = point4(i+1-center_factor,j-center_factor,terrain[i+1][j],1.0); color4 high = color4(.95f, .95f, .95f, 1.0); // White color4 mid = color4(.05f, .75f, .45f, 1.0); // Green color4 low = color4(.05f, .05f, .95f, 1.0); // Blue color4 brown = color4(0.5f, 0.35f, 0.05f, 1.0); // Brown addTriangle(p1, p2, p3, high, mid, low, brown); addTriangle(p1, p3, p4, high, mid, low, brown); } } }
void TestSnapStrategy::testSquareDistanceToLine() { BoundingBoxSnapStrategy toTestOne; const QPointF lineA(4,1); const QPointF lineB(6,3); const QPointF point(5,8); QPointF pointOnLine(0,0); qreal result = toTestOne.squareDistanceToLine(lineA, lineB, point, pointOnLine); //Should be HUGE_VAL because scalar > diffLength QVERIFY(result == HUGE_VAL); BoundingBoxSnapStrategy toTestTwo; QPointF lineA2(4,4); QPointF lineB2(4,4); QPointF point2(5,8); QPointF pointOnLine2(0,0); qreal result2 = toTestTwo.squareDistanceToLine(lineA2, lineB2, point2, pointOnLine2); //Should be HUGE_VAL because lineA2 == lineB2 QVERIFY(result2 == HUGE_VAL); BoundingBoxSnapStrategy toTestThree; QPointF lineA3(6,4); QPointF lineB3(8,6); QPointF point3(2,2); QPointF pointOnLine3(0,0); qreal result3 = toTestThree.squareDistanceToLine(lineA3, lineB3, point3, pointOnLine3); //Should be HUGE_VAL because scalar < 0.0 QVERIFY(result3 == HUGE_VAL); BoundingBoxSnapStrategy toTestFour; QPointF lineA4(2,2); QPointF lineB4(8,6); QPointF point4(3,4); QPointF pointOnLine4(0,0); QPointF diff(6,4); //diff = lineB3 - point3 = 6,4 //diffLength = sqrt(52) //scalar = (1*(6/sqrt(52)) + 2*(4/sqrt(52))); //pointOnLine = lineA + scalar / diffLength * diff; lineA + ((1*(6/sqrt(52)) + 2*(4/sqrt(52))) / sqrt(52)) * 6,4; QPointF distToPointOnLine = (lineA4 + ((1*(6/sqrt(52.0)) + 2*(4/sqrt(52.0))) / sqrt(52.0)) * diff)-point4; qreal toCompWithFour = distToPointOnLine.x()*distToPointOnLine.x()+distToPointOnLine.y()*distToPointOnLine.y(); qreal result4 = toTestFour.squareDistanceToLine(lineA4, lineB4, point4, pointOnLine4); //Normal case with example data QVERIFY(qFuzzyCompare(result4, toCompWithFour)); }
/* * Gets the (x, y) position on the screen of the given 3D point. * * The coordinates are in the range [0, 1], with the origin in the top left * corner. The x-axis is width of the screen, and y-axis is the height. * * Input: * point: The 3D point whose screen position we want. * camera: The camera we're looking from. * * Output: * screen_x: The x position of the point on the screen. * screen_y: The y position of the point on the screen. */ void VisibilityChecker::GetScreenPosition(const Ogre::Vector3& point, float* screen_x, float* screen_y) { // This projection returns x and y in the range of [-1, 1]. The (-1, -1) point // is in the bottom left corner. Ogre::Vector4 point4(point.x, point.y, point.z, 1); Ogre::Vector4 projected = camera_->getProjectionMatrix() * camera_->getViewMatrix() * point4; projected = projected / projected.w; *screen_x = (projected.x + 1) / 2; *screen_y = (1 - projected.y) / 2; }
void Terrain::storePointsLines(){ int i,j,k=0; float init_scale_factor = 0.5; int center_factor = (this->side_size-1)/2; for (i=0; i<this->side_size; i++){ for (j=0; j<this->side_size-1; j++){ // Y Line points[k] = point4(i-center_factor,j-center_factor,terrain[i][j],1.0); colors[k++] = color4(1.0, 1.0, 1.0, 1.0); // White points[k] = point4(i-center_factor,j+1-center_factor,terrain[i][j+1],1.0); colors[k++] = color4(1.0, 1.0, 1.0, 1.0); // White // X Line if (i < this->side_size-1){ points[k] = point4(i-center_factor,j-center_factor,terrain[i][j],1.0); colors[k++] = color4(1.0, 1.0, 1.0, 1.0); // White points[k] = point4(i+1-center_factor,j-center_factor,terrain[i+1][j],1.0); colors[k++] = color4(1.0, 1.0, 1.0, 1.0); // White } } // Final X Line if (i < this->side_size-1){ points[k] = point4((i-center_factor),j-center_factor,terrain[i][j],1.0); colors[k++] = color4(1.0, 1.0, 1.0, 1.0); // White points[k] = point4(i+1-center_factor,(j-center_factor),terrain[i+1][j],1.0); colors[k++] = color4(1.0, 1.0, 1.0, 1.0); // White } } this->num_points = k; }
vec4* Geometry::createUnitCube(){ int i = 0; vec4 * vertices = new vec4[8]; vertices[i] = point4( -U_CUBE_C, -U_CUBE_C, U_CUBE_C, 1.0 ); i++; vertices[i] = point4( -U_CUBE_C, U_CUBE_C, U_CUBE_C, 1.0 ); i++; vertices[i] = point4( U_CUBE_C, U_CUBE_C, U_CUBE_C, 1.0 ); i++; vertices[i] = point4( U_CUBE_C, -U_CUBE_C, U_CUBE_C, 1.0 ); i++; vertices[i] = point4( -U_CUBE_C, -U_CUBE_C, -U_CUBE_C, 1.0 ); i++; vertices[i] = point4( -U_CUBE_C, U_CUBE_C, -U_CUBE_C, 1.0 ); i++; vertices[i] = point4( U_CUBE_C, U_CUBE_C, -U_CUBE_C, 1.0 ); i++; vertices[i] = point4( U_CUBE_C, -U_CUBE_C, -U_CUBE_C, 1.0 ); //end return vertices; }
//Begin FanGen void FanGen::generate(const color4& insideColor, const color4& outsideColor) { const float init = M_PI / 4.0; const float theta = M_PI / 9.0; //set vertices elements[0] = MatMath::ORIGIN; for (int i = 1; i < 5; ++i) elements[i] = point4(cos(init + (i - 1) * theta), sin(init + (i - 1) * theta), 0.0, 1.0); //set colors elements[5] = insideColor; elements[6] = outsideColor; //set normals elements[7] = MatMath::zNORM; elements[8] = -MatMath::zNORM; //front points data[0] = elements[0]; for (int i = 1; i < 5; ++i) data[i] = elements[i]; //back points data[5] = elements[0]; for (int i = 1; i < 5; ++i) data[i + 5] = elements[5 - i]; //colors data[10] = data[15] = insideColor; for (int i = 1; i < 5; ++i) { //front data[i + 10] = outsideColor; //back data[i + 15] = outsideColor; } //normals for (int i = 0; i < 5; ++i) { //front data[20 + i] = MatMath::zNORM; //bacl data[25 + i] = -MatMath::zNORM; } //front fan for (int i = 0; i < 3; ++i) { indices[3 * i] = 0; indices[3 * i + 1] = i + 1; indices[3 * i + 2] = i + 2; } //back fan for (int i = 0; i < 3; ++i) { indices[3 * (i + 3)] = 5; indices[3 * (i + 3) + 1] = i + 6; indices[3 * (i + 3) + 2] = i + 7; } }
void WCX_floor::generateAxis(){ // axis x axis_points[0] = point4(0.0,0.0,0.0,1.0); axis_colors[0] = color4(1.0,0.0,0.0,1.0); axis_points[1] = point4(10.0,0.0,0.0,1.0); axis_colors[1] = color4(1.0,0.0,0.0,1.0); axis_points[2] = point4(0.0,0.0,0.0,1.0); axis_colors[2] = color4(1.0,0.0,1.0,1.0); axis_points[3] = point4(0.0,10.0,0.0,1.0); axis_colors[3] = color4(1.0,0.0,1.0,1.0); axis_points[4] = point4(0.0,0.0,0.0,1.0); axis_colors[4] = color4(0.0,0.0,1.0,1.0); axis_points[5] = point4(0.0,0.0,10.0,1.0); axis_colors[5] = color4(0.0,0.0,1.0,1.0); }
void EyeCalibration::createTestData() { CalibrationPoint point1(20, 5, osg::Vec3(-1.2f, -1.f, 2.f)); calibrationPoints.push_back(point1); CalibrationPoint point2(700, 25, osg::Vec3(1.4f, -1.f, 1.6f)); calibrationPoints.push_back(point2); CalibrationPoint point3(-10, 520, osg::Vec3(-0.8f, -1.f, -1.4f)); calibrationPoints.push_back(point3); CalibrationPoint point4(730, 542, osg::Vec3(1.f, -1.f, -1.3f)); calibrationPoints.push_back(point4); }
bool pocketCollision(sphere* sphere1) { float disty =distance(sphere1->currpos, point4(sphere1->currpos.x,2,0,1)); //collision with top wall float distny = distance(sphere1->currpos, point4(sphere1->currpos.x,-2,0,1)); //collision with bottom wall float distx = distance(sphere1->currpos, point4(1,sphere1->currpos.y,0,1)); //collision with right wall float distnx = distance(sphere1->currpos, point4(-1,sphere1->currpos.y,0,1)); //collision with left wall //collision with top wall //top left if((sphere1->currpos.y>1.86) && (sphere1->currpos.x<=-.9)) { return false; } //top right if((sphere1->currpos.y>1.86) && (sphere1->currpos.x>=.9)) { return false; } //left if((sphere1->currpos.x<=-.9) && (sphere1->currpos.y<.1 && sphere1->currpos.y>-.1)) { return false; } //right if((sphere1->currpos.x>=.9) && (sphere1->currpos.y<.1 && sphere1->currpos.y>-.1)) { return false; } //bottom left if((sphere1->currpos.y<-1.86) && (sphere1->currpos.x<=-.88)) { return false; } //bottom right if((sphere1->currpos.y<-1.86) && (sphere1->currpos.x>=.88)) { return false; } return true; }
void poly4::calcCenter4() { int mSize = points4.size(); if (mSize == 0){ std::cout << "Error : poly::calcCenter4() called with empty points4 " << std::endl; exit(1); } center4 = point4(0.,0.,0.,0.); for (int i=0;i<mSize;i++){ center4 += points4[i]; } center4 /= double(mSize); // std::cout << "center = " << center4 << std::endl; }
void MyPrimitive::GenerateCube(float a_mSize, vector3 a_vColor) { //If the size is less than this make it this large if (a_mSize < 0.01f) a_mSize = 0.01f; //Clean up Memory Release(); Init(); float fValue = 0.5f * a_mSize; //3--2 //| | //0--1 vector3 point0(-fValue, -fValue, fValue); //0 vector3 point1(fValue, -fValue, fValue); //1 vector3 point2(fValue, fValue, fValue); //2 vector3 point3(-fValue, fValue, fValue); //3 //7--6 //| | //4--5 vector3 point4(-fValue, -fValue, -fValue); //4 vector3 point5(fValue, -fValue, -fValue); //5 vector3 point6(fValue, fValue, -fValue); //6 vector3 point7(-fValue, fValue, -fValue); //7 //F AddQuad(point0, point1, point3, point2); //B AddQuad(point5, point4, point6, point7); //L AddQuad(point4, point0, point7, point3); //R AddQuad(point1, point5, point2, point6); //U AddQuad(point3, point2, point7, point6); //D AddQuad(point4, point5, point0, point1); //Compile the object in this color and assign it this name CompileObject(a_vColor); }
CubeCreator::CubeCreator(float width, float height, float depth) : index(0) { float hW = width / 2; float hH = height / 2; float hD = depth / 2; vertices[0] = point4(-hW, -hH, hD, 1.0); vertices[1] = point4(-hW, hH, hD, 1.0); vertices[2] = point4(hW, hH, hD, 1.0); vertices[3] = point4(hW, -hH, hD, 1.0); vertices[4] = point4(-hW, -hH, -hD, 1.0); vertices[5] = point4(-hW, hH, -hD, 1.0); vertices[6] = point4(hW, hH, -hD, 1.0); vertices[7] = point4(hW, -hH, -hD, 1.0); colors_[0] = { 0.0f, 0.0f, 0.0f }; colors_[1] = { 0.0f, 0.0f, 1.0f }; colors_[2] = { 0.0f, 1.0f, 0.0f }; colors_[3] = { 0.0f, 1.0f, 1.0f }; colors_[4] = { 1.0f, 0.0f, 0.0f }; colors_[5] = { 1.0f, 0.0f, 1.0f }; colors_[6] = { 1.0f, 1.0f, 0.0f }; colors_[7] = { 1.0f, 1.0f, 1.0f }; //fe::fill(colors_, glm::vec3(1.f)); face_colors_ = { glm::vec3(1.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 1.f), glm::vec3(1.f, 1.f, 0.f), glm::vec3(1.f, 0.f, 0.f), glm::vec3(1.f, 0.f, 1.f), glm::vec3(1.f, 0.f, 0.f), }; fe::fill(face_colors_, glm::vec3(1.f)); quad(1, 0, 3, 2); quad(2, 3, 7, 6); quad(3, 0, 4, 7); quad(6, 5, 1, 2); quad(4, 5, 6, 7); quad(5, 4, 0, 1); }
void MyPrimitive::GenerateCube(float a_fSize, vector3 a_v3Color) { if (a_fSize < 0.01f) a_fSize = 0.01f; Release(); Init(); float fValue = 0.5f * a_fSize; //3--2 //| | //0--1 vector3 point0(-fValue, -fValue, fValue); //0 vector3 point1(fValue, -fValue, fValue); //1 vector3 point2(fValue, fValue, fValue); //2 vector3 point3(-fValue, fValue, fValue); //3 vector3 point4(-fValue, -fValue, -fValue); //4 vector3 point5(fValue, -fValue, -fValue); //5 vector3 point6(fValue, fValue, -fValue); //6 vector3 point7(-fValue, fValue, -fValue); //7 //F AddQuad(point0, point1, point3, point2); //B AddQuad(point5, point4, point6, point7); //L AddQuad(point4, point0, point7, point3); //R AddQuad(point1, point5, point2, point6); //U AddQuad(point3, point2, point7, point6); //D AddQuad(point4, point5, point0, point1); CompileObject(a_v3Color); }
void MyPrimitive::GenerateCylinder(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color) { if (a_nSubdivisions < 3) a_nSubdivisions = 3; if (a_nSubdivisions > 360) a_nSubdivisions = 360; Release(); Init(); //Your code starts here float fValue = 0.5f; //3--2 //| | //0--1 //vector3 point0(-fValue, -fValue, fValue); //0 //vector3 point1(fValue, -fValue, fValue); //1 //vector3 point2(fValue, fValue, fValue); //2 //vector3 point3(-fValue, fValue, fValue); //3 // //AddQuad(point0, point1, point3, point2); vector3 point0(0, 0, 0); vector3 point1(0, a_fHeight, 0); for (int i = 0; i < a_nSubdivisions; i++) { float ang = (2 * PI) / a_nSubdivisions; vector3 point2(a_fRadius*cos(i*ang), 0, a_fRadius*sin(i*ang)); //0 vector3 point3(a_fRadius*cos((i + 1)*ang), 0, a_fRadius*sin((i + 1)*ang)); //3 vector3 point4(a_fRadius*cos(i*ang), a_fHeight, a_fRadius*sin(i*ang)); //0 vector3 point5(a_fRadius*cos((i + 1)*ang), a_fHeight, a_fRadius*sin((i + 1)*ang)); //3 AddQuad(point1, point3, point2, point4); AddQuad(point1, point4, point5, point3); } //Your code ends here CompileObject(a_v3Color); }
/** * @brief Determines if any edge of the polygon intersects with any edge of a branch * @param currLeaf * @return */ bool PolygonSearch::PolygonHasEdgeIntersection(leaf *currLeaf) { Point point1(currLeaf->bounds[0], currLeaf->bounds[2]); /* Bottom Left */ Point point2(currLeaf->bounds[1], currLeaf->bounds[2]); /* Bottom Right */ Point point3(currLeaf->bounds[0], currLeaf->bounds[3]); /* Top Left */ Point point4(currLeaf->bounds[1], currLeaf->bounds[3]); /* Top Right */ unsigned int pointCount = polygonPoints.size(); for (unsigned int i=0; i<pointCount-1; ++i) if (EdgesIntersect(point1, point2, polygonPoints[i], polygonPoints[i+1]) || EdgesIntersect(point1, point3, polygonPoints[i], polygonPoints[i+1]) || EdgesIntersect(point3, point4, polygonPoints[i], polygonPoints[i+1]) || EdgesIntersect(point2, point4, polygonPoints[i], polygonPoints[i+1])) return true; if (EdgesIntersect(point1, point2, polygonPoints[0], polygonPoints[pointCount-1]) || EdgesIntersect(point1, point3, polygonPoints[0], polygonPoints[pointCount-1]) || EdgesIntersect(point3, point4, polygonPoints[0], polygonPoints[pointCount-1]) || EdgesIntersect(point2, point4, polygonPoints[0], polygonPoints[pointCount-1])) return true; return false; }
void Terra::make(){ static vec3 base_colors[] = { vec3( 1.0, 0.0, 0.0 ), vec3( 0.0, 1.0, 0.0 ), vec3( 0.0, 0.0, 1.0 ), vec3( 1.0, 1.0, 0.0 ) }; Index=6; this->points[0] = point4(-x, y,-z, 1.0); this->points[1] = point4( x, y,-z, 1.0); this->points[2] = point4(-x, y, z, 1.0); this->points[3] = point4(-x, y, z, 1.0); this->points[4] = point4( x, y,-z, 1.0); this->points[5] = point4( x, y, z, 1.0); }
Cube::Cube(vec3 pos, vec3 s) { numVertices = 36; quadIndex = 0; position = pos; scale = s; points = new point4[numVertices]; normals = new vec3[numVertices]; diffuse = color4(0.2, 0.2, 0.6, 1.0); ambient = color4(1.0, 1.0, 1.0, 1.0); specular = color4(1.0, 1.0, 1.0, 1.0); shininess = 100.0; vertices = new point4[8]; vertices[0] = point4( -0.5, -0.5, 0.5, 1.0 ); vertices[1] = point4( -0.5, 0.5, 0.5, 1.0 ); vertices[2] = point4( 0.5, 0.5, 0.5, 1.0 ); vertices[3] = point4( 0.5, -0.5, 0.5, 1.0 ); vertices[4] = point4( -0.5, -0.5, -0.5, 1.0 ); vertices[5] = point4( -0.5, 0.5, -0.5, 1.0 ); vertices[6] = point4( 0.5, 0.5, -0.5, 1.0 ); vertices[7] = point4( 0.5, -0.5, -0.5, 1.0 ); vertex_colors = new point4[8]; vertex_colors[0] = color4( 0.0, 0.0, 0.0, 1.0 ); vertex_colors[1] = color4( 1.0, 0.0, 0.0, 1.0 ); vertex_colors[2] = color4( 1.0, 1.0, 0.0, 1.0 ); vertex_colors[3] = color4( 0.0, 1.0, 0.0 , 1.0 ); vertex_colors[4] = color4( 0.0, 0.0, 1.0, 1.0 ); vertex_colors[5] = color4( 1.0, 0.0, 1.0, 1.0 ); vertex_colors[6] = color4( 1.0, 1.0, 1.0, 1.0 ); vertex_colors[7] = color4( 0.0, 1.0, 1.0, 1.0 ); colorcube(); setUpShader(); }