Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

3d brush to move points

$
0
0

movement

Hello. I'm in "dead end" with my code and I need help. Trying to create my own little 3d sculpting app. My main question now is how to create something like "Move Brush", to move the points up and down, left and right (look at screenshot from Zbrush sculpting app, something like this). The main problem is that my brush in moving on the screen which is 2d coordinates, but my points is in rotating 3d space. Can't understand how to make 3d coordintes hold still and move only in 2d space, parallel to the screen.

Here is the code, PeasyCam library is required, you can rotate zoom and pan using mouse.

import peasy.*;
PeasyCam jcam;

float r=200;
int segments=30;
int brushsize = 200;

ArrayList <Point> points = new ArrayList <Point>();

Brush brush;


void setup()
{
  size(800,800,P3D);
  jcam = new PeasyCam(this,600);

  for(int i=0; i<segments;i++)   // initialize
  {
    float lat = map(i,0,segments,-HALF_PI,HALF_PI);
    for(int j=0;j<segments;j++)
    {
      float lon=map(j,0,segments,-PI,PI);

      float x = r*sin(lon)*cos(lat);
      float y = r*sin(lon)*sin(lat);
      float z = r*cos(lon);
      PVector temp = new PVector(x,y,z);
      Point pt1= new Point(temp);
      points.add(pt1);
    }
  }

  PVector brushPos = new PVector(0,0);
  brush = new Brush(brushPos);
}


void draw()
{
  background(150);

   for (int i = points.size ()-1; i >= 0; i--)   // points display
  {
    points.get(i).display();
  }

  for(int i=0;i<points.size();i++)   // smooth selection
  {
    float xx = screenX(points.get(i).pos.x,points.get(i).pos.y);
    float yy = screenY(points.get(i).pos.x,points.get(i).pos.y);

    float force = (dist(xx,yy,mouseX,mouseY)*255)/(brushsize/2);

    colorMode(RGB);
    if(dist(xx,yy,mouseX,mouseY)<brushsize/2)
    {
      points.get(i).colore = color(255,0+force,0+force);
    }
    else
    {
      points.get(i).colore = 255;
    }
  }


  jcam.beginHUD();   // 2D menu


  brush.pos= new PVector(mouseX,mouseY);  // brush
  brush.display();


  jcam.endHUD();
}


class Point
{
  PVector pos;
  color colore;

  Point(PVector posIn)
  {
    pos = posIn;
  }

  void display()
  {
    noStroke();
    fill(colore);
    pushMatrix();
    translate(pos.x,pos.y,pos.z);
    box(3);
    popMatrix();
  }
}


class Brush
{
  PVector pos;
  color brColor = color(255,0,0);

  Brush(PVector posIn)
  {
    pos = posIn;
  }

  void display()
  {
    noFill();
    stroke(255,0,0);
    pushMatrix();
    ellipse(pos.x,pos.y,brushsize,brushsize);
    ellipse(pos.x,pos.y,brushsize/2,brushsize/2);
    ellipse(pos.x,pos.y,2,2);
    popMatrix();
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles