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:19:29 EDT (-0400)
  Re: Can't work out the right scale/translate  
From: Phil Cook
Date: 1 Jul 2004 09:52:19
Message: <opsagoqsxcefp2ch@news.povray.org>
And lo on Wed, 30 Jun 2004 11:36:51 -0500, Shay <sah### [at] simcopartscom> did  
spake, saying:

> 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]]].

Understand completely, that's what I was trying to do.

> 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;

Ah, as it said ~67.38 I tried to use tan/atan which cancelled out in the  
Length no doubt that helped screw it up.

> 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>;

Yep makes complete sense

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

Thinks... hmm yes missed that.

What I was trying to do was calculate a box that at a distance would fill  
the viewing field, slap the texture on and cut it to fit, amusing I tried  
a varient of your method first and couldn't get it to gel, probably due to  
some dodgy math.

> 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.

Ah now the catch, the Magic Gate is fixed and is always perpendicular to  
the origin I'll explain why at the end.

> Well, this post is a f- mess. I did my best, dude. This is why I don't  
> mess with many math related posts.

Hey you understood what I was sort-of doing (which takes some doing) and  
produced code that works and an explanation I can follow. I can't see how  
you could do more. I extend a grateful thank-you.

> 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
> }

It works and matches fine I just need to tweak for my bizzaro needs.
Grr I hate talking about WIP but:

Essentially this is a test image (of course) what I'm going to do  
(eventually) is have Magic Gate1 as a desert landscape and Magic Gate2 as  
the *same* landscape but lush and green then animate the desert to show  
the camera approaching and moving around the 'gate' with the 'gate'  
display always showing the equivalent scene as you would see it if the  
'gate' wasn't there rather than as a flat painted-on image, which is why  
it can't rotate with the camera and why I was carving it out, I hope that  
makes some sense :)

--
Phil Cook

-- 
All thoughts and comments are my own unless otherwise stated and I am  
happy to be proven wrong.


Post a reply to this message

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