|
Author |
Topic: 3 Dimensional button tracking (Base26 by Toxi)? (Read 720 times) |
|
Eric K Guest
|
3 Dimensional button tracking (Base26 by Toxi)?
« on: Apr 29th, 2004, 7:41pm » |
|
I am having trouble figuring out how to create buttons by assigning mouse input (mousePressed or "mouse over") to 3D objects I create in my program. I understand you need to assign coordinates for where the button hotspot will be but, how is this accomplished in a 3 dimensional space like in Toxi's Base26 project. I have created a small experiment in which I am trying to get each Node (currently a box) act as a link when the mouse moves over it and is pressed. Here is where the example is located: http://www.select-start.com/002/ The Problem is that when I apply rotation to the camera, the coordinates I set for the mouse input are incorrect. Any help would be appreciated. Thank you, Eric
|
|
|
|
skloopy
|
Re: 3 Dimensional button tracking (Base26 by Toxi)
« Reply #1 on: Apr 29th, 2004, 10:18pm » |
|
I think what yr lookin for is to use screenX(x,y,z); and screenY(x,y,z); to get your point and then test for closeness to that. Okay back to work for me.
|
|
|
|
mflux
|
Re: 3 Dimensional button tracking (Base26 by Toxi)
« Reply #2 on: Apr 29th, 2004, 10:19pm » |
|
This is a common (and basic) problem in 3d graphics. I forgot the exact terminology, but solving this involves translating the 2d coordinates of the mouse to where it ACTUALLY is referring to in 3d space. One way is to keep a "dummy" object oriented to the camera, but have the mouse control the dummy object's X and Y, in relation to the camera/viewing plane. Then draw a line from this dummy object to infinity (or.. a very long length). This line is now perpendicular to the camera plane, and thus, the screen. Whichever object intersects with this line is what the user is actually trying to hit. If there are two, you might need a routine to sort things out by z-depth. I hope that helps a bit.
|
|
|
|
mflux
|
Re: 3 Dimensional button tracking (Base26 by Toxi)
« Reply #3 on: Apr 29th, 2004, 10:20pm » |
|
lol.. or that too... >_< ah I just woke up.
|
|
|
|
justo
|
Re: 3 Dimensional button tracking (Base26 by Toxi)
« Reply #4 on: Apr 29th, 2004, 10:54pm » |
|
i believe what youre referring to is called "picking," mflux. im not sure how screenx() and screeny() work exactly, but conceptually you are generating a ray that originates at the mouse click, translating it into world space (the transformed space, basically), and seeing if it intersects with anything. how do screenX() and screenY() work? do they return a single point? i dont know how helpful that would be for translating mouse click coordinates. edit: haha, ok, now reading your post mflux, thats exactly what you just said. we're both a little groggy today i guess.
|
« Last Edit: Apr 29th, 2004, 11:03pm by justo » |
|
|
|
|
Eric K Guest
|
Re: 3 Dimensional button tracking (Base26 by Toxi)
« Reply #5 on: May 1st, 2004, 3:42am » |
|
Awsome! screenX() and screenY() was just what I was looking for. Thanks for the advice.
|
|
|
|
Mythmon
|
Re: 3 Dimensional button tracking (Base26 by Toxi)
« Reply #6 on: May 16th, 2004, 3:40am » |
|
from what ive seen in various lanquages i think screenx(x,y,z) and screeny(x,y,z) basically ask where this point in 3d space is compared to the 2d origin, in any non-native-3d-lanquage, you would need functions like this tofirst translate from 2d to 3d to figure out where everything is then from 3d to 2d to draw it on the screen
|
|
|
|
Sjeiti
|
Re: 3 Dimensional button tracking (Base26 by Toxi)
« Reply #7 on: Jul 2nd, 2004, 5:20pm » |
|
hi... I have a similar problem: I want to click on a 3D landscape an then put something in there. So let me get this straight: When I render this landscape I have to use screenx and screeny on all the vertice coordinates and save the results. Then when I click I compare my mouse coordinates with the ones I've saved. But then (if I take the point closest to my mouse position) I might select the back of a mountain (very likely because points further away are closer together). ...or am I aproaching this the wrong way? ...Ron
|
« Last Edit: Jul 2nd, 2004, 7:30pm by Sjeiti » |
|
http://www.sjeiti.com/
|
|
|
|