Convert mouse position to Texture position on ball

Thread Solved

Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Convert mouse position to Texture position on ball

 
0
  #1
Jul 20th, 2006
Hi All,

I am an experienced Java developer and since a few weeks I joined a project which involved real time rendering of 3D objects and interaction with those objects. I have a problem for which I hope that an experienced 3D programmer can help me. Usage:
  • I’ve rendered an 3D Sphere object which in this case is a perfect ball (not eggs shape) using Spherical Texture mapping.
  • The idea is that a user can interact with this ball and rotate the ball. The user clicks a location on the ball and the user is to enter a ‘dot’ on the ball. Thereafter the user can rotate the ball and place other dots on the ball.
Problem statement
  1. When a user clicks the surface of the ball our application is able to get the mouse position (x, y) in Canvas2D.
Question: How can I convert the mouse position to the Texture position in order to update the ball surface?

If you are able to help or if you need more information please let me know because I am really stuck with this.

Martijn Hermanns
Last edited by 3DStarter; Jul 20th, 2006 at 1:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Convert mouse position to Texture position on ball

 
0
  #2
Jul 20th, 2006
Ok kiddo, what api are you using?

JOGL or java 3d?

How much of this have you read.

Have you been through the tutorials?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

 
0
  #3
Jul 20th, 2006
I read a lot but haven't found a solution for my problem so far. Please instruct me if there are any tutorials which could meet my problem.

The problem is that we have to rotate the ball and that is where I get lost.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Convert mouse position to Texture position on ball

 
0
  #4
Jul 21st, 2006
Ok, first of all I'd use the JOGL api. It looks good.

Then I'd work throught the NeHe tutorials. Fortunately, some kind soul has ported them to JOGL.

Read this
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Convert mouse position to Texture position on ball

 
0
  #5
Jul 21st, 2006
Have a look at this as well.

It's a basic java program that rotates a wireframe object in 3d space.
All you have to do is provide the coordinates of the model. (Source code provided)

Just make sure you unzip the file after downloading it. (Right -clicked the folder icon and select extract all)

http://img136.imageshack.us/img136/5761/oirz8.th.gif
Attached Files
File Type: zip weee.zip (34.8 KB, 20 views)
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

 
0
  #6
Jul 21st, 2006
thank you for responding. We will have a look at the link you provided to and hope to find the answer to the solution.

Unfortunately the weee.zip sample does solve our problem because it simply rotates a sphere when user the user drags the mouse. I really need to know "How can I convert the mouse position to the Texture position in order to update the ball surface?".
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Convert mouse position to Texture position on ball

 
0
  #7
Jul 21st, 2006
I think the best way to do this is to download the JOGL stuff and work with some of the tutorials. Then you can apply the texture mapping in a 3d environment.

The mouse listeners should be no different to the ones you use for any other bog standard java application. It's just the texture gets updated straight away.

Try it.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

 
0
  #8
Jul 22nd, 2006
Maybe you misunderstand my problem. Converting coodinates after applying texture mapping is not the same as simply applying texture mapping.

I see that Zaknixon got the same problem but couldn't find a proper feedback in JOGL forum.

http://www.javagaming.org/forums/index.php?topic=1595.0

Can you please clarify?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Convert mouse position to Texture position on ball

 
0
  #9
Jul 22nd, 2006
If you were only using a circle, not a sphere, it's simple trigonometry; sphere is abit more difficult though, do you have to take rotation (of the sphere) into account?

For a circle though; see attached image, and you must know:

- The distance (D) from the viewing platform to the center of the object
- The distance (Y) from the line Y=0 (relative the sphere AND viewing platform) to the point where the click is received from.
- The radius (R) of the object.

This won’t work directly with spheres, it assumes a cylindrical object lateral to the viewing platform, with a zoom factor of 1, and no transformations.

The point you’ll get is X,Y,Z where (X,Y) are the clicked co-ordinate, and Z is the result of:

t = asin(Y/R)
B = cos(t) x R
Z = D – B

If the X and Y values are within a distance (the object’s size as centred around the line X = 0, Y = 0) from the point X = 0, Y = 0; then the point is on the surface of the object, at the point X,Y,Z relative to the viewing platform.

To map that to a texture co-ordinate is different, it depends on your texturing system/method of creating the object; you can find the point relative to the object as opposed to relative to the viewing platform by subtracting the value of Z from the value of D, or taking the initial value of B.

Taking that from a circle function to a sphere function could be simple, but could be difficult depending on the potential for/possibility of rotation, particularly if it's about arbitrary axes.

Hope that helps; but definately try looking for third party packages/extensions that implement point picking; there may be some in Java3D already somewhere, look in the Java3D examples folder, I remember seeing some nice picking demos in there.

Another solution (if texture point picking isn't implemented) is to put objects (which CAN be picked easily using the mouse) at every texture point, store reference to the texture point in that object, catch the pick with a behaviour and mutate or return the reference depending on what kind of app you're making.

Matt
Attached Thumbnails
circle.GIF  
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

 
0
  #10
Jul 23rd, 2006
Hi Matt,

Thank you for the detailed explanation. Assuming that the convert formula

t = asin(Y/R)
B = cos(t) x R
Z = D – B

is correct this would answer a part of the problem. This only converts from Canvas coordinates (x, y) to Virtual World coordinates (x, y, z). How about convert from Virtual World coordinates (x, y, z) to Spherical coordinates (rho, phi, theta) and to Texture coordinates (u, v).

Do you have any idea on that?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Game Development Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC