Placing the camera into a heightfield
The following question was posted to CGRR. This page is my try at providing an answer and sample-code.
Subject: hf-lab - need a good povray primer file Date: Wed, 29 Apr 1998 00:08:09 +0100 From: Darren Fisher <daz@dazzy-d.demon.co.uk> Newsgroups: comp.graphics.rendering.raytracing Hello. I am looking for a 'normal' view povray file for height field images created with HF-LAB. I have tried to convert Land1.pov & land4.pov to 'normal' view, but am having tremendous problems. By 'normal' view, I mean not looking down onto the height field, but looking at the height field from eye level.
remaining part snipped
The one thing needed for placing the camera as an observer into the HF is already built into John Beale's HF-Lab - and had I read it's online help more thouroughly, I'd known that before I'd written the HF-Val-Utility ;-) The command is named sample.
Let's start with defining some corner-values:
- Note, that POV mirrors the HF on the Z-Axis, thus the 1-coord further below!
- Our HF will be 512x512 pixels in size.
- 1 pixel equals 1 meter.
- Our observer will stand at (0.33/0.33) looking towards (0.75/0.75).
- I'm about 1.87m, so my eyes' height is about 1.78m which translates into 1.78 pixels along the Y-axis.
- POV scales that HF to a cube of size 1.
We'll create a simple HF 512x512 pixels in size:
HL>seed 0 HL>gf 512 filling array...taking IFFT.... HL>zero 512 created [512x512] zero matrix. HL>gauss 0.5 0.5 0.3 HL>neg HL>mul HL>norm 0.3 0.7
Next we translate the eye-offset into POV-space coordinates:
1/HF_SIZE*PIXELS => 1/512*1.78 => 0.0178*y in POV-space
Now we ask HF-Lab for the height of our pixels of interrest:
HL>sample 0.33 0.33 mul at [169,169] (0.330,0.330) is 3.521e-01 HL>sample 0.75 0.75 mul at [384,384] (0.750,0.750) is 4.568e-01
The coords of our observer standing on that HF are thus
<0.33, 4.568e-01+EYE_HEIGHT, 0.33>
looking towards
<0.33, 3.521e-01+EYE_HEIGHT, 0.33>
which can nicely be wrapped into the following piece of POV-code:
#declare SIZE=512 // Assume square HF for simplicity #declare FROM_COORDS = <0.33, 3.521e-01, 1-0.33> #declare TO_COORDS = <0.75, 4.568e-01, 1-0.75> #declare EYE_HEIGHT = 1/SIZE*1.78*y #declare LOCATION = FROM_COORDS + EYE_HEIGHT #declare LOOK_AT = TO_COORDS + EYE_HEIGHT
The complete POV-source for the above images can either be downloaded as a zipfile (1K), or as a tar-archive (1K).
Here are the above shots with a quick'n dirty texture-map projected onto
Please send suggestions, corrections,
or just some blurb to mike AT lamertz DOT net

