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 / Spherical Vectors

Author
Message
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 5th May 2011 12:40 Edited at: 5th May 2011 13:00
Hi,

If theres one thing that slows me down it's less than obvious 3D maths! I started a new game about 2 weeks ago and its been pretty much a fulltime development since then and it's looking pretty damn good if I do say so myself.

I'm needing a way of calculating a vector on a spherical surface. So units can move around on the surface of a sphere basically. They also need to have very basic pathfinding abilities. All they need to know is which way is the quickest. Up,down,clockwise,anticlockwise.

Has anyone found a good way of doing this? or have the maths abilities to help please? I've tried a few things with only a bit of success.

Thanks
Nick

*Edit. Just to make things clearer. I'm not currently using vectors, but simple coordinates as vectors.
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 5th May 2011 13:35
I was thinking about a similar idea a couple of days ago, kinda like what's found in Maxis Spore? Maybe, the trick for yourself might be in a camera effect, like a fish eye lens. The geometry is square, but the camera gives the effect that it's spherical.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 5th May 2011 13:56 Edited at: 5th May 2011 15:15
I'm only really moving 3D symbols around Earth on mine. I may have another way of doing it, though I don't think it'd work for anything more complicated than basic moving around. I'm going to make a few other minor additions to my game in other areas before looking into it.

*Edit. It looks like I've found a way that surprisingly doesn't use vectors at all, but uses EZrotate instead. The model of the symbol is offset on the Z-axis by the radius of the planet model. Using pitch and turn to commands in EZRotate my little unit symbol now goes to a waypoint. Time to put this in my game for real I think!

It's not perfect, but it's close enough for now. It always goes to the target, which is what counts!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th May 2011 06:23 Edited at: 6th May 2011 06:31
If you /want/ a mathematical solution, I have a video showcasing that it is I think you want to do:

(the small green spheres would be the path you want)

Errm, sorry, I don't have the code anymore. As I said in the comments of that video:
Quote: "Basically, I took the cross product between the two unit vectors (the two larger destination spheres), and used that as an axis, then constructed a rotation matrix to rotate about that axis, aaand then calculated euler angles from that matrix. I also used the dot product between the two vectors to figure out how much to turn,"


but that won't help you mch unless you're alright with matrices.

[edit]
in other words, given two /unit/ vectors, A and B, let C=AxB (the cross product of A and B). Given the matrix described here:
http://www.cprogramming.com/tutorial/3d/rotation.html
plugin C's x y and z values for the axis of rotation. Then, take the acos(A.B) (inverse cosine of the dot product of A and B), and plug in an angle to that matrix inbetween 0 and acos(A.B), to get a matrix, R. R*A (matrix*vector), gives you another vector C that lies on the shortest path between A and B.

in a better explained way:

Cross product -> axis
dot product -> angle -> theta ranging from 0 to angle
axis + theta -> matrix
matrix * vector -> result


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 12th May 2011 11:27 Edited at: 12th May 2011 11:42
Thanks Neuro Fuzzy

I'll keep all that in mind when I go back to that part of my game. I've been thinking about asking around to see if anyone wants to give me a hand directly with that section of my game, but only after I've had another go at it. I had it working fine, but then I had to make a change to the way my game worked in another part of it and that means I need to change this part again. I had tried to keep the Earth from moving or rotating, but in order for me to do some other things I had to make it rotate.

Thanks

Login to post a reply

Server time is: 2026-07-11 02:36:40
Your offset time is: 2026-07-11 02:36:40