diff --git a/examples/Basic/Basic.pde b/examples/Basic/Basic.pde index d5f69dd..54458a1 100644 --- a/examples/Basic/Basic.pde +++ b/examples/Basic/Basic.pde @@ -26,6 +26,29 @@ void draw() { ziviDome.draw(); } +// Forward key events to the library +void keyPressed() { + ziviDome.keyPressed(); + // Optionally call keyPressed of the current scene + if (currentScene != null) { + currentScene.keyPressed(key); + } +} + +// Forward mouse events to the library +void mouseEvent(processing.event.MouseEvent event) { + ziviDome.mouseEvent(event); + // Optionally call mouseEvent of the current scene + if (currentScene != null) { + currentScene.mouseEvent(event); + } +} + +// Forward control events to the library +void controlEvent(controlP5.ControlEvent theEvent) { + ziviDome.controlEvent(theEvent); +} + // Implementation of Scene1 that uses the Scene interface class Scene1 implements Scene { zividomelive parent; @@ -70,31 +93,8 @@ class Scene1 implements Scene { } @Override - public void mouseEvent(int mouseX, int mouseY, int button) { + public void mouseEvent(MouseEvent event) { // Implement mouse event logic, if necessary - println("Mouse event in Scene1: " + mouseX + ", " + mouseY + ", button: " + button); + println("Mouse event in Scene1: " + event.getX() + ", " + event.getY() + ", button: " + event.getButton()); } -} - -// Forward key events to the library -void keyPressed() { - ziviDome.keyPressed(); - // Optionally call keyPressed of the current scene - if (currentScene != null) { - currentScene.keyPressed(key); - } -} - -// Forward mouse events to the library -void mouseEvent(processing.event.MouseEvent event) { - ziviDome.mouseEvent(event); - // Optionally call mouseEvent of the current scene - if (currentScene != null) { - currentScene.mouseEvent(event.getX(), event.getY(), event.getButton()); - } -} - -// Forward control events to the library -void controlEvent(controlP5.ControlEvent theEvent) { - ziviDome.controlEvent(theEvent); } \ No newline at end of file diff --git a/examples/ChangeScene/ChangeScene.pde b/examples/ChangeScene/ChangeScene.pde new file mode 100644 index 0000000..521a9a4 --- /dev/null +++ b/examples/ChangeScene/ChangeScene.pde @@ -0,0 +1,211 @@ +import com.victorvalentim.zividomelive.*; +import controlP5.*; +import codeanticode.syphon.*; +import spout.*; + +// Main instances +zividomelive ziviDome; // Instance of the zividomelive library +Scene currentScene; // Current scene implementing the Scene interface + +void settings() { + size(1280, 720, P3D); // Set the window size and P3D mode +} + +void setup() { + // Initialize the zividomelive library + ziviDome = new zividomelive(this); + ziviDome.setup(); // Initial setup of the library + + // Initialize the first scene and set it in the library + currentScene = new Scene1(ziviDome); + ziviDome.setScene(currentScene); +} + +void draw() { + // Call the draw method of the library for additional rendering + ziviDome.draw(); +} + +// Forward key events to the library and switch scenes +void keyPressed() { + ziviDome.keyPressed(); + if (currentScene != null) { + currentScene.keyPressed(key); + } + switch (key) { + case 'i': + currentScene = new Scene1(ziviDome); + break; + case 'o': + currentScene = new Scene2(ziviDome); + break; + } + ziviDome.setCurrentScene(currentScene); +} + +// Forward mouse events to the library +void mouseEvent(processing.event.MouseEvent event) { + ziviDome.mouseEvent(event); + if (currentScene != null) { + currentScene.mouseEvent(event.getX(), event.getY(), event.getButton()); + } +} + +// Forward control events to the library +void controlEvent(controlP5.ControlEvent theEvent) { + ziviDome.controlEvent(theEvent); +} + +// Implementation of Scene1 that uses the Scene interface +class Scene1 implements Scene { + zividomelive parent; + + Scene1(zividomelive parent) { + this.parent = parent; + } + + + public void setupScene() { + // Specific scene setup, if necessary + println("Scene1 setup completed."); + } + + + public void sceneRender(PGraphics pg) { + pg.ambientLight(128, 128, 128); // Add ambient light + pg.pushMatrix(); + pg.background(0, 0, 80, 0); + pg.ambientLight(128, 128, 128); // Add ambient light + float radius = 700; // Distance from the center + int numPillars = 8; + float angleStep = TWO_PI / numPillars; + int[] colors = {#FF0000, #00FF00, #0000FF, #FFFF00, #FF00FF, #00FFFF, #FFFFFF, #FF8000}; + float time = millis() / 2000.0; // Time in seconds for animation + for (int i = 0; i < numPillars; i++) { + float angle = angleStep * i + time; // Add rotation animation + float x = sin(angle) * radius; + float y = cos(angle) * radius; + pg.pushMatrix(); + pg.translate(x, y, 0); + pg.rotateX(time); // Add rotation on the X axis + pg.fill(colors[i]); + pg.box(200); // Adjust parameters as needed to change the size + pg.popMatrix(); + } + pg.popMatrix(); + } + + + public void keyPressed(char key) { + // Implement key response logic, if necessary + println("Key pressed in Scene1: " + key); + } + + + public void mouseEvent(int mouseX, int mouseY, int button) { + // Implement mouse event logic, if necessary + println("Mouse event in Scene1: " + mouseX + ", " + mouseY + ", button: " + button); + } +} + +// Forward control events to the library +void controlEvent(controlP5.ControlEvent theEvent) { + ziviDome.controlEvent(theEvent); +} + +// Implementation of Scene2 that uses the Scene interface +class Scene2 implements Scene { + zividomelive parent; + + Scene2(zividomelive parent) { + this.parent = parent; + } + + + public void setupScene() { + // Specific scene settings, if necessary + } + + + public void sceneRender(PGraphics pg) { + pg.pushMatrix(); + pg.background(25, 25, 112); + pg.pushMatrix(); + pg.fill(255); + drawLabeledBox(pg, 200); // Draw the cube with labels and mesh + pg.popMatrix(); + pg.popMatrix(); + } + + + public void keyPressed(char key) { + // Implement key response logic, if necessary + } + + + public void mouseEvent(int mouseX, int mouseY, int button) { + // Implement mouse event logic, if necessary + println("Mouse event in Scene2: " + mouseX + ", " + mouseY + ", button: " + button); + } + + void drawLabeledBox(PGraphics pg, float size) { + pg.pushMatrix(); + // Front (+Z) + pg.pushMatrix(); + pg.translate(0, 0, size / 2); + drawFaceWithMesh(pg, size, "+Z Front", pg.color(255, 0, 0)); // Red (Primary) // Purple // Vibrant blue + pg.popMatrix(); + // Back (-Z) + pg.pushMatrix(); + pg.translate(0, 0, -size / 2); + pg.rotateY(PI); // Rotate so the text faces outward + drawFaceWithMesh(pg, size, "-Z Back", pg.color(0, 255, 0)); // Green (Secondary) // Orange // Vibrant green + pg.popMatrix(); + // Right (+X) + pg.pushMatrix(); + pg.translate(size / 2, 0, 0); + pg.rotateY(-HALF_PI); // Rotate so the text faces outward + drawFaceWithMesh(pg, size, "+X Right", pg.color(0, 0, 255)); // Blue (Primary) // Teal // Vibrant red + pg.popMatrix(); + // Left (-X) + pg.pushMatrix(); + pg.translate(-size / 2, 0, 0); + pg.rotateY(HALF_PI); // Rotate so the text faces outward + drawFaceWithMesh(pg, size, "-X Left", pg.color(255, 255, 0)); // Yellow (Secondary) // Olive // Vibrant yellow + pg.popMatrix(); + // Top (+Y) + pg.pushMatrix(); + pg.translate(0, -size / 2, 0); + pg.rotateX(-HALF_PI); // Rotate so the text faces outward + drawFaceWithMesh(pg, size, "+Y Top", pg.color(255, 0, 255)); // Magenta (Secondary) // Indigo // Vibrant magenta + pg.popMatrix(); + // Bottom (-Y) + pg.pushMatrix(); + pg.translate(0, size / 2, 0); + pg.rotateX(HALF_PI); // Rotate so the text faces outward + drawFaceWithMesh(pg, size, "-Y Bottom", pg.color(0, 255, 255)); // Cyan (Secondary) // Deep Pink // Vibrant cyan + pg.popMatrix(); + pg.popMatrix(); + } + + void drawFaceWithMesh(PGraphics pg, float size, String label, int faceColor) { + pg.fill(faceColor); + pg.beginShape(); + pg.vertex(-size / 2, -size / 2, 0); + pg.vertex(size / 2, -size / 2, 0); + pg.vertex(size / 2, size / 2, 0); + pg.vertex(-size / 2, size / 2, 0); + pg.endShape(CLOSE); + pg.stroke(0); + pg.strokeWeight(1); + float step = size / 10.0; + for (float i = -size / 2; i <= size / 2; i += step) { + pg.line(i, -size / 2, 0, i, size / 2, 0); // Vertical lines + pg.line(-size / 2, i, 0, size / 2, i, 0); // Horizontal lines + } + pg.fill(0); + pg.textAlign(CENTER, CENTER); + pg.textSize(30); // Increase font size + pg.text(label, 0, 0, 0); + } +} \ No newline at end of file diff --git a/examples/EmptyProject/EmptyProject b/examples/EmptyProject/EmptyProject new file mode 100644 index 0000000..a10ef4b --- /dev/null +++ b/examples/EmptyProject/EmptyProject @@ -0,0 +1,79 @@ +import com.victorvalentim.zividomelive.*; +import controlP5.*; +import codeanticode.syphon.*; +import spout.*; + +// Main instances +zividomelive ziviDome; // Instance of the zividomelive library +Scene currentScene; // Current scene implementing the Scene interface + +void settings() { + size(1280, 720, P3D); // Set the window size and P3D mode +} + +void setup() { + // Initialize the zividomelive library + ziviDome = new zividomelive(this); + ziviDome.setup(); // Initial setup of the library + + // Initialize the scene and set it in the library + currentScene = new Scene1(ziviDome); + ziviDome.setScene(currentScene); +} + +void draw() { + // Call the draw method of the library for additional rendering + ziviDome.draw(); +} + +// Forward key events to the library +void keyPressed() { + ziviDome.keyPressed(); + // Optionally call keyPressed of the current scene + if (currentScene != null) { + currentScene.keyPressed(key); + } +} + +// Forward mouse events to the library +void mouseEvent(processing.event.MouseEvent event) { + ziviDome.mouseEvent(event); + // Optionally call mouseEvent of the current scene + if (currentScene != null) { + currentScene.mouseEvent(event); + } +} + +// Forward control events to the library +void controlEvent(controlP5.ControlEvent theEvent) { + ziviDome.controlEvent(theEvent); +} + +// Implementation of Scene1 that uses the Scene interface +class Scene1 implements Scene { + zividomelive parent; + + Scene1(zividomelive parent) { + this.parent = parent; + } + + @Override + public void setupScene() { + // Specific scene setup, if necessary + } + + @Override + public void sceneRender(PGraphics pg) { + // Scene rendering logic + } + + @Override + public void keyPressed(char key) { + // Key response logic + } + + @Override + public void mouseEvent(MouseEvent event) { + // Mouse event logic + } +} diff --git a/examples/MouseParticle/MouseParticle.pde b/examples/MouseParticle/MouseParticle.pde new file mode 100644 index 0000000..b797c4c --- /dev/null +++ b/examples/MouseParticle/MouseParticle.pde @@ -0,0 +1,178 @@ +import com.victorvalentim.zividomelive.*; +import controlP5.*; +import codeanticode.syphon.*; +import spout.*; + +// Main instances +zividomelive ziviDome; // Instance of the zividomelive library +Scene currentScene; // Current scene implementing the Scene interface + +void settings() { + size(1280, 720, P3D); // Set the window size and P3D mode +} + +void setup() { + // Initialize the zividomelive library + ziviDome = new zividomelive(this); + ziviDome.setup(); // Initial setup of the library + + // Initialize the scene and set it in the library + currentScene = new Scene1(ziviDome); + ziviDome.setScene(currentScene); +} + +void draw() { + // Call the draw method of the library for additional rendering + ziviDome.draw(); +} + +// Forward key events to the library +void keyPressed() { + ziviDome.keyPressed(); + // Optionally call keyPressed of the current scene + if (currentScene != null) { + currentScene.keyPressed(key); + } +} + +// Forward mouse events to the library +void mouseEvent(processing.event.MouseEvent event) { + ziviDome.mouseEvent(event); + // Optionally call mouseEvent of the current scene + if (currentScene != null) { + currentScene.mouseEvent(event); + } +} + +// Forward control events to the library +void controlEvent(controlP5.ControlEvent theEvent) { + ziviDome.controlEvent(theEvent); +} + +// Implementation of Scene1 that uses the Scene interface +class Scene1 implements Scene { + zividomelive parent; + PGraphics pg; + ArrayList mass; + ArrayList positionX; + ArrayList positionY; + ArrayList positionZ; + ArrayList velocityX; + ArrayList velocityY; + ArrayList velocityZ; + ArrayList birthTime; + + Scene1(zividomelive parent) { + this.parent = parent; + mass = new ArrayList(); + positionX = new ArrayList(); + positionY = new ArrayList(); + positionZ = new ArrayList(); + velocityX = new ArrayList(); + velocityY = new ArrayList(); + velocityZ = new ArrayList(); + birthTime = new ArrayList(); + } + + @Override + public void setupScene() { + noStroke(); + fill(64, 255, 255, 192); // Set fill color for particles + } + + @Override + public void sceneRender(PGraphics pg) { + pg.beginDraw(); + pg.background(32); + pg.noStroke(); + pg.fill(64, 255, 255, 192); // Ensure fill color is applied in PGraphics + + // Ambient light and spotlight + //pg.ambientLight(64, 64, 64); + //pg.pointLight(255, 255, 255, 0, 0, 0); + + pg.translate(0,0,250); + pg.rotateX(-PI/2 * (frameCount*0.01)); + + long currentTime = millis(); + for (int particleA = mass.size() - 1; particleA >= 0; particleA--) { + if (currentTime - birthTime.get(particleA) > 10000) { + // Remove particle if it has existed for more than 10 seconds + mass.remove(particleA); + positionX.remove(particleA); + positionY.remove(particleA); + positionZ.remove(particleA); + velocityX.remove(particleA); + velocityY.remove(particleA); + velocityZ.remove(particleA); + birthTime.remove(particleA); + continue; + } + + float accelerationX = 0; + float accelerationY = 0; + float accelerationZ = 0; + + for (int particleB = 0; particleB < mass.size(); particleB++) { + if (particleA != particleB) { + float distanceX = positionX.get(particleB) - positionX.get(particleA); + float distanceY = positionY.get(particleB) - positionY.get(particleA); + float distanceZ = positionZ.get(particleB) - positionZ.get(particleA); + + float distance = PApplet.sqrt(distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ); + if (distance < 1) distance = 1; + + float force = (distance - 320) * mass.get(particleB) / distance; + accelerationX += force * distanceX; + accelerationY += force * distanceY; + accelerationZ += force * distanceZ; + } + } + + velocityX.set(particleA, velocityX.get(particleA) * 0.99f + accelerationX * mass.get(particleA)); + velocityY.set(particleA, velocityY.get(particleA) * 0.99f + accelerationY * mass.get(particleA)); + velocityZ.set(particleA, velocityZ.get(particleA) * 0.99f + accelerationZ * mass.get(particleA)); + } + + for (int particle = 0; particle < mass.size(); particle++) { + positionX.set(particle, positionX.get(particle) + velocityX.get(particle)); + positionY.set(particle, positionY.get(particle) + velocityY.get(particle)); + positionZ.set(particle, positionZ.get(particle) + velocityZ.get(particle)); + + + + pg.pushMatrix(); + pg.translate(positionX.get(particle), positionY.get(particle), positionZ.get(particle)); + pg.ellipse(0, 0, mass.get(particle) * 1000, mass.get(particle) * 1000); + pg.popMatrix(); + } + + pg.endDraw(); + } + + @Override + public void keyPressed(char key) { + // Key response logic + } + + @Override + public void mouseEvent(MouseEvent event) { + if (event.getAction() == MouseEvent.PRESS || event.getAction() == MouseEvent.DRAG) { + addNewParticle((event.getX())*0.1, (event.getY())*0.1); + } + } + + void addNewParticle(float x, float y) { + if (mass.size() >= 300) { + return; + } + mass.add(random(0.003f, 0.03f)); + positionX.add(x); + positionY.add(y); + positionZ.add(random(-200, 200)); + velocityX.add(0f); + velocityY.add(0f); + velocityZ.add(0f); + birthTime.add(Long.valueOf(millis())); + } +} \ No newline at end of file diff --git a/src/main/java/com/victorvalentim/zividomelive/CubemapRenderer.java b/src/main/java/com/victorvalentim/zividomelive/CubemapRenderer.java index 95635be..2bce06d 100644 --- a/src/main/java/com/victorvalentim/zividomelive/CubemapRenderer.java +++ b/src/main/java/com/victorvalentim/zividomelive/CubemapRenderer.java @@ -60,7 +60,7 @@ void updateResolution(int newResolution) { private void configureCameraForFace(PGraphics pg, CameraOrientation orientation, float pitch, float yaw, float roll) { PVector eye = new PVector(0, 0, 0); pg.camera(eye.x, eye.y, eye.z, orientation.centerX, orientation.centerY, orientation.centerZ, orientation.upX, orientation.upY, orientation.upZ); - pg.perspective(PApplet.PI / 2, 1, 0.1f, 20000); + pg.perspective(PApplet.PI / 2, 1, 10f, 20000); pg.translate(pg.width / 2, pg.height / 2, 0); pg.rotateX(pitch); pg.rotateY(roll); diff --git a/src/main/java/com/victorvalentim/zividomelive/Scene.java b/src/main/java/com/victorvalentim/zividomelive/Scene.java index a8ea056..8478958 100644 --- a/src/main/java/com/victorvalentim/zividomelive/Scene.java +++ b/src/main/java/com/victorvalentim/zividomelive/Scene.java @@ -1,6 +1,7 @@ package com.victorvalentim.zividomelive; import processing.core.PGraphics; +import processing.event.MouseEvent; /** * The Scene interface defines the structure for a scene in the application. @@ -30,9 +31,7 @@ public interface Scene { /** * Handles mouse events. * - * @param mouseX the x-coordinate of the mouse - * @param mouseY the y-coordinate of the mouse - * @param button the mouse button that was pressed + * @param event the MouseEvent object containing details of the mouse event */ - void mouseEvent(int mouseX, int mouseY, int button); + void mouseEvent(MouseEvent event); } \ No newline at end of file diff --git a/src/main/java/com/victorvalentim/zividomelive/StandardRenderer.java b/src/main/java/com/victorvalentim/zividomelive/StandardRenderer.java index 1b21ae6..675afc3 100644 --- a/src/main/java/com/victorvalentim/zividomelive/StandardRenderer.java +++ b/src/main/java/com/victorvalentim/zividomelive/StandardRenderer.java @@ -37,6 +37,14 @@ private void initializeStandardView(int width, int height) { standardView = parent.createGraphics(width, height, PApplet.P3D); } + /** + * Sets the current scene to be rendered. + * @param newScene the new scene to be set as the current scene + */ + public void setCurrentScene(Scene newScene) { + this.currentScene = newScene; + } + /** * Renders the current scene using the standard view PGraphics object. * Updates the camera and applies its settings before rendering the scene. diff --git a/src/main/java/com/victorvalentim/zividomelive/zividomelive.java b/src/main/java/com/victorvalentim/zividomelive/zividomelive.java index 980abe8..67104d6 100644 --- a/src/main/java/com/victorvalentim/zividomelive/zividomelive.java +++ b/src/main/java/com/victorvalentim/zividomelive/zividomelive.java @@ -469,6 +469,9 @@ public void mouseEvent(MouseEvent event) { if (event.getAction() == MouseEvent.WHEEL) { standardRenderer.getCam().mouseWheel(event); } + if (currentScene != null) { + currentScene.mouseEvent(event); + } } /** @@ -686,6 +689,16 @@ public void resetGraphics(int newResolution) { System.out.println("Changing resolution to: " + newResolution); // Imprime a nova resolução no console } + /** + * Sets the current scene to be rendered and updates all relevant components. + * @param newScene the new scene to be set as the current scene + */ + public void setCurrentScene(Scene newScene) { + this.currentScene = newScene; + this.setScene(newScene); // Update the scene in the parent PApplet + standardRenderer.setCurrentScene(newScene); // Update the scene in StandardRenderer + } + /** * Gets the current FisheyeDomemaster instance. * @@ -710,15 +723,35 @@ public void setFisheyeDomemaster(FisheyeDomemaster fisheyeDomemaster) { * @return the current PApplet instance */ public PApplet getPApplet() { + return p; } + /** + * Gets the width of the PApplet window. + * + * @return the width of the PApplet window + */ + public int getWidth() { + return p.width; + } + + /** + * Gets the height of the PApplet window. + * + * @return the height of the PApplet window + */ + public int getHeight() { + return p.height; + } + /** * Checks if the instance is initialized. * * @return true if the instance is initialized, false otherwise */ public boolean isInitialized() { + return initialized; } } \ No newline at end of file