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 Classic Chat / Set 2D Text Position to 3D Position

Author
Message
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 5th Oct 2014 16:02 Edited at: 5th Oct 2014 16:03
How can I properly display AppGameKit 2D text over a 3D object when the object is moved in 3D space?

// I obviously no how to retrieve my objects 3D position...
MyPlayerY = GetObjectX(Player)
MyPlayerY = GetObjectY(Player)
MyPlayerZ = GetObjectZ(Player)


// Don't know the math to get the text over the objects 3D space...
SetTextPosition(mytext, x?, y?)

*** I did this a while back in TV3D using a 2DBillboard just don't know how to achieve this in AGK. ***


I have a multiplayer fps shooter where I am trying to display the tagname of all client players slightly over there respective 3D object player in 3D space.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Oct 2014 17:33
maybe this is useful
GetScreenXFrom3D
GetScreenYFrom3D
http://www.appgamekit.com/documentation/Reference/3D.htm
http://www.appgamekit.com/documentation/Reference/3D/GetScreenXFrom3D.htm

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 5th Oct 2014 19:22
Thanks again Markus. Gonna play with those commands later. Im just wondering if im gonna have to somehow implement this by rendering the text onto a transparent 3dplane (billboard) to somehow achieve this.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Oct 2014 19:36
hmm,
on detours, print name on screen, grab image,save image,
create plane,load image as texture,turn plane to camera allways,
set plane to object positions above.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 6th Oct 2014 04:28
Quote: "maybe this is useful
GetScreenXFrom3D
GetScreenYFrom3D"


Works great! Thanks Markus
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 6th Oct 2014 17:22 Edited at: 6th Oct 2014 17:24
OK... Slight problem I don't know how to fix.

All works well using when the camera is facing the player 3d object.

Using:


However when the camera is turned completely away from the Player object the text is still displaying on screen as its behind the camera.

Unfortunately, GetObjectInScreen doesn't work as it should. When the player is off screen, GetObjectInScreen(Player) always returns 1 as I'm guessing its not working properly because it should return 0.

Any other way to set the text visible property to 0 when the player is not in view of the camera?





Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 6th Oct 2014 17:26 Edited at: 6th Oct 2014 17:32
ups, did not read that GetObjectInScreen did not work
...
do u use latest agk v1 108.19-21 version?

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 6th Oct 2014 17:49
I'm using v2 7.1
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Oct 2014 18:12
You could do a quick check between the angle of the camera and the angle between the camera and the object. If it is greater than 90 degrees then you know the object is off screen. GetObjectInScreen needs to be fixed though...
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 6th Oct 2014 18:35
Quote: "You could do a quick check between the angle of the camera and the angle between the camera and the object. If it is greater than 90 degrees then you know the object is off screen."


@baxslash

Can you please post some quick code for what you explained. I'm just not that good with camera stuff and angles.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Oct 2014 20:05 Edited at: 6th Oct 2014 20:06
Not very tested and hacked from some ideas of the net:
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 6th Oct 2014 20:37 Edited at: 6th Oct 2014 20:38
@ baxslash

Very, very thankful. It works 100%.....

GetObjectInScreen should be fixed. Maybe we should write that to Paul to fix.

Love this forum community. I would've been stuck for a long time.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 6th Oct 2014 21:32
was the cube a .obj file you had loaded or created by CreateObjectBox?

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 6th Oct 2014 21:51 Edited at: 6th Oct 2014 21:53
Quote: "was the cube a .obj file you had loaded or created by CreateObjectBox?"


It was a generated cube using CreateObjectBox for testing only.

Now that I have it working (thanks to you) I am gonna load my actual models as .obj.

You are either going to tell me that your code doesn't work on .obj models or GetObjectInScreen will only work on actual models...lol
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Oct 2014 00:00
just thought that the middle point of a exported 3d model can be anywhere,
means outside. thats why i had asked.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 7th Oct 2014 00:23
Yup your right! Just tested on my 3d model and now your code from before is giving me different results than an object created with CreateObjectBox. I guess the center point is not right.

Also, GetObjectInScreen doesn't work with .obj either

Now back to square one....
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 7th Oct 2014 04:42
Quote: "just thought that the middle point of a exported 3d model can be anywhere,
means outside. thats why i had asked."


UPDATE: Markus's code to this temporary fix until TGC fixes works excellent & 100%

However, if your using a .obj the objects origin must be centered.

I did this in Blender ->
Object-> Transform -> Origin to geometry

Thank you again Markus!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Oct 2014 10:29
Quote: "Very, very thankful. It works 100%....."

Glad to hear it.

Quote: "Just tested on my 3d model and now your code from before is giving me different results than an object created with CreateObjectBox"

I have had a few problems with AppGameKit primitives. It would be worth logging this with an example on the bug list

Login to post a reply

Server time is: 2024-11-25 10:50:58
Your offset time is: 2024-11-25 10:50:58