Author Topic: Entity height/width in view angle?  (Read 10021 times)

0 Members and 1 Guest are viewing this topic.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Entity height/width in view angle?
« on: July 13, 2006, 06:33:44 AM »
Using Lua, how would one go about getting the height and width, in standard _GmodRect_SetPos (,,h,w) format, accounting for various screen resolutions, of a Entity in the HUD?
(if you know of a mod/script/function that has been released, and can provide link to it, please do!)

Gmod Rect uses 0 to 1 for its X/Y co-ordinates, so
Rect_Set(.5,.5 would place the start of the rectangle in the center of the screen, and (.5,.5, .5,.5) where the last two are height/width of rectangle, would make the rectangle fill lower-right quadrant of the users screen.

However, how would I adjust the height/width dynamically depending on how close I am to an ent? Things farther away would have much smaller height/width perspective than closer of course.

------------------------------------------------------
|           |2|                                                          |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
|                                               w                        |
|                                   -|-     |    |                      |
|                                            |  1 | h                   |
|                                            |___|                     |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
------------------------------------------------------

Say 1 and 2 in my 'hud' above are trashcans/barrels,whatever.
I know I can use EntGetPos to grab vectors, but how would I get the h/w they're using of my screen?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: Entity height/width in view angle?
« Reply #1 on: July 13, 2006, 07:12:40 AM »
I think that _GModRect_SetEntity and _GModRect_SetEntityOffset are what you're looking for.

Under notes for setentity: "Actually, the rect doesn't technically "hover" over the entity in the game. The command tells the clients its sent to to constantly setpos the floating rect at the position of the entity on the user's screen, or hide it if the entity is not on the user's screen. ".

So I'm not sure if this will make the rect resize automagically based off distance or not, but if it doesn't, you can easily do it yourself.

Let me know how it works out, I was thinking of doing something similar. :P
Experiencing God's grace one day at a time.

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given