Advertisement
PAXSemperFidelis

Untitled

Apr 19th, 2024
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | Source Code | 0 0
  1. import processing.core.*;
  2. import peasycam.*;
  3.  
  4. class Flight {
  5.   PVector origin;
  6.   PVector destination;
  7. }
  8.  
  9. public class FlightAnimation extends PApplet {
  10.  
  11.   float radius = 150;
  12.   PeasyCam cam;
  13.   PVector lightPosition = new PVector(300, 300, 200);
  14.   Flight flight;
  15.   PVector target;  // Target point for "fly to" animation
  16.  
  17.   void setup() {
  18.     size(600, 600, P3D);
  19.     cam = new PeasyCam(this);
  20.     background(0);
  21.     smoothLighting();
  22.  
  23.     // Define flight data (Moscow to Washington coordinates are estimates)
  24.     flight = new Flight();
  25.     flight.origin = new PVector(0, radius * sin(radians(55.75)), radius * cos(radians(55.75)));  // Moscow (latitude, longitude)
  26.     flight.destination = new PVector(0, radius * sin(radians(38.90)), radius * cos(radians(38.90)));  // Washington (latitude, longitude)
  27.  
  28.     // Define target point (replace with your desired coordinates)
  29.     target = flight.destination;  // Initially target the flight destination
  30.   }
  31.  
  32.   void draw() {
  33.     pointLight(255, 255, 255, lightPosition.x, lightPosition.y, lightPosition.z);
  34.     noStroke();
  35.     fill(200);
  36.     sphere(radius);
  37.  
  38.     // Draw flight path
  39.     stroke(255);
  40.     strokeWeight(2);
  41.     line(flight.origin.x, flight.origin.y, flight.origin.z, flight.destination.x, flight.destination.y, flight.destination.z);
  42.  
  43.     // Simple plane at origin (replace with your plane model)
  44.     pushMatrix();
  45.     translate(flight.origin.x, flight.origin.y, flight.origin.z);
  46.     rotateX(HALF_PI);  // Adjust rotation for desired plane orientation
  47.     box(10, 20, 5);  // Replace with your plane dimensions
  48.     popMatrix();
  49.  
  50.     // "Fly to" animation (comment out for a simple rotation)
  51.     // float angleX = lerp(cam.getRotationX(), atan2(target.z, target.x), 0.01f);
  52.     // float angleY = lerp(cam.getRotationY(), asin(target.y / radius), 0.01f);
  53.     // cam.setRotation(angleX, angleY);
  54.  
  55.     // Simple rotation animation (uncomment for basic rotation)
  56.     float angle = frameCount * 0.01f;
  57.     rotateY(angle);
  58.   }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement