User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Game Development section within the Software Development category of DaniWeb, a massive community of 391,549 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,543 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Game Development advertiser:
Views: 5932 | Replies: 16 | Solved
Reply
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Question Convert mouse position to Texture position on ball

  #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 12:10 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Convert mouse position to Texture position on ball

  #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?
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

  #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  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Convert mouse position to Texture position on ball

  #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
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Convert mouse position to Texture position on ball

  #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, 11 views)
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

  #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  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Convert mouse position to Texture position on ball

  #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.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

  #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  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is online now Online
Posting Shark

Re: Convert mouse position to Texture position on ball

  #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 Images
File Type: gif circle.GIF (7.4 KB, 6 views)
Reply With Quote  
Join Date: Jul 2006
Posts: 9
Reputation: 3DStarter is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
3DStarter 3DStarter is offline Offline
Newbie Poster

Re: Convert mouse position to Texture position on ball

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Game Development Marketplace
Thread Tools Display Modes

Other Threads in the Game Development Forum

All times are GMT -4. The time now is 9:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC