@Chrisir : thank's for your response listview contain 9 element(name of the 3d object) and when i click under the name to one of them it will be pin up ..
// states -------------------------------
// consts
final int normal = 0;
final int program0 = 1;
final int program1 = 2;
final int program2 = 3;
int state = normal; // var: current
// buttons --------------------------
int count;
Button[] buts;
// for 3D ----------------------------------
ThreeD threeD = new ThreeD();
// for movement ----------------------------
int tetrahedronY = 0;
int tetrahedronAddY = 1;
// Misc for programs ------------------------------
float rotateValue=0.0; // for Box, left segment
PVector helpPoint=new PVector(); // for Line etc., left segment, Point #1
PVector helpPoint2=new PVector(); // Point #2
PVector helpPointAdd; // vector for moving Point #1
PVector helpPoint2Add; // vector for moving Point #2
//-------------------------------------------------
// the core functions
void setup() {
size(400, 700, OPENGL);
// colorMode(RGB);
int unit = 40;
// int wide = width/unit;
int count = 3;
buts = new Button[count];
String[] name = {
"tetrahedron", "box", "sphere"
};
for (int x = 0; x < count; x++) {
buts[x] = new Button(66, x*50+55, 25,
color(255, 0, 0), color(0, 255, 0), color(0, 0, 255),
x, name[x]);
}
}
void draw() {
background(0, 0, 0);
lights();
if (state==normal) {
text("Please select one sketch to show", 17, 17);
for (Button but : buts) {
but.update();
but.display();
}
} else if (state==program0) {
draw0();
} else if (state==program1) {
draw1();
} else if (state==program2) {
draw2();
} else {
println ("Unknown state (error #965)");
}
}
//-------------------------------------------------
// Inputs
void mousePressed() {
if (state==program0 || state==program1 || state==program2) {
// go back to normal
state = normal;
} else if (state==normal ) {
for (Button but : buts) {
but.press();
if (but.pressed) {
evalButton(but);
break; // Other buttons won't be pressed, just stop
} // if
} // for
} // else if
else {
println ("Unknown state (error #1065)");
}
} // func
void evalButton(Button but) {
println(but.index);
if (but.index==0) {
setup0();
state=program0;
} else if (but.index==1) {
setup1();
state=program1;
} else if (but.index==2) {
setup2();
state=program2;
} else {
println ("Unknown button index (error #1165)");
}
} // func
void mouseReleased() {
for (Button but : buts) {
but.release();
}
}
void keyPressed() {
state=normal; // return to normal state
key=0; // kill escape
}
// --------------------------------------------
// the sub-sketches we want to start
void setup0() {
initPointsForLine();
}
void draw0() {
fill(0, 0, 255);
//noFill();
noStroke();
pushMatrix();
strokeWeight(1);
// translate(width/2, height/2, map(millis()%5000, 0, 5000, -100, 100));
translate(width/2, height/2, 0);
rotateY(map(millis()%5000, 0, 5000, 0, TWO_PI));
threeD.tetrahedron ( 0, 0, 0, 44 );
tetrahedronY+=tetrahedronAddY;
if (tetrahedronY<0)
tetrahedronAddY=abs(tetrahedronAddY);
if (tetrahedronY>height)
tetrahedronAddY=-1*abs(tetrahedronAddY);
popMatrix();
}
// ---
void setup1() {
initPointsForLine();
}
void draw1() {
stroke(0);
fill(0, 0, 222);
pushMatrix();
translate(width/2, height/2);
rotateX(.213);
rotateY(.713);
box(93);
popMatrix();
}
// ---
void setup2() {
initPointsForLine();
}
void draw2() {
noStroke();
fill(0, 0, 222);
pushMatrix();
translate(width/2, height/2);
sphere(83);
popMatrix();
}
// ----------------------------------------------
// help funcs for the sub-functions
void initPointsForLine() {
// invisible help lines on the left side leading to green line
helpPoint = new PVector(random(width), random(height));
helpPoint2 = new PVector(random(width), random(height));
helpPointAdd = new PVector(random(-2, 2), random(-2, 2));
helpPoint2Add = new PVector(random(-2, 2), random(-2, 2));
}
void checkHelpPointsForLine() {
// lines on the left side leading to green line on page 1
helpPoint.add(helpPointAdd);
helpPoint2.add(helpPoint2Add);
// check helpPoint ----------------------------
helpPointAdd.x = keepInBoundary(helpPoint.x, 12, width-13, helpPointAdd.x);
helpPointAdd.y = keepInBoundary(helpPoint.y, 13, height -13, helpPointAdd.y);
// check helpPoint2 ----------------------------
helpPoint2Add.x = keepInBoundary(helpPoint2.x, 12, width-13, helpPoint2Add.x);
helpPoint2Add.y = keepInBoundary(helpPoint2.y, 13, height -13, helpPoint2Add.y);
} // func
float keepInBoundary(float testPoint, float lowerBoundary, float upperBoundary, float valueToAdd) {
// Situation: testPoint is a ball position and valueToAdd gets added to it, so testPoint flies.
// Now testPoint must stay within lowerBoundary and upperBoundary (e.g. screen).
// ValueToAdd gets changed accordingly and is returned as return value.
if (testPoint<lowerBoundary) {
valueToAdd=abs(valueToAdd);
}
if (testPoint>upperBoundary) {
valueToAdd=-1*abs(valueToAdd);
}
return valueToAdd;
} // func
//_____________________________//
class Button {
int x, y; // The x- and y-coordinates
int size; // Dimension (width and height)
color baseGray; // Default gray value
color overGray; // Value when mouse is over the button
color pressGray; // Value when mouse is over and pressed
boolean over = false; // True when the mouse is over
boolean pressed = false; // True when the mouse is over and pressed
int index;
String name;
Button(int xp, int yp,
int s,
color b,
color o,
color p,
int index_,
String name_) {
x = xp;
y = yp;
size = s;
baseGray = b;
overGray = o;
pressGray = p;
index=index_;
name=name_;
}
// Updates the over field every frame
void update() {
if ((mouseX >= x) && (mouseX <= x + size) &&
(mouseY >= y) && (mouseY <= y + size)) {
over = true;
} else {
over = false;
}
}
boolean press() {
if (over == true) {
pressed = true;
return true;
} else {
pressed = false;
return false;
}
}
void release() {
// Set to false when the mouse is released
pressed = false;
}
void display() {
if (pressed == true) {
fill(pressGray);
} else if (over == true) {
fill(overGray);
} else {
fill(baseGray);
}
// rect
stroke(255);
rect(x, y, size, size);
// text above
fill(0, 255, 0);
// text(index, x+12, y-8);
text(name, x+size+12, y+9);
}
}
// ==================================================
//
class ThreeD {
/*
This class shows different solids to draw in 3D.
This class is not about one item (Car) but more a
collection of different commands for the realm of 3D.
section 1: reference section "2D Primitives" now in 3D
section 2: reference section "3D Primitives" now in enhanced version
section 3: Platonic solids
section 4: other, non platonic solids
section 5: coordinate system and related
section 6: HUD funcs / Head-up-Display funcs
section 7: floor
section 8: minor help functions
*/
// consts
final color RED = color (255, 0, 0);
final color GREEN = color (0, 255, 0);
final color BLUE = color (0, 0, 255);
final color WHITE = color (255);
final color BLACK = color (0);
final color GRAY = color (111);
final color YELLOW = color (255, 255, 0);
final color YELLOWWARM = color (255, 245, 49);
final color VIOLET = color (143, 0, 255);
final color INDIGO = color (111, 0, 255);
final color MAGENTA = color (255, 0, 255);
final color PINK = color (255, 192, 203);
// vars
boolean crosshair;
// section 1:
// reference section "2D Primitives" now in 3D ----------------------
// read the ref there, they are just changed a bit to be 3D
void point(PVector pos) {
// version with PVector parameter.
// calls another method in the same class.
// See there for description.
point(pos.x, pos.y, pos.z);
}
void point(PVector pos, String str) {
// version with PVector parameter.
// calls another method in the same class.
// See there for description.
// With local text next to the point.
point(pos.x, pos.y, pos.z);
text(str, pos.x+6, pos.y+6, pos.z);
}
void point(float x, float y, float z) {
// point as a sphere, fixed size 5,
// fixed noStroke, no fill color, you
// must set the fill color before using
// this method.
noStroke();
pushMatrix();
translate(x, y, z);
sphere(5);
popMatrix();
}
void ellipse3D(float x, float y, float z, float size1) {
// point as a sphere, fixed size 5,
// fixed noStroke, no fill color, you
// must set the fill color before using
// this method.
noStroke();
pushMatrix();
translate(x, y, z);
ellipse(0, 0, size1, size1);
popMatrix();
}
void line3D(float x1, float y1, float z1,
float x2, float y2, float z2,
float weight, color colorLine)
// drawLine was programmed by James Carruthers
// see http://processing.org/discourse/yabb2/YaBB.pl?num=1262458611/0#9
{
// scale(90);
PVector p1 = new PVector(x1, y1, z1);
PVector p2 = new PVector(x2, y2, z2);
PVector v1 = new PVector(x2-x1, y2-y1, z2-z1);
float rho = sqrt(pow(v1.x, 2)+pow(v1.y, 2)+pow(v1.z, 2));
float phi = acos(v1.z/rho);
float the = atan2(v1.y, v1.x);
v1.mult(0.5);
pushMatrix();
PVector v2 = new PVector ( x1, y1, z1 );
translate(v2.x, v2.y, v2.z);
translate(v1.x, v1.y, v1.z);
rotateZ(the);
rotateY(phi);
noStroke();
fill(colorLine);
box(weight, weight, p1.dist(p2));
popMatrix();
} // method
void triangle(float x1, float y1, float z1,
float x2, float y2, float z2,
float x3, float y3, float z3) {
beginShape();
vertex(x1, y1, z1);
vertex(x2, y2, z2);
vertex(x3, y3, z3);
endShape(CLOSE);
}
void quad(
float x1, float y1, float z1,
float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4) {
beginShape();
vertex(x1, y1, z1);
vertex(x2, y2, z2);
vertex(x3, y3, z3);
vertex(x4, y4, z4);
endShape(CLOSE);
}
void rect(
float x1, float y1, float z1,
float w, float h) {
beginShape();
vertex(x1, y1, z1);
vertex(x1+w, y1, z1);
vertex(x1+w, y1+h, z1);
vertex(x1, y1+h, z1);
endShape(CLOSE);
}
// section 2:
// reference section "3D Primitives" now in enhanced version ----------------------
void box3D (float x, float y, float z,
float sizeBox,
color col ) {
fill(col);
pushMatrix();
translate(x, y, z);
box(sizeBox);
popMatrix();
}
void sphere3D (float x, float y, float z,
float sizeBox,
color col ) {
fill(col);
pushMatrix();
translate(x, y, z);
sphere(sizeBox);
popMatrix();
}
// section 3:
// Platonic solids ----------------------
// http://en.wikipedia.org/wiki/Platonic_solid
// also cube / box is a Platonic solid - see above
void tetrahedron(float x1, float y1, float z1,
float size1 ) {
// tetrahedron
// A(1,1,–1), C(–1,–1,–1), F(–1,1,1) und H(1,–1,1).
// see http://en.wikipedia.org/wiki/Tetrahedron#Formulas_for_a_regular_tetrahedron
// see http://de.wikipedia.org/wiki/Datei:Tetraeder_animation_with_cube.gif
scale (size1);
// fill(GREEN);
beginShape();
vertex(1, 1, -1);
vertex(-1, -1, -1);
vertex(-1, 1, 1) ;
endShape();
// fill(BLUE);
beginShape();
vertex(1, -1, 1);
vertex(-1, -1, -1);
vertex(-1, 1, 1) ;
endShape();
// fill(PINK);
beginShape();
vertex(1, -1, 1);
vertex(-1, -1, -1);
vertex(1, 1, -1);
endShape();
// fill(YELLOW);
beginShape();
vertex(1, 1, -1);
vertex(1, -1, 1);
vertex(-1, 1, 1) ;
endShape();
//
// noFill();
// box(2);
//
}
//
// section 4:
// other, non platonic solids ----------------------
void pyramid () {
translate(width/2, height/2, 0);
scale(100);
beginShape();
vertex(-1, -1, -1);
vertex( 1, -1, -1);
vertex( 0, 0, 1);
vertex( 1, -1, -1);
vertex( 1, 1, -1);
vertex( 0, 0, 1);
vertex( 1, 1, -1);
vertex(-1, 1, -1);
vertex( 0, 0, 1);
vertex(-1, 1, -1);
vertex(-1, -1, -1);
vertex( 0, 0, 1);
endShape();
}
// section 5:
// coordinate system and related ----------------------
// by ofey
void coorWalls() {
// draw 3 walls in 3D which mark a coordinate systems.
// coordinate system wall
// by ofey
//
fill(BLUE);//blue left side
beginShape();
vertex(0, 0, 0);
vertex(0, 0, -400);
vertex(0, 400, -400);
vertex(0, 400, 0);
endShape(CLOSE);
fill(YELLOW);//yellow bottom
beginShape();
vertex(0, 400, 0);
vertex(0, 400, -400);
vertex(400, 400, -400);
vertex(400, 400, 0);
endShape(CLOSE);
fill(GREEN);//green back
beginShape();
vertex(0, 0, -400);
vertex(400, 0, -400);
vertex(400, 400, -400);
vertex(0, 400, -400);
endShape(CLOSE);
}
void ShowCoordinates () {
// Show Coordinates x, y and z as lines
//
// X
stroke (255, 0, 0);
line (0, 0, 0, 100, 0, 0 ) ;
sphere3D (100, 0, 0, 13, color (255, 0, 0) );
text ("X", 120, 60, 0);
// Y
stroke (0, 255, 0);
line (0, 0, 0, 0, 100, 0 ) ;
sphere3D(0, 100, 0, 13, GREEN);
text ("Y", 0, 180, 0);
// Z
stroke (0, 0, 255);
line (0, 0, 0, 0, 0, -300 ) ;
sphere3D (0, 0, -300, 33, BLUE);
text ("-Z", 30, 50, -300);
} // function
void show3DCursor( float theX, float theY, float theZ) {
// show 3D cursor
//
if (crosshair) {
// 3D crosshair
final int len = 15;
stroke(244, 2, 2); // red
line (theX, theY, theZ-len, theX, theY, theZ+len);
stroke(0, 0, 255);
line (theX, theY-len, theZ, theX, theY+len, theZ);
stroke(2, 244, 2);
line (theX-len, theY, theZ, theX+len, theY, theZ);
pushMatrix();
translate(theX, theY, theZ+len);
fill(244, 2, 2);
noStroke();
sphere(1);
popMatrix();
} else
{
// sphere
pushMatrix();
translate(theX, theY, theZ);
fill(WHITE);
noStroke();
sphere(10);
popMatrix();
} // else
} // func
// section 6:
// HUD funcs ----------------------
// Head-up-Display
// see http://de.wikipedia.org/wiki/Head-up-Display
void showTextInHUD(String str1) {
// A small 2D HUD for text in the
// upper left corner.
// This func may only be called a the very end of draw() afaik.
camera();
hint(DISABLE_DEPTH_TEST);
noLights();
textMode(MODEL);
if (str1!=null)
text(str1, 20, 20);
hint(ENABLE_DEPTH_TEST);
} // func
void showTextInHUD(String str1, float x, float y) {
// A small 2D HUD for text at
// free pos.
// This func may only be called a the very end of draw() afaik.
camera();
hint(DISABLE_DEPTH_TEST);
noLights();
textMode(MODEL);
if (str1!=null)
text(str1, x, y);
hint(ENABLE_DEPTH_TEST);
} // func
// section 7:
// floor (later walls (but see coordinate system wall above), sky sphere...) --------------------------------
void CheckeredFloor() {
noStroke();
for (int i = 0; i < 40; i = i+1) {
for (int j = 0; j < 40; j = j+1) {
// % is modulo, meaning rest of division
if (i%2 == 0) {
if (j%2 == 0) {
fill (255, 0, 0);
} else
{
fill ( 103 );
}
} else {
if (j%2 == 0) {
fill ( 103 );
} else
{
fill (255, 0, 0);
}
} // if
pushMatrix();
translate ( 40*i-500, 360, 40*j-640 );
box (40, 7, 40);
popMatrix();
} // for
} // for
} // function
//
} // class ThreeD
//``
@Chrisir===> try this code you gonna anderstand me what i realy want to do ;) here i make liste view and what i realy want to do is to fill that liste with the 3d model i build it with blender ..
no it'S not for me :/ i don't find a way to create a liste of object :/ because i buil my object with blender and then i shouw them from processing with the cam actif on my execution .. so i need a liste and when i open it i choose my model i wanna show it .. because me i'm used the keyboard and that is not professional ..
you see that bed ? i build it with blender and it pin up for me when i click on a button from the keyboard .. but i realy don't like to do that with this way , i wanna a liste i see it on the execution like this liste on the photo
Answers
can you explain?
how many Elements...?
download here...
http://www.openprocessing.org/sketch/77843
@Chrisir : thank's for your response listview contain 9 element(name of the 3d object) and when i click under the name to one of them it will be pin up ..
and list view shows only text or 3D as well?
liste view show me the name of the 3d object and when i click on it then the 3d object will pin up ..:)
@Chrisir===> try this code you gonna anderstand me what i realy want to do ;) here i make liste view and what i realy want to do is to fill that liste with the 3d model i build it with blender ..
you said:
9:03PM liste view show me the name of the 3d object and when i click on it then the 3d object will pin up ..:)
???
never mind
my previous example shows just that
yes @Chrisir but it's not exactly what i need .. i need a liste not a button :/
yeah, just go on from there
it's easy now
no it'S not for me :/ i don't find a way to create a liste of object :/ because i buil my object with blender and then i shouw them from processing with the cam actif on my execution .. so i need a liste and when i open it i choose my model i wanna show it .. because me i'm used the keyboard and that is not professional ..
you don't describe exactly what you want...
what is a liste? can you make an image of what you want...?
you see that bed ? i build it with blender and it pin up for me when i click on a button from the keyboard .. but i realy don't like to do that with this way , i wanna a liste i see it on the execution like this liste on the photo
If I didn't need a Drop Down Menu myself, I wouldn't have bothered to write this.
thanks for the code...
can I publish it on my website?
also, I noticed you use MI v and ArrayList a in your menu, but v could be part of the ArrayList a as well (as the 1st entry)
Why did you separate this if I may ask?
ah, Is it because with v the menu opens but with a, these are the lines in the menu...?
Chrisir ;-)
@TFGuy44
thanks for the code...
can I publish it on my website?
Yes, you have sussed the reasoning.
Feel free to publish/share this. It's not the best drop down menu ever...
thank you!
;-)