On 09/01/2018 at 08:45, xxxxxxxx wrote:
Has anyone done anything with working out the Min/Max X,Y of points in screen space before? I'm trying to work out the screen space center of an object and need these two vectors to work out the middle.
Any help would be awesome Thank you
On 10/01/2018 at 03:55, xxxxxxxx wrote:
Hi more4d, thanks for writing us.
With reference to your request, assuming you'r just interested in the object's center it's enough to retrieve the object's bounding box position via BaseObject::GetMp() and simply transform it using BaseView::WS(). This way you can in a few lines get the position of the object's center in screen space.
# get the active BaseDraw
bd = doc.GetActiveBaseDraw()
# check both active BaseDraw and active BaseObject
if bd is None:
if op is None:
# retrieve object's bounding-box coordinates in world space
opBBoxWorld = op.GetMg() * op.GetMp()
# transform from world-space to screen-space using BaseView::WS()
opBBoxScreen = bd.WS(opBBoxWorld)
# print results
print "Object's center in world-space: ", opBBoxWorld
print "Object's center in screen-space: (x:", opBBoxScreen.x, ", y:", opBBoxScreen.y, ")"
In case instead you need to refine your investigation to all the vertexes of the object, just loop over them and transform in screen-space using the same technique described above.
For the sake of completeness, it could worth having a look here where details are explained.