GetAbsOrigin(): Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Robot: fixing template case.)
No edit summary
Line 1: Line 1:
'''<code>GetAbsOrigin()</code>''' returns the world co-ordinates of the [[origin]] of any [[point]] or [[model]] entity as a [[vector]]. This is ''theoretically'' the centre of the object, but for NPCs (to choose a prominent example) it will be a point exactly half way between the soles of their feet when in the [[reference posture]], or wherever else the modeller has placed it.
'''<code>GetAbsOrigin()</code>''' returns the absolute (i.e. [[world]]-relative) [[origin]] of an entity as a [[vector]]. Sister function '''<code>SetAbsOrigin()</code>''' sets it.
 
The origin is actually stored in local space (i.e [[parent]]-relative), meaning that the Abs functions perform a conversion before returning. If you can, use the more direct <code>[[GetLocalOrigin()]]</code> and <code>[[SetLocalOrigin()]]</code> instead.


== Alternatives ==
== Alternatives ==


You may want to use a different method of finding an entity's location, particularly given the fact that <code>GetAbsOrigin()</code> will not work with [[brush]]es unless they are tied to an [[entity]] that creates one for them - which may well not mark the location of the object in any useful way!
A different approach for finding an origin can be useful, particularly when dealing with a [[brush entity]] which might not have one stored. Bear in mind that these alternatives are all significantly slower than <code>GetAbsOrigin()</code>!
 
{{note|These alternatives are all significantly slower than <code>GetAbsOrigin()</code>.}}
 
{{TODO|How many of these OBB functions work with vphysics?}}


;<code>WorldSpaceCenter()</code>
; [[Vector]] <code>WorldSpaceCenter()</code>
:Returns the centre of an entity's [[object-aligned bounding box]] as a vector.
: Returns the centre of an entity's [[object-aligned bounding box]].
;<code>[[CollisionProp()]]->CalcNearestPoint( [[const]] Vector &vecWorldPt, Vector *pVecNearestWorldPt )</code>
; void <code>[[CollisionProp()]]->CalcNearestPoint(&vecWorldPt,*pVecNearestWorldPt)</code>
:Calculates the nearest point to <code>vecWorldPt</code> of an entity's [[object-aligned bounding box]].  
: Finds the nearest point on the entity's [[OBB]] to <code>vecWorldPt</code>. Modifies <code>pVecNearestWorldPt</code> with the result.
:{{note|Instead of returning a value, this function will modify whatever variable is passed for <code>pVecNearestWorldPt</code>.}}


{{TODO|More...}}
{{TODO|Do these OBB functions work with vphysics?}}


[[Category:Functions]]
[[Category:Functions]]

Revision as of 10:57, 14 April 2009

GetAbsOrigin() returns the absolute (i.e. world-relative) origin of an entity as a vector. Sister function SetAbsOrigin() sets it.

The origin is actually stored in local space (i.e parent-relative), meaning that the Abs functions perform a conversion before returning. If you can, use the more direct GetLocalOrigin() and SetLocalOrigin() instead.

Alternatives

A different approach for finding an origin can be useful, particularly when dealing with a brush entity which might not have one stored. Bear in mind that these alternatives are all significantly slower than GetAbsOrigin()!

Vector WorldSpaceCenter()
Returns the centre of an entity's object-aligned bounding box.
void CollisionProp()->CalcNearestPoint(&vecWorldPt,*pVecNearestWorldPt)
Finds the nearest point on the entity's OBB to vecWorldPt. Modifies pVecNearestWorldPt with the result.
Todo: Do these OBB functions work with vphysics?