POV-Ray : Newsgroups : povray.general : Can't work out the right scale/translate : Re: Can't work out the right scale/translate Server Time
2 Aug 2024 22:15:50 EDT (-0400)
  Re: Can't work out the right scale/translate  
From: Shay
Date: 30 Jun 2004 12:36:52
Message: <40e2ec24$1@news.povray.org>
Phil Cook wrote:
> 
> Hopefully it should be obvious from the images and the  titles what I'm
> trying to do, but the images don't quite line up as I would expect.  
> Horizontally not bad; vertically enough of a discrepency to bug me.  
> Knowing me probably something simple, but I just can't see it.
> 

Well, fairly simple, at least. I can't tell exactly what you were trying 
to do with the texture scaling, but this is how it could be done.

The pigment is mapped from <0,0> to <1,1>, so the first thing to do is 
canter the pigment at the origin:

translate -.5

Then the pigment should be scaled to fit perfectly in the viewing 
window. I'm making these terms up, but by "viewing window" I mean the 
visible portion of a plane located at CameraLookat with a normal of 
CameraLocation - CameraLookat. The default camera angle is (from the 
docs) ~67.380. [[[I've tried this sentence a half-dozen times, but don't 
have the vocabulary to say what I need to say. Hopefully the code (or 
some generous math person) will make it clear]]].

You will need to use radians, because the sin and cos functions 
understand radians.

#local Length = vlength(CameraLocation-CameraLookat);
#local HalfAngle = radians(67.380)/2;

Half the angle is used because twice the height of half the angle is 
equal to the distance between the two ends. <phew> I *hope* that made at 
least some sense. Now get the radius of an imaginary circle centered at 
the CameraLocation which just touches the edges of the viewing window.

#local Radius = Length / cos(HalfAngle);

Now that the radius is known, sin of half the angle times the radius 
time two will give us the width of the viewing window.

#local Width = sin(HalfAngle) * Radius * 2;

Of course, adjust to the standard aspect ratio
#local Scale = Width * <1,3/4,1>;

After scaling, translate the texture up to your CameraLookat point of 
<0,1,0>

translate <0,1,0>

Don't put the texture on a box and then cut at that box with planes. 
Construct the difference first. Also, instead of rotating the texture 
onto a crooked box, rotate the magic box to face the camera.

Well, this post is a f- mess. I did my best, dude. This is why I don't 
mess with many math related posts. Anyway, the whole thing will look 
like this:

difference{
	box{
		z*5,<Length*(2/3)*2,(Length*(2/3)*2)/1.33,0>
	}
     plane{z, -0}
	plane{-z, -.001}
	plane{-x, -1}
	plane{x, -1}
	plane{y, 0}
	plane{-y, -5}
	pigment{
		image_map{
			png "Magic Gate2.png"
		}
		translate -.5
		// already have length defined earlier in your code
		#local HalfAngle = radians(67.380)/2;
		#local Radius = Length / cos(HalfAngle);
		#local Width = sin(HalfAngle) * Radius * 2;
		#local Scale = Width * <1,3/4,1>;
		scale Scale
		translate <0,1,0>
	}
	finish {
		ambient 1
	}
	rotate y*CameraRotate
	no_shadow
}

  -Shay


Post a reply to this message

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