POV-Ray : Newsgroups : povray.advanced-users : Extract 2D screen coordinates from 3D : Re: Extract 2D screen coordinates from 3D Server Time
25 Sep 2021 13:50:43 EDT (-0400)
  Re: Extract 2D screen coordinates from 3D  
From: jr
Date: 18 Jan 2020 13:50:01
Message: <web.5e2352c8c5d107b38c662f470@news.povray.org>
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

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.