Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Placing objects on a sphere in relation to the camera position and viewing angle

Author
Message
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 7th Jul 2012 20:52
I have a size 10 sphere placed at a "0, 0, 0" position in space. I have a camera that can move around this sphere, zoom in, as well as pivot it's viewing frame (like off to the left, or right).

My question is how do I translate the current camera view/perspective to u,v coordinates I can use to place objects on the sphere with the mouse cursor?

Perhaps there is a simpler way to achieve this, but I been hard pressed to find anything to help me out.

Home is where my souped-up computer is...
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 7th Jul 2012 21:14 Edited at: 7th Jul 2012 21:22
I need this too, but gridded coordinates.

But for now here is a Sparky's plugin example...

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 7th Jul 2012 21:32
I'm also working on a new way to do this but I remember asking about this in the past.

What someone explained to me was (sorry for no snippet, I'm on linux at mo):

Create the main object and the smaller objects, rotate them and move them according to the radius of the sphere. No special math needed. Using the coords of the smaller objects, when you attach it as a limb you can use that for the OFFSET LIMB command.

When I get some spare time I'll be working with spheres a lot more, seamless texturing, converting 2d textures to a 3d sphere, and LOD, etc

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th Jul 2012 23:54
Hi there.
Heres the thread that comment the same.

http://forum.thegamecreators.com/?m=forum_view&t=189625&b=1

Cheers.

I'm not a grumpy grandpa
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Jul 2012 00:18
Quote: "My question is how do I translate the current camera view/perspective to u,v coordinates I can use to place objects on the sphere with the mouse cursor?"


Here's an idea: if you convert your sphere to a mesh and then to a memblock, the UV information will be contained in the memblock. I'm not sure if sparkys collision does this or not, but cast a ray from the camera to the center of the sphere. If you can return the triangle being collided with, you can get the indexes of the vertices for that triangle. These should correspond to the UV indexes as well so you can pull your UVs directly out of the memblock.

Enjoy your day.
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 8th Jul 2012 01:33
well, the UV data isn't that important to me as far as I can tell.

What I do need to know is how to use the mouse cursor to put items on the sphere where the mouse cursor is over at.

I can place randomly items on the surface of a sphere just fine, but what I need is for the item to be placed on the sphere where the mouse cursor is over.

Maybe I'm not explaining myself good enough.

Home is where my souped-up computer is...
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 8th Jul 2012 02:02
I guess then using sparkys raycast then you would be able to get the selected triangle from the surface where the mouse points to.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Jul 2012 02:19 Edited at: 8th Jul 2012 02:46
Quote: " but what I need is for the item to be placed on the sphere where the mouse cursor is over."

Ah, you want translate the mouse screen coordinates into 3D coordinates, cast a ray from there into the screen, and get the position it collides with on the sphere so you can place an object there. In effect, where ever the mouse cursor is over is the position on the 3D sphere to place an object. Does that sound about right?

If so, the you can use PICK SCREEN and get 2 start points to cast a ray from the mouse to some distance into the screen and use sparkys to return the collision point.

mx=mousex() : my=mousey()
pick screen mx,my,1.0
x1#=get pick vector x()
y1#=get pick vector y()
z1#=get pick vector z()

pick screen mx,my,1000.0
x2#=get pick vector x()
y2#=get pick vector y()
z2#=get pick vector z()

plug x1,y1,z1 and x2,y2,z2 into sparkys and get the point of intersection.

Enjoy your day.
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 8th Jul 2012 02:45
Quote: "What I do need to know is how to use the mouse cursor to put items on the sphere where the mouse cursor is over at."


Is this what you mean?

JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 8th Jul 2012 03:20
29 games.....That is EXACTLY what I needed! I knew that someone already figured this out. I ran the code you provided and it worked as I needed it to. Now to look at the code more closely to see how it works.

Thanks a bunch!

Home is where my souped-up computer is...
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 8th Jul 2012 03:32
Probably the most important commands to look at and play with are the PICK OBJECT and the PICK VECTOR commands, as these are the ones that connect the mouse position to the 3d world.

Glad it was what you were after.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Jul 2012 05:56 Edited at: 8th Jul 2012 05:56
I wrote an example not too long ago that returns the UV coordinates of the texture on an object. For some reason flat surfaces are glitchy, but you want a sphere so it will work. Have fun!



Download

TheComet

Login to post a reply

Server time is: 2026-07-08 12:26:55
Your offset time is: 2026-07-08 12:26:55