Need help with camera (PeasyCam)!

edited March 2014 in Library Questions

Hello!

I am trying to randomly place and orient ellipsoids in 3D space using the Shapes 3D Library with the ability to rotate and zoom around them. The ultimate goal is to model synapses (components of brain cells roughly shaped like ellipsoids) in 3D space.

Here is a drawing of what I hope to do

So far, I have been able to place ten ellipsoids in 3D space using Shapes 3D Library (see code below).

Screenshot of my progress

I think I got this all figured out except that... - My camera (using PeasyCam Library) does not work at all - All of my synapses are oddly clustered in the bottom right corner of the window - There are not always ten ellipsoids making me suspect that some are outside of the screen

Note: I am not looking for a fully-coded answer that achieves my ultimate goal (this defeats the purpose of learning, I think). Rather, I am looking for advice on how to take the next steps going forward.

Note: I am using Mac OS X and Processing 2

Any help would be much appreciated! Thank you!

// Imports OpenGL library for 3D modeling
import processing.opengl.*;

// Imports PeasyCam library for an easy-to-use camera
import peasy.*;
PeasyCam cam;

// Imports Shapes 3D library for creating 3D shapes like ellipsoids
import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;

// Declares an Ellipsoid from the Shapes 3D library and names it "synapse"
// A "synapse" is part of a brain cell that can be modeled as an ellipsoid
Ellipsoid synapse;

// Sets dimensions of each synapse
float semiaxisA = 20;
float semiaxisB = 10;
float semiaxisC = 10;

// Creates arrays to store random coordinates of each synapse
float[] x = new float[1];
float[] y = new float[1];
float[] z = new float[1];

void setup() {

  // Sets size of window, background color, and framerate 
  size(500, 500, OPENGL);
  background(0);
  frameRate(1000);

  // Defines position and maximum/minimum distance of camera
  cam = new PeasyCam(this, 500);
  cam.setMinimumDistance(50);
  cam.setMaximumDistance(500);

  // Draws the first synapse and stores its random coordinates and angle orientations in the arrays
  // semiaxisA is used instead of semiaxisB or semiaxisC because it is the longest dimension of the synapse
  // This will ensure that no synapse overlaps with another synapse
  x[0] = random(semiaxisA, width/2-semiaxisA);
  y[0] = random(semiaxisA, height/2-semiaxisA);
  z[0] = random(semiaxisA, 500/2 - semiaxisA);
  drawSynapse(x[0], y[0], z[0]);
}

void draw() {

  // Creates directional light
  lights();
  directionalLight(255, 255, 255, -1, 0, 0);

  // Checks to see if there are less than 10 elements in the z coordinate array
  if(x.length < 10){

    // Generates random x, y, and z coordinates for a new synapse
    float tempX = random(semiaxisA, width/2-semiaxisA);
    float tempY = random(semiaxisA, height/2-semiaxisA);
    float tempZ = random(semiaxisA, 500/2-semiaxisA);

    // Checks to see if the generated x, y, and z coordinates are too close to any (x, y, z) coordinates in the arrays
    for(int i = 0; i < x.length; i++){
      if (sqrt(sq(x[i] - tempX) + sq(y[i] - tempY)+ sq(z[i] - tempZ)) < semiaxisA) {
        println("Too close to another synapse!");
        return;
      }
    }

    // Draws synapse using drawSynapse function and adds its coordinates to the x, y, and z coordinate arrays
    drawSynapse(tempX, tempY, tempZ);
    x = append(x, tempX);
    y = append(y, tempY);
    z = append(z, tempZ);
  }
}

// Defines function used to draw each synapse
void drawSynapse(float x, float y, float z){
  pushMatrix();

  // Defines how many gridlines make up the synapse
  synapse = new Ellipsoid(this, 15, 15);

  // Sets size, color, texture, location, and orientation of the synapse to be drawn
  synapse.setRadius(semiaxisA, semiaxisB, semiaxisC);
  synapse.fill(#19BF38);
  synapse.drawMode(Shape3D.TEXTURE);
  synapse.moveTo(x, y, z);
  synapse.rotateBy(random(0,360.0), random(0,360.0), random(0,360.0));

  // Draws synapse
  synapse.draw();
  popMatrix();
}
Tagged:

Answers

  • edited March 2014

    Never mind, solved!

  • Answer ✓

    Please do not duplicate topics. This is the same question as you posted here and I answered it with a solution and advice on your code

    I will close this topic and future replies need to be in the other topic..

This discussion has been closed.