POV-Ray : Newsgroups : povray.text.tutorials : WANTED: a straightforward macro for keeping objects lined up for the camera : WANTED: a straightforward macro for keeping objects lined up for the camera Server Time
20 Apr 2024 03:25:44 EDT (-0400)
  WANTED: a straightforward macro for keeping objects lined up for the camera  
From: Defective
Date: 29 Oct 2000 03: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

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