bool Polygon::EqualBaseAngles() const { //checks for a pair of equal base angles (isosceles) double angle_1, angle_2; for (unsigned int i=0;i<points.size();i++) { if (i==points.size()-1) { angle_1 = Angle(points[i],points[0],points[1]); angle_2 = Angle(points[0],points[1],points[2]); } else if (i==points.size()-2) { angle_1 = Angle(points[i],points[i+1],points[0]); angle_2 = Angle(points[i+1],points[0],points[1]); } else if (i==points.size()-3) { angle_1 = Angle(points[i],points[i+1],points[i+2]); angle_2 = Angle(points[i+1],points[i+2],points[0]); } else { angle_1 = Angle(points[i],points[i+1],points[i+2]); angle_2 = Angle(points[i+1],points[i+2],points[i+3]); } if (EqualAngles(angle_1,angle_2)) { if (RightAngle(angle_1) and RightAngle(angle_2) and HasAllEqualAngles()) return true; if (AcuteAngle(angle_1) and AcuteAngle(angle_2)) return true; } } return false; }
bool Polygon::HasARightAngle() const { double angle; for (unsigned int i=0;i<points.size();i++) { if (i==points.size()-1) { angle = Angle(points[i], points[0], points[1]); } else if (i==points.size()-2) { angle = Angle(points[i], points[i+1], points[0]); } else { angle = Angle(points[i], points[i+1], points[i+2]); } if (RightAngle(angle)) return true; //foound a right angle } return false; }
void Render(double time) { gl.Clear().ColorBuffer().StencilBuffer(); int border = 20; std::stringstream text; // shape colors GLfloat shape_color_gen_coeffs[9] = { 0.0f, 0.0f, 0.2f, 0.2f, 0.0f, 0.2f, 0.0f, 0.0f, 0.2f }; npr.ColorGen( PathNVColor::Primary, PathNVGenMode::ObjectBoundingBox, PathNVColorFormat::RGB, shape_color_gen_coeffs ); // Shape dsa.ModelviewMatrix() .LoadIdentity() .Translate(64, 64, 0) .Translate(192, 192, 0) .Rotate(RightAngles(time), Vec3f::Unit(2)) .Translate(-192, -192, 0); shape.StencilFill(PathNVFillMode::CountUp, 0xFF); shape.CoverFill(PathNVFillCoverMode::BoundingBox); // text colors GLfloat text_color_gen_coeffs[9] = { -0.3f, 0.0f, 0.3f, 0.0f, 0.2f, 0.6f, 0.3f, 0.0f, 0.0f }; npr.ColorGen( PathNVColor::Primary, PathNVGenMode::ObjectBoundingBox, PathNVColorFormat::RGB, text_color_gen_coeffs ); // Time dsa.ModelviewMatrix() .LoadIdentity() .Translate(border, border, 0); text << "Time: " << std::setw(7) << std::setprecision(2) << std::fixed << time << "[s]"; RenderText(text.str()); text.str(std::string()); // Frame no dsa.ModelviewMatrix() .LoadIdentity() .Translate(tex_side-border, border, 0) .Rotate(RightAngle(), Vec3f::Unit(2)); text << "Frame: " << std::setw(7) << std::fixed << frame_no; RenderText(text.str()); text.str(std::string()); // FPS dsa.ModelviewMatrix() .LoadIdentity() .Translate(tex_side-border, tex_side-border, 0) .Rotate(RightAngles(2), Vec3f::Unit(2)); text << "FPS: "; if(time < 1) text << "<N/A>"; else text << std::setw(7) << std::fixed << frame_no / time; RenderText(text.str()); text.str(std::string()); // title dsa.ModelviewMatrix() .LoadIdentity() .Translate(border, tex_side-border, 0) .Rotate(RightAngles(3), Vec3f::Unit(2)); RenderText("OpenGL"); // sync thread_ready.Signal(); parent_ready.Wait(); ++frame_no; }
Mat4f RayMatrix(const AppData& app_data, unsigned face) { Vec3f cx, cy, cz; switch(face) { case 0: // +X { cx = +Vec3f::Unit(2); cy = +Vec3f::Unit(1); cz = -Vec3f::Unit(0); break; } case 1: // -X { cx = -Vec3f::Unit(2); cy = +Vec3f::Unit(1); cz = +Vec3f::Unit(0); break; } case 2: // +Y { cx = -Vec3f::Unit(0); cy = +Vec3f::Unit(2); cz = +Vec3f::Unit(1); break; } case 3: // -Y { cx = -Vec3f::Unit(0); cy = -Vec3f::Unit(2); cz = -Vec3f::Unit(1); break; } case 4: // +Z { cx = -Vec3f::Unit(0); cy = +Vec3f::Unit(1); cz = -Vec3f::Unit(2); break; } case 5: // -Z { cx = +Vec3f::Unit(0); cy = +Vec3f::Unit(1); cz = +Vec3f::Unit(2); break; } default: OGLPLUS_ABORT("Invalid cube face"); } return CamMatrixf::PerspectiveX( RightAngle(), 1, app_data.cam_near, app_data.cam_far )* Mat4f( Vec4f(cx, 0), Vec4f(cy, 0), Vec4f(cz, 0), Vec4f::Unit(3) ); }