Hello, I have a code with a 3D shape loaded, it's and obj file and I'm using peasy cam to move it, now I have to make some buttons on the 3D shape but this is going to be moved so I would need that the "buttons" in the 3D shape move with the 3D shape, how could I do it?
Answers
Can you post your entire code?
Basically just translate and rotate the buttons together with the shape.
Instead of moving the buttons on the shape you can make a fixed screen area and place the buttons there - then the buttons don’t rotate with the shape
It‘s called HUD, see beginHUD in peasyCam.
To evaluate mouse clicks in real 3D space you can use a color trick I can tell you more about
interesting!
you have a 3D shape loaded and you want to click child shapes of the shape with the mouse and depending on the child / the part of the shape that has been clicked display the name of the part
@jeremydouglass : do you know how to say
childShape.hasBeenClicked()
?or picking in 3D for child shapes?
E.g. shape is a car, you click on shape child wheel, info WHEEL appears, you click on window, info pane WINDOW appears
thanks guys!
Chrisir
still trying to help tiwis here a bit........
related question I
I am not sure why my pg doesn't show the shape ammonite?
in setup ...
in draw
or is
shape
not possible in pg?related question II
If it would work: How could I apply a peasycam on the shape in my pg?
I'd like to have the peasycam on the pg be exactly the same angle and dist and all as the peasycam on my real screen is. So when I rotate on screen, shape on pg would rotate the same amount.
Is that possible?
thanks !
Chrisir ;-)
I found out how to apply the same peasycam on my pg canvas [see above related question II]:
Here is the code that Chrisir make to help me, in case anyone needs something similar!
Now, I have the problem that the images that appear when click on the ball shouldnt be rotated, they have to be static in the place you clicked to open it.
PeasyCam cam; PShape ammonite; PImage fondo, titulo, titulo2; String estado; PFont helvetica, nexa;
Just move the part lines 167 to 215 in the HUD section
I put that part between beginHUD and endHUD and the program crashes, why can it be?
Also, the things that appear in screen when a part is clicked shouldn't be rotated but if I do it in a way they stay estatic, the program crashes :(( :(( :((
What could I do?
Post your entire code
How can we see what you did wrong now without seeing your code??
Now it doesn't crash but the text appears in another site.
Instead of making an new HUD section bettee use the old one
So move the section up into the HUD section adjust the position there
I tried that but it doesn't work, try it yourself so you understand what happened
Now I put it like this and the program runs good and the image is 2D mode, but, which value should I change there
In order to make it appear in the place I clicked?
Sorry for all the questions, but I don't understand all the code at all. :(
I am not at home so I can really help you
in translate use mouseX,mouseY,0
Or look at screenX, screenY
(Or even modelX....)
You will figure it out - I am sure
Thanks, I'm trying with mouseX and mouseY because I know them better but i'm having a problem with how I could make the image be static, because it's following my mouse all the time, I had thought in a boolean but I don't know how to do it really :((
I wish I had the knowledge you have :((
A lot of people share that wish.
Before setup ()
int mousePressedAtX, mousePressedAtY;
set both in function mousePressed() where hit the sphere: set it to mouseX and to mouseY
Use it in translate() in our output section
[EDITED]
Sorry, but I don't know if it's because we don't share the same language but I didn't understand this,
int mousePressedAtX ....and ....Y
which is the thing I have to initialize before setup()?
I mean, which text I should put where you put points?
Sorry for asking too much
I mean, which value should I give to that int variable?
Chrisir, I was able to do it!!
The code is like this right now
import peasy.*;
The only problem is that sometimes when text is showed I click out of the spheres and the text doesn't disappear, it just changes the place.
doEstadoModelo:
You still have two different sections with beginHud endhud
Please write it that you only have one section. It‘s quite processor time costly.
MousePressed:
Where you set mousePressedAtX: both lines belong inside the if clause after line 132, not where they are now
Did you notice: when you click a new sphere text changes. When you click the same sphere again, text is switched off! Nice, isn’t it?
Yes, that's correct!
If I set mousePressedAtX after the if clause, it's the same. what could I do to "desactivate" the text when I press in any place?
Also, I will need to make in that text some kind of buttonthat will show an animation when oressed, could I put an if clause in void mousePressed that says something like
Or that's not going to work?
Updated
I tried that line of code and it doesn't work.
Sorry about my bad writing, I have been awake all the night and my eyes and my brain don't work really good at this time...
The code is now like this.
I commented unintentionally so i'm editing the comment because i don't know how to delete it.
Check
This
hotSpotFound=undefined;
at start of mousePressed ()
This would turn off text with mousePressed
But you really should understand the code better because only then you learn
Yes, I understand ir, I was able to desactivate it by myself! I post the code in my last comment.
But nos, how could I do to make a button on the image that would load another image on the screen?
You could also draw 3 mouse buttons on the text field like close animation image
Then you need to check the buttons position and size against mouseX and mouseY but only when text field is open
if(hotSpotFound != undefined && mouseX > buttonX&&......
See examples: buttons for that
just draw a rect like
rect(mousePressedAtX,...,44, 19);
text („show image“,....);
Check it with mouse - see above
I understand the logic you told me but I don't understand why 3 mouse buttons?
Okey, I understand, but you are telling me two differents ways to do it? Also, the image showed will be different depending on the part you have clicked, that would be to show the same image every time, doesn't it?
3 buttons or 1 just as you like it
Yeah different ways
Images: line 60 to 63: load different images here
Well, I'm gonna tell you what I understand and it didn't work.
//I draw a rect rect(mousePressedAtX, mousePressedAtY, 200, 200)
Then I should write an if clause?
if ( HotSpotFound! == undefined && mouseX == mousePressedAtX && mouseY == mousePressedAtY) {
display the image
}
Maybe I was wrong with the place I put it.
But I still thinking that that code has something wrong with the mousePressedAtY and such things.
??
you mixed up my if clause a little
It’s != not !==
It’s > not ==
Listen, no use that you write more here than to look at your code. Just think it through and bend it to your will.
Chrisir, look what I'm doing, tell me if it's ok.
I'm drawing a box that then i'm going to put the oppacity in 0 and then I'm going to write an if clause which will check if mouseY and X it's equal to mousePressedButtonX && mousePressedButtonY and state is undefined! it will show you the image, am I right with the logic?
Sorry but I didn't understand
Well the rect above is your button
It‘s in the text field and only visible when the text field is visible. Ok?
When the button is there it can be clicked. But we need to check whther the click was inside the button (check mouseX and mouseY against button position).
It’s slightly complex because different layers what can be clicked when ;-)
Yes, I know it, but Is it right using a new variable with the same value as mousePressedAtX and mousePressedAtY to check if the box is clicked?
Well ....
break your problem down into steps
Step A : press a sphere with mouse, text field appears
Step B : text field shows a small button
Step C : press small button with mouse something happens (image) - best set a variable buttonIsClicked to true
Step D : something happens when buttonIsClicked Is true
No. Make new variables.
As i said i am not at home and can’t do anything for you now
Yes it's all okey, but I don't know how to make the if clause in order to check if I pressed the small button :(
Did you look at examples: buttons on the website?
It’s ( mouseX>buttonX &&
mouseY > buttonY &&
mouseX < buttonX+buttonWidth &&
mouseY < buttonY+buttonHeight) {
Basically you check if mouse is inside button
Use this in mousePressed () in the right estado when the text field is open
Yes I know that is just checking if the click is insde, but the thing I don't know is which value should I put on buttonY and ButtonX cause the X and Y of the rect it will basically be the mouseX and mouseY.
No.
When the text field is opened you display the text field and you can calculate the button position from the stored mousePressedAtX and Y
Store the calculated position of the button in the 4 variables buttonX, Y , buttonwidth and buttonheight
Chrisir, you don't understand what I mean, I don't know what values put there
rect(????, ????, ???, ???);
If this variables are the values I should put there
** buttonX, Y , buttonwidth and buttonheight **
which is the value of that variables????
I know it will seem silly for you, sorry it's my first time with such a complex program.
Did you play with the button example??
You should.
rect(????, ????, ???, ???);
If this variables are the values I should put there
** buttonX, buttonY , buttonwidth and buttonheight **
Correct!!!
Declare them before
setup()
The position is just the Position of the text field
+ 70
or soThe size: buttonWidth can be =44 e.g. and buttonHeight = 19.
The idea is to store the variables upon opening the text field and then use the variables when checking the mouse
But I will keep on spoon feeding you