Hello guys, I have a code which i'm gonna share to you on a link because it has images and a lot of things but the problem I am having is this.
With a lot of help of Chrisir, user of the forum, I was able to develop this program, it works like this.
1- You press a sphere and it shows you an image 2- when you press that image it shows you another image in another part of the screen. 3- If you click outside it "resets" the and nothing is showed.
What I have to do now is to make both images appear with the first click, (when I click the sphere) I have been deleting some if clauses and editing in order to make it work but there are so many if clauses and else that I always get errors.
The code is this...
import peasy.*;
import gifAnimation.*;
PeasyCam cam;
Gif myAnimation;
boolean showingAnim=false;
PShape ammonite;
PImage fondo, titulo, titulo2, ammoniteinicio, almeja;
String estado;
PFont helvetica, nexa;
// invisible PGraphics
PGraphics pg;
//define hot spots
PVector[] hotSpotsPosition=new PVector[5];
color[] hotSpotsColor =new color [hotSpotsPosition.length];
String[] hotSpotsText = new String [hotSpotsPosition.length];
PImage[] hotSpotsImg = new PImage [hotSpotsPosition.length];
boolean [] hotSpotsRightSide = new boolean [hotSpotsPosition.length];
Gif [] hotSpotsGif = new Gif [hotSpotsPosition.length];
boolean almejacerrada;
int undefined=-1;
int hotSpotFound=undefined; // when undefined no text is displayed
int mousePressedAtX;
int mousePressedAtY;
// button data
int buttonX, buttonY,
buttonWidth, buttonHeight;
void setup() {
fullScreen(P3D);
// size(900, 900, P3D);
rectMode(CENTER);
imageMode(CENTER);
textAlign(CENTER);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(110);
cam.setMaximumDistance(500);
ammonite = loadShape("ammonite.obj");
// define the hot spots in parallel arrays
// the first hot spot is defined in hotSpotsPosition[0] and hotSpotsColor[0] and hotSpotsText[0] and so on
// positions:
hotSpotsPosition[0] = new PVector(-15, -20, 0);
hotSpotsPosition[1] = new PVector(-5, -5, -25);
hotSpotsPosition[2] = new PVector(-20, -10, 3);
hotSpotsPosition[3] = new PVector(-25, -10, 15);
hotSpotsPosition[4] = new PVector(-5, 19, -5);
//colors: colors are not visible but must be unique
hotSpotsColor[0] = color(255, 0, 0);
hotSpotsColor[1] = color(100, 0, 0);
hotSpotsColor[2] = color(110, 0, 0);
hotSpotsColor[3] = color(120, 0, 0);
hotSpotsColor[4] = color(160, 0, 0);
// texts
hotSpotsText[0] = "embudo";
hotSpotsText[1] = "caparazon";
hotSpotsText[2] = "ojos";
hotSpotsText[3] = "tentaculos";
hotSpotsText[4] = "sifon";
//images
hotSpotsImg[0] = loadImage ("EMBUDO.png");
hotSpotsImg[1] = loadImage ("CAPARAZON.png");
hotSpotsImg[2] = loadImage ("OJOS.png");
hotSpotsImg[3] = loadImage ("TENTACULOS.png");
hotSpotsImg[4] = loadImage ("SIFON.png");
// for (PImage img : hotSpotsImg)
// img.resize(200, 0);
// Gifs
hotSpotsGif[0] = new Gif(this, "embudoanim.gif");
hotSpotsGif[1] = new Gif(this, "caparazonanim.gif");
hotSpotsGif[2] = new Gif(this, "ojosanim.gif");
hotSpotsGif[3] = new Gif(this, "tentaculosanim.gif");
hotSpotsGif[4] = new Gif(this, "sifonanim.gif");
for (Gif g1 : hotSpotsGif) {
g1.play();
}
// whether we display the spot left or right
hotSpotsRightSide[0] = false;
hotSpotsRightSide[1] = true;
hotSpotsRightSide[2] = true;
hotSpotsRightSide[3] = true;
hotSpotsRightSide[4] = false;
fondo = loadImage("fondo.jpg");
titulo = loadImage("titulo.png");
titulo2 = loadImage("conociendo.png");
ammoniteinicio = loadImage("ammoniteparainicio.png");
almeja = loadImage("almeja.png");
buttonX = 0;
buttonY = 0;
buttonWidth = 400;
buttonHeight = 400;
estado = "inicio";
almejacerrada = false;
helvetica = createFont("HelveticaWorld-Regular.ttf", 30);
nexa = createFont("Nexa Bold.otf", 50);
pg = createGraphics(width, height, P3D);
fondo.resize(width, height);
image(fondo, width/2, height/2);
} //func
void draw() {
avoidClipping(); // so the graphic AMMONITE is not cut when rotating
if (estado.equals("inicio")) {
//-----------Stopping peasy ------
cam.beginHUD();
image(fondo, width/2, height/2);
textFont(nexa);
text("AMMONITE", width/2, height/6 - 50);
text("EL ANCESTRO MARINO", width/2, height/6);
textFont(helvetica);
text("Toca para comenzar", width/2, height/2 + 300);
image(ammoniteinicio, width/2, height/2);
cam.endHUD(); //--------------------------------
}//if
// --------------------- next estado !!!! --------
else if ( estado.equals("modelo")) {
doEstadoModelo(); // most important
}//else if
// --------------------- EROR - NO estado - program error !!!! --------
else {
println ("--------------- EROR - NO estado in draw() !!!! --------");
exit();
return;
}//else
}//func draw()
//------------------------------------------------------------------------
void mousePressed() {
// mouse is pressed
if (estado.equals("inicio")) {
// start screen
estado = "modelo";
}
//
// --------------------- next estado --------
//
else if (estado.equals("modelo")) {
mousePressedAtX = 0;
mousePressedAtY = 0;
//
int oldHotSpotFound=hotSpotFound;
if (hotSpotFound != undefined) {
// text field is OPEN
if (dist( buttonX, buttonY, mouseX, mouseY ) < 110) {
almejacerrada = false;
showingAnim=true;
} else {
// clicked outside - closing
hotSpotFound = undefined;
almejacerrada=true;
showingAnim=false;
}//else
} // if
else {
// text field is NOT open
// -----------
color colorFromMouse = pg.get(mouseX, mouseY);
// hotSpotFound=undefined; // reset
for (int i=0; i<hotSpotsPosition.length; i++) {
if (colorFromMouse==hotSpotsColor[i]) {
if (i==oldHotSpotFound) {
// hotSpotFound=undefined; // reset ??
} else {
hotSpotFound=i; // set
}
break;
}// if
}//for
}// else
//---
}//else if
// --------------------- EROR - NO estado
else {
println ("--------------- EROR - NO estado in mousePressed() --------");
exit();
return;
}//else
}//func
void doEstadoModelo() {
makeInternalPGraphics();
// background
cam.beginHUD(); // ----
image(fondo, width/2, height/2, width, height);
textFont(nexa);
fill(255);
text("CONOCIENDO AL AMMONITE", width/2, height/6 - 50);
if (almejacerrada == true) {
image(almeja, width-300, height-130, 250, 250);
}
cam.endHUD(); // ----
// show Ammonite
pushMatrix();
spotLight(255, 255, 255, 80, 20, 40, -1, 0, 0, PI/2, 2);
directionalLight(255, 255, 255, width/2, height/2, 20);
scale(20);
shape(ammonite);
popMatrix();
cam.beginHUD(); // ----
if (showingAnim) {
if (hotSpotFound!=undefined)
image(hotSpotsGif[hotSpotFound], width-300, height-130, 250, 250); // !!!
} else {
// ----
// text field
if (hotSpotFound!=undefined) {
if (hotSpotsRightSide[hotSpotFound]) {
// show rect with text
// on right side
pushMatrix();
// translate(mousePressedAtX, mousePressedAtY, hotSpotsPosition[hotSpotFound].z);
translate(mousePressedAtX, mousePressedAtY );
buttonX=mousePressedAtX;
buttonY=mousePressedAtY;
scale(0.5);
fill(250, 250, 35);
// rect(mousePressedAtX, mousePressedAtY, 100, 100);
fill(0);
textFont(helvetica);
textSize(9);
textMode(SHAPE);
translate(0, 0, 0.2);
text(hotSpotsText[hotSpotFound], 4, 4, 90, 92);
if (hotSpotsImg[hotSpotFound]!=null) {
// translate(100+hotSpotsImg[hotSpotFound].width/2, 0, 0);
image(hotSpotsImg[hotSpotFound], 0, 0);
//fill(0, 0, 0, 50);
}
popMatrix();
} else
{
// show rect with text
// on left side
pushMatrix();
// translate(mousePressedAtX, mousePressedAtY, hotSpotsPosition[hotSpotFound].z);
translate(mousePressedAtX, mousePressedAtY );
buttonX=mousePressedAtX;
buttonY=mousePressedAtY;
// translate(-50, 0, 0);
fill(250, 250, 35, 0);
scale(0.5);
fill(0);
// rect(mousePressedAtX, mousePressedAtY, 100, 100);
textFont(helvetica);
textSize(9);
textMode(SHAPE);
translate(0, 0, 0.2);
text(hotSpotsText[hotSpotFound], 4, 4, 90, 92);
if (hotSpotsImg[hotSpotFound]!=null) {
// translate(-25-hotSpotsImg[hotSpotFound].width/4, hotSpotsImg[hotSpotFound].height/2, 0);
image(hotSpotsImg[hotSpotFound], 0, 0);
//fill(0, 0, 0, 50);
//rect(buttonX, buttonY, buttonWidth, buttonHeight);
}
popMatrix();
}// else
}//if
}
cam.endHUD(); // ----
// spheres
for (int i=0; i<hotSpotsPosition.length; i++) {
PVector pv = hotSpotsPosition[i];
pushMatrix();
translate(pv.x, pv.y, pv.z);
noStroke();
// use any color your want here
fill(255, 2, 2, 50); // normal
if (i==hotSpotFound) {
fill(2, 255, 2, 50); // highlight
}
sphere(7);
popMatrix();
}
}//func
void makeInternalPGraphics() {
pg.beginDraw();
pg. perspective(PI/3.0, (float) width/height, 1, 1000000);
pg.setMatrix(getMatrix()); // replace the PGraphics-matrix
pg.background(0);
pg.noLights();
for (int i=0; i<hotSpotsPosition.length; i++) {
PVector pv=hotSpotsPosition[i];
pg.pushMatrix();
pg.translate(pv.x, pv.y, pv.z);
pg.noStroke();
pg.fill(hotSpotsColor[i]);
pg.sphere(7);
pg.popMatrix();
}//for
pg.endDraw();
}//func
void avoidClipping() {
// avoid clipping :
// https : // // forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func
//
If someone could have a look at that and help me I would be so thankful, maybe a person who knows more than me will solve it really quickly, it's not something difficult but is it for me that don't know very much of the program, anyway, thanks!!
Here is the link in case you want to download it and have a look
https://www.mediafire.com/file/87st6mk20eduo3e/Processing_avance.rar