Posted: 10th Nov 2021 5:14
I want to map a path from A to B following the curvature of the sphere (in 3D space), I know the dimension and location of the sphere but currently know diddily squat about the math I am going to need

I just bookmarked a bunch of pages that look like something that I might be able to use but thought I'd ask you guys fi anyone has done anything like this before I spend the entirety of tomorrow studying.

Posted: 10th Nov 2021 5:19
What you could do is use FixObjectToObject to attach a sphere to your sphere and then rotate the first sphere
Posted: 10th Nov 2021 5:40
I did consider that but there will be lots of moving objects so I'd have to give each one its own extra sphere adding too much unneeded geo data on the GPU, I might have better results using a plane and try some gnomonic mapping but again its going to take some research,

Distance from origin might be the best approach, I can get angle data from the collision normal from outside the sphere but mapping the points from the sphere centre wont work with RayCast, unless, maybe 1 extra sphere with inverted normals for the mapping routines ... yeah that could work, right?

Edit: Mental Note to Self

Map line from centre of sphere from A to B then cast a ray along the line to get spherical data on inward facing normal, move object to path point and get angle from outward facing normal, job done!

I wonder if an object with a solidify modifier registers contact with RayCast, or extrude and flip faces ...., looks like I got some experimenting to do, lol
Posted: 11th Nov 2021 3:16
Do you know the points A and B on the sphere? If not and these are points in space around the sphere, I think it'll be easier to first project them onto the sphere, keeping track of the original point's distance from the surface.

This might help for starters, calculating the distance between the two points along the surface of the sphere:

+ Code Snippet
A, B = points relative to sphere with center origin of [0,0,0]
r = sphere radius

dot# = (A.x * B.x) + (A.y * B.y) + (A.z * B.z)

distance = r * acos(dot# / r^2)





Example in 2D:
+ Code Snippet
c = makeColor(255,255,255)
c2 = makeColor(255,0,0)
c3 = makeColor(0,255,0)
Type Vector2D
	x as float
	y as float
EndType
A as Vector2D
B as Vector2D

radius = 150

// Stationary point
angle = random(0,360)
A.x = cos(angle)*radius
A.y = sin(angle)*radius



do
    
    
    // Dynamic point follows mouse
    B.x = getRawMouseX() - 400
    B.y = getRawMouseY() - 400
    d = sqrt(B.x^2 + B.y^2)
    B.x = (B.x / d) * radius
    B.y = (B.y / d) * radius
    
    dot# = (A.x * B.x) + (A.y * B.y)
    distance# = acos(dot# / radius^2)
    

    drawEllipse(400,400,radius,radius,c,c,1)
	drawEllipse(400+A.x,400+A.y,10,10,c2,c2,1)
	drawEllipse(400+B.x,400+B.y,10,10,c3,c3,1)

	print(distance#)
    Sync()
loop





Here's an idea I have. Red (A) is trying to get to green (B). If you draw a straight path between them but then plot those points to the surface of the sphere (the pink dots)




+ Code Snippet
1. Use linear interpolation (LERP) to move along the straight path.  P is a point on that path,  t is a value from 0 (A) to 1 (B).
	P = A + (B - A) *t

2. Project that point to the surface of the sphere (S).
    D = S - P (direction)
    normalize D
    W = S + D * radius

    Where 'W' is your new point along the surface




Working example (2D):

+ Code Snippet
c = makeColor(255,255,255)
c2 = makeColor(255,0,0)
c3 = makeColor(0,255,0)
blue = MakeColor(0,0,255)

Type Vector2D
	x as float
	y as float
EndType
A as Vector2D
B as Vector2D
P as Vector2D


radius = 150


angle = random(0,360)
A.x = cos(angle)*radius
A.y = sin(angle)*radius

angle = random(0,360)
B.x = cos(angle)*radius
B.y = sin(angle)*radius


t# = 0

do

    
    dot# = (A.x * B.x) + (A.y * B.y)
    distance# = acos(dot# / radius^2)
    

    drawEllipse(400,400,radius,radius,c,c,1)
	drawEllipse(400+A.x,400+A.y,10,10,c2,c2,1)
	drawEllipse(400+B.x,400+B.y,10,10,c3,c3,1)
	
	
	
	if getRawKeyPressed(32)
		angle = random(0,360)
		A.x = cos(angle)*radius
		A.y = sin(angle)*radius

		angle = random(0,360)
		B.x = cos(angle)*radius
		B.y = sin(angle)*radius
		
		t# = 0
	endif

	

	if t# < 1
		inc t#, 0.01
	endif


	
	P.x = (A.x + (B.x-A.x)*t#)
	P.y = (A.y + (B.y-A.y)*t#)
	
	// Normalize
	d# = sqrt(P.x^2 + P.y^2)
	P.x = P.x / d#
	P.y = P.y / d#
	
	P.x = P.x*radius
	P.y = P.y*radius
	
	
	drawEllipse(400+P.x,400+P.y,10,10,blue,blue,1)
	

	print(t#)
	print(distance#)
    Sync()
loop
Posted: 11th Nov 2021 4:21
Here's an idea I have.


That's pretty much what I have in mind.

distance between the two points along the surface of the sphere


that will come in handy for calculating valid targets in range, nice one, I was just going to hack that with a straight point to point distance but surface distance is so much better

it always helps to have a plan when opening an editor and I got a train day today so can sit and code while on the payroll
Posted: 12th Nov 2021 2:36
Humphf!!!

What sound easy in my head is turning out to be quite difficult!!



Edit: and this new lappy does nice screen cap.... might have to start uploading rants!! lmao!!
Posted: 12th Nov 2021 6:04
ok what I might do here is add points all around the circle by adding shapes and then getting each line to match each point.

You could even cast a distance to see how far you are from each point.

This is what I would do.

Might take a couple days to do but worth it in the end because you can reuse the same saved shape points.

I had to do this for my other game for collision on slopes.

Shapes do work good if you add them right.

Send me the picture so I can try to add shape points to it if this is what you would like to try.
Posted: 12th Nov 2021 7:32
It does not need shapes it needs math, these are not fixed points they will be dynamic and always moving and the paths need to be calculated frame by frame, sure I can manually add a bunch of path nodes and call it a day but.... Na, this has to be procedural, I set myself the challenge and refuse to quit!

Mind you, if I just did that I could have got some sleep last night!!! lol

its not a picture its a generated sphere "CreateObjectSphere()"
Posted: 12th Nov 2021 7:54
its not a picture its a generated sphere "CreateObjectSphere()"


Is it a 3d model?

if so it has polys with point

I wonder if you can get the poly point positions?

What do you need this for anyhow?

Just so I know why you are trying to math out 3d spear sin positions, I'm just curious is all.
Posted: 12th Nov 2021 8:27
Yeah its 3D, and no polys wont help as that would mean memblocks and they are slow, to slow for pathfinding

I need it for A.I. path mapping, imagine a RTS game on a flat plane, ok, now imagine that same game on a sphere ...

Dyson Sphere Program is the kind of gameplay mechanic I am aiming for, but obviously not as advanced or polished as that, but the spherical aspect to it

I found a pretty nice math lib for agk that will certainly help, just have to figure out how to use it.
Posted: 12th Nov 2021 8:40
A.I. path mapping


I guess it depends on what you are trying to map a path for.

Different things means different ways.

For anyone approaching I would add a joint that rotates around the approaching elements so it rotates around the planet.

There easy to make and work good.

you can make a joint for just about anything and it would work.

I've been doing a lot of playing around with joints and been surprised.

But what you showed me is a big, no huge project for a one month competition.

That would scare me a lot lol.
Posted: 12th Nov 2021 8:51
I found these functions if any of them help

+ Code Snippet
//This command will return a value that represents the new X position of a point in 3D space
// currentXValue -- current value to calculate the new value from.
// angleValue -- angle value in degrees 0 to 360
// stepValue -- specifies how far in the specified direction you would like to calculate
function CalculateNewXValue( currentXValue as float, angleValue as float, stepValue as float ) 
	result# = currentXValue + ( sin( angleValue ) * stepValue )
endfunction result#

//This command will return a value that represents the new Y position of a point in 3D space
// currentXValue -- current value to calculate the new value from.
// angleValue -- angle value in degrees 0 to 360
// stepValue -- specifies how far in the specified direction you would like to calculate
function CalculateNewYValue( currentYValue as float, angleValue as float, stepValue as float ) 
	result# = currentYValue - ( sin( angleValue ) * stepValue )
endfunction result#

//This command will return a value that represents the new Z position of a point in 3D space
// currentXValue -- current value to calculate the new value from.
// angleValue -- angle value in degrees 0 to 360
// stepValue -- specifies how far in the specified direction you would like to calculate
function CalculateNewZValue( currentZValue as float, angleValue as float, stepValue as float ) 
	result# = currentZValue + ( cos( angleValue ) * stepValue )
endfunction result#
Posted: 12th Nov 2021 9:54
ifferent things means different ways.


No, a path is a path, a start point, an end point and nodes inbetween, any AI or system just draws info from the path data and uses it to move, every path system in every game engine ever made works like this, you make the AI suit the path not the path suit the AI, anything else is just a hack!

hat would scare me a lot lol.


its huge for one month, its gargantuan for one month and one man!, if its ready its ready, if not, oh well, I'll come out on the other side knowing a whole bunch of stuff I didn't know before so it will be time well spent, no?

I found these functions if any of them help


not for my path mapping but I use similar code for my camera movement, I usually put stuff like that directly into my code, no need for functions
+ Code Snippet
  OrbitX = gCameraOrbit.distance * sin(gCameraOrbit.elevation) * sin(gCameraOrbit.angle) + origX#
  OrbitY = gCameraOrbit.distance * cos(gCameraOrbit.elevation) + origY#
  OrbitZ = gCameraOrbit.distance * sin(gCameraOrbit.elevation) * cos(gCameraOrbit.angle) + origZ#



've been doing a lot of playing around with joints and been surprised.


Hmmmmm, context really is everything, isn't it! lmao!
Posted: 12th Nov 2021 10:13
Right, now I am getting closer, 3 days of searching and finally found this

Hyperbolic quaternion sounds like exactly what I need, might pull a sicky!! lol
Posted: 12th Nov 2021 10:35
Hmmmmm, context really is everything, isn't it! lmao!


As a Girl I have heard them all. lol, but this is a new one.
Posted: 12th Nov 2021 10:51
I am sure you have, but as a builder I guarantee I have heard more! lol

Anyway... success!



I have to admit, that was a serious 14 hour brain ache!!
Posted: 14th Nov 2021 16:23
I found these functions if any of them help

Those equations don't look correct to me. What PartTimeCoder posted for calculating his orbit values looks more like what I'd expect for finding x,y,z values. Problem with that however is the possibility of gimbal lock, so you use quaternions instead, which it looks like you found.

I can't tell in the video, but is spacing of the points along the surface equal distances? I noticed that was my problem in my 2d example, which made traveling at a constant speed not so constant.

Isn't it so satisfying to to solve a problem that's plagued you for days?
Posted: 14th Nov 2021 16:57
Isn't it so satisfying to to solve a problem that's plagued you for days?


It is, the best feeling in the world.

But you are right, its not quite as perfect as I first thought, the spacing is off and the further apart the A and B nodes are the less accurate it becomes and I have to extend the ray out or reverse it, still playing with the formula to get that but its *acceptable*, it breaks when I push it far beyond the limits of what I am actually going to use it for.

I had considered the constant speed issue and figured if I can calculate an average and divide it by the node count and distance between each node when I generate the path I can fudge something that looks good enough, not quite sure how that calculation looks yet but once the path is generated I am dealing with fixed values so it will be a dam sight easier than generating the path in the first place, just loop the path nodes, get the distance to the next node, store them in an array and kiss goodbye to another 2 days trying to work it out! lol