POV-Ray : Newsgroups : povray.text.tutorials : WANTED: a straightforward macro for keeping objects lined up for the camera Server Time: 26 Jan 2020 13:21:33 GMT
  WANTED: a straightforward macro for keeping objects lined up for the camera (Message 1 to 4 of 4)  
From: Defective
Subject: WANTED: a straightforward macro for keeping objects lined up for the camera
Date: 29 Oct 2000 08:32:34
Message: <ojmnvs8tjf3pi37rsnl6lcil363sq7lqgt@4ax.com>
For some time now, I've been trying to find a way to make objects in
my scenes face the camera.  It's not as easy as it sounds.

The background to this:  Whenever I'm working on an object of any
complexity, I like to move the camera around and see what it'll look
like from different angles.  This, of course, means I keep forgetting
which way is up.

My early attempts to keep track of direction involved placing colored
spheres some distance out along the axes and trying to remember that
red means X, green means Y and blue means Z.  Of course, this doesn't
help with positive vs. negative.  So I changed the ones on the
negative ends to boxes.

Now, I keep tripping over these silly little spheres and boxes.

Now, I'm trying to do this with text.  (I find the little Xs, Ys and
Zs less distracting...)  Unfortunately, the letters are just a bit
hard to read except from directly in front or back.  I've managed to
find a little macro using atan() that allows me to aim objects at a
focal point.  (Someone on the POV-Ray Study Forum at Delphi worked it
out for aiming eyeballs...)  Problem is that it doesn't work if the
camera (and focal point) are on the Z plane and things seem to forget
where to look if I get near the Y axis.

Anybody got ideas?

Defective O-O
-----------------------------------------------------------------------------------------------------------

Sample code follows:

The macro:

	#macro LookHere(from_pos)
	  #local dist=ViewPoint - from_pos;
	
	  #local xrot= degrees(atan2(dist.y,-dist.z));
	  #local yrot=-degrees(atan2(dist.x,-dist.z));
	
	  // rotate about the origin  
	  rotate <0,yrot,0>
	  rotate <xrot,0,0>
	  
	  //and move to the desired position
	  translate from_pos
	#end


The application:

	#include "colors.inc"

	#declare ViewPoint = <50, 50, -0.1> ;
		// change parameters of ViewPoint to move both the
		// camera and the point the objects are aimed at.

	camera { location ViewPoint look_at   <0,  0, 0> }

	object { text { ttf "arial.ttf" "+X" .1, 0
		 pigment { White } finish { ambient 1 } scale 3 }
		 LookHere(<15.0, 0.0, 0.0>) }
	object { text { ttf "arial.ttf" "+Y" .1, 0
		 pigment { White } finish { ambient 1 } scale 3 }
		 LookHere(<0.0, 15.0, 0.0>) }
	object { text { ttf "arial.ttf" "+Z" .1, 0
		 pigment { White } finish { ambient 1 } scale 3 }
		 LookHere(<0.0, 0.0, 15.0>) }

	object { text { ttf "arial.ttf" "-X" .1, 0
		 pigment { White } finish { ambient 1 } scale 3 }
		 LookHere(<-15.0, 0.0, 0.0>) }
	object { text { ttf "arial.ttf" "-Y" .1, 0
		 pigment { White } finish { ambient 1 } scale 3 }
		 LookHere(<0.0, -15.0, 0.0>) }
	object { text { ttf "arial.ttf" "-Z" .1, 0
		 pigment { White } finish { ambient 1 } scale 3 }
		 LookHere(<0.0, 0.0, -15.0>) }

	object { text { ttf "arial.ttf" "Origin" .1, 0
		 pigment { White } finish { ambient 1 } scale 3 } }


Post a reply to this message

From: Peter Popov
Subject: Re: WANTED: a straightforward macro for keeping objects lined up for the camera
Date: 30 Oct 2000 06:20:33
Message: <ob4qvssj0vem9q5855b5unl2hjc2hh0t8e@4ax.com>
On Sun, 29 Oct 2000 03:30:39 -0500, Defective <def### [at] homecom>
wrote:

>My early attempts to keep track of direction involved placing colored
>spheres some distance out along the axes and trying to remember that
>red means X, green means Y and blue means Z.  Of course, this doesn't
>help with positive vs. negative.  So I changed the ones on the
>negative ends to boxes.
>
>Now, I keep tripping over these silly little spheres and boxes.

Try using arrows made of cylinders and cones. I think there's a sample
scene included with POV-Ray and/or an item in the Insert menu in the
Windows version.

>Now, I'm trying to do this with text.  (I find the little Xs, Ys and
>Zs less distracting...)  Unfortunately, the letters are just a bit
>hard to read except from directly in front or back.  I've managed to
>find a little macro using atan() that allows me to aim objects at a
>focal point.  (Someone on the POV-Ray Study Forum at Delphi worked it
>out for aiming eyeballs...)  Problem is that it doesn't work if the
>camera (and focal point) are on the Z plane and things seem to forget
>where to look if I get near the Y axis.
>
>Anybody got ideas?

Try using John VanSickle's Reorient macro, part of his Throroughly
Useful Macros package. There's a link to his site on the povray.org
link section.


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Defective
Subject: Re: WANTED: a straightforward macro for keeping objects lined up for the camera
Date: 31 Oct 2000 18:19:37
Message: <102uvs8uvgqeivkth4ko9chk1dsdusu1ft@4ax.com>
On Mon, 30 Oct 2000 08:18:34 +0200, Peter Popov <pet### [at] usanet>
wrote:

>>Now, I keep tripping over these silly little spheres and boxes.
>
>Try using arrows made of cylinders and cones. I think there's a sample
>scene included with POV-Ray and/or an item in the Insert menu in the
>Windows version.

Unfortunately, this method leads to the same problem as the spheres
and boxes.  It creates shapes that distract from the object I'm
working on...

>
>>Now, I'm trying to do this with text.  (I find the little Xs, Ys and
>>Zs less distracting...)  Unfortunately, the letters are just a bit
>>hard to read except from directly in front or back.  I've managed to
>>find a little macro using atan() that allows me to aim objects at a
>>focal point.  (Someone on the POV-Ray Study Forum at Delphi worked it
>>out for aiming eyeballs...)  Problem is that it doesn't work if the
>>camera (and focal point) are on the Z plane and things seem to forget
>>where to look if I get near the Y axis.
>>
>>Anybody got ideas?
>
>Try using John VanSickle's Reorient macro, part of his Throroughly
>Useful Macros package. There's a link to his site on the povray.org
>link section.

This method still requires that I work out the axes to point the
letters along.  I think I've got this worked out now.  But I keep
finding that things like to point the wrong way.  I'm starting to
think that, maybe, there's a bug someplace in PoV...

I've created a little sample scene to test the algorithm and it's
giving me odd results.

The following bit of code draws the axes and places a little yellow
ball at the position indicated by HereItIs.  Then it draws a line
starting at the origin and running through HereItIs.  I haven't quite
worked out how to deal with the ball sitting on the X, Y or Z axis,
but it tells me the angles are right for all other cases.  Just
doesn't seem to draw the line there...

-------------------------------------------------
example code:
-------------------------------------------------

#include "colors.inc"
#include "macs.inc"

	#declare ViewPoint = <50, -50, -50> ;

	camera { location ViewPoint look_at   <0,  0, 0> }

//////////////////////  Draw the axes  /////////////////////

sphere   {<0,0,0>,1             
	 pigment { White } finish { ambient 1 } }
cylinder {<-49,0,0>,<49,0,0>,.05 
	pigment { Red   } finish { ambient 1 } }
cylinder {<0,-49,0>,<0,49,0>,.05 
	pigment { Green } finish { ambient 1 } }
cylinder {<0,0,-49>,<0,0,49>,.05 
	pigment { Blue  } finish { ambient 1 } }

//////////////////////////////////////////////////////////////////

#macro LookHere(from_pos, to_pos)
  #local Dx = to_pos.x - from_pos.x * sgn(to_pos.x) ;
  #local Dy = to_pos.y - from_pos.y * sgn(to_pos.y) ;
  #local Dz = to_pos.z - from_pos.z * sgn(to_pos.z) ;

  #if (Dy)
    #local Ax = degrees(atan2(Dz,Dy)) ;
  #else
    #local Ax = 0 ;
  #end
  
  #if (Dz)
    #local Ay = degrees(atan2(Dx,Dz)) ;
  #else
    #local Ay = 0 ;
  #end
  
  #if (Dx)
    #local Az = degrees(atan2(Dy,Dx)) ;
  #else
    #local Az = 0 ;
  #end

#render concat("Dx: ",str(Dx, 5, 2),"\n",
	"Dy: ",str(Dy, 5, 2),"\n",
	"Dz: ",str(Dz, 5, 2),"\n")
#render concat("Ax: ",str(Ax, 10, 7),"\n",
	"Ay: ",str(Ay, 10, 7),"\n",
	"Az: ",str(Az, 10, 7),"\n\n")

  Reorient(y,<Ax,Ay,Az>)

#end


#declare HereItIs = <10,15,10> ;

sphere   {HereItIs,1 pigment { Yellow } finish { ambient 1 } }

cylinder {<0,0,0>,<0,45,0>.1 
	pigment { Orange } finish { ambient 1 }
	LookHere(<0,0,0>,HereItIs)      }


Post a reply to this message

From: Defective
Subject: Re: WANTED: a straightforward macro for keeping objects lined up for the camera
Date: 8 Nov 2000 18:29:36
Message: <b27i0tg8l509mufq63lg56efmdotq6kgqs@4ax.com>
I think my brain just exploded!

I may have just worked out a useable method...

The basic idea is this:

If the objects being controlled and the camera are manipulated in
exactly the same way as the camera, they stay lined up.

What I've done is to pick a distance for the camera from the origin
and done all other aiming by rotation.  Then I placed the objects (in
this case, markers for the axes) at the origin and aimed them at where
the camera would be with no rotations.  Next, I rotate them the same
as the camera.  Finally, I translate them to their final locations.

Now I just need to wrap my mind around aiming the camera by
rotation...

I've generated a nifty little animation that demonstrates the
idea...It runs through rotations around X, Y, Z, XY, XZ, YZ and XYZ.

WARNING:  loading up the output in ACDSee and starting a full-speed,
looping slideshow in full screen mode can damage your brain!  :P

Defective O_O

---------------------------------------------------------------------------------------------------------
Sample code follows:

The scene:  (direction markers.pov)
~~~~~~~~~~

#include "metals.inc"
#include "colors.inc"           

global_settings { assumed_gamma 2.2 }

#render concat(  "\nClock: <",str(clock, 5, 2), ">\n")

///////////////////////////////////////////////////////////
#declare VXrot = clock * (
                         (clock < 360)
                       | ((clock >= 1080) & (clock < 1440))
                       | ((clock >= 1440) & (clock < 1800))
                       | ((clock >= 2160) & (clock < 2520))
                         ) ;

#declare VYrot = clock * (
                         ((clock >= 360) & (clock < 720))
                       | ((clock >= 1080) & (clock < 1440))
                       | ((clock >= 1800) & (clock < 2160))
                       | ((clock >= 2160) & (clock < 2520))
                         ) ;

#declare VZrot = clock * (
                         ((clock >= 720) & (clock < 1080))
                       | ((clock >= 1440) & (clock < 1800))
                       | ((clock >= 1800) & (clock < 2160))
                       | ((clock >= 2160) & (clock < 2520))
                         ) ;

///////////////////////////////////////////////////////////

camera { location <0, 0, -50> look_at <0,  0, 0>
        rotate <VXrot, VYrot, VZrot>        
       }

#declare Material  = T_Chrome_1D 

sphere { <0,0,0>,10 texture { T_Chrome_1D } finish { ambient 1} }


   text { 
      ttf "timrom.ttf" "+X" .1, 0
      pigment { Orange } finish { ambient 1 }
      scale 5
      rotate <VXrot, VYrot, VZrot>        
      translate <20, 0, 0>
   }

   text { 
      ttf "timrom.ttf" "+Y" .1, 0
      pigment { Orange } finish { ambient 1 }
      scale 5
      rotate <VXrot, VYrot, VZrot>        
      translate <0, 20, 0>
   }

   text { 
      ttf "timrom.ttf" "+Z" .1, 0
      pigment { Orange } finish { ambient 1 }
      scale 5
      rotate <VXrot, VYrot, VZrot>        
      translate <0, 0, 20>
   }

   text { 
      ttf "timrom.ttf" "-X" .1, 0
      pigment { Orange } finish { ambient 1 }
      scale 5
      rotate <VXrot, VYrot, VZrot>        
      translate <-20, 0, 0>
   }

   text { 
      ttf "timrom.ttf" "-Y" .1, 0
      pigment { Orange } finish { ambient 1 }
      scale 5
      rotate <VXrot, VYrot, VZrot>        
      translate <0, -20, 0>
   }

   text { 
      ttf "timrom.ttf" "-Z" .1, 0
      pigment { Orange } finish { ambient 1 }
      scale 5
      rotate <VXrot, VYrot, VZrot>        
      translate <0, 0, -20>
   }


My INI file:  (direction markers.ini)
~~~~~~~~~~~~

Initial_Clock=0
Final_Clock=2520
Initial_Frame=0
Final_Frame=360
Input_File_Name=direction markers.pov


Post a reply to this message

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