POV-Ray : Newsgroups : povray.general : Look_at_macro Server Time
31 Jul 2024 00:31:01 EDT (-0400)
  Look_at_macro (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: H  Karsten
Subject: Look_at_macro
Date: 12 Mar 2008 05:55:00
Message: <web.47d7b561a456511410a45770@news.povray.org>
Hi people,

has anybody an idea, how to make a look_at_macro?

Means, that I have a point and the macro gives my back the angles, looking to it
from the origin.

-Holger-


Post a reply to this message

From: H  Karsten
Subject: Re: Look_at_macro
Date: 12 Mar 2008 06:15:01
Message: <web.47d7b9c5d9327eeb10a45770@news.povray.org>
Here a little script, that should go, but it doesn't.
It only works, if you use only one of the coordinates...

the Box "looks" toe the ball:

/*
Initial_Frame=0
Final_Frame=360
Initial_Clock=0
Final_Clock=360
*/

camera {
  location  <-1, 1, -2.0>*4
  look_at   0
  rotate <clock/10,clock,0>
}

light_source {<-3,3,-3>*10 color rgb 1}

plane {y, -1 pigment { color rgb 0.5 }}

#declare xp=2*sin(clock/6);
#declare yp=3;
#declare zp=4*sin(clock/10);


sphere {
  <xp,yp,zp>, .5
  texture {pigment {color rgb 0.7}}
}


#declare zf=((zp>0)-0.5)*2;
#declare xw=zf*degrees(acos(yp/(sqrt(pow(zp,2)+pow(yp,2)))));
#declare xf=((xp>0)-0.5)*2;
#declare yw=xf*degrees(acos(zp/(sqrt(pow(xp,2)+pow(zp,2)))))-90;
#declare yf=-((yp>0)-0.5)*2;
#declare zw=yf*degrees(asin(xp/(sqrt(pow(xp,2)+pow(yp,2)))))+90;

box {
  <-2,-1,-0.5>,-<-2,-1,-0.5>
pigment{color rgb <1,0,0>}
scale 0.5
//rotate <xw,yw,zw>
rotate <xw,0,0> // If you use
rotate <0,yw,0> // one of these
rotate <0,0,zw> // alone, it goes!
}
cylinder {0*x,3*x,0.2 pigment{color rgb 1}}
cylinder {0*y,3*y,0.2 pigment{color rgb 1}}
cylinder {0*z,3*z,0.2 pigment{color rgb 1}}


Post a reply to this message

From: Tim Attwood
Subject: Re: Look_at_macro
Date: 12 Mar 2008 06:57:50
Message: <47d7c53e$1@news.povray.org>
I think you want something like Reorient_Trans
from transforms.inc

//+kff360
#include "transforms.inc"
#declare P = <2*sin(clock*60),3,4*sin(clock*36)>;
sphere {P,0.05
   pigment {Red}
}
cone {<0,0,0>,0.05,<0,0,0.5>,0
   pigment {Cyan}
   Reorient_Trans(z,vnormalize(P))
}


Post a reply to this message

From: H  Karsten
Subject: Re: Look_at_macro
Date: 12 Mar 2008 07:20:01
Message: <web.47d7ca2ad9327eeb10a45770@news.povray.org>
"Tim Attwood" <tim### [at] comcastnet> wrote:
> I think you want something like Reorient_Trans
> from transforms.inc
>
> //+kff360
> #include "transforms.inc"
> #declare P = <2*sin(clock*60),3,4*sin(clock*36)>;
> sphere {P,0.05
>    pigment {Red}
> }
> cone {<0,0,0>,0.05,<0,0,0.5>,0
>    pigment {Cyan}
>    Reorient_Trans(z,vnormalize(P))
> }

Really helpful!!

And nice short ;)

Thanx!!!!!


Post a reply to this message

From: Chris B
Subject: Re: Look_at_macro
Date: 12 Mar 2008 07:26:56
Message: <47d7cc10$1@news.povray.org>
"H. Karsten" <h-karsten()web.de> wrote in message 
news:web.47d7b9c5d9327eeb10a45770@news.povray.org...
> Here a little script, that should go, but it doesn't.
> It only works, if you use only one of the coordinates...
>

Hi,

If you look at Reorient_Trans in the help, I suspect that does exactly what 
you want.

The main problem with your code is that you've worked out the angles based 
on the initial position/orientation of the box. As soon as POV-Ray performs 
the first rotation (around x) it moves it out of it's initial 
position/orientation. The second rotation will therefore be around the 
y-axis of the scene and not around the axis of the box.

This can be a bit hard to get your head around, but imagine a 1 unit high 
line at the origin. Rotate through 45*x and then 45*y to get to a point P.

If I understand what you're trying to do in your calculation (though I 
haven't tested it), it should give you the y rotation, but would give a 
value for x that is less than 45 degrees because it's equivalent to 
projecting a line back onto the YZ plane at right angles, rather than 
rotating it back there around the y axis. Furthermore your calculation will 
give you an equal negative z rotation (a bit less than 45 degrees).

If you now think of applying the three rotations you calculate to the point 
<0,1,0>, the first two bring you to a point a short distance directly above 
point P. The third (around -z) takes you down somewhere close to the XZ 
plane.

Hope this helps.

Regards,
Chris B.


Post a reply to this message

From: H  Karsten
Subject: Re: Look_at_macro
Date: 12 Mar 2008 07:45:00
Message: <web.47d7cf1fd9327eeb10a45770@news.povray.org>
Well I saw, that the includefile makes the transformation itself.

As I open it, the transformaton was made with the matrix keyword.

But I need to have three values that I can assign to the normal rotate <...>
keyword. Because, I need to write this values in to a file!

Maybe by using the "vaxis_rotate(...)" command?

-holger-


Post a reply to this message

From: Chris B
Subject: Re: Look_at_macro
Date: 12 Mar 2008 09:23:18
Message: <47d7e756@news.povray.org>
"H. Karsten" <h-karsten()web.de> wrote in message 
news:web.47d7cf1fd9327eeb10a45770@news.povray.org...
> I need to have three values that I can assign to the normal rotate <...>
> keyword. Because, I need to write this values in to a file!
>
> Maybe by using the "vaxis_rotate(...)" command?
>

Looking at your earlier code you've got a sphere whizzing around at y=3 and 
a box at the origin. If I understand correctly you want the centre of the 
top of the box to point at the sphere and you don't seem bothered about the 
orientation of the box around the centre line between the box and the 
sphere. If this is the case, then you can always achieve this with only two 
rotations. ie You can tilt the box with a rotation in x and then spin it 
round the y axis to point at any point on the plane y=3 (indeed at any point 
in 3D space).

There are quite a few standard POV-Ray macros that could help with this, but 
you might want to look at VRotationD(V1, V2, Axis) and use it to work 
backwards through the 2 rotational axes that you need. For example:

#include "math.inc"
#declare P = <-30,3,5>;
#local TempP = P;
#debug concat("Normalised Point: ",vstr(3,vnormalize(P),",",3,3),"\n")

// Work out the angle between the z axis and
// a point projected down onto the XZ plane
#local YRot = VRotationD(z, TempP*<1,0,1>, y);

// Bring the point back onto the YZ plane
#local TempP = vrotate(TempP,-y*YRot);

// Work out the x rotation
#local XRot = VRotationD(y, TempP, x);

#debug concat("Should be the same: 
",vstr(3,vrotate(y,<XRot,YRot,0>),",",3,3),"\n")


Regards,
Chris B.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Look_at_macro
Date: 12 Mar 2008 18:58:11
Message: <47d86e13$1@news.povray.org>
Tim Attwood wrote:
> I think you want something like Reorient_Trans
> from transforms.inc
> 
> //+kff360
> #include "transforms.inc"
> #declare P = <2*sin(clock*60),3,4*sin(clock*36)>;
> sphere {P,0.05
>    pigment {Red}
> }
> cone {<0,0,0>,0.05,<0,0,0.5>,0
>    pigment {Cyan}
>    Reorient_Trans(z,vnormalize(P))
> } 

There's no need to normalize the vectors
going into the Reorient_Trans() macro.

-- 
Tor Olav
http://subcube.com


Post a reply to this message

From: Tim Attwood
Subject: Re: Look_at_macro
Date: 12 Mar 2008 23:14:20
Message: <47d8aa1c$1@news.povray.org>
> Well I saw, that the includefile makes the transformation itself.
>
> As I open it, the transformaton was made with the matrix keyword.
>
> But I need to have three values that I can assign to the normal rotate 
> <...>
> keyword. Because, I need to write this values in to a file!
>
> Maybe by using the "vaxis_rotate(...)" command?

A full set of rotations really consists of two rotations,
elevation and Y rotation, the third is really just to control
the "up" or "roll" direction. There's not really enough info
in a single vector to determine the desired "up" direction
in all cases. So this code just assumes it starts with Y as
up. The selects are to determine the general direction of
the angles...

//+kff360
#include "math.inc"
#declare P = <2*sin(clock*60),3,4*sin(clock*36)>;
#declare Ay = select(P.x,-VAngleD(z,<P.x,0,P.z>),
                 0,VAngleD(z,<P.x,0,P.z>));
#declare Ax = select(P.y,VAngleD(P,vrotate(z,Ay*y)),
                 0,-VAngleD(P,vrotate(z,Ay*y)));
sphere {P,0.05
   pigment {Red}
}
cone {<0,0,0>,0.05,<0,0,0.5>,0
   pigment {Cyan}
   rotate Ax*x
   rotate Ay*y
}
#debug concat("Elevation = ",str(Ax,0,3)," degrees.\n")
#debug concat("Y Rotation = ",str(Ay,0,3)," degrees.\n")


Post a reply to this message

From: H  Karsten
Subject: Re: Look_at_macro
Date: 13 Mar 2008 05:15:01
Message: <web.47d8fdb4d9327eebbd9f2040@news.povray.org>
Thank you all for the work! I'll try out the code!

Thanx !!

-Holger- :)


Post a reply to this message

Goto Latest 10 Messages Next 1 Messages >>>

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