Discussion:
[Bf-python] drawing callback in clip editor, problems with 'view_to_region'
Dalai Felinto
2013-10-09 07:43:46 UTC
Permalink
Hi,

I'm trying to write an addon where I'll need to draw a quad connecting four
markers.
For that I need to be able to map the markers coordinates to 'screenspace'
glVertex2f coordinates.

I can't match the drawn shape with the image though.
This is a test drawing a quad that was suppose to match the image 1:1

http://www.pasteall.org/pic/show.php?id=60483
Not only there is an 'offset', but the offset changes if I pan around the
region.

Here is a sample script with the bare minimum to illustrate the problem:
http://www.pasteall.org/46273/python
(draw_rectangle is where the transformation is happening).

If anyone has any suggestion it would be much appreciated.
Thanks,
Dalai




--
blendernetwork.org/dalai-felinto
www.dalaifelinto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20131009/435f915e/attachment.htm
CoDEmanX
2013-10-09 12:24:09 UTC
Permalink
Hm your code looks quite complex, don't think you need to calculate all
that things, this works for me:

http://www.pasteall.org/46288/python

view2d.view_to_region() with 0,0 and 1,1 should give you the border
coordinates of the clip in region coordinates.
Post by Dalai Felinto
Hi,
I'm trying to write an addon where I'll need to draw a quad connecting
four markers.
For that I need to be able to map the markers coordinates to
'screenspace' glVertex2f coordinates.
I can't match the drawn shape with the image though.
This is a test drawing a quad that was suppose to match the image 1:1
http://www.pasteall.org/pic/show.php?id=60483
Not only there is an 'offset', but the offset changes if I pan around
the region.
http://www.pasteall.org/46273/python
(draw_rectangle is where the transformation is happening).
If anyone has any suggestion it would be much appreciated.
Thanks,
Dalai
--
blendernetwork.org/dalai-felinto <http://blendernetwork.org/dalai-felinto>
www.dalaifelinto.com <http://www.dalaifelinto.com>
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
Dalai Felinto
2013-10-09 15:42:32 UTC
Permalink
You are right that it works when called from an operator. But I'm trying to
make it work outside the operator, thus I need to define my own matrixes.

That said I found the fix :)
Your example did help to make me explore it further, thanks.

Basically instead of:
glOrtho(-1, 1, -1, 1, -20, 20)
(...)
coordinates = [(size, size), (-size, size), (-size, -size), ( size, -size)]

I'm now doing:
glOrtho(0, 1, 0, 1, -15, 15)
coordinates = [(size, size), (0, size), (0, 0), ( size, 0)]

Final sample file:
http://www.pasteall.org/46298/python

Cheers,
Dalai
--
blendernetwork.org/dalai-felinto
www.dalaifelinto.com


2013/10/9 CoDEmanX <codemanx at gmx.de>
Post by CoDEmanX
Hm your code looks quite complex, don't think you need to calculate all
http://www.pasteall.org/46288/python
view2d.view_to_region() with 0,0 and 1,1 should give you the border
coordinates of the clip in region coordinates.
Post by Dalai Felinto
Hi,
I'm trying to write an addon where I'll need to draw a quad connecting
four markers.
For that I need to be able to map the markers coordinates to
'screenspace' glVertex2f coordinates.
I can't match the drawn shape with the image though.
This is a test drawing a quad that was suppose to match the image 1:1
http://www.pasteall.org/pic/show.php?id=60483
Not only there is an 'offset', but the offset changes if I pan around
the region.
http://www.pasteall.org/46273/python
(draw_rectangle is where the transformation is happening).
If anyone has any suggestion it would be much appreciated.
Thanks,
Dalai
--
blendernetwork.org/dalai-felinto <
http://blendernetwork.org/dalai-felinto>
Post by Dalai Felinto
www.dalaifelinto.com <http://www.dalaifelinto.com>
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20131009/38fa5521/attachment.htm
Loading...