POV-Ray : Newsgroups : povray.general : Can't work out the right scale/translate Server Time
6 Nov 2024 10:24:42 EST (-0500)
  Can't work out the right scale/translate (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: Phil Cook
Subject: Can't work out the right scale/translate
Date: 30 Jun 2004 09:54:00
Message: <opsaet6upaefp2ch@news.povray.org>
I've been staring at this on and off for weeks and just can't figure out  
how to get the vertical scale/translate right:

Three files:

//Magic Gate1.inc
#declare CameraLocation=<0,1,-10>;
#declare CameraLookat=<0,1,0>;
#declare CameraRotate=10;
// end Magic Gate.inc

//Magic Gate2.pov run first with +fn
#include "Magic Gate1.inc"

camera{
location CameraLocation
look_at CameraLookat
rotate y*CameraRotate}
light_source{<0,18,0> rgb 1}

plane{y,0 pigment{red 1}}
plane{-y,-20 pigment{blue 0.5} finish{ambient 1}}

box{0,6 pigment{green 1} rotate y*-30 translate z*10 finish{ambient 0.5}}

sphere{0,1 pigment{red 1} finish{ambient 0.5} translate <0,15,30> rotate  
y*10}
//end Magic Gate2.pov

//Magic Gate1.pov
#include "Magic Gate1.inc"

camera{
location CameraLocation
look_at CameraLookat
rotate y*CameraRotate}
light_source{<0,18,0> rgb 1}

plane{y,0 pigment{rgb 1}}
plane{-y,-20 pigment{blue 1} finish{ambient 1}}

box{0,6 pigment{red 1} rotate y*-30 translate z*10}

#declare Distance = CameraLookat.z;
#declare  
Length=vlength(<0,0,Distance>-<CameraLocation.x,0,CameraLocation.z>);

difference{
box{z*5,<Length*(2/3)*2,(Length*(2/3)*2)/1.33,0>
pigment{image_map{png "Magic Gate2.png"}
scale<Length*(2/3)*2,(Length*(2/3)*2)/1.33,1>

//why -4?
translate y*-4
}
finish {ambient 1}
translate -x*(Length*(2/3))
rotate y*CameraRotate
}

plane{z, 0}
plane{-z, -0.001}
plane{-x, -1}
plane{x, -1}
plane{y, 0}
plane{-y, -5}
cutaway_textures
no_shadow
}

sphere{0,1 pigment{green 1} finish{ambient 0.5} translate <0,15,30> rotate  
y*10}
//end Magic Gate1.pov

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.

TIA

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

From: Shay
Subject: Re: Can't work out the right scale/translate
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

From: Phil Cook
Subject: Re: Can't work out the right scale/translate
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

From: Phil Cook
Subject: Re: Can't work out the right scale/translate
Date: 1 Jul 2004 10:04:42
Message: <opsagpbfwsefp2ch@news.povray.org>
And lo on Thu, 01 Jul 2004 14:50:42 +0100, Phil Cook  
<phi### [at] nospamdeckingdealscouk> did spake, saying:

Yes! Applying the image_map then carving it out with the planes seems to  
keep everything matched up even when changing distances or angles. Great  
now all I've got to do is create two matching landscapes and render all  
the images twice :P

OOC O wise Shay do you happen to know how to get the image_map image to  
the brightness of the original image even {ambient 1} seems to add a grey  
cast, not really a problem adds to the 'magic'.

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

From: Shay
Subject: Re: Can't work out the right scale/translate
Date: 1 Jul 2004 10:27:56
Message: <40e41f6c$1@news.povray.org>
Phil Cook wrote:

> 
> OOC O wise Shay do you happen to know how to get the image_map image to  
> the brightness of the original image even {ambient 1} seems to add a 
> grey  cast, not really a problem adds to the 'magic'.
> 

global_settings { assumed_gamma 1 }

  -Shay


Post a reply to this message

From: Phil Cook
Subject: Re: Can't work out the right scale/translate
Date: 1 Jul 2004 10:45:41
Message: <opsagq7o0oefp2ch@news.povray.org>
And lo on Thu, 01 Jul 2004 09:27:56 -0500, Shay <sah### [at] simcopartscom> did  
spake, saying:

> Phil Cook wrote:
>
>>  OOC O wise Shay do you happen to know how to get the image_map image  
>> to  the brightness of the original image even {ambient 1} seems to add  
>> a grey  cast, not really a problem adds to the 'magic'.
>>
>
> global_settings { assumed_gamma 1 }

I bow before your wisdom :)

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

From: Shay
Subject: Re: Can't work out the right scale/translate
Date: 1 Jul 2004 10:57:33
Message: <40e4265d$1@news.povray.org>
Phil Cook wrote:
>
> I bow before your wisdom :)
> 

LOL. Glad I could help.

  -Shay


Post a reply to this message

From: Christopher James Huff
Subject: Re: Can't work out the right scale/translate
Date: 6 Jul 2004 17:35:41
Message: <cjameshuff-6D6847.16355706072004@news.povray.org>
In article <40e41f6c$1@news.povray.org>, Shay <sah### [at] simcopartscom> 
wrote:

> > OOC O wise Shay do you happen to know how to get the image_map image to  
> > the brightness of the original image even {ambient 1} seems to add a 
> > grey  cast, not really a problem adds to the 'magic'.
> > 
> 
> global_settings { assumed_gamma 1 }

Won't that only work if Display_Gamma is 1? You want to turn gamma 
correction off. Just not specifying assumed_gamma should work.

Anyway, in addition to setting ambient to 1, you should set diffuse to 
0, so light from scene illumination won't wash out the image.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Phil Cook
Subject: Re: Can't work out the right scale/translate
Date: 7 Jul 2004 04:50:25
Message: <opsaret2miefp2ch@news.povray.org>
And lo on Tue, 06 Jul 2004 16:35:57 -0500, Christopher James Huff  
<cja### [at] earthlinknet> did spake, saying:

> In article <40e41f6c$1@news.povray.org>, Shay <sah### [at] simcopartscom>
> wrote:
>
>> > OOC O wise Shay do you happen to know how to get the image_map image  
>> to
>> > the brightness of the original image even {ambient 1} seems to add a
>> > grey  cast, not really a problem adds to the 'magic'.
>> >
>>
>> global_settings { assumed_gamma 1 }
>
> Won't that only work if Display_Gamma is 1? You want to turn gamma
> correction off. Just not specifying assumed_gamma should work.

Well commenting out assumed_gamma produces a darker image on the 'gate'  
with no Display_Gamma set, so default gamma correction of 2.2 is in use.  
Just to check this I changed the two planes in "Magic Gate2.pov" to the  
same colour as that in "Magic Gate1.pov" and ran it both ways, without  
assumed_gamma produces a noticeable difference.
I've posted a tiny file in p.b.images to show the differences.

> Anyway, in addition to setting ambient to 1, you should set diffuse to
> 0, so light from scene illumination won't wash out the image.

diffuse 0 doesn't seem to make a difference but of course might once I  
start changing the landscape.

The only thing I did notice was dark dots appearing on the gate then I  
realised I was missing a cutaway_textures, adding it removes them as you  
might expect.

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

From: Christopher James Huff
Subject: Re: Can't work out the right scale/translate
Date: 7 Jul 2004 17:14:54
Message: <cjameshuff-81E91B.16145307072004@news.povray.org>
In article <opsaret2miefp2ch@news.povray.org>,
 "Phil Cook" <phi### [at] nospamdeckingdealscouk> wrote:

> Well commenting out assumed_gamma produces a darker image on the 'gate'  
> with no Display_Gamma set, so default gamma correction of 2.2 is in use.

No, gamma correction is off by default. (At least, it's supposed to be.) 
It gets turned on when you include assumed_gamma in the global settings.


> Just to check this I changed the two planes in "Magic Gate2.pov" to the  
> same colour as that in "Magic Gate1.pov" and ran it both ways, without  
> assumed_gamma produces a noticeable difference.
> I've posted a tiny file in p.b.images to show the differences.

Weird. If you want the rendered image to appear the same as the original 
map, you obviously don't want any gamma correction to be done...the 
corrected version won't be the same. Your image doesn't show the 
original map, so I can't compare...but the fact that it shows up 
differently from the surrounding scene, which should be the same color 
pre-correction, is very odd.

What formats are you using? It may be an artifact of however POV and 
your other image software handles gamma values in PNG images. You should 
get the effect you want if you render the map without an assumed_gamma 
value, and the final image with assumed_gamma 1.


> > Anyway, in addition to setting ambient to 1, you should set diffuse to
> > 0, so light from scene illumination won't wash out the image.
> 
> diffuse 0 doesn't seem to make a difference but of course might once I  
> start changing the landscape.

Try shining a bright light on the gate.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

Goto Latest 10 Messages Next 3 Messages >>>

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