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.

AppGameKit Studio Chat / [SOLVED] frame an object

Author
Message
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 20th Nov 2019 08:37 Edited at: 20th Nov 2019 08:38
I need some help with this been working on it to no avail.
i have an object of known size. for example 4 units. if i divide by 2 i get 2 units aka my radius.
using screenx=getscreenxfrom3d(objposx#+radius,objposy#,objposz#) so plgging in the object current position plus its radius should give me the screen coord of its outside edge.

so then i want to frame the object with a circle
so i get the object centerpoint
x=getscreenxfrom3d(objposx#,objposy#,objposz#)
y=getscreenyfrom3d(objposx#,objposy#,objposz#)

now i want to draw a circles on x,y and scale the x and y radius to screenx.
but we need to take screenx and subtract x , "outside to center in screen coords" to determine how many pixels to draw

DrawEllipse(x,y,screenx-x ,MakeColor(128,128,255),MakeColor(128,128,255),0)

this code works for the most part but when the camera rotates on the z axis the size of the circle changes and is not consistent. any longer i dont know whats going on. aslo from one side it is large and viewing from the other side very small

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

Go to answer

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 20th Nov 2019 11:13 Edited at: 20th Nov 2019 11:35
This post has been marked by the post author as the answer.
You are measuring the screen position along just the x axis which is fine if your camera isnt rotated at all..but if it is rotated that 3d location could be almost directly behind or infront of the centre of the camera view meaning your circle will indeed be tiny depending on rotation. (at 90 degrees rotation about Y axis the circle will be tiny)

There's quite a few ways of fixing it ...i will list 2 for now....

1) Easy way: You could temporarily move the camera along its local x (MoveCameraLocalX,Y,Z()) by the radius of you object and get the change in camera x,y and z positions then move it back to where it was again. Then add those changes in values dx#, dy#, dz# to your objects position and take the screen x and y position from that. That will work and give you a consistant circle size that isnt dependant on camera rotations.


2) Nerdy Ass Math based method: You can do some trigonometry/quaternion maths to impress the ladies with...


Either of these works
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 21st Nov 2019 00:50
Ill always take a nerdy math option if available . Thank you so much Bengismo it works perfectly. ive been diving into a massive amount of trigonometry lately. Never thought id need it for anything now having to learn it on the fly at every turn there is a new math problem. I am unfamiliar with Quaternary so ill have to do some research on those as well. I was unaware the cameras current angle and position would affect get 3d from and object.

smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 21st Nov 2019 06:15 Edited at: 21st Nov 2019 06:31
Hey math wizard benjiso I have another problem. Ive been researching trig all day and have devised the following function to calculate the position of an object to the camera and return the camera angle relative tot he object but it is broken and i dont know how to make it work. I am def trying here.



sync()
loop

or should i use vector maths?

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Nov 2019 06:38
The "lookAt" commands are very handy for that sort of thing
SetObjectLookAt()
SetCameraLookAt()

Login to post a reply

Server time is: 2024-04-13 17:48:01
Your offset time is: 2024-04-13 17:48:01