### Convert Screen to Laser Coordinates Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Converts mouse click/drag events into laser coordinates for drawing. Ensure no laser is selected for editing before starting to draw. ```cpp // ofApp.h class ofApp : public ofBaseApp { public: ofxLaser::Manager laserManager; vector polyLines; bool drawingShape = false; }; // ofApp.cpp void ofApp::mousePressed(ofMouseEventArgs& e) { // Only start drawing if no laser is selected for editing if (!laserManager.isAnyLaserSelected()) { polyLines.push_back(ofPolyline()); drawingShape = true; } } ``` ```cpp void ofApp::mouseDragged(ofMouseEventArgs& e) { if (!drawingShape) return; // Convert screen position to laser input coordinates glm::vec2 laserPos = laserManager.screenToLaserInput(e); ofPolyline& poly = polyLines.back(); poly.addVertex((ofPoint)laserPos); } ``` ```cpp void ofApp::mouseReleased(ofMouseEventArgs& e) { if (drawingShape) { ofPolyline& poly = polyLines.back(); poly = poly.getSmoothed(2); // Smooth the drawn line drawingShape = false; } } ``` ```cpp void ofApp::draw() { ofBackground(15, 15, 20); // Draw all user-created polylines for (size_t i = 0; i < polyLines.size(); i++) { laserManager.drawPoly(polyLines[i], ofColor::green, OFXLASER_PROFILE_DEFAULT); } laserManager.send(); laserManager.drawUI(); } ``` ```cpp void ofApp::keyPressed(ofKeyEventArgs& e) { if (e.key == 'c') { polyLines.clear(); // Clear all drawings } } ``` -------------------------------- ### Drawing Lines Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Functions for drawing lines to the laser. Supports different input formats for start and end points. ```APIDOC ## drawLine(start, end, colour, profile) ### Description Draws a line to the laser(s). ### Method Not applicable (function call) ### Parameters #### Path Parameters - **start** (*glm::vec2, glm::vec3 or ofPoint*) - Required - The start position of the line. - **end** (*glm::vec2, glm::vec3 or ofPoint*) - Required - The end position of the line. - **colour** (*ofColor*) - Required - The colour of the line. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ## drawLine(x1, y1, x2, y2, colour, profile) ### Description As above but with separate float values for the start and end coordinates of the line. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **x1** (*float*) - Required - The x-coordinate of the start point. - **y1** (*float*) - Required - The y-coordinate of the start point. - **x2** (*float*) - Required - The x-coordinate of the end point. - **y2** (*float*) - Required - The y-coordinate of the end point. - **colour** (*ofColor*) - Required - The colour of the line. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ``` -------------------------------- ### Initialize ofxLaser Manager Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt The ofxLaser::Manager singleton handles laser operations. Call update() every frame and send() after drawing is complete. ```cpp // ofApp.h #pragma once #include "ofMain.h" #include "ofxLaserManager.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); ofxLaser::Manager laser; }; // ofApp.cpp void ofApp::setup() { // Optional: change canvas size from default 800x800 laser.setCanvasSize(1024, 768); } void ofApp::update() { // Must be called every frame before drawing laser.update(); } void ofApp::draw() { ofBackground(15, 15, 20); // Draw laser graphics here... // Send points to DAC after all drawing is complete laser.send(); // Draw the laser UI for configuration laser.drawUI(); } ``` -------------------------------- ### Adding Custom Parameters to GUI Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Integrate application-specific controls into the built-in ImGui-based laser configuration panel. ```cpp // ofApp.h class ofApp : public ofBaseApp { public: ofxLaser::Manager laserManager; ofParameter currentEffect; ofParameter animationSpeed; ofParameter effectColor; ofParameter renderProfileLabel; ofParameter renderProfileIndex; }; // ofApp.cpp void ofApp::setup() { laserManager.setCanvasSize(800, 800); // Add custom parameters to the laser GUI laserManager.addCustomParameter(renderProfileLabel); laserManager.addCustomParameter(renderProfileIndex.set("Render Profile", 0, 0, 2)); laserManager.addCustomParameter(currentEffect.set("Current effect", 0, 0, 8)); laserManager.addCustomParameter(animationSpeed.set("Animation speed", 1, 0, 2)); laserManager.addCustomParameter(effectColor.set("Color", ofColor(0, 255, 0), ofColor(0), ofColor(255))); // Add description text ofParameter description; description.setName("description"); description.set("INSTRUCTIONS:\nTAB to toggle laser selector\nLeft/Right arrows to change effect"); laserManager.addCustomParameter(description); } void ofApp::draw() { ofBackground(15, 15, 20); // Select render profile based on parameter string renderProfile; switch (renderProfileIndex) { case 0: renderProfile = OFXLASER_PROFILE_DEFAULT; break; case 1: renderProfile = OFXLASER_PROFILE_DETAIL; break; case 2: renderProfile = OFXLASER_PROFILE_FAST; break; } renderProfileLabel = "Profile: " + renderProfile; // Draw based on selected effect... laser.drawCircle(400, 400, 100, effectColor, renderProfile); laserManager.send(); laserManager.drawUI(); } ``` -------------------------------- ### Update ofxLaser Manager Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Call this in ofApp::update() to update the system and prepare it to receive new laser graphics. ```cpp ofxLaser::Manager::update() ``` -------------------------------- ### Draw Laser UI Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Call this in ofApp::draw() to display the laser UI system. ```cpp ofxLaser::Manager::drawUI() ``` -------------------------------- ### Load and Render SVG Graphics Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Use the ofxLaser::Graphic class to load, optimize, and render SVG files. ```cpp // ofApp.h #include "ofxLaserManager.h" class ofApp : public ofBaseApp { public: ofxLaser::Manager laserManager; vector laserGraphics; int currentSVG = 0; }; // ofApp.cpp void ofApp::setup() { // Load SVG files into Graphic objects ofDirectory dir("svgs/"); dir.allowExt("svg"); dir.listDir(); const vector& files = dir.getFiles(); for (int i = 0; i < files.size(); i++) { laserGraphics.emplace_back(); // addSvgFromFile(filename, optimise, subtractFills) laserGraphics.back().addSvgFromFile(files.at(i).getAbsolutePath(), false, true); // Center the graphic laserGraphics.back().autoCentre(); } } void ofApp::update() { laserManager.update(); } void ofApp::draw() { ofBackground(15, 15, 20); laserManager.beginDraw(); ofPushMatrix(); ofTranslate(400, 400); ofScale(1.5, 1.5); // Rotate SVG in 3D float angle = fmod(ofGetElapsedTimef() * 30, 180) - 90; ofRotateYDeg(angle); // Draw the laser graphic with brightness and profile laserManager.drawLaserGraphic(laserGraphics[currentSVG], 1.0f, OFXLASER_PROFILE_DETAIL); ofPopMatrix(); laserManager.endDraw(); laserManager.send(); laserManager.drawUI(); } ``` -------------------------------- ### Send Laser Graphics Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Call this in ofApp::draw() after all ofxLaser draw methods to send the prepared graphics to the lasers. ```cpp ofxLaser::Manager::send() ``` -------------------------------- ### Using ofxLaser Render Profiles Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Utilizes built-in render profiles (DEFAULT, FAST, DETAIL) to control laser speed and accuracy. Profiles can be edited via the UI. Drawing without specifying a profile defaults to OFXLASER_PROFILE_DEFAULT. ```cpp // Available render profile constants // OFXLASER_PROFILE_DEFAULT - balanced speed and accuracy // OFXLASER_PROFILE_FAST - smooth lines, less dwelling on corners // OFXLASER_PROFILE_DETAIL - intricate work, may cause flicker void ofApp::draw() { ofBackground(15, 15, 20); // Use DEFAULT for most general drawing laser.drawCircle(200, 400, 80, ofColor::white, OFXLASER_PROFILE_DEFAULT); // Use FAST for smooth continuous motion laser.drawLine(300, 200, 500, 200, ofColor::cyan, OFXLASER_PROFILE_FAST); // Use DETAIL for intricate SVG graphics laser.drawLaserGraphic(complexSvgGraphic, 1.0f, OFXLASER_PROFILE_DETAIL); // Drawing without profile uses DEFAULT laser.drawDot(400, 400, ofColor::red); // Access render profile on specific laser ofxLaser::Laser& laserUnit = laser.getLaser(0); ofxLaser::RenderProfile& profile = laserUnit.getRenderProfile(OFXLASER_PROFILE_DEFAULT); // Profile parameters: speed, acceleration, cornerThreshold, dotMaxPoints laser.send(); laser.drawUI(); } ``` -------------------------------- ### 3D Drawing with beginDraw and endDraw Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Wrap draw calls in beginDraw and endDraw to enable correct 3D perspective and transformations. ```cpp void ofApp::draw() { ofBackground(15, 15, 20); // Required for proper 3D perspective handling laser.beginDraw(); float speed = 20; ofPushMatrix(); ofTranslate(400, 400); ofRotateYDeg(ofGetElapsedTimef() * speed); int hue = (int)(ofGetElapsedTimef() * 32) % 255; ofColor c; c.setHsb(hue, 255, 255); // Draw a 3D rotating cube ofPolyline poly; for (int j = 0; j < 4; j++) { poly.clear(); ofPushMatrix(); ofRotateXDeg(j * 90); poly.addVertex(glm::vec3(100, -100, 100)); poly.addVertex(glm::vec3(100, 100, 100)); poly.addVertex(glm::vec3(-100, 100, 100)); poly.addVertex(glm::vec3(-100, -100, 100)); laser.drawPoly(poly, c, OFXLASER_PROFILE_DEFAULT); ofPopMatrix(); } ofPopMatrix(); laser.endDraw(); laser.send(); laser.drawUI(); } ``` -------------------------------- ### Draw Circles with ofxLaser Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Render circles using coordinates or point objects, with support for custom profiles and animation. ```cpp void ofApp::draw() { ofBackground(15, 15, 20); // Draw circle using x, y coordinates laser.drawCircle(400, 300, 100, ofColor::white); // Draw circle using glm::vec2 center point laser.drawCircle(glm::vec2(200, 500), 50, ofColor::cyan); // Draw circle with FAST profile laser.drawCircle(600, 500, 75, ofColor(0, 50, 255), OFXLASER_PROFILE_FAST); // Draw multiple animated circles int numCircles = 4; float elapsed = ofGetElapsedTimef(); for (int i = 0; i < numCircles; i++) { float progress = (float)i / (float)(numCircles - 1); float xpos = 100 + (600 * progress) + (sin(elapsed * 4 + i * 0.5) * 40); ofColor c; c.setHsb(progress * 255, 255, 255); laser.drawCircle(ofPoint(xpos, 600), 30, c, OFXLASER_PROFILE_FAST); } laser.send(); laser.drawUI(); } ``` -------------------------------- ### Draw Polylines with ofxLaser Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Render ofPolyline objects with support for matrix transformations and custom colors. ```cpp void ofApp::draw() { ofBackground(15, 15, 20); // Create a simple polyline ofPolyline poly; poly.addVertex(100, 100); poly.addVertex(200, 50); poly.addVertex(300, 100); poly.addVertex(250, 200); poly.addVertex(150, 200); poly.close(); laser.drawPoly(poly, ofColor::green, OFXLASER_PROFILE_DEFAULT); // Create a star polyline with transformation ofPolyline starPoly; int numSides = 4; float angle = 360.0f / (float)numSides / 2.0f; for (int i = 0; i <= numSides; i++) { starPoly.rotateDeg(angle, glm::vec3(0, 0, 1)); starPoly.addVertex(-100, 0); if (i == numSides) continue; starPoly.rotateDeg(angle, glm::vec3(0, 0, 1)); starPoly.addVertex(-30, 0); } // Draw with 3D rotation transformation ofPushMatrix(); ofTranslate(500, 400); ofRotateYRad(ofGetElapsedTimef()); // 3D rotation around Y axis laser.drawPoly(starPoly, ofColor::magenta, OFXLASER_PROFILE_DEFAULT); ofPopMatrix(); laser.send(); laser.drawUI(); } ``` -------------------------------- ### Draw Laser Lines Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Use drawLine() to render straight lines. Supports various coordinate types and render profiles like FAST or DETAIL. ```cpp void ofApp::draw() { ofBackground(15, 15, 20); // Draw line using vec2 coordinates laser.drawLine(glm::vec2(100, 100), glm::vec2(700, 100), ofColor::white); // Draw line using separate float values laser.drawLine(100, 200, 700, 200, ofColor::cyan); // Draw line with FAST profile for smooth lines where accuracy matters less laser.drawLine(100, 300, 700, 300, ofColor::yellow, OFXLASER_PROFILE_FAST); // Draw line with DETAIL profile for intricate work (may cause flicker) laser.drawLine(100, 400, 700, 400, ofColor::magenta, OFXLASER_PROFILE_DETAIL); // Draw multiple colored lines int numLines = 7; for (int i = 0; i < numLines; i++) { float progress = (float)i / (float)(numLines - 1); float xpos = 100 + (600 * progress); ofColor c; c.setHsb(progress * 255, 255, 255); laser.drawLine(ofPoint(xpos, 500), ofPoint(xpos, 700), c); } laser.send(); laser.drawUI(); } ``` -------------------------------- ### Managing Multiple Lasers Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Control and monitor multiple laser projectors, including armed states and performance metrics. ```cpp void ofApp::setup() { // Laser discovery and assignment happens automatically via the UI // But you can query and control lasers programmatically } void ofApp::update() { laser.update(); // Get number of connected lasers int numLasers = laser.getNumLasers(); // Access individual lasers for (int i = 0; i < numLasers; i++) { ofxLaser::Laser& laserUnit = laser.getLaser(i); // Get performance stats int pointRate = laser.getLaserPointRate(i); float frameRate = laser.getLaserFrameRate(i); // Check armed state bool armed = laser.isLaserArmed(i); } // Check if all lasers are armed bool allArmed = laser.areAllLasersArmed(); } void ofApp::draw() { ofBackground(15, 15, 20); // Draw graphics (distributed to all active lasers/zones) laser.drawCircle(400, 400, 200, ofColor::white); laser.send(); laser.drawUI(); } void ofApp::keyPressed(ofKeyEventArgs& e) { if (e.key == OF_KEY_TAB) { // Cycle through laser selection laser.selectNextLaser(); } // Select specific laser laser.setSelectedLaser(0); // Arm/disarm all lasers if (e.key == 'a') { laser.armAllLasers(); } if (e.key == 'd') { laser.disarmAllLasers(); } } ``` -------------------------------- ### Set Canvas Size Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Change the default canvas size of 800x800 to a custom width and height. ```cpp ofxLaser::Manager::setCanvasSize(width, height); ``` -------------------------------- ### Draw Laser Dots Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Use drawDot() to render points. Intensity (0-1) controls brightness and dwell time, useful for beam effects. ```cpp void ofApp::draw() { ofBackground(15, 15, 20); // Draw simple dot laser.drawDot(400, 400, ofColor::red); // Draw dot with intensity control (0-1) laser.drawDot(glm::vec2(200, 300), ofColor::green, 0.5f); // Draw dots with varying intensity int numDots = 6; for (int x = 0; x < numDots; x++) { float intensity = (float)(x + 1) / numDots; float xposition = ofMap(x, 0, numDots - 1, 200, 600); laser.drawDot(xposition, 500, ofColor::red, intensity, OFXLASER_PROFILE_FAST); } // Animated particle effect for (int i = 0; i < 30; i++) { ofColor c; c.setHsb(i * 6, 255, 255); ofPoint p; float spread = 0.05f; float elapsed = ofGetElapsedTimef(); p.x = sin((elapsed - ((float)i * spread)) * 1.83f) * 300 + 400; p.y = sin((elapsed - ((float)i * spread)) * 2.71f) * 300 + 400; laser.drawDot(p, c, 1, OFXLASER_PROFILE_FAST); } laser.send(); laser.drawUI(); } ``` -------------------------------- ### Send Raw Laser Points Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Sends raw laser points directly to a specific laser and zone, bypassing shape optimization. Points include position and color information. ```cpp void ofApp::draw() { ofBackground(15, 15, 20); // Create raw laser points std::vector points; // Add points with position and color for (int i = 0; i < 100; i++) { ofxLaser::Point p; float t = (float)i / 99.0f; // Position in normalized -1 to 1 range or laser coordinate space p.x = sin(t * TWO_PI) * 200 + 400; p.y = cos(t * TWO_PI) * 200 + 400; // Set color (0-1 range) p.r = 1.0f; p.g = t; p.b = 0.0f; points.push_back(p); } // Send raw points to laser 0, zone 0 laser.sendRawPoints(points, 0, 0); laser.send(); laser.drawUI(); } ``` -------------------------------- ### Drawing Graphics Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Function for drawing an ofxLaser::Graphic object to the laser. ```APIDOC ## drawLaserGraphic(graphic, brightness, profile) ### Description Draws an ofxLaser::Graphic. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **graphic** (*ofxLaser::Graphic*) - Required - The graphic object to draw. - **brightness** (*float*) - Required - The brightness of the graphic. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ``` -------------------------------- ### Drawing Circles Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Functions for drawing circles to the laser, with options for point or separate coordinates. ```APIDOC ## drawCircle(position, radius, colour, profile) ### Description Draws a circle. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **position** (*glm::vec2, glm::vec3 or ofPoint*) - Required - The position of the circle. - **radius** (*float*) - Required - The radius of the circle. - **colour** (*ofColor*) - Required - The colour of the circle. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ## drawCircle(x, y, radius, colour, profile) ### Description As above but with separate x and y float values. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **x** (*float*) - Required - The x-coordinate of the circle's center. - **y** (*float*) - Required - The y-coordinate of the circle's center. - **radius** (*float*) - Required - The radius of the circle. - **colour** (*ofColor*) - Required - The colour of the circle. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ``` -------------------------------- ### Managing Laser Zones Source: https://context7.com/sebleedelisle/ofxlaser/llms.txt Define and manage canvas areas for laser distribution using automatic or manual modes. ```cpp void ofApp::setup() { // Add custom zones (x, y, width, height) // Default zone is created automatically laser.addZone(0, 0, 400, 400); // Top-left quadrant laser.addZone(400, 0, 400, 400); // Top-right quadrant laser.addZone(0, 400, 400, 400); // Bottom-left quadrant laser.addZone(400, 400, 400, 400); // Bottom-right quadrant // Or using ofRectangle laser.addZone(ofRectangle(200, 200, 400, 400)); // Set zone mode // OFXLASER_ZONE_AUTOMATIC - shapes go to all zones that contain them // OFXLASER_ZONE_MANUAL - manually specify target zone laser.setZoneMode(OFXLASER_ZONE_AUTOMATIC); // For manual mode, set target zone before drawing laser.setTargetZone(0); } void ofApp::draw() { ofBackground(15, 15, 20); // Get zone count and access zones int numZones = laser.getNumZones(); for (int i = 0; i < numZones; i++) { ofxLaser::Zone* zone = laser.getZone(i); // Zone properties available: rect, zoneLabel, shapes } // Check currently selected zone ofxLaser::Zone* selectedZone = laser.getSelectedZone(); // Draw graphics - they will be distributed to zones based on mode laser.drawCircle(200, 200, 50, ofColor::red); laser.drawCircle(600, 600, 50, ofColor::blue); laser.send(); laser.drawUI(); } ``` -------------------------------- ### Drawing Polylines Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Function for drawing an ofPolyline object to the laser. ```APIDOC ## drawPoly(polyline, colour, profile) ### Description Draws an ofPolyline to the laser. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **polyline** (*ofPolyline&*) - Required - The polyline to draw. - **colour** (*ofColor*) - Required - The colour of the polyline. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ``` -------------------------------- ### Drawing Dots Source: https://github.com/sebleedelisle/ofxlaser/blob/main/README.md Functions for drawing dots to the laser, useful for beam effects. Intensity controls brightness and dwell time. ```APIDOC ## drawDot(position, colour, intensity, profile) ### Description Draws a dot to the laser(s). This can also be used to make beam effects. Use the intensity to change the brightness - this changes how long the laser lingers to make the point so is more efficient than darkening the colour. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **position** (*glm::vec2, glm::vec3 or ofPoint*) - Required - The position of the dot. - **colour** (*ofColor*) - Required - The colour of the dot. - **intensity** (*float*) - Optional - A unit value (0-1) defining the brightness of the dot. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ## drawDot(x, y, colour, intensity, profile) ### Description As above but with separate x and y values instead of a point object. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **x** (*float*) - Required - The x-coordinate of the dot. - **y** (*float*) - Required - The y-coordinate of the dot. - **colour** (*ofColor*) - Required - The colour of the dot. - **intensity** (*float*) - Optional - A unit value (0-1) defining the brightness of the dot. - **profile** (*any*) - Optional - The render profile, use one of the profile definitions (defaults to the default profile). ### Response #### Success Response (void) Returns void. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.