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.

Newcomers DBPro Corner / Position objects around sphere

Author
Message
FireIndy
17
Years of Service
User Offline
Joined: 17th Jan 2007
Location: US of A
Posted: 27th Jan 2008 04:03
Im doing a little programming, and Im working on a space sim, just for the heck of it. I have a sphere size 100 located at 0,0,0 for the sun. Im trying to do stars, but Im having problems positioning them. I want to position them outside the sun sphere. What do I have to do to get them positioned at random places, starting outside the sphere?

Now its only this, but it only positions them at positive xyz values:



TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Jan 2008 05:09
position object i,RND(1000)+200,RND(1000)+200,RND(1000)+200

Rnd returns a value between 0 and the number you specify. Adding 200 (or whatever) makes sure the value returned is always greater than the size of your sun sphere.

TDK_Man

FireIndy
17
Years of Service
User Offline
Joined: 17th Jan 2007
Location: US of A
Posted: 27th Jan 2008 05:13
I know that, but what I mean is that since that RND() only returns values from 0 to the specified number, the stars are only positioned at positive xyz values. That leaves negative values too. Is there a way to get the area outside the sphere and randomly position them?

pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 27th Jan 2008 07:25
int = Rnd(2000)-1000
FireIndy
17
Years of Service
User Offline
Joined: 17th Jan 2007
Location: US of A
Posted: 27th Jan 2008 16:48
Thanks pcRaider And TDK. It works now

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 27th Jan 2008 16:50 Edited at: 27th Jan 2008 16:51
I believe you want to do something like this:

value# = abs(rnd(1000) + 200) * (2*rnd(1) - 1)

EDIT: Sorry, I must've misunderstood it.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.

Login to post a reply

Server time is: 2024-11-25 07:47:48
Your offset time is: 2024-11-25 07:47:48