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 onto the surface of a sphere

Author
Message
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 01:51 Edited at: 22nd Sep 2011 01:53
My next project is:

I want to create a planet, and on that planet have some landing zones, depicted by objects which can be selected simply by "Pick Object()".

The planet creation - Easy

Placing the objects on the surface - Erm...

I'd like to rotate them with the sphere too.

My mind has gone a complete blank if anyone has any ideas...?

EDIT: They will be pseudo randomly placed by the way... So that each time I come back to that planet the same positions will be there...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Sep 2011 02:14
You could have a Dummy object that will be in 0,0,0 then all objects that you have on top of the sphere, you have to calculate the distance from the place they are to the dummy ....lastly offset limb cero of all objects the distance, and then use the same var to rotate them.


Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 02:19
Ah ha... Or Eureka!!!

I think I've got it, just going to put it into practice.

Offset for object will be a rotational vector which is added the current orientation of the sphere and then placed at a distance of the radius...

I'll post some code as soon as I've got it...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Sep 2011 02:38 Edited at: 22nd Sep 2011 02:39
Quote: "Ah ha... Or Eureka!!! "


I made some test offseting limb 0, and it works. Then if you want to make them to move of the surface, you will have to increase a var and apply it to your object.



Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 02:54 Edited at: 22nd Sep 2011 02:55
Does "Pick Object" work with limbs? It would help if it did...

I've come up with this. Looks nice but not what I'm after. The objects should stay on the surface. At the moment they orbit the thing...



EDIT: Actually chafari, your "Fix Pivot" is probably a better choice... Thanks...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Sep 2011 02:59
If you are going to move the camera, I think you had better to place dummys in every limb to decide which limb you want to move



Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 03:03


Well, the planet now moves but the surface objects stay in place.

And here's me thinking this was going to be easy...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Sep 2011 03:11 Edited at: 22nd Sep 2011 03:16
You just have move objects, but have not offset its center to rotate with the planet

Edited
Your code updated.




Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 03:16
I think what I need to figure out now is how to set the local object coordinates so that they are the same as the center of the main sphere. They're still rotating on they're own axis.

I'm gonna have another look at my first piece of code.

If I was to use limbs then the pick object wouldn't work.

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Sep 2011 03:22 Edited at: 22nd Sep 2011 03:25
Quote: "They're still rotating on they're own axis."


They rotate as if they were on top of a big planet as it must do.







Edited
You could make a big flat planet and then just rotate the sky.



Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 03:28 Edited at: 22nd Sep 2011 03:29
@chafari - Brilliant! It finally works... Now I can start creating the first stage of my game...



EDIT: I assumed offset limb was absolute positioning and wasn't affected by orientation...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Sep 2011 03:32
Ok don't give up !!

Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 03:34 Edited at: 22nd Sep 2011 03:35
Quote: "Edited You could make a big flat planet and then just rotate the sky."


That idea is for when landing on the planet... Got to have a sequence before the second stage of the game kicks in...

Using a simple matrix and using the matrix rotate commands I should be able to simulate a decent effect...

Warning! May contain Nuts!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd Sep 2011 03:38
Aha! Found the thread.

http://forum.thegamecreators.com/?m=forum_view&t=174630&b=1
Use Dr. Tank's solution, not my solution. What I had going was OK but what Dr Tank was doing was easier and pretty much the same thing.


Why does blue text appear every time you are near?
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 03:54
@Neuro Fuzzy - I remember watching that thread go by, it was very interesting. I'm determined to get some of the vector type of maths that you show quite often fully learnt, because after that I want to write them directly into assembler using the FPU instead of using the standard C/C++ libraries. However I've bookmarked that thread now as a reference. Thank you...

In the meantime, have you got any easy to learn vector maths links? I should have learnt it years ago really...

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 04:16
Final proto type code in case anyone would like a nosey...



Warning! May contain Nuts!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd Sep 2011 07:55
Quote: "In the meantime, have you got any easy to learn vector maths links? I should have learnt it years ago really..."

Funny you should ask. I started learning linear algebra with this awesome tutorial made for DBPro. "vectors don't bite"
http://forum.thegamecreators.com/?m=forum_view&t=133126&b=7

That covers vector addition, subtraction, scalar multiplication, dot product, cross product, length, inversion, normalization, and most importantly - how to use vector math.

Of course, vector math can be expressed with matrices, and after I read that tutorial, it took me a while of googling and trying to solve problems before I had a grip on affine transformation matrices. Affine transformations represent scaling, rotation, translation, skew, and mirroring. Usually the latter two types of transforms aren't used. An affine matrix like that quite literally represents axes in coordinate space.

Here's an example of how awesome affine transformations are/standard linear algebra is: If you hold your hand out in front of you, so that your thumb, index, and middle finger are all perpendicular to each other, then move your arm around and rotate your wrist, that is a surprisingly precise representation of a translation/rotation matrix. If you took the position of the tip of your thumb relative to the knuckle of your index finger (because your knuckle is approximately the origin of our coordinate space), then the resulting direction (vector of length one) is one column of your affine transformation matrix. If you do the same with your index and middle fingers, you get an entire rotation matrix! Of course, another cool thing, is that if you take the dot product of two of these fingers, you get zero. eg

(IndexTipPos.x-KnucklePos.x)*(ThumbTipPos.x-KnucklePos.x)+(IndexTipPos.y-KnucklePos.y*(ThumbTipPos.y-KnucklePos.y)+(IndexTipPos.z-KnucklePos.x)*(ThumbTipPos.z-KnucklePos.z)=0

this is the mathematical way of saying the two vectors are perpendicular!

There's lots of stuff like this. Suffice it to say that after you go through the "why" of it all, matrices and vectors are really intuitive.


Why does blue text appear every time you are near?
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 14:00
Before I move on with my larger project I think I need to take a little stand back and study this subject a little further.

I remember doing some things like you describe Nuero in school. 2D vector maths I have an almost decent grasp on. I've had a once over through the link above and will re-read it. I've found this which seems to also be a good start:

http://chortle.ccsu.edu/vectorlessons/vectorIndex.html#00

I'm so used to using x's, y's, and z's and never considered vectors as such, apart from angles, distances, etc. Hopefully I can put together soon some proper code involving vector maths.

Thanks again...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Sep 2011 14:46
Quote: "Final proto type code in case anyone would like a nosey..."


You got it working!! but Dr Tank examples are awesome. Thanks Neuro Fuzzy for showing us that thread and for the good vector tuto.


Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2011 19:54
The testing code in this thread was basically all I wanted. I'm after generating a planet with a perlin noise texture (fixed on a sphere). Placing landing sites on it, the user rotates around the planet and selects a landing zone. Then it moves on the the next segment.

A lot of the other code involves heavy maths which I don't yet understand fully. In the meantime I'm buffing up on vectors and matrices, might take a while.

The help from the members of these forums is amazing, I wouldn't be at this point if it wasn't for that help.

Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-10 06:08:15
Your offset time is: 2026-07-10 06:08:15