modify code to draw on mouse click
in
Contributed Library Questions
•
2 years ago
Hello all,
How might I modify this code so it draw only based on mouse click, and I can drag only the shape that I choose with the mouse?
How might I modify this code so it draw only based on mouse click, and I can drag only the shape that I choose with the mouse?
import peasy.*;
import kGeom.*;
import processing.opengl.*;
PeasyCam cam;
int depth = 600;
void setup(){
size(600,400,OPENGL);
cam = new PeasyCam(this, 600);
smooth();
}
void draw(){
background(0);
stroke(0);
strokeWeight(1);
//noFill();
fill(255);
float pSize = 100;
draw_tetrahedron(new kVec(0,0,0),pSize);
}
//---------------------------------------------------------------------------------------
// This function will draw a tetrahedron (4 sided solid) to the screen.
void draw_tetrahedron(kVec pos,float pSize){
pushMatrix();
translate(pos.x,pos.y,pos.z);
scale(pSize);
float[] four_sided_x = {
0, (2*sqrt(2))/3, -sqrt(2)/3, -sqrt(2)/3 };
float[] four_sided_y = {
0, 0, sqrt(6)/3, -sqrt(6)/3 };
float[] four_sided_z = {
1, -1/3, -1/3, -1/3 };
int[] tetra_vertex_faces_0 = {
0, 1, 2 };
int[] tetra_vertex_faces_1 = {
0, 2, 3 };
int[] tetra_vertex_faces_2 = {
0, 3, 1 };
int[] tetra_vertex_faces_3 = {
1, 3, 2 };
int[][] tetrahedron_array = {
tetra_vertex_faces_0,tetra_vertex_faces_1, tetra_vertex_faces_2, tetra_vertex_faces_3 };
beginShape(TRIANGLES);
for (int e=0; e<tetrahedron_array.length;e++)
{
for (int f=0; f<tetrahedron_array[e].length;f++)
{
vertex(four_sided_x[tetrahedron_array[e][f]], four_sided_y[tetrahedron_array[e][f]], four_sided_z[tetrahedron_array[e][f]]);
}
}
endShape();
popMatrix();
}
1