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 AppGameKit Corner / [SOLVED] Finding the center point between two objects

Author
Message
Wilf
Valued Member
13
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Doha, Qatar
Posted: 5th Feb 2020 15:49
Hey guys,
I'm trying to find the center point between 2 (or more) 3d objects, but I'm missing something super basic.
I want to find the object that is furthest along the x axis, the object that is furthest along -x, and place another object equidistant between the two.

If you compile the attached code, you'll see by dragging the boxes around it sorta sometimes works - the sphere positions correctly if both boxes are -x and object 1 is 'above' object 0.
Basically I'm doing something stupid in the loop to find the bounds.

Can anyone help?


Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

fubarpk
Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 5th Feb 2020 16:28
The get object world commands should do that

but I believe they work from the objects pivot position and you may have to use the mesh size calculations to get an accurate representation

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
JosephB
13
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 5th Feb 2020 19:36
I think there might be a slight miscalculation in the FindXCenterOfGroup() function where you were only calculating half the difference between the lower and upper bounds. I changed your function a bit to subtract that distance from the upper bound to calculate the center point between the two objects. I hope that works for you and is what you were looking for.

Golelorn
3
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 6th Feb 2020 01:35 Edited at: 6th Feb 2020 01:39
This post has been marked by the post author as the answer.
It looks like you're making it way too complicated.

Add the X positions and divide by the number of objects. In your case (-116+47)/2 = -34.5. That is 81.5 units away from both.

The reason why your code is not working is you're changing your upperboundx# to -116 in the second pass.



(-116) < (-47) = TRUE So your upperboundX now equals -116. And even a math dummy like me knows (-116+-116)/2 = -116.

To find the lowest value - set x# to the first object in the array. Then loop replacing the lowest value if its less than itself.


Then just vice versa for the max.
Wilf
Valued Member
13
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Doha, Qatar
Posted: 6th Feb 2020 04:26
Thanks so much fubarpk JoesephB and Golelorn!
Golelorn you were right - I was overcomplicating things - your solution works real nice.

Login to post a reply

Server time is: 2020-04-06 19:25:10
Your offset time is: 2020-04-06 19:25:10