void ColorTest::fromHue() { CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f), 1.0f, 1.0f), Color3(255, 0, 182)); }
void RigidMatrixTransformation2DTest::setTransformation() { Object2D o; /* Can't transform with non-rigid transformation */ std::ostringstream out; Error::setOutput(&out); o.setTransformation(Matrix3::scaling(Vector2(3.0f))); CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation\n"); /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); o.setTransformation(Matrix3::rotation(Deg(17.0f))); CORRADE_VERIFY(o.isDirty()); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); /* Scene cannot be transformed */ Scene2D s; s.setClean(); s.setTransformation(Matrix3::rotation(Deg(17.0f))); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); }
void DualComplexTransformationTest::setTransformation() { Object2D o; /* Can't transform with non-rigid transformation */ std::ostringstream out; Error::setOutput(&out); o.setTransformation(DualComplex({1.0f, 2.0f}, {})); CORRADE_COMPARE(out.str(), "SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized\n"); /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); o.setTransformation(DualComplex::rotation(Deg(17.0f))); CORRADE_VERIFY(o.isDirty()); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); /* Scene cannot be transformed */ Scene2D s; s.setClean(); s.setTransformation(DualComplex::rotation(Deg(17.0f))); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); }
CubeMapExample::CubeMapExample(const Arguments& arguments): Platform::Application(arguments, Configuration().setTitle("Magnum Cube Map Example")) { MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::invalidate_subdata); Renderer::setFeature(Renderer::Feature::DepthTest, true); Renderer::setFeature(Renderer::Feature::FaceCulling, true); /* Set up perspective camera */ (cameraObject = new Object3D(&scene)) ->translate(Vector3::zAxis(3.0f)); (camera = new SceneGraph::Camera3D(*cameraObject)) ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend) .setPerspective(Deg(55.0f), 1.0f, 0.001f, 100.0f) .setViewport(defaultFramebuffer.viewport().size()); /* Load TGA importer plugin */ PluginManager::Manager<Trade::AbstractImporter> manager(MAGNUM_PLUGINS_IMPORTER_DIR); if(!(manager.load("JpegImporter") & PluginManager::LoadState::Loaded)) std::exit(1); resourceManager.set<Trade::AbstractImporter>("jpeg-importer", manager.instance("JpegImporter").release(), ResourceDataState::Final, ResourcePolicy::Manual); /* Add objects to scene */ (new CubeMap(arguments.argc == 2 ? arguments.argv[1] : "", &scene, &drawables)) ->scale(Vector3(20.0f)); (new Reflector(&scene, &drawables)) ->scale(Vector3(0.5f)) .translate(Vector3::xAxis(-0.5f)); (new Reflector(&scene, &drawables)) ->scale(Vector3(0.3f)) .rotate(Deg(37.0f), Vector3::xAxis()) .translate(Vector3::xAxis(0.3f)); /* We don't need the importer anymore */ resourceManager.free<Trade::AbstractImporter>(); }
void DualQuaternionTransformationTest::setTransformation() { Object3D o; /* Can't transform with non-rigid transformation */ std::ostringstream out; Error redirectError{&out}; o.setTransformation(DualQuaternion({{1.0f, 2.0f, 3.0f}, 4.0f}, {})); CORRADE_COMPARE(out.str(), "SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized\n"); /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); CORRADE_VERIFY(o.isDirty()); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); /* Scene cannot be transformed */ Scene3D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); s.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); }
CubeMapExample::CubeMapExample(const Arguments& arguments): Platform::Application(arguments, Configuration().setTitle("Magnum Cube Map Example")) { GL::Renderer::enable(GL::Renderer::Feature::DepthTest); GL::Renderer::enable(GL::Renderer::Feature::FaceCulling); /* Set up perspective camera */ (_cameraObject = new Object3D(&_scene)) ->translate(Vector3::zAxis(3.0f)); (_camera = new SceneGraph::Camera3D(*_cameraObject)) ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend) .setProjectionMatrix(Matrix4::perspectiveProjection(Deg(55.0f), 1.0f, 0.001f, 100.0f)) .setViewport(GL::defaultFramebuffer.viewport().size()); /* Load image importer plugin */ PluginManager::Manager<Trade::AbstractImporter> manager; Containers::Pointer<Trade::AbstractImporter> importer = manager.loadAndInstantiate("JpegImporter"); if(!importer) std::exit(1); _resourceManager.set<Trade::AbstractImporter>("jpeg-importer", importer.release(), ResourceDataState::Final, ResourcePolicy::Manual); /* Add objects to scene */ (new CubeMap(arguments.argc == 2 ? arguments.argv[1] : "", &_scene, &_drawables)) ->scale(Vector3(20.0f)); (new Reflector(&_scene, &_drawables)) ->scale(Vector3(0.5f)) .translate(Vector3::xAxis(-0.5f)); (new Reflector(&_scene, &_drawables)) ->scale(Vector3(0.3f)) .rotate(Deg(37.0f), Vector3::xAxis()) .translate(Vector3::xAxis(0.3f)); /* We don't need the importer anymore */ _resourceManager.free<Trade::AbstractImporter>(); }
void SphereTest::applyTransformation() { Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f); sphere.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::yAxis())); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(3.0f, 2.0f, -1.0f)); CORRADE_COMPARE(sphere.transformedRadius(), 7.0f); /* Symmetric scaling */ sphere.applyTransformationMatrix(Matrix4::scaling(Vector3(2.0f))); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(2.0f, 4.0f, 6.0f)); CORRADE_COMPARE(sphere.transformedRadius(), 14.0f); /* Apply average scaling to radius */ sphere.applyTransformationMatrix(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f})); CORRADE_COMPARE(sphere.transformedRadius(), Constants::sqrt3()*7.0f); }
void CapsuleRendererTest::antiParallel3D() { const Vector3 a(0.5f, 3.0f, 7.0f); const Vector3 b(0.5f, 3.0f, 3.0f); std::array<Matrix4, 3> transformation = Implementation::capsuleRendererTransformation<3>(a, b, 3.5f); const auto rotation = Matrix4::rotationX(-Deg(90.0f)); const auto rotationScaling = (rotation*Matrix4::scaling(Vector3(3.5f))).rotationScaling(); CORRADE_COMPARE(transformation[0].rotationScaling(), rotationScaling); CORRADE_COMPARE(transformation[1].rotationScaling(), (rotation*Matrix4::scaling({3.5f, 2.0f, 3.5f})).rotationScaling()); CORRADE_COMPARE(transformation[2].rotationScaling(), rotationScaling); const auto capDistance = Vector3::zAxis(-3.5f); CORRADE_COMPARE(transformation[0].translation(), a+capDistance); CORRADE_COMPARE(transformation[1].translation(), a+Vector3::zAxis(-2.0f)); CORRADE_COMPARE(transformation[2].translation(), b-capDistance); }
void ListenerTest::testUpdateGroups() { Scene3D scene; Object3D sourceObject{&scene}; Object3D object{&scene}; PlayableGroup3D group; Playable3D playable{sourceObject, &group}; Listener3D listener{object}; constexpr Vector3 offset{6.0f, 2.0f, -2.0f}; object.rotateY(Deg(90.0f)); object.translate(offset); sourceObject.translate(offset*13.0f); listener.update({group}); CORRADE_COMPARE(Renderer::listenerPosition(), offset); constexpr Vector3 rotatedFwd{-1.0f, 0.0f, 0.0f}; CORRADE_COMPARE(Renderer::listenerOrientation()[0], rotatedFwd); CORRADE_COMPARE(playable.source().position(), offset*13.0f); }
void ColorTest::fromValue() { CORRADE_COMPARE(Color3::fromHSV(Deg(0.0f), 1.0f, 0.522f), Color3(133, 0, 0)); }
void LineTest::transformed() { const auto line = Shapes::Line3D({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}) .transformed(Matrix4::rotation(Deg(90.0f), Vector3::zAxis())); CORRADE_COMPARE(line.a(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(line.b(), Vector3(2.0f, -1.0f, -3.0f)); }
void DualQuaternionTransformationTest::compose() { DualQuaternion parent = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis()); DualQuaternion child = DualQuaternion::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(Implementation::Transformation<DualQuaternionTransformation>::compose(parent, child), parent*child); }
void DualQuaternionTransformationTest::inverted() { DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(Implementation::Transformation<DualQuaternionTransformation>::inverted(q)*q, DualQuaternion()); }
void DualComplexTransformationTest::inverted() { DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); CORRADE_COMPARE(Implementation::Transformation<DualComplexTransformation>::inverted(c)*c, DualComplex()); }
void ColorTest::hsvAlpha() { CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(Deg(230.0f), 0.749f, 0.427f), 23), Color4(27, 40, 108, 23)); CORRADE_COMPARE(Color4::fromHSV(Deg(230.0f), 0.749f, 0.427f, 23), Color4(27, 40, 108, 23)); }
void DL_Jww::CreateEnko(DL_CreationInterface* creationInterface, CDataEnko& DEnko) { string lName = HEX[DEnko.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DEnko.m_nGLayer] + "-" + HEX[DEnko.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DEnko.m_nLayer]; // add layer creationInterface->addLayer(DL_LayerData(lName,0)); int width; if(DEnko.m_nPenWidth > 26) width = 0; else width = DEnko.m_nPenWidth; int color = colTable[DEnko.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DEnko.m_nPenColor]; attrib = DL_Attributes(values[8], // layer color, // color width, // width lTable[DEnko.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DEnko.m_nPenStyle]); // linetype creationInterface->setAttributes(attrib); creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 ); double angle1, angle2; //正円 if(DEnko.m_bZenEnFlg){ if(DEnko.m_dHenpeiRitsu == 1.0){ DL_CircleData d(DEnko.m_start.x, DEnko.m_start.y, 0.0, DEnko.m_dHankei); creationInterface->addCircle(d); }else{ double angle1, angle2; if(DEnko.m_radEnkoKaku > 0.0){ angle1 = DEnko.m_radKaishiKaku; angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku; }else{ angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku; angle2 = DEnko.m_radKaishiKaku; } angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0; angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0; if( angle2 <= angle1 ) angle1 = angle1 - M_PI * 2.0; //楕円 DL_EllipseData d(DEnko.m_start.x, DEnko.m_start.y, 0.0, DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku), 0.0, DEnko.m_dHenpeiRitsu, angle1, angle2); creationInterface->addEllipse(d); } }else{ if(DEnko.m_dHenpeiRitsu == 1.0){ //円弧 if(DEnko.m_radEnkoKaku > 0.0){ angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku; angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku; }else{ angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku; angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku; } angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0; angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0; if( angle2 <= angle1 ) angle1 = angle1 - M_PI * 2.0; DL_ArcData d(DEnko.m_start.x, DEnko.m_start.y, 0.0, DEnko.m_dHankei, Deg(angle1), Deg(angle2)); creationInterface->addArc(d); }else{ double angle1, angle2; if(DEnko.m_radEnkoKaku > 0.0){ angle1 = DEnko.m_radKaishiKaku; angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku; }else{ angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku; angle2 = DEnko.m_radKaishiKaku; } angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0; angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0; if( angle2 <= angle1 ) angle1 = angle1 - M_PI * 2.0; //楕円 DL_EllipseData d(DEnko.m_start.x, DEnko.m_start.y, 0.0, DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku), 0.0, DEnko.m_dHenpeiRitsu, angle1, angle2); creationInterface->addEllipse(d); } } #ifdef FINISHED RS_CircleData data1(RS_Vector(0.0, 0.0), 0.0); RS_Circle* circle; RS_ArcData arc_data(RS_Vector(0.0, 0.0), 0.0, 0.0, 0.0, false); RS_Arc* arc; RS_Ellipse* elps; //正円 if(DEnko.m_bZenEnFlg){ if(DEnko.m_dHenpeiRitsu == 1.0){ data1.center = RS_Vector(DEnko.m_start.x, DEnko.m_start.y); data1.radius = DEnko.m_dHankei; circle = new RS_Circle(graphic, data1); RS2::LineType ltype = lTable[DEnko.m_nPenStyle]; RS_Color col = colTable[DEnko.m_nPenColor]; RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12 circle->setPen(RS_Pen(col, lw, ltype)); RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" + HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer]; if( graphic->findLayer(lName) == (RS_Layer*)NULL ){ #ifdef DEBUG std::cout << lName.ascii() << std::endl; #endif RS_Layer* layer = new RS_Layer(lName); graphic->addLayer(layer); } circle->setLayer(lName); // add the line to the graphic graphic->addEntity(circle); #ifdef DEBUG std::cout << *circle; #endif }else{ //楕円 double angle1, angle2; if(DEnko.m_radEnkoKaku > 0.0){ angle1 = DEnko.m_radKaishiKaku; angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku; }else{ angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku; angle2 = DEnko.m_radKaishiKaku; } angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0; angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0; if( angle2 <= angle1 ) angle1 = angle1 - M_PI * 2.0; RS_EllipseData elps_data(RS_Vector(DEnko.m_start.x, DEnko.m_start.y), RS_Vector(DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku)), DEnko.m_dHenpeiRitsu, angle1, angle2, false); elps = new RS_Ellipse(graphic, elps_data); RS2::LineType ltype = lTable[DEnko.m_nPenStyle]; RS_Color col = colTable[DEnko.m_nPenColor]; RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12 elps->setPen(RS_Pen(col, lw, ltype)); RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" + HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer]; if( graphic->findLayer(lName) == (RS_Layer*)NULL ){ RS_Layer* layer = new RS_Layer(lName); graphic->addLayer(layer); } elps->setLayer(lName); // add the line to the graphic graphic->addEntity(elps); } }else{ //円弧 arc_data.center = RS_Vector(DEnko.m_start.x, DEnko.m_start.y); arc_data.radius = DEnko.m_dHankei; if(DEnko.m_radEnkoKaku > 0.0){ arc_data.angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku; arc_data.angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku; }else{ arc_data.angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku; arc_data.angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku; } if( arc_data.angle2 <= arc_data.angle1 ) arc_data.angle1 = arc_data.angle1 - M_PI * 2.0; arc_data.angle1 = Deg(arc_data.angle1); arc_data.angle2 = Deg(arc_data.angle2); arc_data.reversed = false; arc = new RS_Arc(graphic, arc_data); RS2::LineType ltype = lTable[DEnko.m_nPenStyle]; RS_Color col = colTable[DEnko.m_nPenColor]; RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12 arc->setPen(RS_Pen(col, lw, ltype)); RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" + HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer]; if( graphic->findLayer(lName) == (RS_Layer*)NULL ){ #ifdef DEBUG std::cout << lName.ascii() << std::endl; #endif RS_Layer* layer = new RS_Layer(lName); graphic->addLayer(layer); } arc->setLayer(lName); // add the line to the graphic graphic->addEntity(arc); } #endif }
void DualComplexTransformationTest::toMatrix() { DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(Implementation::Transformation<DualComplexTransformation>::toMatrix(c), m); }
double Tracker::getRotation(){ return Deg(getTransformation().angle()); }
void ColorTest::hsvOverflow() { CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f-360.0f), 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f-360.0f), 1.0f, 1.0f), Color3(144, 255, 0)); CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f-360.0f), 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f-360.0f), 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f-360.0f), 1.0f, 1.0f), Color3(123, 0, 255)); CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f-360.0f), 1.0f, 1.0f), Color3(255, 0, 182)); CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+317.0f), 1.0f, 1.0f), Color3(255, 0, 182)); }
bool RotationInstance::ExecuteOn( View& view ) { if ( !view.IsMainView() ) return false; // should never reach this point! AutoViewLock lock( view ); ImageVariant image = view.Image(); if ( image.IsComplexSample() ) return false; double degrees = Round( Deg( p_angle ), 4 ); if ( degrees == 0 ) { Console().WriteLn( "<end><cbr><* Identity *>" ); return true; } ImageWindow window = view.Window(); window.RemoveMaskReferences(); window.RemoveMask(); window.DeletePreviews(); Console().EnableAbort(); StandardStatus status; image.SetStatusCallback( &status ); if ( p_optimizeFast ) switch ( TruncI( degrees ) ) { case 90: Rotate90CCW() >> image; return true; case -90: Rotate90CW() >> image; return true; case 180: case -180: Rotate180() >> image; return true; default: break; } AutoPointer<PixelInterpolation> interpolation( NewInterpolation( p_interpolation, 1, 1, 1, 1, true, p_clampingThreshold, p_smoothness, image ) ); Rotation T( *interpolation, p_angle ); /* * On 32-bit systems, make sure the resulting image requires less than 4 GB. */ if ( sizeof( void* ) == sizeof( uint32 ) ) { int width = image.Width(), height = image.Height(); T.GetNewSizes( width, height ); uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample(); if ( sz > uint64( uint32_max-256 ) ) throw Error( "Rotation: Invalid operation: Target image dimensions would exceed four gigabytes" ); } T.SetFillValues( p_fillColor ); T >> image; return true; }
MotionBlurExample::MotionBlurExample(const Arguments& arguments): Platform::Application(arguments, Configuration().setTitle("Magnum Motion Blur Example")) { (cameraObject = new Object3D(&scene)) ->translate(Vector3::zAxis(3.0f)); (camera = new MotionBlurCamera(*cameraObject)) ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend) .setProjectionMatrix(Matrix4::perspectiveProjection(Deg(35.0f), 1.0f, 0.001f, 100)) .setViewport(GL::defaultFramebuffer.viewport().size()); GL::Renderer::setClearColor({0.1f, 0.1f, 0.1f}); GL::Renderer::enable(GL::Renderer::Feature::DepthTest); GL::Renderer::enable(GL::Renderer::Feature::FaceCulling); const Trade::MeshData3D data = Primitives::icosphereSolid(3); buffer.setData(MeshTools::interleave(data.positions(0), data.normals(0)), GL::BufferUsage::StaticDraw); Containers::Array<char> indexData; MeshIndexType indexType; UnsignedInt indexStart, indexEnd; std::tie(indexData, indexType, indexStart, indexEnd) = MeshTools::compressIndices(data.indices()); indexBuffer.setData(indexData, GL::BufferUsage::StaticDraw); mesh.setPrimitive(data.primitive()) .setCount(data.indices().size()) .addVertexBuffer(buffer, 0, Shaders::Phong::Position{}, Shaders::Phong::Normal{}) .setIndexBuffer(indexBuffer, 0, indexType, indexStart, indexEnd); /* Add spheres to the scene */ new Icosphere(&mesh, &shader, {1.0f, 1.0f, 0.0f}, &scene, &drawables); spheres[0] = new Object3D(&scene); (new Icosphere(&mesh, &shader, {1.0f, 0.0f, 0.0f}, spheres[0], &drawables)) ->translate(Vector3::yAxis(0.25f)); (new Icosphere(&mesh, &shader, {1.0f, 0.0f, 0.0f}, spheres[0], &drawables)) ->translate(Vector3::yAxis(0.25f)) .rotateZ(Deg(120.0f)); (new Icosphere(&mesh, &shader, {1.0f, 0.0f, 0.0f}, spheres[0], &drawables)) ->translate(Vector3::yAxis(0.25f)) .rotateZ(Deg(240.0f)); spheres[1] = new Object3D(&scene); (new Icosphere(&mesh, &shader, {0.0f, 1.0f, 0.0f}, spheres[1], &drawables)) ->translate(Vector3::yAxis(0.50f)); (new Icosphere(&mesh, &shader, {0.0f, 1.0f, 0.0f}, spheres[1], &drawables)) ->translate(Vector3::yAxis(0.50f)) .rotateZ(Deg(120.0f)); (new Icosphere(&mesh, &shader, {0.0f, 1.0f, 0.0f}, spheres[1], &drawables)) ->translate(Vector3::yAxis(0.50f)) .rotateZ(Deg(240.0f)); spheres[2] = new Object3D(&scene); (new Icosphere(&mesh, &shader, {0.0f, 0.0f, 1.0f}, spheres[2], &drawables)) ->translate(Vector3::yAxis(0.75f)); (new Icosphere(&mesh, &shader, {0.0f, 0.0f, 1.0f}, spheres[2], &drawables)) ->translate(Vector3::yAxis(0.75f)) .rotateZ(Deg(120.0f)); (new Icosphere(&mesh, &shader, {0.0f, 0.0f, 1.0f}, spheres[2], &drawables)) ->translate(Vector3::yAxis(0.75f)) .rotateZ(Deg(240.0f)); setSwapInterval(16); setMinimalLoopPeriod(40); }
int32_t Direction(SPos& pos1, SPos& pos2){ return Deg(pos2.x - pos1.x, pos2.y - pos1.y); }
Bool SmplMatrixDialog::Command(Int32 id, const BaseContainer& msg) { Bool update_settings = false; if (preview.Command(id, msg)) return true; switch (id) { case GADGET_SMPL_MATRIX_TYPE_POPUP: { Int32 type; preview.ChangedSettings(); // stop running threads before settings are changed type = msg.GetInt32(BFM_ACTION_VALUE); if (settings->emr) { delete_effect_matrix(settings->emr); settings->emr = 0; } settings->type = type; update_settings = true; // indicates changed effect settings break; } case GADGET_SMPL_MATRIX_SLIDER_ANGLE: { Float32 slider_value; slider_value = (Float32)Deg(msg.GetFloat(BFM_ACTION_VALUE)); if (real_time || (msg.GetInt32(BFM_ACTION_INDRAG) == false)) { if (settings->angle != slider_value) { preview.ChangedSettings(); // stop running threads before settings are changed settings->angle = slider_value; update_settings = true; // indicates changed effect settings } } break; } case GADGET_SMPL_MATRIX_SLIDER_MIX: { Float32 slider_value; slider_value = (Float32)msg.GetFloat(BFM_ACTION_VALUE); if (real_time || msg.GetInt32(BFM_ACTION_INDRAG) == false) { if (settings->matrix_opacity != slider_value) { preview.ChangedSettings(); // stop running threads before settings are changed settings->matrix_opacity = slider_value; update_settings = true; // indicates changed effect settings } } break; } case GADGET_SMPL_MATRIX_TEXTURE_MODE: { preview.ChangedSettings(); // stop running threads before settings are changed settings->tile_flags = msg.GetInt32(BFM_ACTION_VALUE) ? TILE_REPEAT_TILING : TILE_REPEAT_BORDER; update_settings = true; break; } case GADGET_SMPL_MATRIX_DOCUMENT_PREVIEW: { document_preview = msg.GetInt32(BFM_ACTION_VALUE); preview.SetDocumentPreview(document_preview); break; } } if (update_settings) { change_effect_matrix(settings, bm); preview.Update(); } return true; }
void DualQuaternionTransformationTest::rotate() { { Object3D o; o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f)) .rotateY(Deg(25.0f)) .rotateZ(Deg(-23.0f)) .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* Matrix4::rotationZ(Deg(-23.0f))* Matrix4::rotationY(Deg(25.0f))* Matrix4::rotationX(Deg(17.0f))* Matrix4::translation({1.0f, -0.3f, 2.3f})); } { Object3D o; o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); o.rotateXLocal(Deg(17.0f)) .rotateYLocal(Deg(25.0f)) .rotateZLocal(Deg(-23.0f)) .rotateLocal(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})* Matrix4::rotationX(Deg(17.0f))* Matrix4::rotationY(Deg(25.0f))* Matrix4::rotationZ(Deg(-23.0f))* Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); } }
void DualComplexTransformationTest::normalizeRotation() { Object2D o; o.setTransformation(DualComplex::rotation(Deg(17.0f))); o.normalizeRotation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); }
void DualQuaternionTransformationTest::normalizeRotation() { Object3D o; o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); o.normalizeRotation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); }
void DualComplexTransformationTest::compose() { DualComplex parent = DualComplex::rotation(Deg(17.0f)); DualComplex child = DualComplex::translation({1.0f, -0.3f}); CORRADE_COMPARE(Implementation::Transformation<DualComplexTransformation>::compose(parent, child), parent*child); }
void DualQuaternionTransformationTest::toMatrix() { DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(Implementation::Transformation<DualQuaternionTransformation>::toMatrix(q), m); }
double MovementTracker::rotation() { return Deg(getTransformation().angle()); }
Camera::Camera(Object3D* parent): Object3D(parent), SceneGraph::Camera3D(*this), _blurred(true), multisampleFramebuffer({{}, defaultFramebuffer.viewport().size()/8}), framebuffer1(multisampleFramebuffer.viewport()), framebuffer2(multisampleFramebuffer.viewport()), blurShaderHorizontal(Shaders::Blur::Direction::Horizontal), blurShaderVertical(Shaders::Blur::Direction::Vertical) { /* Get full screen triangle */ fullScreenTriangleBuffer = SceneResourceManager::instance().get<Buffer>("fullscreentriangle"); fullScreenTriangle = SceneResourceManager::instance().get<Mesh>("fullscreentriangle"); setPerspective(Deg(35.0f), 1.0f, 0.001f, 100.0f); setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); SceneGraph::Camera3D::setViewport(defaultFramebuffer.viewport().size()); /* Decide about multisampling on ES2 */ #ifdef MAGNUM_TARGET_GLES2 if(Context::current()->isExtensionSupported<Extensions::GL::ANGLE::framebuffer_multisample>() || Context::current()->isExtensionSupported<Extensions::GL::NV::framebuffer_multisample>()) { _multisample = true; } else { Debug() << "Neither" << Extensions::GL::ANGLE::framebuffer_multisample::string() << "nor" << Extensions::GL::NV::framebuffer_multisample::string() << "is supported, expect ugly blur :-)"; _multisample = false; } #else _multisample = true; #endif /* Configure depth buffer */ RenderbufferFormat depthFormat = RenderbufferFormat::DepthComponent24; #ifdef MAGNUM_TARGET_GLES2 if(!Context::current()->isExtensionSupported<Extensions::GL::OES::depth24>()) { Debug() << Extensions::GL::OES::depth24::string() << "not supported, fallback to 16bit depth buffer"; depthFormat = RenderbufferFormat::DepthComponent16; } #endif depth.setStorage(depthFormat, multisampleFramebuffer.viewport().size()); framebuffer1.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, depth); framebuffer2.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, depth); /* Configure multisample framebuffer */ if(_multisample) { #ifdef MAGNUM_TARGET_GLES MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::rgb8_rgba8); #endif multisampleColor.setStorageMultisample(16, RenderbufferFormat::RGBA8, multisampleFramebuffer.viewport().size()); multsampleDepth.setStorageMultisample(16, depthFormat, multisampleFramebuffer.viewport().size()); multisampleFramebuffer.attachRenderbuffer(Framebuffer::ColorAttachment(0), multisampleColor); multisampleFramebuffer.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, multsampleDepth); CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(FramebufferTarget::ReadDraw) == Framebuffer::Status::Complete); } /* Configure textures */ TextureFormat internalFormat = TextureFormat::RGB8; #ifdef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported<Extensions::GL::OES::required_internalformat>()) internalFormat = TextureFormat::RGB; #endif texture1.setStorage(1, internalFormat, multisampleFramebuffer.viewport().size()) .setMagnificationFilter(Sampler::Filter::Linear) .setMinificationFilter(Sampler::Filter::Nearest) .setWrapping(Sampler::Wrapping::ClampToEdge); texture2.setStorage(1, internalFormat, multisampleFramebuffer.viewport().size()) .setMagnificationFilter(Sampler::Filter::Linear) .setMinificationFilter(Sampler::Filter::Nearest) .setWrapping(Sampler::Wrapping::ClampToEdge); framebuffer1.attachTexture(Framebuffer::ColorAttachment(0), texture1, 0); framebuffer2.attachTexture(Framebuffer::ColorAttachment(0), texture2, 0); /* Verify that everything is sane */ CORRADE_INTERNAL_ASSERT(framebuffer1.checkStatus(FramebufferTarget::ReadDraw) == Framebuffer::Status::Complete); CORRADE_INTERNAL_ASSERT(framebuffer2.checkStatus(FramebufferTarget::ReadDraw) == Framebuffer::Status::Complete); }