|
|
|
|
|
|
| |
| |
|
|
From: kurtz le pirate
Subject: Extract 2D screen coordinates from 3D
Date: 18 Jan 2020 12:16:43
Message: <5e233d7b@news.povray.org>
|
|
|
| |
| |
|
|
Hello,
My goal is to place text on an image at a certain position known by its
3d coordinates. With classic "screen.inc" this code do the job :
---
#include "screen.inc" // standard inc file
Set_Camera(<25,15,-33>, <2,2,0>, 70) // set location, look_at and angle
Set_Camera_Aspect(4,3) // set width in relation to height
Set_Camera_Sky(<0,1,0.3>) // set the sky vector
#declare MyTextObject = text {...}
Screen_Object ( MyTextObject, <0.00, 0.50>, <0.01,0.01>, true, 0.01 )
---
I found the "Updated screen.inc" in newsgroup.
<http://news.povray.org/povray.text.scene-files/attachment/%3C5b889a96%40news.povray.org%3E/screen.inc.txt>
In this file there's the macro : *Get_Screen_XY(Loc)*. This macro return
<x,y> coordinates in the image from <x,y,z> coordinates of 3d scene.
That's exactly what I need.
I update my code to :
---
#include "screen2.inc" // updated inc file from newsgroup
Set_Camera(<25,15,-33>, <2,2,0>, 70) // set location, look_at and angle
Set_Camera_Aspect(4,3) // set width in relation to height
Set_Camera_Sky(<0,1,0.3>) // set the sky vector
#declare MyTextObject = text {...}
#declare Point3D = <a,b,c>;
// here, screenXY contain the right "image coordinates"
// like <400,300> for center of an image 800x600
#declare screenXY = Get_Screen_XY(Point3D);
// because Screen_Object use <u,v> from 0..1, i calc
#declare screenU = screenXY.x/image_width;
#declare screenV = screenXY.y/image_height;
// which produces <0.50, 0.50> always for the center
// and now, display text at this pos
Screen_Object ( MyTextObject, <screenU, screenV>, <0.01,0.01>, true, 0.01 )
---
and, uh... nothing shows up !
where's my mistake? Is there a bug in the macro or in my code ?
if you have any ideas...
thanks
--
Kurtz le pirate
Compagnie de la Banquise
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
hi,
kurtz le pirate <kur### [at] gmailcom> wrote:
> Hello,
>
> My goal is to place text on an image at a certain position known by its
> 3d coordinates. With classic "screen.inc" this code do the job :
>
> ---
> #include "screen.inc" // standard inc file
>
> Set_Camera(<25,15,-33>, <2,2,0>, 70) // set location, look_at and angle
> Set_Camera_Aspect(4,3) // set width in relation to height
> Set_Camera_Sky(<0,1,0.3>) // set the sky vector
>
> #declare MyTextObject = text {...}
> Screen_Object ( MyTextObject, <0.00, 0.50>, <0.01,0.01>, true, 0.01 )
> ---
>
>
> I found the "Updated screen.inc" in newsgroup.
>
<http://news.povray.org/povray.text.scene-files/attachment/%3C5b889a96%40news.povray.org%3E/screen.inc.txt>
> In this file there's the macro : *Get_Screen_XY(Loc)*. This macro return
> <x,y> coordinates in the image from <x,y,z> coordinates of 3d scene.
> That's exactly what I need.
>
> I update my code to :
>
> ---
> #include "screen2.inc" // updated inc file from newsgroup
>
> Set_Camera(<25,15,-33>, <2,2,0>, 70) // set location, look_at and angle
> Set_Camera_Aspect(4,3) // set width in relation to height
> Set_Camera_Sky(<0,1,0.3>) // set the sky vector
>
> #declare MyTextObject = text {...}
>
> #declare Point3D = <a,b,c>;
> // here, screenXY contain the right "image coordinates"
> // like <400,300> for center of an image 800x600
> #declare screenXY = Get_Screen_XY(Point3D);
>
> // because Screen_Object use <u,v> from 0..1, i calc
> #declare screenU = screenXY.x/image_width;
> #declare screenV = screenXY.y/image_height;
> // which produces <0.50, 0.50> always for the center
>
> // and now, display text at this pos
> Screen_Object ( MyTextObject, <screenU, screenV>, <0.01,0.01>, true, 0.01 )
> ---
>
> and, uh... nothing shows up !
in both files, the 2nd arg (Position) is a 3-vector. maybe that?
> where's my mistake? Is there a bug in the macro or in my code ?
>
> if you have any ideas...
> thanks
>
> --
> Kurtz le pirate
> Compagnie de la Banquise
regards, jr.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"jr" <cre### [at] gmailcom> wrote:
> hi,
> > where's my mistake? Is there a bug in the macro or in my code ?
> >
> > if you have any ideas...
> > thanks
> >
> > --
> > Kurtz le pirate
> > Compagnie de la Banquise
> regards, jr.
I have done it, it's not easy. There are two ways; data readout at same screen
xy always, no mater where you're looking,
2:
labels on objects, no matter where you're looking. here's lunar label from the
planetarium --- stuff like this requires writing some matrix functions,
#local vl = vlength(Lunar_v-campos)/88;
#local camup = <cameramatrix[4],cameramatrix[5],cameramatrix[6]>;
#local pnt = -camup*(IDS(EarthRad * 0.2724*1.05)+vl*FontSize)+Lunar_v;
#local eye = vnormalize(pnt-campos);
object {
text {
ttf "Arial.ttf" "Moon" 1 0
texture { pigment { rgb 1 } finish { ambient 1 diffuse 0 } }
}
translate x*(strlen("Moon")*-0.28)
#if (vlength(campos) < 10000) scale <vl*FontSize,vl*FontSize,vl*FontSize>
#else scale
<vl*FontSize,vl*FontSize,vl*FontSize+0.009*(vlength(campos)/150000)>
#end// adjust text if blurry or breaking up
popmatrix(vcross(camup,eye),vcross(eye,vcross(camup,eye)),eye,pnt)
no_shadow
}
#macro popmatrix(A, B, C,T)
transform {
matrix <A.x, A.y, A.z,
B.x, B.y, B.z,
C.x, C.y, C.z, T.x, T.y, T.z>
}
#end
huge distances was a problem, stick around home and u should be fine
text.pov is a heads up display for the lego plane. ... hmm where to put it.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
kurtz le pirate <kur### [at] gmailcom> wrote:
> I found the "Updated screen.inc" in newsgroup.
> // and now, display text at this pos
> Screen_Object ( MyTextObject, <screenU, screenV>, <0.01,0.01>, true, 0.01 )
> and, uh... nothing shows up !
> where's my mistake? Is there a bug in the macro or in my code ?
>
> if you have any ideas...
> thanks
Well, I mean it looks like it should work.
I don't know what version you're using, and I can never figure out which one I'm
using either. There's never any version number, date, revision history, etc.
I'd say just check your light source, texture, positions of everything, etc.
Then output the number to the debug stream.
If that looks ok, then make a super simple scene and see if that works.
Compare the old and new screen.inc results.
Also, do you use the Update_Camera () macro before you render?
This is sort of related, and just including this here in case you're interested.
http://news.povray.org/povray.binaries.images/thread/%3C5baddad1%40news.povray.org%3E/?mtop=424795
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
i see trouble with that original code when I was first out ...
if you grok 3D math its ALWAYS normalize a vcross() that's the crossProduct.
even 2 normals with a length of 1 != length of 1
vlen(crossprod(normalize(3,5,8),normalize(7,4,6))) = 0.4469
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 1/18/2020 12:16 PM, kurtz le pirate wrote:
> I found the "Updated screen.inc" in newsgroup.
>
<http://news.povray.org/povray.text.scene-files/attachment/%3C5b889a96%40news.povray.org%3E/screen.inc.txt>
> In this file there's the macro : *Get_Screen_XY(Loc)*. This macro return
> <x,y> coordinates in the image from <x,y,z> coordinates of 3d scene.
> That's exactly what I need.
>
If it helps, the latest version of this script is on GitHub.
https://github.com/mjhorvath/POVRay-Updated-Screen-Inc
See if that solves your problem and let me know.
Michael
Post a reply to this message
|
|
| |
| |
|
|
From: kurtz le pirate
Subject: Re: Extract 2D screen coordinates from 3D
Date: 22 Feb 2020 03:55:21
Message: <5e50ec79@news.povray.org>
|
|
|
| |
| |
|
|
On 17/02/2020 04:00, Mike Horvath wrote:
>
> If it helps, the latest version of this script is on GitHub.
>
> https://github.com/mjhorvath/POVRay-Updated-Screen-Inc
>
> See if that solves your problem and let me know.
Michael, thanks for your work.
I put the test image in p.b.i. and yes it's OK
Code used in my scene :
#include "screen_mjh.inc"
...
// set the sky vector
Set_Camera_Sky(y)
// set the type of projection (orthographic or perspective)
Set_Camera_Orthographic(false)
// set width in relation to height
Set_Camera_Aspect(image_width,image_height)
// set the location, look_at, and angle
Set_Camera(CamLoc, CamLookAt, CamAngle)
...
...
#declare pt1 = <6,4,6>;
drawPoint(pt1, rPoint, Red, true)
#declare ScreenXY1 = Get_Screen_XY(pt1);
#declare Text1 = text { ttf "crystal.ttf" "Pt1" 0.01 <0, 0, 0> pigment {
color Red } scale 0.03 }
Screen_Object(Text1, <ScreenXY1.x/image_width,
1-(ScreenXY1.y/image_height)> , 0.01, false, 1)
#declare pt2 = <-3,2,-5>;
drawPoint(pt2, rPoint, Cyan, true)
#declare ScreenXY2 = Get_Screen_XY(pt2);
#declare Text2 = text { ttf "crystal.ttf" "Pt2" 0.01 <0, 0, 0> pigment {
color Cyan } scale 0.03 }
Screen_Object(Text2, <ScreenXY2.x/image_width,
1-(ScreenXY2.y/image_height)> , 0.01, false, 1)
#declare pt3 = <4,6,-1>;
drawPoint(pt3, rPoint, Orange, true)
#declare ScreenXY3 = Get_Screen_XY(pt3);
#declare Text3 = text { ttf "crystal.ttf" "Pt3" 0.01 <0, 0, 0> pigment {
color Orange } scale 0.03 }
Screen_Object(Text3, <ScreenXY3.x/image_width,
1-(ScreenXY3.y/image_height)> , 0.01, false, 1)
However, some very small adjustments need to be made as you can see.
Get_Screen_XY() return coordinates in "image unit" and they must be
reduced to [0..1] and vertical position must also be changed with
1-value. Resulting in :
<ScreenXY/image_width, 1-(ScreenXY.y/image_height)>
for the *location* parameter of the *Screen_Object* macro.
Great !!
--
Kurtz le pirate
Compagnie de la Banquise
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 2/22/2020 3:55 AM, kurtz le pirate wrote:
> However, some very small adjustments need to be made as you can see.
> Get_Screen_XY() return coordinates in "image unit" and they must be
> reduced to [0..1] and vertical position must also be changed with
> 1-value. Resulting in :
> <ScreenXY/image_width, 1-(ScreenXY.y/image_height)>
> for the *location* parameter of the *Screen_Object* macro.
>
>
> Great !!
>
>
I don't quite understand your response. Are you satisfied with how the
tool works, or do you think there need to be changes?
Michael
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 23/02/2020 14:03, Mike Horvath wrote:
> I don't quite understand your response. Are you satisfied with how the
> tool works, or do you think there need to be changes?
Sorry Michael if I wasn't clear.
Tool are perfect !
--
Kurtz le pirate
Compagnie de la Banquise
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|