944,035 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jul 20th, 2006
0

Convert mouse position to Texture position on ball

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3DStarter is offline Offline
9 posts
since Jul 2006
Jul 20th, 2006
0

Re: Convert mouse position to Texture position on ball

Ok kiddo, what api are you using?

JOGL or java 3d?

How much of this have you read.

Have you been through the tutorials?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 20th, 2006
0

Re: Convert mouse position to Texture position on ball

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3DStarter is offline Offline
9 posts
since Jul 2006
Jul 21st, 2006
0

Re: Convert mouse position to Texture position on ball

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
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 21st, 2006
0

Re: Convert mouse position to Texture position on ball

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, 55 views)
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 21st, 2006
0

Re: Convert mouse position to Texture position on ball

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?".
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3DStarter is offline Offline
9 posts
since Jul 2006
Jul 21st, 2006
0

Re: Convert mouse position to Texture position on ball

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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 22nd, 2006
0

Re: Convert mouse position to Texture position on ball

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3DStarter is offline Offline
9 posts
since Jul 2006
Jul 22nd, 2006
0

Re: Convert mouse position to Texture position on ball

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
Click image for larger version

Name:	circle.GIF
Views:	23
Size:	7.4 KB
ID:	2197  
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Jul 23rd, 2006
0

Re: Convert mouse position to Texture position on ball

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3DStarter is offline Offline
9 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: rectangle in vb
Next Thread in Game Development Forum Timeline: 7.1 volume control





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC